TSpecdevCcController.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. package com.ruoyi.project.sems.controller;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.UUID;
  11. import com.alibaba.fastjson.JSON;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.ruoyi.common.utils.DateUtils;
  14. import com.ruoyi.common.utils.file.ExcelUtils;
  15. import com.ruoyi.framework.config.RuoYiConfig;
  16. import com.ruoyi.project.sems.domain.*;
  17. import com.ruoyi.project.sems.service.ITSpecCheckService;
  18. import com.ruoyi.project.system.domain.SysDept;
  19. import com.ruoyi.project.system.domain.SysDictData;
  20. import com.ruoyi.project.system.service.ISysDeptService;
  21. import com.ruoyi.project.system.service.ISysDictTypeService;
  22. import org.apache.poi.ss.formula.functions.T;
  23. import org.apache.poi.ss.usermodel.*;
  24. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  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.sems.service.ITSpecdevCcService;
  31. import com.ruoyi.framework.web.controller.BaseController;
  32. import com.ruoyi.framework.web.domain.AjaxResult;
  33. import com.ruoyi.common.utils.poi.ExcelUtil;
  34. import com.ruoyi.framework.web.page.TableDataInfo;
  35. import org.springframework.web.multipart.MultipartFile;
  36. /**
  37. * 特种设备叉车台账Controller
  38. *
  39. * @author ruoyi
  40. * @date 2021-07-26
  41. */
  42. @RestController
  43. @RequestMapping("/sems/specCc")
  44. public class TSpecdevCcController extends BaseController
  45. {
  46. @Autowired
  47. private ITSpecdevCcService tSpecdevCcService;
  48. @Autowired
  49. private ITSpecCheckService tSpecCheckService;
  50. @Autowired
  51. private ISysDeptService iSysDeptService;
  52. @Autowired
  53. private ISysDictTypeService iSysDictTypeService;
  54. /**
  55. * 查询特种设备叉车台账列表
  56. */
  57. @PreAuthorize("@ss.hasPermi('sems:specCc:list')")
  58. @GetMapping("/list")
  59. public TableDataInfo list(TSpecdevCc tSpecdevCc)
  60. {
  61. startPage();
  62. List<TSpecdevCc> list = tSpecdevCcService.selectTSpecdevCcList(tSpecdevCc);
  63. return getDataTable(list);
  64. }
  65. /**
  66. * 导出特种设备叉车台账列表
  67. */
  68. @PreAuthorize("@ss.hasPermi('sems:specCc:export')")
  69. @Log(title = "特种设备叉车台账", businessType = BusinessType.EXPORT)
  70. @GetMapping("/export")
  71. public AjaxResult export(TSpecdevCc tSpecdevCc)
  72. {
  73. List<TSpecdevCc> list = tSpecdevCcService.selectTSpecdevCcList(tSpecdevCc);
  74. ExcelUtil<TSpecdevCc> util = new ExcelUtil<TSpecdevCc>(TSpecdevCc.class);
  75. return util.exportExcel(list, "specCc");
  76. }
  77. /**
  78. * 获取特种设备叉车台账详细信息
  79. */
  80. @PreAuthorize("@ss.hasPermi('sems:specCc:query')")
  81. @GetMapping(value = "/{id}")
  82. public AjaxResult getInfo(@PathVariable("id") Long id)
  83. {
  84. return AjaxResult.success(tSpecdevCcService.selectTSpecdevCcById(id));
  85. }
  86. /**
  87. * 新增特种设备叉车台账
  88. */
  89. @PreAuthorize("@ss.hasPermi('sems:specCc:add')")
  90. @Log(title = "特种设备叉车台账", businessType = BusinessType.INSERT)
  91. @PostMapping
  92. public AjaxResult add(@RequestBody TSpecdevCc tSpecdevCc)
  93. {
  94. return toAjax(tSpecdevCcService.insertTSpecdevCc(tSpecdevCc));
  95. }
  96. /**
  97. * 修改特种设备叉车台账
  98. */
  99. @PreAuthorize("@ss.hasPermi('sems:specCc:edit')")
  100. @Log(title = "特种设备叉车台账", businessType = BusinessType.UPDATE)
  101. @PutMapping
  102. public AjaxResult edit(@RequestBody TSpecdevCc tSpecdevCc)
  103. {
  104. TSpecdevCc old = tSpecdevCcService.selectTSpecdevCcById(tSpecdevCc.getId());
  105. if (!old.getReportNo().equals(tSpecdevCc.getReportNo())) {
  106. TSpecCheck tc = new TSpecCheck();
  107. tc.setDevType(6l);
  108. tc.setCheckUnit(tSpecdevCc.getCheckUnit());
  109. tc.setDevId(tSpecdevCc.getId());
  110. tc.setNextWarnDate(tSpecdevCc.getNextWarnDate());
  111. tc.setReportNo(tSpecdevCc.getReportNo());
  112. tc.setWarnDate(tSpecdevCc.getWarnDate());
  113. tc.setCheckConclusion(tSpecdevCc.getPerTestConclusion());
  114. tSpecCheckService.insertTSpecCheck(tc);
  115. }
  116. return toAjax(tSpecdevCcService.updateTSpecdevCc(tSpecdevCc));
  117. }
  118. /**
  119. * 删除特种设备叉车台账
  120. */
  121. @PreAuthorize("@ss.hasPermi('sems:specCc:remove')")
  122. @Log(title = "特种设备叉车台账", businessType = BusinessType.DELETE)
  123. @DeleteMapping("/{ids}")
  124. public AjaxResult remove(@PathVariable Long[] ids)
  125. {
  126. return toAjax(tSpecdevCcService.deleteTSpecdevCcByIds(ids));
  127. }
  128. /**
  129. * 去重
  130. */
  131. @PreAuthorize("@ss.hasPermi('sems:plant:remove')")
  132. @Log(title = "特种设备叉车台账去重", businessType = BusinessType.OTHER)
  133. @GetMapping("/duplicate")
  134. public AjaxResult duplicate()
  135. {
  136. tSpecdevCcService.duplicateTSpecdevCc();
  137. return AjaxResult.success();
  138. }
  139. /**
  140. * 批量导入
  141. */
  142. @PreAuthorize("@ss.hasPermi('sems:specCc:add')")
  143. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  144. @PostMapping("/importData")
  145. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException
  146. {
  147. //获取操作人员ID
  148. Long userId = getUserId();
  149. //报错行数统计
  150. List<Integer> failRow =new ArrayList<Integer>();
  151. Workbook workbook = ExcelUtils.getWorkBook(file);
  152. Sheet sheet = workbook.getSheetAt(0);
  153. List<TSpecdevCc> list = new ArrayList<TSpecdevCc>();
  154. //字典查询
  155. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  156. //部门查询
  157. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  158. int rowNum = sheet.getPhysicalNumberOfRows();
  159. int failNumber = 0;
  160. for (int i = 1; i < rowNum; i++) {
  161. try {
  162. logger.info("读取行数:" + i);
  163. Row row = sheet.getRow(i);
  164. int cellNum = row.getLastCellNum();
  165. TSpecdevCc entity = new TSpecdevCc();
  166. for (int j = 0; j < cellNum; j++) {
  167. Cell cell = row.getCell(j);
  168. if (cell == null) {
  169. continue;
  170. }
  171. String cellValue = ExcelUtils.getCellValue(cell);
  172. logger.info("cellValue:" + cellValue);
  173. if (j == 0) {
  174. //序号
  175. } else if (j == 1) {
  176. entity.setPlantCode(cellValue);//装置名称
  177. } else if (j == 2) {
  178. entity.setUnit(cellValue);//使用部门
  179. }else if (j == 3) {
  180. entity.setUseDept(cellValue);//使用部门
  181. } else if (j == 4) {
  182. entity.setPlantMaint(cellValue);//装置维护组
  183. }else if (j == 5) {
  184. entity.setEngineer(cellValue);//装置维护人员
  185. } else if (j == 6) {
  186. entity.setCarNo(cellValue);//车牌号
  187. } else if (j == 7) {
  188. entity.setDocno(cellValue);//档案号
  189. } else if (j == 8) {
  190. entity.setEngineNo(cellValue);//发动机号
  191. } else if (j == 9) {
  192. entity.setRegno(cellValue);//注册代码
  193. } else if (j == 10) {
  194. entity.setColor(cellValue);//颜色
  195. } else if (j == 11) {
  196. entity.setCapacity(cellValue);//工作能力
  197. } else if (j == 12) {
  198. entity.setDevname(cellValue);//设备名称
  199. } else if (j == 13) {
  200. entity.setEngineType(cellValue);//动力形式
  201. } else if (j == 14) {
  202. entity.setModel(cellValue);//型号
  203. } else if (j == 15) {
  204. entity.setFrameNo(cellValue);//车架号
  205. } else if (j == 16) {
  206. entity.setProductNo(cellValue);//产品编号
  207. } else if (j == 17) {
  208. entity.setCreateUnit(cellValue);//生产厂家
  209. } else if (j == 18) {
  210. entity.setExUnit(cellValue);//防爆改造厂家
  211. } else if (j == 19) {
  212. entity.setExGrade(cellValue);//最高防爆级别
  213. } else if (j == 20) {
  214. if (cellValue.length() > 3) {//初检日期
  215. entity.setFirstWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  216. }
  217. } else if (j == 21) {
  218. entity.setCheckStrategy(cellValue);//检验策略
  219. } else if (j == 22) {
  220. if (cellValue.length() > 3) {//检验日期
  221. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  222. }
  223. } else if (j == 23) {
  224. if (cellValue.length() > 3) {//下次年检日期
  225. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  226. }
  227. } else if (j == 24) {
  228. entity.setReportNo(cellValue);//报告编号
  229. }else if (j == 25) {
  230. entity.setAssetOwner(cellValue);//资产形式
  231. } else if (j == 26) {
  232. entity.setPerTestConclusion(cellValue);
  233. }else if (j == 27) {
  234. entity.setRemarks(cellValue);//备注
  235. }/*else if (j == 25) {
  236. for (SysDept d : dept) {
  237. if (d.getDeptName().equals(cellValue)) {
  238. entity.setDeptId(d.getDeptId());//部门编号
  239. }
  240. }
  241. }*/
  242. }
  243. entity.setCreaterCode(userId);
  244. logger.info("entity:" + entity);
  245. list.add(entity);
  246. }catch (Exception e){
  247. failNumber++;
  248. logger.info("e:" + JSON.toJSONString(e));
  249. failRow.add(i + 1);
  250. }
  251. }
  252. int successNumber = 0;
  253. int failNum = 0;
  254. for (TSpecdevCc t : list
  255. ) {
  256. failNum++;
  257. try {
  258. tSpecdevCcService.insertTSpecdevCc(t);
  259. successNumber++;
  260. }catch (Exception e){
  261. failNumber++;
  262. logger.info("e:" + e);
  263. failRow.add(failNum + 1);
  264. }
  265. }
  266. logger.info("list:" + JSON.toJSONString(list));
  267. logger.info("successNumber:" +String.valueOf(successNumber));
  268. logger.info("failNumber:" +String.valueOf(failNumber));
  269. logger.info("failRow:" +String.valueOf(failRow));
  270. return AjaxResult.success(String.valueOf(successNumber), failRow);
  271. }
  272. /**
  273. * 批量导入
  274. * 检验更新中的批量导入
  275. */
  276. @PreAuthorize("@ss.hasPermi('sems:specCc:add')")
  277. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  278. @PostMapping("/updateData")
  279. public AjaxResult updateData(@RequestParam("file") MultipartFile file)throws IOException{
  280. //获取操作人员ID
  281. Long userId = getUserId();
  282. //报错行数统计
  283. List<Integer> failRow =new ArrayList<Integer>();
  284. Workbook workbook = ExcelUtils.getWorkBook(file);
  285. Sheet sheet = workbook.getSheetAt(0);
  286. List<TSpecdevCc> list = new ArrayList<TSpecdevCc>();
  287. List<TSpecdevCc> oldList = new ArrayList<TSpecdevCc>();
  288. TSpecdevCc oldEntity = new TSpecdevCc();
  289. //字典查询
  290. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  291. //部门查询
  292. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  293. int rowNum = sheet.getPhysicalNumberOfRows();
  294. int failNumber = 0;
  295. for (int i = 1; i < rowNum; i++) {
  296. try {
  297. logger.info("读取行数:" + i);
  298. Row row = sheet.getRow(i);
  299. int cellNum = row.getLastCellNum();
  300. TSpecdevCc entity = new TSpecdevCc();
  301. for (int j = 0; j < cellNum; j++) {
  302. Cell cell = row.getCell(j);
  303. if (cell == null) {
  304. continue;
  305. }
  306. String cellValue = ExcelUtils.getCellValue(cell);
  307. logger.info("cellValue:" + cellValue);
  308. if (j == 0) {
  309. //序号
  310. Double d = Double.parseDouble(cellValue);
  311. long s = new Double(d).longValue();
  312. entity.setId(s);
  313. } else if (j == 1) { //装置名称
  314. entity.setPlantCode(cellValue);
  315. } else if (j == 2) {
  316. entity.setCarNo(cellValue);
  317. } else if (j == 3) {
  318. entity.setDocno(cellValue);
  319. } else if (j == 4) {
  320. logger.info("日期格式:" + cellValue);
  321. if (cellValue.length() > 3) {
  322. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  323. }
  324. } else if (j == 5) {
  325. logger.info("日期格式:" + cellValue);
  326. if (cellValue.length() > 3) {
  327. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  328. }
  329. } else if (j == 6) {
  330. entity.setReportNo(cellValue);
  331. }
  332. else if (j == 7) {
  333. entity.setPerTestConclusion(cellValue);
  334. }
  335. }
  336. logger.info("entity:" + entity);
  337. list.add(entity);
  338. oldEntity = entity;
  339. oldList.add(oldEntity);
  340. }catch (Exception e){
  341. failNumber++;
  342. logger.info("e:" + JSON.toJSONString(e));
  343. failRow.add(i + 1);
  344. }
  345. }
  346. int successNumber = 0;
  347. int failNum = 0;
  348. for (TSpecdevCc t : list) {
  349. failNum++;
  350. try {
  351. tSpecdevCcService
  352. .update(t,
  353. new QueryWrapper<TSpecdevCc>()
  354. .eq("DOCNO", t.getDocno())
  355. .eq("CAR_NO", t.getCarNo())
  356. .eq("PLANT_CODE", t.getPlantCode())
  357. );
  358. successNumber++;
  359. }catch (Exception e){
  360. failNumber++;
  361. logger.info("e:" + e);
  362. failRow.add(failNum + 1);
  363. e.printStackTrace();
  364. }
  365. }
  366. for (TSpecdevCc t: oldList) {
  367. TSpecCheck tc = new TSpecCheck();
  368. tc.setDevType(6l);
  369. tc.setCheckUnit(t.getCheckUnit());
  370. tc.setDevId(t.getId());
  371. tc.setNextWarnDate(t.getNextWarnDate());
  372. tc.setReportNo(t.getReportNo());
  373. tc.setWarnDate(t.getWarnDate());
  374. tc.setCheckConclusion(t.getPerTestConclusion());
  375. tSpecCheckService.insertTSpecCheck(tc);
  376. }
  377. logger.info("list:" + JSON.toJSONString(list));
  378. logger.info("successNumber:" +String.valueOf(successNumber));
  379. logger.info("failNumber:" +String.valueOf(failNumber));
  380. logger.info("failRow:" +String.valueOf(failRow));
  381. return AjaxResult.success(String.valueOf(successNumber),failRow);
  382. }
  383. @GetMapping("/exportDevList")
  384. public AjaxResult exportbmy(ParamData params) throws IOException {
  385. logger.info(JSON.toJSONString(params));
  386. String id = params.getIds();
  387. String[] ids = id.split(",");
  388. List<TSpecdevCc> list = new ArrayList<>();
  389. for (String i : ids
  390. ) {
  391. TSpecdevCc ccEntity = tSpecdevCcService.getById(i);
  392. list.add(ccEntity);
  393. }
  394. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  395. CellStyle wrapStyle = wb.createCellStyle();
  396. wrapStyle.setWrapText(true); //设置自动换行
  397. //创建sheet页
  398. Sheet sheet = wb.createSheet("sheet1");
  399. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  400. sheet.setColumnWidth(0, 12*256);
  401. sheet.setColumnWidth(1, 26*256);
  402. sheet.setColumnWidth(2, 26*256);
  403. sheet.setColumnWidth(3, 26*256);
  404. sheet.setColumnWidth(4, 26*256);
  405. sheet.setColumnWidth(5, 26*256);
  406. sheet.setColumnWidth(6, 26*256);
  407. sheet.setColumnWidth(7, 26*256);
  408. sheet.setColumnWidth(8, 40*256);
  409. //设置开始行和开始列
  410. Row row0 = sheet.createRow(0);
  411. CellStyle style = wb.createCellStyle();
  412. style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
  413. style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  414. // Font headerFont = wb.createFont();
  415. // headerFont.setFontName("Arial");
  416. // headerFont.setFontHeightInPoints((short) 12);
  417. // headerFont.setBold(false);
  418. // headerFont.setColor(IndexedColors.BLACK.getIndex());
  419. // style.setFont(headerFont);
  420. Cell cell0 = row0.createCell(0);
  421. row0.createCell(0).setCellValue("序号");
  422. row0.createCell(1).setCellValue("装置");
  423. row0.createCell(2).setCellValue("车牌号");
  424. row0.createCell(3).setCellValue("档案号");
  425. row0.createCell(4).setCellValue("检验日期");row0.getCell(4).setCellStyle(style);
  426. row0.createCell(5).setCellValue("下次检验日期");row0.getCell(5).setCellStyle(style);
  427. row0.createCell(6).setCellValue("报告编号");row0.getCell(6).setCellStyle(style);
  428. row0.createCell(7).setCellValue("定期检验结论");row0.getCell(7).setCellStyle(style);
  429. //填充数据
  430. int rowIndex = 1;
  431. int columnIndex = 1;
  432. for (TSpecdevCc t: list
  433. ) {
  434. Row row = sheet.createRow(rowIndex);
  435. row.createCell(0).setCellValue(t.getId());
  436. row.createCell(1).setCellValue(t.getPlantCode());
  437. row.createCell(2).setCellValue(t.getCarNo());
  438. row.createCell(3).setCellValue(t.getDocno());
  439. if (t.getWarnDate()!= null){
  440. row.createCell(4).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
  441. }
  442. if (t.getNextWarnDate()!= null){
  443. row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
  444. }
  445. row.createCell(6).setCellValue(t.getReportNo());
  446. row.createCell(7).setCellValue(t.getPerTestConclusion());
  447. rowIndex++;
  448. }
  449. OutputStream out = null;
  450. String filename = ExcelUtil.encodingFilename("叉车批量更新");
  451. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  452. wb.write(out);
  453. wb.close();
  454. out.close();
  455. return AjaxResult.success(filename);
  456. }
  457. }