TMocController.java 20 KB

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