THealthapprovalController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package com.ruoyi.project.ehs.controller;
  2. import java.io.IOException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import com.alibaba.fastjson.JSON;
  7. import com.ruoyi.common.utils.DateUtils;
  8. import com.ruoyi.common.utils.file.ExcelUtils;
  9. import com.ruoyi.project.plant.domain.TStaffmgr;
  10. import com.ruoyi.project.plant.service.ITStaffmgrService;
  11. import com.ruoyi.project.system.domain.SysDept;
  12. import com.ruoyi.project.system.domain.SysDictData;
  13. import com.ruoyi.project.system.service.ISysDeptService;
  14. import com.ruoyi.project.system.service.ISysDictTypeService;
  15. import org.apache.poi.ss.usermodel.*;
  16. import org.springframework.security.access.prepost.PreAuthorize;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.*;
  19. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  20. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  21. import com.ruoyi.project.ehs.domain.THealthapproval;
  22. import com.ruoyi.project.ehs.service.ITHealthapprovalService;
  23. import com.ruoyi.framework.web.controller.BaseController;
  24. import com.ruoyi.framework.web.domain.AjaxResult;
  25. import com.ruoyi.common.utils.poi.ExcelUtil;
  26. import com.ruoyi.framework.web.page.TableDataInfo;
  27. import org.springframework.web.multipart.MultipartFile;
  28. /**
  29. * 卫生批文清单Controller
  30. *
  31. * @author ruoyi
  32. * @date 2021-07-13
  33. */
  34. @RestController
  35. @RequestMapping("/ehs/healthapproval")
  36. public class THealthapprovalController extends BaseController
  37. {
  38. @Autowired
  39. private ITHealthapprovalService tHealthapprovalService;
  40. @Autowired
  41. private ISysDeptService iSysDeptService;
  42. @Autowired
  43. private ISysDictTypeService iSysDictTypeService;
  44. @Autowired
  45. private ITStaffmgrService tStaffmgrService;
  46. /**
  47. * 查询卫生批文清单列表
  48. */
  49. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:list')")
  50. @GetMapping("/list")
  51. public TableDataInfo list(THealthapproval tHealthapproval)
  52. {
  53. startPage();
  54. List<THealthapproval> list = tHealthapprovalService.selectTHealthapprovalList(tHealthapproval);
  55. return getDataTable(list);
  56. }
  57. /**
  58. * 导出卫生批文清单列表
  59. */
  60. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:export')")
  61. @Log(title = "卫生批文清单", businessType = BusinessType.EXPORT)
  62. @GetMapping("/export")
  63. public AjaxResult export(THealthapproval tHealthapproval)
  64. {
  65. List<THealthapproval> list = tHealthapprovalService.selectTHealthapprovalList(tHealthapproval);
  66. ExcelUtil<THealthapproval> util = new ExcelUtil<THealthapproval>(THealthapproval.class);
  67. return util.exportExcel(list, "healthapproval");
  68. }
  69. /**
  70. * 获取卫生批文清单详细信息
  71. */
  72. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:query')")
  73. @GetMapping(value = "/{id}")
  74. public AjaxResult getInfo(@PathVariable("id") Long id)
  75. {
  76. return AjaxResult.success(tHealthapprovalService.selectTHealthapprovalById(id));
  77. }
  78. /**
  79. * 新增卫生批文清单
  80. */
  81. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:add')")
  82. @Log(title = "卫生批文清单", businessType = BusinessType.INSERT)
  83. @PostMapping
  84. public AjaxResult add(@RequestBody THealthapproval tHealthapproval)
  85. {
  86. return toAjax(tHealthapprovalService.insertTHealthapproval(tHealthapproval));
  87. }
  88. /**
  89. * 修改卫生批文清单
  90. */
  91. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:edit')")
  92. @Log(title = "卫生批文清单", businessType = BusinessType.UPDATE)
  93. @PutMapping
  94. public AjaxResult edit(@RequestBody THealthapproval tHealthapproval)
  95. {
  96. return toAjax(tHealthapprovalService.updateTHealthapproval(tHealthapproval));
  97. }
  98. /**
  99. * 删除卫生批文清单
  100. */
  101. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:remove')")
  102. @Log(title = "卫生批文清单", businessType = BusinessType.DELETE)
  103. @DeleteMapping("/{ids}")
  104. public AjaxResult remove(@PathVariable Long[] ids)
  105. {
  106. return toAjax(tHealthapprovalService.deleteTHealthapprovalByIds(ids));
  107. }
  108. /**
  109. * 批量导入安全批文清单
  110. */
  111. @PreAuthorize("@ss.hasPermi('ehs:healthapproval:add')")
  112. @Log(title = "卫生批文清单", businessType = BusinessType.INSERT)
  113. @PostMapping("/importData")
  114. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
  115. {
  116. //获取操作人员ID
  117. Long userId = getUserId();
  118. //报错行数统计
  119. List<Integer> failRow =new ArrayList<Integer>();
  120. Workbook workbook = ExcelUtils.getWorkBook(file);
  121. Sheet sheet = workbook.getSheetAt(0);
  122. List<THealthapproval> list = new ArrayList<THealthapproval>();
  123. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  124. //字典查询
  125. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  126. List<SysDictData> yesNo = iSysDictTypeService.selectDictDataByType("YES_NO");
  127. //部门查询
  128. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  129. //人员查询
  130. List<TStaffmgr> staffmgrs = tStaffmgrService.selectTStaffmgrList(new TStaffmgr());
  131. int rowNum = sheet.getPhysicalNumberOfRows();
  132. int failNumber = 0;
  133. for (int i = 1; i < rowNum; i++) {
  134. try {
  135. logger.info("读取行数:" + i);
  136. Row row = sheet.getRow(i);
  137. int cellNum = row.getPhysicalNumberOfCells();
  138. THealthapproval entity = new THealthapproval();
  139. for (int j = 0; j < cellNum; j++) {
  140. Cell cell = row.getCell(j);
  141. cell.setCellType(CellType.STRING);
  142. String cellValue = ExcelUtils.getCellValue(cell);
  143. logger.info("cellValue:" + cellValue);
  144. if (j == 0) {
  145. entity.setApprovalname(cellValue);//批文名称
  146. } else if (j == 1) {
  147. entity.setCertno(cellValue);//证书编号
  148. } else if (j == 2) {
  149. if (cellValue.length() > 3) {
  150. entity.setEffetivedate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//批准日期
  151. }
  152. } else if (j == 3) {
  153. entity.setScope(cellValue);//适用范围
  154. } else if (j == 4) {
  155. entity.setRelatedlaw(cellValue);//相关法规
  156. } else if (j == 5) {
  157. entity.setResponsauth(cellValue);//审批单位
  158. } else if (j == 6) {
  159. if (cellValue.length() > 3) {
  160. entity.setValidityBefore(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//证书有效期前
  161. entity.setIsPermanent(Long.parseLong("0"));
  162. }else {
  163. entity.setIsPermanent(Long.parseLong("1"));
  164. }
  165. } else if (j == 7) {
  166. if (cellValue.length() > 3) {
  167. entity.setValidityAfter(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//证书有效期后
  168. }
  169. } else if (j == 8) {
  170. for (SysDictData p : yesNo) {
  171. if (p.getDictLabel().equals(cellValue.trim())) {
  172. entity.setFollow(p.getDictValue());//是否需要跟进
  173. }
  174. }
  175. } else if (j == 9) {
  176. entity.setAllowance(cellValue);//使用/储存/废物最大量
  177. } else if (j == 10) {
  178. entity.setRequirements(cellValue);//排放/监控要求
  179. } else if (j == 11) {
  180. entity.setContent(cellValue);//主要内容
  181. } else if (j == 12) {
  182. entity.setOwner(cellValue);//负责人
  183. } else if (j == 14) {
  184. for (TStaffmgr s : staffmgrs) {
  185. if (s.getStaffid().equals(cellValue.trim())) {
  186. entity.setReviewer(s.getStaffid());//回顾人
  187. }
  188. }
  189. } else if (j == 15) {
  190. if (cellValue.length() > 3) {
  191. entity.setReviewdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//本次回顾日期
  192. }
  193. } else if (j == 16) {
  194. entity.setReviewResult(cellValue);//回顾结果
  195. } else if (j == 17) {
  196. if (cellValue.length() > 3) {
  197. entity.setNextreviewdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//下次回顾日期
  198. }
  199. } else if (j == 18) {
  200. for (SysDept d : dept) {
  201. if (d.getDeptName().equals(cellValue.trim())) {
  202. entity.setDeptId(d.getDeptId());//部门编号
  203. }
  204. }
  205. } else if (j == 19) {
  206. entity.setRemarks(cellValue);//备注
  207. }
  208. }
  209. entity.setCreaterCode(userId.toString());
  210. logger.info("entity:" + entity);
  211. list.add(entity);
  212. }catch (Exception e){
  213. failNumber++;
  214. failRow.add(i+1);
  215. }
  216. }
  217. int successNumber = 0;
  218. int failNum = 0;
  219. for (THealthapproval t : list
  220. ) {
  221. failNum++;
  222. try {
  223. tHealthapprovalService.insertTHealthapproval(t);
  224. successNumber++;
  225. }catch (Exception e){
  226. failNumber++;
  227. failRow.add(failNum+1);
  228. }
  229. }
  230. logger.info("list:" + JSON.toJSONString(list));
  231. logger.info("successNumber:" +String.valueOf(successNumber));
  232. logger.info("failNumber:" +String.valueOf(failNumber));
  233. logger.info("failRow:" +String.valueOf(failRow));
  234. return AjaxResult.success(String.valueOf(successNumber), failRow);
  235. }
  236. }