081a4b41430f6598010eaa7d71b606fd20819a73.svn-base 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package cn.com.goldenwater.dcproj.controller.ducha;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.model.BisInspBaseNew;
  5. import cn.com.goldenwater.dcproj.param.BisInspBaseNewParam;
  6. import cn.com.goldenwater.dcproj.service.BisInspBaseNewService;
  7. import cn.com.goldenwater.dcproj.util.ReadExcelUtil;
  8. import cn.com.goldenwater.dcproj.utils.StringUtils;
  9. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  10. import cn.com.goldenwater.id.util.UuidUtil;
  11. import com.github.pagehelper.PageInfo;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiOperation;
  14. import io.swagger.annotations.ApiParam;
  15. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.beans.factory.annotation.Value;
  20. import org.springframework.util.Assert;
  21. import org.springframework.web.bind.annotation.*;
  22. import org.springframework.web.multipart.MultipartFile;
  23. import javax.servlet.http.HttpServletResponse;
  24. import java.io.File;
  25. import java.io.IOException;
  26. import java.nio.file.Paths;
  27. import java.util.HashMap;
  28. import java.util.List;
  29. import java.util.Map;
  30. /**
  31. * @author lql
  32. * @date 2026-1-12
  33. */
  34. @Api(value = "通用对象表管理", tags = "通用对象表管理")
  35. @RestController
  36. @RequestMapping("/bis/insp/baseNew")
  37. public class BisInspBaseNewController extends BaseController {
  38. private Logger logger = LoggerFactory.getLogger(getClass());
  39. @Value("${export.templatePath}")
  40. private String templatePath;
  41. @Autowired
  42. private BisInspBaseNewService bisInspBaseNewService;
  43. @ApiOperation(value = "添加通用对象表")
  44. @RequestMapping(value = "/add", method = RequestMethod.POST)
  45. public BaseResponse<BisInspBaseNew> insert(@ApiParam(name = "bisInspBaseNew", value = "BisInspBaseNew", required = true) @RequestBody BisInspBaseNew bisInspBaseNew) {
  46. int ret = bisInspBaseNewService.insert(bisInspBaseNew);
  47. return buildSuccessResponse(bisInspBaseNew);
  48. }
  49. @ApiOperation(value = "根据ID删除通用对象表")
  50. @RequestMapping(value = "delete", method = RequestMethod.POST)
  51. public BaseResponse delete(@ApiParam(name = "ids", value = "ids", required = true) @RequestParam String ids) {
  52. String[] idArray = ids.split(",");
  53. for (String id : idArray) {
  54. int ret = bisInspBaseNewService.delete(id);
  55. }
  56. return buildSuccessResponse();
  57. }
  58. @ApiOperation(value = "更新通用对象表信息")
  59. @RequestMapping(value = "/update", method = RequestMethod.POST)
  60. public BaseResponse<BisInspBaseNew> update(@ApiParam(name = "bisInspBaseNew", value = "BisInspBaseNew", required = true) @RequestBody BisInspBaseNew bisInspBaseNew) {
  61. Assert.notNull(bisInspBaseNew.getId(), "主键id为必填参数");
  62. int ret = bisInspBaseNewService.update(bisInspBaseNew);
  63. return buildSuccessResponse(bisInspBaseNew);
  64. }
  65. @ApiOperation(value = "根据ID获取通用对象表(单表)")
  66. @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  67. public BaseResponse<BisInspBaseNew> get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  68. BisInspBaseNew bisInspBaseNew = bisInspBaseNewService.get(id);
  69. return buildSuccessResponse(bisInspBaseNew);
  70. }
  71. @ApiOperation(value = "根据ID获取通用对象表(单表)")
  72. @RequestMapping(value = "/getByRgstr/{id}", method = RequestMethod.GET)
  73. public BaseResponse<BisInspBaseNew> getByRgstr(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) {
  74. BisInspBaseNew bisInspBaseNew = bisInspBaseNewService.getByRgstrId(id);
  75. return buildSuccessResponse(bisInspBaseNew);
  76. }
  77. @ApiOperation(value = "根据ID获取通用对象表(分页)")
  78. @RequestMapping(value = "/list", method = RequestMethod.POST)
  79. public BaseResponse<PageInfo> pageList(@ApiParam(name = "bisInspBaseNewParam", value = "bisInspBaseNewParam", required = true)
  80. @RequestBody(required = false) BisInspBaseNewParam param) {
  81. if (StringUtils.isNotBlank(param.getAdCode())) {
  82. param.setAdCode(param.getAdCode().replace("00", ""));
  83. }
  84. PageInfo<BisInspBaseNew> bisInspBaseNew = bisInspBaseNewService.findPageInfo(param);
  85. return buildSuccessResponse(bisInspBaseNew);
  86. }
  87. @ApiOperation(value = "根据ID获取通用对象表(单表)")
  88. @GetMapping("/getTypes")
  89. public BaseResponse<List<String>> getTypes() {
  90. return buildSuccessResponse(bisInspBaseNewService.getTypes());
  91. }
  92. @ApiOperation("获取导入模板")
  93. @GetMapping(value = "/getExl")
  94. public void getExl(HttpServletResponse response) {
  95. String path = templatePath + File.separator + "bisInspBaseNews.xlsx";
  96. try {
  97. ExpAndImpUtil.downloadFile(response, path, "基础对象表");
  98. } catch (Exception e) {
  99. logger.error(e.getMessage(), e);
  100. }
  101. }
  102. @ApiOperation("上传 xls 导入数据")
  103. @RequestMapping(value = "/impExl", method = RequestMethod.POST)
  104. public BaseResponse<Map<String, Object>> impExl(@RequestParam("file") MultipartFile multfile) throws IOException, InvalidFormatException {
  105. // 获取文件名
  106. String fileName = multfile.getOriginalFilename();
  107. // 获取文件后缀
  108. String prefix = fileName.substring(fileName.lastIndexOf("."));
  109. // 用uuid作为文件名,防止生成的临时文件重复
  110. String uuid = UuidUtil.uuid();
  111. File file = File.createTempFile(uuid, prefix);
  112. // MultipartFile to File
  113. multfile.transferTo(Paths.get(file.getPath()));
  114. Map<String, Object> map = new HashMap<>(2);
  115. int shu = 0;
  116. int success = 0;
  117. String[][] data = ReadExcelUtil.getData(file, 1);
  118. try {
  119. if (data != null && data.length > 0) {
  120. for (int i = 0; i < data.length; i++) {
  121. BisInspBaseNew bisInspBaseNew = new BisInspBaseNew();
  122. bisInspBaseNew.setObjType(data[i][0]);
  123. bisInspBaseNew.setCode(data[i][1]);
  124. bisInspBaseNew.setNm(data[i][2]);
  125. bisInspBaseNew.setEngrType(data[i][3]);
  126. bisInspBaseNew.setAdCode(data[i][4]);
  127. bisInspBaseNew.setAdName(data[i][5]);
  128. bisInspBaseNew.setLoc(data[i][6]);
  129. if (data[i].length > 7) {
  130. if (StringUtils.isNotBlank(data[i][7])) {
  131. bisInspBaseNew.setGdX(Double.valueOf(data[i][7]));
  132. bisInspBaseNew.setCenterX(Double.valueOf(data[i][7]));
  133. }
  134. }
  135. if (data[i].length > 8) {
  136. if (StringUtils.isNotBlank(data[i][8])) {
  137. bisInspBaseNew.setGdY(Double.valueOf(data[i][8]));
  138. bisInspBaseNew.setCenterY(Double.valueOf(data[i][8]));
  139. }
  140. }
  141. insert(bisInspBaseNew);
  142. success++;
  143. }
  144. }
  145. } catch (Exception e) {
  146. shu++;
  147. logger.error(e.getMessage(), e);
  148. }
  149. map.put("false", shu);
  150. map.put("success", success);
  151. return buildSuccessResponse(map);
  152. }
  153. }