TSpecdevDtController.java 19 KB

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