43d1aea1941bf518eaecd0db91ca51ac96176416.svn-base 8.0 KB

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