TLockValveController.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package com.ruoyi.project.process.controller;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.ruoyi.common.annotation.Log;
  4. import com.ruoyi.common.core.controller.BaseController;
  5. import com.ruoyi.common.core.domain.AjaxResult;
  6. import com.ruoyi.common.core.page.TableDataInfo;
  7. import com.ruoyi.common.enums.BusinessType;
  8. import com.ruoyi.common.utils.DateUtils;
  9. import com.ruoyi.common.utils.file.ExcelUtils;
  10. import com.ruoyi.common.utils.poi.ExcelUtil;
  11. import com.ruoyi.project.process.domain.TLockValve;
  12. import com.ruoyi.project.process.service.ITLockValveService;
  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.beans.factory.annotation.Autowired;
  18. import org.springframework.security.access.prepost.PreAuthorize;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.IOException;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. /**
  26. * 阀门锁开锁关状态记录Controller
  27. *
  28. * @author ruoyi
  29. * @date 2024-04-03
  30. */
  31. @RestController
  32. @RequestMapping("/process/valve")
  33. public class TLockValveController extends BaseController {
  34. @Autowired
  35. private ITLockValveService tLockValveService;
  36. /**
  37. * 查询阀门锁开锁关状态记录列表
  38. */
  39. @PreAuthorize("@ss.hasPermi('process:valve:list')")
  40. @GetMapping("/list")
  41. public TableDataInfo list(TLockValve tLockValve) {
  42. startPage();
  43. List<TLockValve> list = tLockValveService.selectTLockValveList(tLockValve);
  44. return getDataTable(list);
  45. }
  46. /**
  47. * 导出阀门锁开锁关状态记录列表
  48. */
  49. @PreAuthorize("@ss.hasPermi('process:valve:export')")
  50. @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.EXPORT)
  51. @PostMapping("/export")
  52. public void export(HttpServletResponse response, TLockValve tLockValve) {
  53. List<TLockValve> list = tLockValveService.selectTLockValveList(tLockValve);
  54. ExcelUtil<TLockValve> util = new ExcelUtil<TLockValve>(TLockValve.class);
  55. util.exportExcel(response, list, "阀门锁开锁关状态记录数据");
  56. }
  57. /**
  58. * 获取阀门锁开锁关状态记录详细信息
  59. */
  60. @PreAuthorize("@ss.hasPermi('process:valve:query')")
  61. @GetMapping(value = "/{id}")
  62. public AjaxResult getInfo(@PathVariable("id") Long id) {
  63. return success(tLockValveService.selectTLockValveById(id));
  64. }
  65. /**
  66. * 新增阀门锁开锁关状态记录
  67. */
  68. @PreAuthorize("@ss.hasPermi('process:valve:add')")
  69. @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.INSERT)
  70. @PostMapping
  71. public AjaxResult add(@RequestBody TLockValve tLockValve) {
  72. return toAjax(tLockValveService.insertTLockValve(tLockValve));
  73. }
  74. /**
  75. * 修改阀门锁开锁关状态记录
  76. */
  77. @PreAuthorize("@ss.hasPermi('process:valve:edit')")
  78. @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.UPDATE)
  79. @PutMapping
  80. public AjaxResult edit(@RequestBody TLockValve tLockValve) {
  81. return toAjax(tLockValveService.updateTLockValve(tLockValve));
  82. }
  83. /**
  84. * 删除阀门锁开锁关状态记录
  85. */
  86. @PreAuthorize("@ss.hasPermi('process:valve:remove')")
  87. @Log(title = "阀门锁开锁关状态记录", businessType = BusinessType.DELETE)
  88. @DeleteMapping("/{ids}")
  89. public AjaxResult remove(@PathVariable Long[] ids) {
  90. return toAjax(tLockValveService.deleteTLockValveByIds(ids));
  91. }
  92. @Log(title = "阀门锁开锁关状态记录批量导入", businessType = BusinessType.INSERT)
  93. @PostMapping("/importData")
  94. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  95. //获取操作人员ID
  96. Long userId = getUserId();
  97. //报错行数统计
  98. List<Integer> failRow = new ArrayList<>();
  99. Workbook workbook = ExcelUtils.getWorkBook(file);
  100. Sheet sheet = workbook.getSheetAt(0);
  101. List<TLockValve> list = new ArrayList<>();
  102. int rowNum = sheet.getPhysicalNumberOfRows();
  103. int failNumber = 0;
  104. for (int i = 2; i < rowNum; i++) {
  105. try {
  106. logger.info("读取行数:" + i);
  107. Row row = sheet.getRow(i);
  108. int cellNum = row.getLastCellNum();
  109. TLockValve entity = new TLockValve();
  110. for (int j = 0; j < cellNum; j++) {
  111. Cell cell = row.getCell(j);
  112. if (cell == null) {
  113. continue;
  114. }
  115. String cellValue = ExcelUtils.getCellValue(cell);
  116. logger.info("cellValue:" + cellValue);
  117. if (j == 0) {
  118. entity.setUnit(cellValue);
  119. } else if (j == 1) {
  120. entity.setVtNo(cellValue);
  121. } else if (j == 2) {
  122. entity.setPidNo(cellValue);
  123. } else if (j == 3) {
  124. entity.setLocationDes(cellValue);
  125. } else if (j == 4) {
  126. entity.setMedium(cellValue);
  127. } else if (j == 5) {
  128. entity.setValveType(cellValue);
  129. } else if (j == 6) {
  130. entity.setValveSize(cellValue);
  131. } else if (j == 7) {
  132. entity.setIdentifier(cellValue);
  133. } else if (j == 8) {
  134. entity.setValvePosition(cellValue);
  135. } else if (j == 9) {
  136. entity.setFirmlySecured(cellValue);
  137. } else if (j == 10) {
  138. entity.setResponsibility(cellValue);
  139. } else if (j == 11) {
  140. entity.setCheckedBy(cellValue);
  141. } else if (j == 12) {
  142. entity.setCheckBeforeSu(cellValue);
  143. } else if (j == 13) {
  144. entity.setPidStatus(cellValue);
  145. } else if (j == 14) {
  146. entity.setRiskLevel(cellValue);
  147. } else if (j == 15) {
  148. entity.setSheReview(cellValue);
  149. } else if (j == 16) {
  150. entity.setCheckDate(DateUtils.parseDate(cellValue));
  151. } else if (j == 17) {
  152. entity.setRemarks(cellValue);
  153. }
  154. }
  155. entity.setCreaterCode(String.valueOf(userId));
  156. logger.info("entity:" + entity);
  157. list.add(entity);
  158. } catch (Exception e) {
  159. failNumber++;
  160. logger.info("e:" + JSON.toJSONString(e));
  161. failRow.add(i + 1);
  162. }
  163. }
  164. int successNumber = 0;
  165. int failNum = 0;
  166. for (TLockValve t : list
  167. ) {
  168. failNum++;
  169. try {
  170. //根据使用证、注册编号、位号,进行数据更新
  171. add(t);
  172. successNumber++;
  173. } catch (Exception e) {
  174. failNumber++;
  175. logger.info("e:" + e);
  176. failRow.add(failNum + 1);
  177. }
  178. }
  179. logger.info("list:" + JSON.toJSONString(list));
  180. logger.info("successNumber:" + successNumber);
  181. logger.info("failNumber:" + failNumber);
  182. logger.info("failRow:" + failRow);
  183. return AjaxResult.success(String.valueOf(successNumber), failRow);
  184. }
  185. }