TSpecdevCcController.java 19 KB

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