TCheckRepairpointsController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package com.ruoyi.project.check.controller;
  2. import java.math.BigDecimal;
  3. import java.math.RoundingMode;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.List;
  8. import java.util.concurrent.CopyOnWriteArrayList;
  9. import java.util.concurrent.CountDownLatch;
  10. import java.util.concurrent.ExecutorService;
  11. import java.util.concurrent.Executors;
  12. import java.util.concurrent.atomic.AtomicInteger;
  13. import javax.servlet.http.HttpServletResponse;
  14. import com.alibaba.fastjson2.JSON;
  15. import com.ruoyi.common.utils.DateUtils;
  16. import com.ruoyi.common.utils.StringUtils;
  17. import com.ruoyi.common.utils.file.ExcelUtils;
  18. import com.ruoyi.project.base.domain.TBasePoint;
  19. import com.ruoyi.project.check.domain.TCheckCheckpoints;
  20. import com.ruoyi.project.check.domain.TCheckEnvironment;
  21. import com.ruoyi.project.check.domain.TCheckLawitems;
  22. import com.ruoyi.project.check.service.ITCheckCheckpointsService;
  23. import com.ruoyi.project.task.domain.TTaskInspection;
  24. import com.ruoyi.project.task.domain.TTaskRepair;
  25. import com.ruoyi.project.task.service.ITTaskRepairService;
  26. import org.apache.commons.collections4.CollectionUtils;
  27. import org.apache.poi.ss.usermodel.Cell;
  28. import org.apache.poi.ss.usermodel.Row;
  29. import org.apache.poi.ss.usermodel.Sheet;
  30. import org.apache.poi.ss.usermodel.Workbook;
  31. import org.springframework.security.access.prepost.PreAuthorize;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.web.bind.annotation.*;
  34. import com.ruoyi.common.annotation.Log;
  35. import com.ruoyi.common.core.controller.BaseController;
  36. import com.ruoyi.common.core.domain.AjaxResult;
  37. import com.ruoyi.common.enums.BusinessType;
  38. import com.ruoyi.project.check.domain.TCheckRepairpoints;
  39. import com.ruoyi.project.check.service.ITCheckRepairpointsService;
  40. import com.ruoyi.common.utils.poi.ExcelUtil;
  41. import com.ruoyi.common.core.page.TableDataInfo;
  42. import org.springframework.web.multipart.MultipartFile;
  43. /**
  44. * 维修点Controller
  45. *
  46. * @author ruoyi
  47. * @date 2022-12-06
  48. */
  49. @RestController
  50. @RequestMapping("/check/repairpoints")
  51. public class TCheckRepairpointsController extends BaseController {
  52. @Autowired
  53. private ITCheckRepairpointsService tCheckRepairpointsService;
  54. @Autowired
  55. private ITTaskRepairService taskRepairService;
  56. @Autowired
  57. private ITCheckCheckpointsService tCheckCheckpointsService;
  58. /**
  59. * 查询维修点列表
  60. */
  61. // @PreAuthorize("@ss.hasPermi('check:repairpoints:list')")
  62. @GetMapping("/list")
  63. public TableDataInfo list(TCheckRepairpoints tCheckRepairpoints) {
  64. startPage();
  65. List<TCheckRepairpoints> list = tCheckRepairpointsService.selectTCheckRepairpointsList(tCheckRepairpoints);
  66. return getDataTable(list);
  67. }
  68. /**
  69. * 导出维修点列表
  70. */
  71. // @PreAuthorize("@ss.hasPermi('check:repairpoints:export')")
  72. @Log(title = "维修点导出", businessType = BusinessType.EXPORT)
  73. @PostMapping("/export")
  74. public void export(HttpServletResponse response, TCheckRepairpoints tCheckRepairpoints) {
  75. List<TCheckRepairpoints> list = tCheckRepairpointsService.selectTCheckRepairpointsList(tCheckRepairpoints);
  76. ExcelUtil<TCheckRepairpoints> util = new ExcelUtil<TCheckRepairpoints>(TCheckRepairpoints.class);
  77. util.exportExcel(response, list, "维修点数据");
  78. }
  79. /**
  80. * 获取维修点详细信息
  81. */
  82. // @PreAuthorize("@ss.hasPermi('check:repairpoints:query')")
  83. @GetMapping(value = "/{checkId}")
  84. public AjaxResult getInfo(@PathVariable("checkId") Long checkId) {
  85. return AjaxResult.success(tCheckRepairpointsService.selectTCheckRepairpointsByCheckId(checkId));
  86. }
  87. @GetMapping(value = "/byInspectionId/{inspectionId}")
  88. public TableDataInfo selectRepairpointsByInspectionId(@PathVariable("inspectionId") Long inspectionId) {
  89. startPage();
  90. List<TCheckRepairpoints> list = tCheckRepairpointsService.selectRepairpointsByInspectionId(inspectionId);
  91. return getDataTable(list);
  92. }
  93. @PreAuthorize("@ss.hasPermi('check:checkpoints:edit')")
  94. @Log(title = "审核维修结果", businessType = BusinessType.APPROVE)
  95. @PutMapping("/toApprove")
  96. public AjaxResult toApprove(@RequestBody TCheckRepairpoints tCheckRepairpoints) {
  97. int i = tCheckRepairpointsService.updateApproveStatusByIds(tCheckRepairpoints);
  98. List<TCheckCheckpoints> tCheckCheckpoints = new ArrayList<>();
  99. if (i > 0) {
  100. if (2 == tCheckRepairpoints.getApproveStatus()) {
  101. TTaskRepair tTaskRepair = taskRepairService.selectTTaskRepairById(tCheckRepairpoints.getRepairId());
  102. tTaskRepair.setTaskDoneNum(new BigDecimal(StringUtils.isNotEmpty(tTaskRepair.getTaskDoneNum()) ? tTaskRepair.getTaskDoneNum() : "0").add(new BigDecimal(tCheckRepairpoints.getCheckIds().length)).toString());
  103. tTaskRepair.setTaskUndoneNum(new BigDecimal(tTaskRepair.getTaskNum()).subtract(new BigDecimal(tTaskRepair.getTaskDoneNum())).toString());
  104. taskRepairService.updateTTaskRepair(tTaskRepair);
  105. for (TCheckRepairpoints point : tCheckRepairpointsService.selectTCheckRepairpointsByIds(tCheckRepairpoints.getCheckIds())) {
  106. TCheckCheckpoints points = new TCheckCheckpoints();
  107. points.setMediumType(point.getMediumType());
  108. points.setPlantType(point.getPlantType());
  109. points.setPlantId(point.getPlantId());
  110. points.setRegionId(point.getRegionId());
  111. points.setDevId(point.getDevId());
  112. points.setPointId(point.getPointId());
  113. points.setPlantName(point.getPlantName());
  114. points.setRegionName(point.getRegionName());
  115. points.setLayer(point.getLayer());
  116. points.setDevName(point.getDevName());
  117. points.setDevCode(point.getDevCode());
  118. points.setGroupCode(point.getGroupCode());
  119. points.setExtendCode(point.getExtendCode());
  120. points.setPointType(point.getPointType());
  121. points.setCreaterCode(getUserId());
  122. points.setCreatedate(new Date());
  123. points.setUpdaterCode(getUserId());
  124. points.setUpdatedate(new Date());
  125. points.setRepairId(point.getCheckId());
  126. tCheckCheckpoints.add(points);
  127. }
  128. if (CollectionUtils.isNotEmpty(tCheckCheckpoints)) {
  129. tCheckCheckpointsService.insertTCheckCheckpointsByList(tCheckCheckpoints);
  130. }
  131. }
  132. } else
  133. return AjaxResult.error();
  134. return AjaxResult.success();
  135. }
  136. /**
  137. * 新增维修点
  138. */
  139. // @PreAuthorize("@ss.hasPermi('check:repairpoints:add')")
  140. @Log(title = "维修点新增", businessType = BusinessType.INSERT)
  141. @PostMapping
  142. public AjaxResult add(@RequestBody TCheckRepairpoints tCheckRepairpoints) {
  143. return toAjax(tCheckRepairpointsService.insertTCheckRepairpoints(tCheckRepairpoints));
  144. }
  145. /**
  146. * 修改维修点
  147. */
  148. // @PreAuthorize("@ss.hasPermi('check:repairpoints:edit')")
  149. @Log(title = "维修点修改", businessType = BusinessType.UPDATE)
  150. @PutMapping
  151. public AjaxResult edit(@RequestBody TCheckRepairpoints tCheckRepairpoints) {
  152. return toAjax(tCheckRepairpointsService.updateTCheckRepairpointsByCheckIds(tCheckRepairpoints));
  153. }
  154. /**
  155. * 删除维修点
  156. */
  157. // @PreAuthorize("@ss.hasPermi('check:repairpoints:remove')")
  158. @Log(title = "维修点删除", businessType = BusinessType.DELETE)
  159. @DeleteMapping("/{checkIds}")
  160. public AjaxResult remove(@PathVariable Long[] checkIds) {
  161. return toAjax(tCheckRepairpointsService.deleteTCheckRepairpointsByCheckIds(checkIds));
  162. }
  163. @Log(title = "维修数据录入", businessType = BusinessType.INSERT)
  164. @PostMapping("/importData/{repairId}")
  165. public AjaxResult importData(@RequestParam("file") MultipartFile file, @PathVariable Long repairId) {
  166. //获取操作人员ID
  167. Long userId = getUserId();
  168. //报错行数统计
  169. CopyOnWriteArrayList<Integer> failRow = new CopyOnWriteArrayList<>();
  170. Workbook workbook = ExcelUtils.getWorkBook(file);
  171. Sheet sheet = workbook.getSheetAt(0);
  172. List<TCheckRepairpoints> list = new ArrayList<>();
  173. int rowNum = sheet.getPhysicalNumberOfRows();
  174. //线程池
  175. ExecutorService executorService = Executors.newFixedThreadPool(20);
  176. final CountDownLatch latch = new CountDownLatch(rowNum - 1); //相同线程数量的计数
  177. AtomicInteger failNumber = new AtomicInteger();
  178. AtomicInteger successNumber = new AtomicInteger();
  179. for (int i = 1; i < rowNum; i++) {
  180. int finalI = i;
  181. executorService.execute(() -> {
  182. try {
  183. logger.info("读取行数:" + finalI);
  184. Row row = sheet.getRow(finalI);
  185. int cellNum = row.getLastCellNum();
  186. TCheckRepairpoints entity = new TCheckRepairpoints();
  187. for (int j = 0; j < cellNum; j++) {
  188. Cell cell = row.getCell(j);
  189. if (cell == null) {
  190. continue;
  191. }
  192. String cellValue = ExcelUtils.getCellValue(cell);
  193. logger.info("cellValue:" + cellValue);
  194. if (j == 0) {
  195. //装置名称
  196. entity.setPlantName(cellValue);
  197. } else if (j == 1) {
  198. //群组编号
  199. entity.setGroupCode(cellValue);
  200. } else if (j == 2) {
  201. // 密封点扩展编码
  202. entity.setExtendCode(cellValue);
  203. } else if (j == 3) {
  204. //维修方法
  205. entity.setRepairFunc(cellValue);
  206. } else if (j == 4) {
  207. // 维修人员
  208. entity.setRepairer(cellValue);
  209. } else if (j == 5) {
  210. // 维修日期
  211. entity.setRepairDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  212. } else if (j == 6) {
  213. // 描述
  214. entity.setRemarks(cellValue);
  215. }
  216. }
  217. entity.setUpdatedate(new Date());
  218. entity.setUpdaterCode(userId);
  219. entity.setRepairId(repairId);// 任务id
  220. entity.setApproveStatus(0l);// 任务id
  221. int upload = tCheckRepairpointsService.updateTCheckRepairpointsByUpload(entity); //更新检测点数据
  222. if (upload == 1) {
  223. successNumber.getAndIncrement();
  224. } else {
  225. logger.info("数据不存在");
  226. failRow.add(finalI + 1);
  227. throw new InterruptedException();//中止线程
  228. }
  229. } catch (InterruptedException e) {
  230. logger.info("中止线程" + Thread.currentThread().getName());
  231. } catch (Exception e) {
  232. failRow.add(finalI + 1);
  233. e.printStackTrace();
  234. } finally {
  235. latch.countDown(); //线程计数
  236. }
  237. });
  238. }
  239. try {
  240. latch.await(); //线程计数完毕后继续执行
  241. } catch (InterruptedException e) {
  242. e.printStackTrace();
  243. }
  244. executorService.shutdown();
  245. logger.info("list:" + JSON.toJSONString(list));
  246. logger.info("successNumber:" + successNumber);
  247. logger.info("failNumber:" + failRow.size());
  248. logger.info("failRow:" + failRow);
  249. return AjaxResult.success(String.valueOf(successNumber.get()), failRow);
  250. }
  251. }