TApprovalController.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package com.cpms.project.approval.controller;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.cpms.common.annotation.Log;
  4. import com.cpms.common.core.controller.BaseController;
  5. import com.cpms.common.core.domain.AjaxResult;
  6. import com.cpms.common.core.page.TableDataInfo;
  7. import com.cpms.common.enums.BusinessType;
  8. import com.cpms.common.utils.DateUtils;
  9. import com.cpms.common.utils.file.ExcelUtils;
  10. import com.cpms.common.utils.poi.ExcelUtil;
  11. import com.cpms.project.approval.domain.TApproval;
  12. import com.cpms.project.approval.service.ITApprovalService;
  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 admin
  29. * @date 2023-10-18
  30. */
  31. @RestController
  32. @RequestMapping("/ehs/approval")
  33. public class TApprovalController extends BaseController {
  34. @Autowired
  35. private ITApprovalService tApprovalService;
  36. /**
  37. * 查询批文清单列表
  38. */
  39. @PreAuthorize("@ss.hasPermi('ehs:approval:list')")
  40. @GetMapping("/list")
  41. public TableDataInfo list(TApproval tApproval) {
  42. startPage();
  43. List<TApproval> list = tApprovalService.selectTApprovalList(tApproval);
  44. return getDataTable(list);
  45. }
  46. /**
  47. * 导出批文清单列表
  48. */
  49. @PreAuthorize("@ss.hasPermi('ehs:approval:export')")
  50. @Log(title = "批文清单", businessType = BusinessType.EXPORT)
  51. @PostMapping("/export")
  52. public void export(HttpServletResponse response, TApproval tApproval) {
  53. List<TApproval> list = tApprovalService.selectTApprovalList(tApproval);
  54. ExcelUtil<TApproval> util = new ExcelUtil<TApproval>(TApproval.class);
  55. util.exportExcel(response, list, "批文清单数据");
  56. }
  57. /**
  58. * 获取批文清单详细信息
  59. */
  60. @PreAuthorize("@ss.hasPermi('ehs:approval:query')")
  61. @GetMapping(value = "/{id}")
  62. public AjaxResult getInfo(@PathVariable("id") Long id) {
  63. return AjaxResult.success(tApprovalService.selectTApprovalById(id));
  64. }
  65. /**
  66. * 新增批文清单
  67. */
  68. @PreAuthorize("@ss.hasPermi('ehs:approval:add')")
  69. @Log(title = "批文清单", businessType = BusinessType.INSERT)
  70. @PostMapping
  71. public AjaxResult add(@RequestBody TApproval tApproval) {
  72. return toAjax(tApprovalService.insertTApproval(tApproval));
  73. }
  74. /**
  75. * 修改批文清单
  76. */
  77. @PreAuthorize("@ss.hasPermi('ehs:approval:edit')")
  78. @Log(title = "批文清单", businessType = BusinessType.UPDATE)
  79. @PutMapping
  80. public AjaxResult edit(@RequestBody TApproval tApproval) {
  81. return toAjax(tApprovalService.updateTApproval(tApproval));
  82. }
  83. /**
  84. * 删除批文清单
  85. */
  86. @PreAuthorize("@ss.hasPermi('ehs:approval:remove')")
  87. @Log(title = "批文清单", businessType = BusinessType.DELETE)
  88. @DeleteMapping("/{ids}")
  89. public AjaxResult remove(@PathVariable Long[] ids) {
  90. return toAjax(tApprovalService.deleteTApprovalByIds(ids));
  91. }
  92. @PreAuthorize("@ss.hasPermi('ehs:approval:add')")
  93. @Log(title = "批文清单批量导入", businessType = BusinessType.INSERT)
  94. @PostMapping("/importData")
  95. public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException {
  96. //获取操作人员ID
  97. Long userId = getUserId();
  98. //报错行数统计
  99. List<Integer> failRow = new ArrayList<Integer>();
  100. Workbook workbook = ExcelUtils.getWorkBook(file);
  101. Sheet sheet = workbook.getSheetAt(0);
  102. List<TApproval> list = new ArrayList<>();
  103. int rowNum = sheet.getPhysicalNumberOfRows();
  104. int failNumber = 0;
  105. for (int i = 2; i < rowNum; i++) {
  106. try {
  107. logger.info("读取行数:" + i);
  108. Row row = sheet.getRow(i);
  109. int cellNum = row.getLastCellNum();
  110. TApproval entity = new TApproval();
  111. for (int j = 0; j < cellNum; j++) {
  112. Cell cell = row.getCell(j);
  113. if (cell == null) {
  114. continue;
  115. }
  116. String cellValue = ExcelUtils.getCellValue(cell);
  117. logger.info("cellValue:" + cellValue);
  118. if (j == 0) {
  119. entity.setApprovalAttibutes(cellValue);
  120. } else if (j == 1) {
  121. entity.setEffetivedate(DateUtils.parseDate(cellValue));//装置名称
  122. } else if (j == 2) {
  123. entity.setItemName(cellValue);//位号
  124. } else if (j == 3) {
  125. entity.setItemOverview(cellValue);//设备名称
  126. } else if (j == 4) {
  127. entity.setApprovalname(cellValue);//使用证号
  128. } else if (j == 5) {
  129. entity.setFileno(cellValue);//检验单位
  130. } else if (j == 6) {
  131. entity.setResponsauth(cellValue);
  132. } else if (j == 7) {
  133. entity.setContent(cellValue);//内部检验结论
  134. } else if (j == 8) {
  135. entity.setScope(cellValue);//内部检验报告编号
  136. } else if (j == 9) {
  137. entity.setRelatedlaw(cellValue);
  138. } else if (j == 10) {
  139. entity.setValidityBefore(DateUtils.parseDate(cellValue));
  140. } else if (j == 11) {
  141. entity.setValidityAfter(DateUtils.parseDate(cellValue));//外部检验结论
  142. } else if (j == 12) {
  143. if ("是".equals(cellValue)) {
  144. entity.setIsPermanent("1");
  145. } else if ("否".equals(cellValue)) {
  146. entity.setIsPermanent("0");
  147. }
  148. } else if (j == 13) {
  149. entity.setFollow(cellValue);
  150. } else if (j == 14) {
  151. entity.setOwner(cellValue);
  152. } else if (j == 15) {
  153. entity.setReviewer(cellValue);
  154. } else if (j == 16) {
  155. entity.setReviewdate(DateUtils.parseDate(cellValue));
  156. } else if (j == 17) {
  157. entity.setIsCompliance(cellValue);
  158. } else if (j == 18) {
  159. entity.setNextreviewdate(DateUtils.parseDate(cellValue));
  160. } else if (j == 19) {
  161. entity.setRemarks(cellValue);
  162. }
  163. }
  164. logger.info("entity:" + JSON.toJSONString(entity));
  165. list.add(entity);
  166. } catch (Exception e) {
  167. failNumber++;
  168. logger.info("e:" + JSON.toJSONString(e));
  169. failRow.add(i + 1);
  170. }
  171. }
  172. int successNumber = 0;
  173. int failNum = 0;
  174. for (TApproval t : list) {
  175. failNum++;
  176. try {
  177. add(t);
  178. successNumber++;
  179. } catch (Exception e) {
  180. failNumber++;
  181. logger.info("e:" + e);
  182. failRow.add(failNum + 1);
  183. e.printStackTrace();
  184. }
  185. }
  186. logger.info("list:" + JSON.toJSONString(list));
  187. logger.info("successNumber:" + String.valueOf(successNumber));
  188. logger.info("failNumber:" + String.valueOf(failNumber));
  189. logger.info("failRow:" + String.valueOf(failRow));
  190. return AjaxResult.success(String.valueOf(successNumber), failRow);
  191. }
  192. }