TLeakagePointsController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package com.cpms.project.asset.controller;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import javax.servlet.http.HttpServletResponse;
  6. import com.alibaba.fastjson2.JSON;
  7. import com.cpms.common.core.domain.entity.SysDictData;
  8. import com.cpms.common.utils.DateUtils;
  9. import com.cpms.common.utils.file.ExcelUtils;
  10. import com.cpms.project.asset.service.ITLeakagePointsService;
  11. import com.cpms.system.service.ISysDictDataService;
  12. import com.cpms.system.service.ISysDictTypeService;
  13. import org.apache.poi.ss.usermodel.Cell;
  14. import org.apache.poi.ss.usermodel.Row;
  15. import org.apache.poi.ss.usermodel.Sheet;
  16. import org.apache.poi.ss.usermodel.Workbook;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import com.cpms.common.annotation.Log;
  21. import com.cpms.common.core.controller.BaseController;
  22. import com.cpms.common.core.domain.AjaxResult;
  23. import com.cpms.common.enums.BusinessType;
  24. import com.cpms.project.asset.domain.TLeakagePoints;
  25. import com.cpms.common.utils.poi.ExcelUtil;
  26. import com.cpms.common.core.page.TableDataInfo;
  27. import org.springframework.web.multipart.MultipartFile;
  28. /**
  29. * 漏点清单Controller
  30. *
  31. * @author admin
  32. * @date 2024-03-28
  33. */
  34. @RestController
  35. @RequestMapping("/asset/points")
  36. public class TLeakagePointsController extends BaseController
  37. {
  38. @Autowired
  39. private ITLeakagePointsService tLeakagePointsService;
  40. @Autowired
  41. private ISysDictTypeService sysDictTypeService;
  42. /**
  43. * 查询漏点清单列表
  44. */
  45. @PreAuthorize("@ss.hasPermi('asset:points:list')")
  46. @GetMapping("/list")
  47. public TableDataInfo list(TLeakagePoints tLeakagePoints)
  48. {
  49. startPage();
  50. List<TLeakagePoints> list = tLeakagePointsService.selectTLeakagePointsList(tLeakagePoints);
  51. return getDataTable(list);
  52. }
  53. /**
  54. * 导出漏点清单列表
  55. */
  56. @PreAuthorize("@ss.hasPermi('asset:points:export')")
  57. @Log(title = "漏点清单", businessType = BusinessType.EXPORT)
  58. @PostMapping("/export")
  59. public void export(HttpServletResponse response, TLeakagePoints tLeakagePoints)
  60. {
  61. List<TLeakagePoints> list = tLeakagePointsService.selectTLeakagePointsList(tLeakagePoints);
  62. ExcelUtil<TLeakagePoints> util = new ExcelUtil<TLeakagePoints>(TLeakagePoints.class);
  63. util.exportExcel(response, list, "漏点清单数据");
  64. }
  65. /**
  66. * 获取漏点清单详细信息
  67. */
  68. @PreAuthorize("@ss.hasPermi('asset:points:query')")
  69. @GetMapping(value = "/{id}")
  70. public AjaxResult getInfo(@PathVariable("id") Long id)
  71. {
  72. return success(tLeakagePointsService.selectTLeakagePointsById(id));
  73. }
  74. /**
  75. * 新增漏点清单
  76. */
  77. @PreAuthorize("@ss.hasPermi('asset:points:add')")
  78. @Log(title = "漏点清单", businessType = BusinessType.INSERT)
  79. @PostMapping
  80. public AjaxResult add(@RequestBody TLeakagePoints tLeakagePoints)
  81. {
  82. return toAjax(tLeakagePointsService.insertTLeakagePoints(tLeakagePoints));
  83. }
  84. /**
  85. * 修改漏点清单
  86. */
  87. @PreAuthorize("@ss.hasPermi('asset:points:edit')")
  88. @Log(title = "漏点清单", businessType = BusinessType.UPDATE)
  89. @PutMapping
  90. public AjaxResult edit(@RequestBody TLeakagePoints tLeakagePoints)
  91. {
  92. return toAjax(tLeakagePointsService.updateTLeakagePoints(tLeakagePoints));
  93. }
  94. /**
  95. * 删除漏点清单
  96. */
  97. @PreAuthorize("@ss.hasPermi('asset:points:remove')")
  98. @Log(title = "漏点清单", businessType = BusinessType.DELETE)
  99. @DeleteMapping("/{ids}")
  100. public AjaxResult remove(@PathVariable Long[] ids)
  101. {
  102. return toAjax(tLeakagePointsService.deleteTLeakagePointsByIds(ids));
  103. }
  104. @Log(title = "漏点清单批量导入", businessType = BusinessType.INSERT)
  105. @PostMapping("/importData")
  106. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  107. //获取操作人员ID
  108. Long userId = getUserId();
  109. List<SysDictData> dictData = sysDictTypeService.selectDictDataByType("leakage_result");
  110. logger.info(JSON.toJSONString(dictData));
  111. //报错行数统计
  112. List<Integer> failRow = new ArrayList<>();
  113. Workbook workbook = ExcelUtils.getWorkBook(file);
  114. Sheet sheet = workbook.getSheetAt(0);
  115. List<TLeakagePoints> list = new ArrayList<>();
  116. int rowNum = sheet.getPhysicalNumberOfRows();
  117. int failNumber = 0;
  118. for (int i = 2; i < rowNum; i++) {
  119. try {
  120. logger.info("读取行数:" + i);
  121. Row row = sheet.getRow(i);
  122. int cellNum = row.getLastCellNum();
  123. TLeakagePoints entity = new TLeakagePoints();
  124. for (int j = 0; j < cellNum; j++) {
  125. Cell cell = row.getCell(j);
  126. if (cell == null) {
  127. continue;
  128. }
  129. String cellValue = ExcelUtils.getCellValue(cell);
  130. logger.info("cellValue:" + cellValue);
  131. if (j == 0) {
  132. entity.setPointNo(cellValue);
  133. } else if (j == 1) {
  134. entity.setLeakagePosition(cellValue);
  135. } else if (j == 2) {
  136. entity.setLeakageMedium(cellValue);
  137. } else if (j == 3) {
  138. entity.setDiscoveryTime(DateUtils.parseDate(cellValue));
  139. } else if (j == 4) {
  140. entity.setDiscoveryName(cellValue);
  141. } else if (j == 5) {
  142. entity.setLeakageAmount(cellValue);
  143. } else if (j == 6) {
  144. entity.setSapNo(cellValue);
  145. } else if (j == 7) {
  146. entity.setLeakageEliminationTime(DateUtils.parseDate(cellValue));
  147. } else if (j == 8) {
  148. entity.setLeakageEliminationFunc(cellValue);
  149. } else if (j == 9) {
  150. entity.setListing(cellValue);
  151. } else if (j == 10) {
  152. entity.setPressurePlugging(cellValue);
  153. } else if (j == 11) {
  154. for (SysDictData data : dictData) {
  155. if (data.getDictLabel().equals(cellValue)){
  156. entity.setLeakageEliminationResult(data.getDictValue());
  157. }
  158. }
  159. } else if (j == 12) {
  160. entity.setNextCheckDate(DateUtils.parseDate(cellValue));
  161. } else if (j == 13) {
  162. entity.setRemarks(cellValue);
  163. }
  164. }
  165. entity.setCreaterCode(String.valueOf(userId));
  166. logger.info("entity:" + entity);
  167. list.add(entity);
  168. } catch (Exception e) {
  169. failNumber++;
  170. logger.info("e:" + JSON.toJSONString(e));
  171. failRow.add(i + 1);
  172. }
  173. }
  174. int successNumber = 0;
  175. int failNum = 0;
  176. for (TLeakagePoints t : list
  177. ) {
  178. failNum++;
  179. try {
  180. //根据使用证、注册编号、位号,进行数据更新
  181. add(t);
  182. successNumber++;
  183. } catch (Exception e) {
  184. failNumber++;
  185. logger.info("e:" + e);
  186. failRow.add(failNum + 1);
  187. }
  188. }
  189. logger.info("list:" + JSON.toJSONString(list));
  190. logger.info("successNumber:" + successNumber);
  191. logger.info("failNumber:" + failNumber);
  192. logger.info("failRow:" + failRow);
  193. return AjaxResult.success(String.valueOf(successNumber), failRow);
  194. }
  195. }