TMocController.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. package com.ruoyi.project.process.controller;
  2. import java.io.IOException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.*;
  5. import com.alibaba.fastjson.JSON;
  6. import com.ruoyi.common.utils.DateUtils;
  7. import com.ruoyi.common.utils.file.ExcelUtils;
  8. import com.ruoyi.common.utils.file.FileUploadUtils;
  9. import com.ruoyi.framework.config.RuoYiConfig;
  10. import com.ruoyi.project.common.domain.DataEntity;
  11. import com.ruoyi.project.common.domain.TCommonfile;
  12. import com.ruoyi.project.common.service.ITCommonfileService;
  13. import com.ruoyi.project.process.mapper.TMocMapper;
  14. import com.ruoyi.project.system.domain.SysDept;
  15. import com.ruoyi.project.system.domain.SysDictData;
  16. import com.ruoyi.project.system.service.ISysDeptService;
  17. import com.ruoyi.project.system.service.ISysDictTypeService;
  18. import com.ruoyi.project.training.domain.TTraining;
  19. import com.ruoyi.project.training.service.ITTrainingService;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.apache.poi.ss.usermodel.*;
  22. import org.springframework.security.access.prepost.PreAuthorize;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.web.bind.annotation.*;
  25. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  26. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  27. import com.ruoyi.project.process.domain.TMoc;
  28. import com.ruoyi.project.process.service.ITMocService;
  29. import com.ruoyi.framework.web.controller.BaseController;
  30. import com.ruoyi.framework.web.domain.AjaxResult;
  31. import com.ruoyi.common.utils.poi.ExcelUtil;
  32. import com.ruoyi.framework.web.page.TableDataInfo;
  33. import org.springframework.web.multipart.MultipartFile;
  34. import javax.annotation.Resource;
  35. /**
  36. * MOC管理Controller
  37. *
  38. * @author ruoyi
  39. * @date 2020-12-07
  40. */
  41. @RestController
  42. @RequestMapping("/process/moc")
  43. public class TMocController extends BaseController
  44. {
  45. @Autowired
  46. private ITMocService tMocService;
  47. @Autowired
  48. private ISysDictTypeService iSysDictTypeService;
  49. @Autowired
  50. private ISysDeptService iSysDeptService;
  51. @Resource
  52. private TMocMapper tMocMapper;
  53. @Autowired
  54. private ITTrainingService tTrainingService;
  55. @Autowired
  56. private ITCommonfileService commonfileService;
  57. /**
  58. * 遍历MOC filelist
  59. * 设置isEhsCheck、isTrainingset、ispssr
  60. *
  61. * @param list MOC list
  62. */
  63. private void getFiles(List<TMoc> list) {
  64. for (TMoc m : list) {
  65. TCommonfile commonfile = new TCommonfile();
  66. commonfile.setpId(m.getId());
  67. if (m.getEhsCheck() != null) {
  68. commonfile.setpType("moc-ehsCheck");
  69. List<TCommonfile> commonfilesEhsCheck = commonfileService.selectAllFileList(commonfile);
  70. if (commonfilesEhsCheck.size() == 0) {
  71. m.setIsEhsCheck("1");
  72. }
  73. }
  74. if (m.getTraining() != null) {
  75. commonfile.setpType("moc-training");
  76. List<TCommonfile> commonfilesTraining = commonfileService.selectAllFileList(commonfile);
  77. if (commonfilesTraining.size() == 0) {
  78. m.setIsTraining("1");
  79. }
  80. }
  81. if (m.getPssr() != null) {
  82. commonfile.setpType("moc-pssr");
  83. List<TCommonfile> commonfilesPssr = commonfileService.selectAllFileList(commonfile);
  84. if (commonfilesPssr.size() == 0) {
  85. m.setIsPssr("1");
  86. }
  87. }
  88. }
  89. }
  90. /**
  91. * 查询临时MOC管理列表 - 仪表联锁旁路
  92. */
  93. @PreAuthorize("@ss.hasPermi('process:moc:list')")
  94. @GetMapping("/listinterlock")
  95. public TableDataInfo listInterlock(TMoc tMoc)
  96. {
  97. tMoc.setTimeliness("2");
  98. tMoc.setTempCategory("3");
  99. startPage();
  100. List<TMoc> list = tMocService.selectTMocList(tMoc);
  101. this.getFiles(list);
  102. return getDataTable(list);
  103. }
  104. /**
  105. * 查询临时MOC管理列表 - 临时设施、其它
  106. */
  107. @PreAuthorize("@ss.hasPermi('process:moc:list')")
  108. @GetMapping("/listfacility")
  109. public TableDataInfo listFacility(TMoc tMoc)
  110. {
  111. tMoc.setTimeliness("2");
  112. tMoc.setTempCategory("2");
  113. startPage();
  114. List<TMoc> list = tMocService.selectTMocList(tMoc);
  115. this.getFiles(list);
  116. return getDataTable(list);
  117. }
  118. /**
  119. * 查询临时MOC管理列表 - 带压消漏清单
  120. */
  121. @PreAuthorize("@ss.hasPermi('process:moc:list')")
  122. @GetMapping("/listaquifier")
  123. public TableDataInfo listAquifier(TMoc tMoc)
  124. {
  125. tMoc.setTimeliness("2");
  126. tMoc.setTempCategory("1");
  127. startPage();
  128. List<TMoc> list = tMocService.selectTMocList(tMoc);
  129. this.getFiles(list);
  130. return getDataTable(list);
  131. }
  132. /**
  133. * 查询临时MOC管理列表
  134. */
  135. @PreAuthorize("@ss.hasPermi('process:moc:list')")
  136. @GetMapping("/listtemporary")
  137. public TableDataInfo listTemporary(TMoc tMoc)
  138. {
  139. tMoc.setTimeliness("2");
  140. startPage();
  141. List<TMoc> list = tMocService.selectTMocList(tMoc);
  142. this.getFiles(list);
  143. return getDataTable(list);
  144. }
  145. /**
  146. * 查询永久MOC管理列表
  147. */
  148. @PreAuthorize("@ss.hasPermi('process:moc:list')")
  149. @GetMapping("/listpermanent")
  150. public TableDataInfo list(TMoc tMoc)
  151. {
  152. tMoc.setTimeliness("1");
  153. startPage();
  154. List<TMoc> list = tMocService.selectTMocList(tMoc);
  155. this.getFiles(list);
  156. return getDataTable(list);
  157. }
  158. //申请年份统计
  159. @GetMapping("/yearData")
  160. public List<DataEntity> engData(Map param)
  161. {
  162. param.put("params" , new HashMap<>());
  163. List<DataEntity> list = tMocMapper.selectYearData(param);
  164. return list;
  165. }
  166. //情况统计
  167. @GetMapping("/trueStateData")
  168. public List<DataEntity> trueStateData(Map param)
  169. {
  170. param.put("params" , new HashMap<>());
  171. List<DataEntity> list = tMocMapper.selectTrueStateData(param);
  172. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("MOC_STATE");
  173. for (DataEntity d: list
  174. ) {
  175. for (SysDictData s: dictList
  176. ) {
  177. if (StringUtils.isBlank(d.getDataName())){
  178. d.setDataName("未知");
  179. break;
  180. }
  181. if (s.getDictValue().equals(d.getDataName())){
  182. d.setDataName(s.getDictLabel());
  183. break;
  184. }
  185. }
  186. }
  187. return list;
  188. }
  189. //变更统计
  190. @GetMapping("/changeData")
  191. public List<DataEntity> changeData(Map param)
  192. {
  193. param.put("params" , new HashMap<>());
  194. List<DataEntity> list = tMocMapper.selectChangeData(param);
  195. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("MOC_CHANGE");
  196. for (DataEntity d: list
  197. ) {
  198. for (SysDictData s: dictList
  199. ) {
  200. if (StringUtils.isBlank(d.getDataName())){
  201. d.setDataName("未知");
  202. break;
  203. }
  204. if (s.getDictValue().equals(d.getDataName())){
  205. d.setDataName(s.getDictLabel());
  206. break;
  207. }
  208. }
  209. }
  210. return list;
  211. }
  212. //变更统计
  213. @GetMapping("/categoryData")
  214. public List<DataEntity> categoryData(Map param)
  215. {
  216. param.put("params" , new HashMap<>());
  217. List<DataEntity> list = tMocMapper.selectCategoryData(param);
  218. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("MOC_CATEGORY");
  219. for (DataEntity d: list
  220. ) {
  221. for (SysDictData s: dictList
  222. ) {
  223. if (StringUtils.isBlank(d.getDataName())){
  224. d.setDataName("未知");
  225. break;
  226. }
  227. if (s.getDictValue().equals(d.getDataName())){
  228. d.setDataName(s.getDictLabel());
  229. break;
  230. }
  231. }
  232. }
  233. return list;
  234. }
  235. //风险统计
  236. @GetMapping("/riskData")
  237. public List<DataEntity> riskData(Map param)
  238. {
  239. param.put("params" , new HashMap<>());
  240. List<DataEntity> list = tMocMapper.selectRiskData(param);
  241. List<SysDictData> dictList = iSysDictTypeService.selectDictDataByType("MOC_RISKLEVEL");
  242. for (DataEntity d: list
  243. ) {
  244. for (SysDictData s: dictList
  245. ) {
  246. if (StringUtils.isBlank(d.getDataName())){
  247. d.setDataName("未知");
  248. break;
  249. }
  250. if (s.getDictValue().equals(d.getDataName())){
  251. d.setDataName(s.getDictLabel());
  252. break;
  253. }
  254. }
  255. }
  256. return list;
  257. }
  258. /**
  259. * 导出MOC管理列表
  260. */
  261. @PreAuthorize("@ss.hasPermi('process:moc:export')")
  262. @Log(title = "MOC管理", businessType = BusinessType.EXPORT)
  263. @GetMapping("/export")
  264. public AjaxResult export(TMoc tMoc)
  265. {
  266. List<TMoc> list = tMocService.selectTMocList(tMoc);
  267. ExcelUtil<TMoc> util = new ExcelUtil<TMoc>(TMoc.class);
  268. return util.exportExcel(list, "moc");
  269. }
  270. /**
  271. * 获取MOC管理详细信息
  272. */
  273. @PreAuthorize("@ss.hasPermi('process:moc:query')")
  274. @GetMapping(value = "/{id}")
  275. public AjaxResult getInfo(@PathVariable("id") Long id)
  276. {
  277. return AjaxResult.success(tMocService.selectTMocById(id));
  278. }
  279. /**
  280. * 新增MOC管理
  281. */
  282. @PreAuthorize("@ss.hasPermi('process:moc:add')")
  283. @Log(title = "MOC管理", businessType = BusinessType.INSERT)
  284. @PostMapping
  285. public AjaxResult add(@RequestBody TMoc tMoc)
  286. {
  287. tMoc.setCreaterCode(getUserId().toString());
  288. TTraining tTraining = new TTraining();
  289. SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
  290. tTraining.setPlantCode(tMoc.getPlantCode());
  291. tTraining.setCourseid(tMoc.getMocNo());
  292. tTraining.setYear(sdf.format(new Date()));;
  293. tTraining.setCourse("MOC培训");
  294. tTraining.setTrainingType("12");
  295. tTraining.setContent(tMoc.getTitle());
  296. tTraining.setIsfinish(Long.parseLong("0"));
  297. tTraining.setDeptId(tMoc.getDeptId());
  298. tTrainingService.insertTTraining(tTraining);
  299. return toAjax(tMocService.insertTMoc(tMoc));
  300. }
  301. /**
  302. * 修改MOC管理
  303. */
  304. @PreAuthorize("@ss.hasPermi('process:moc:edit')")
  305. @Log(title = "MOC管理", businessType = BusinessType.UPDATE)
  306. @PutMapping
  307. public AjaxResult edit(@RequestBody TMoc tMoc)
  308. {
  309. tMoc.setUpdaterCode(getUserId().toString());
  310. tMoc.setUpdatedate(new Date());
  311. // if (tMoc.getChangeNature().equals("12")) {
  312. // tMoc.setTemporaryState("14");
  313. // }
  314. return toAjax(tMocService.updateTMoc(tMoc));
  315. }
  316. /**
  317. * 删除MOC管理
  318. */
  319. @PreAuthorize("@ss.hasPermi('process:moc:remove')")
  320. @Log(title = "MOC管理", businessType = BusinessType.DELETE)
  321. @DeleteMapping("/{ids}")
  322. public AjaxResult remove(@PathVariable Long[] ids)
  323. {
  324. return toAjax(tMocService.deleteTMocByIds(ids));
  325. }
  326. /**
  327. * 批量导入MOC管理
  328. */
  329. @PreAuthorize("@ss.hasPermi('process:moc:add')")
  330. @Log(title = "MOC管理", businessType = BusinessType.INSERT)
  331. @PostMapping("/importData")
  332. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
  333. {
  334. //获取操作人员ID
  335. Long userId = getUserId();
  336. //报错行数统计
  337. List<Integer> failRow =new ArrayList<Integer>();
  338. Workbook workbook = ExcelUtils.getWorkBook(file);
  339. Sheet sheet = workbook.getSheetAt(0);
  340. List<TMoc> list = new ArrayList<TMoc>();
  341. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  342. //字典查询
  343. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  344. List<SysDictData> state = iSysDictTypeService.selectDictDataByType("MOC_STATE");
  345. List<SysDictData> change = iSysDictTypeService.selectDictDataByType("MOC_CHANGE");
  346. List<SysDictData> risklevel = iSysDictTypeService.selectDictDataByType("MOC_RISKLEVEL");
  347. List<SysDictData> area = iSysDictTypeService.selectDictDataByType("MOC_AREA");
  348. List<SysDictData> temporarystate = iSysDictTypeService.selectDictDataByType("MOC_TEMPORARYSTATE");
  349. List<SysDictData> yesno = iSysDictTypeService.selectDictDataByType("YES_NO");
  350. //部门查询
  351. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  352. int rowNum = sheet.getPhysicalNumberOfRows();
  353. int failNumber = 0;
  354. for (int i = 1; i < rowNum; i++) {
  355. try {
  356. logger.info("读取行数:" + i);
  357. Row row = sheet.getRow(i);
  358. int cellNum = row.getPhysicalNumberOfCells();
  359. TMoc entity = new TMoc();
  360. for (int j = 0; j < cellNum; j++) {
  361. Cell cell = row.getCell(j);
  362. // cell.setCellType(CellType.STRING);
  363. String cellValue = ExcelUtils.getCellValue(cell);
  364. logger.info("cellValue:" + cellValue);
  365. if (j == 0) {
  366. for (SysDictData p : plant) {
  367. if (p.getDictLabel().equals(cellValue.trim())) {
  368. entity.setPlantCode(p.getDictValue());//装置名称
  369. }
  370. }
  371. } else if (j == 1) {
  372. entity.setMocNo(cellValue);//MOC编号
  373. } else if (j == 2) {
  374. for (SysDictData a : area) {
  375. if (a.getDictLabel().equals(cellValue.trim())) {
  376. entity.setArea(a.getDictValue());//区域
  377. }
  378. }
  379. } else if (j == 3) {
  380. entity.setTitle(cellValue);//标题
  381. } else if (j == 4) {
  382. entity.setOwner(cellValue);//负责人
  383. } else if (j == 5) {
  384. if (cellValue.length() > 3) {
  385. entity.setApproveTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//申请时间
  386. }
  387. } else if (j == 6) {
  388. if (cellValue.length() > 3) {
  389. entity.setEndtime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//完成时间
  390. }
  391. } else if (j == 7) {
  392. for (SysDictData s : state) {
  393. if (s.getDictLabel().equals(cellValue.trim())) {
  394. entity.setTrueState(s.getDictValue());//实施情况
  395. }
  396. }
  397. } else if (j == 8) {
  398. for (SysDictData c : change) {
  399. if (c.getDictLabel().equals(cellValue.trim())) {
  400. entity.setChangeNature(c.getDictValue());//变更性质
  401. }
  402. }
  403. } else if (j == 9) {
  404. if (cellValue.length() > 3) {
  405. entity.setOverTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//到期时间
  406. }
  407. } else if (j == 10) {
  408. for (SysDictData t : temporarystate) {
  409. if (t.getDictLabel().equals(cellValue.trim())) {
  410. entity.setTemporaryState(t.getDictValue());//临时moc状态
  411. }
  412. }
  413. } else if (j == 11) {
  414. entity.setRemarks(cellValue);//备注
  415. } else if (j == 12) {
  416. for (SysDictData r : risklevel) {
  417. if (r.getDictLabel().equals(cellValue.trim())) {
  418. entity.setRiskLevel(r.getDictValue());//风险等级
  419. }
  420. }
  421. } else if (j == 13) {
  422. if (cellValue.length() > 3) {
  423. entity.setEhsCheck(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//EHS审查
  424. }
  425. } else if (j == 14) {
  426. if (cellValue.length() > 3) {
  427. entity.setTraining(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//培训
  428. }
  429. } else if (j == 15) {
  430. if (cellValue.length() > 3) {
  431. entity.setPssr(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//PSSR
  432. }
  433. } else if (j == 16) {
  434. for (SysDictData y : yesno) {
  435. if (y.getDictLabel().equals(cellValue.trim())) {
  436. entity.setSopUpdate(y.getDictValue());//SOP更新
  437. }
  438. }
  439. } else if (j == 17) {
  440. for (SysDictData y : yesno) {
  441. if (y.getDictLabel().equals(cellValue.trim())) {
  442. entity.setPidMaster(y.getDictValue());//PID更新
  443. }
  444. }
  445. } else if (j == 18) {
  446. for (SysDept d : dept) {
  447. if (d.getDeptName().equals(cellValue.trim())) {
  448. entity.setDeptId(d.getDeptId());//部门编号
  449. }
  450. }
  451. }
  452. }
  453. entity.setCreaterCode(userId.toString());
  454. logger.info("entity:" + entity);
  455. list.add(entity);
  456. }catch (Exception e){
  457. failNumber++;
  458. failRow.add(i+1);
  459. }
  460. }
  461. int successNumber = 0;
  462. int failNum = 0;
  463. for (TMoc t : list
  464. ) {
  465. failNum++;
  466. try {
  467. tMocService.insertTMoc(t);
  468. successNumber++;
  469. }catch (Exception e){
  470. failNumber++;
  471. logger.info("e:" + e);
  472. failRow.add(failNum+1);
  473. }
  474. }
  475. logger.info("list:" + JSON.toJSONString(list));
  476. logger.info("successNumber:" +String.valueOf(successNumber));
  477. logger.info("failNumber:" +String.valueOf(failNumber));
  478. logger.info("failRow:" +String.valueOf(failRow));
  479. return AjaxResult.success(String.valueOf(successNumber), failRow);
  480. }
  481. }