TSpecdevGlController.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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.*;
  7. import java.util.concurrent.CopyOnWriteArrayList;
  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.ServletUtils;
  12. import com.ruoyi.common.utils.file.ExcelUtils;
  13. import com.ruoyi.common.utils.spring.SpringUtils;
  14. import com.ruoyi.framework.security.LoginUser;
  15. import com.ruoyi.framework.security.service.TokenService;
  16. import com.ruoyi.project.sems.domain.*;
  17. import com.ruoyi.project.sems.his.controller.TApproveSpecModifyController;
  18. import com.ruoyi.project.sems.his.controller.TSpechiDzsbController;
  19. import com.ruoyi.project.sems.his.controller.TSpechiGlController;
  20. import com.ruoyi.project.sems.his.domain.TApproveSpecModify;
  21. import com.ruoyi.project.sems.his.service.ITApproveSpecModifyService;
  22. import com.ruoyi.project.sems.service.ITSpecCheckService;
  23. import com.ruoyi.project.system.domain.SysDept;
  24. import com.ruoyi.project.system.domain.SysDictData;
  25. import com.ruoyi.project.system.service.ISysDeptService;
  26. import com.ruoyi.project.system.service.ISysDictTypeService;
  27. import org.activiti.engine.RuntimeService;
  28. import org.activiti.engine.impl.identity.Authentication;
  29. import org.activiti.engine.runtime.ProcessInstance;
  30. import org.apache.commons.lang.StringUtils;
  31. import org.apache.poi.ss.usermodel.*;
  32. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  33. import org.springframework.security.access.prepost.PreAuthorize;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.web.bind.annotation.*;
  36. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  37. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  38. import com.ruoyi.project.sems.service.ITSpecdevGlService;
  39. import com.ruoyi.framework.web.controller.BaseController;
  40. import com.ruoyi.framework.web.domain.AjaxResult;
  41. import com.ruoyi.common.utils.poi.ExcelUtil;
  42. import com.ruoyi.framework.web.page.TableDataInfo;
  43. import org.springframework.web.multipart.MultipartFile;
  44. /**
  45. * 特种设备锅炉台账Controller
  46. *
  47. * @author ruoyi
  48. * @date 2021-07-21
  49. */
  50. @RestController
  51. @RequestMapping("/sems/specGl")
  52. public class TSpecdevGlController extends BaseController
  53. {
  54. @Autowired
  55. private ITSpecdevGlService tSpecdevGlService;
  56. @Autowired
  57. private ITSpecCheckService tSpecCheckService;
  58. @Autowired
  59. private ISysDeptService iSysDeptService;
  60. @Autowired
  61. private ISysDictTypeService iSysDictTypeService;
  62. @Autowired
  63. private ITApproveSpecModifyService tApproveSpecModifyService;
  64. @Autowired
  65. private RuntimeService runtimeService;
  66. @Autowired
  67. private TApproveSpecModifyController approveSpecModifyController;
  68. @Autowired
  69. private TSpechiGlController tSpechiGlController;
  70. /**
  71. * 查询特种设备锅炉台账列表
  72. */
  73. @PreAuthorize("@ss.hasPermi('sems:specGl:list')")
  74. @GetMapping("/list")
  75. public TableDataInfo list(TSpecdevGl tSpecdevGl)
  76. {
  77. startPage();
  78. List<TSpecdevGl> list = tSpecdevGlService.selectTSpecdevGlList(tSpecdevGl);
  79. return getDataTable(list);
  80. }
  81. /**
  82. * 导出特种设备锅炉台账列表
  83. */
  84. @PreAuthorize("@ss.hasPermi('sems:specGl:export')")
  85. @Log(title = "特种设备锅炉台账", businessType = BusinessType.EXPORT)
  86. @GetMapping("/export")
  87. public AjaxResult export(TSpecdevGl tSpecdevGl)
  88. {
  89. List<TSpecdevGl> list = tSpecdevGlService.selectTSpecdevGlList(tSpecdevGl);
  90. ExcelUtil<TSpecdevGl> util = new ExcelUtil<TSpecdevGl>(TSpecdevGl.class);
  91. return util.exportExcel(list, "specGl");
  92. }
  93. /**
  94. * 获取特种设备锅炉台账详细信息
  95. */
  96. @PreAuthorize("@ss.hasPermi('sems:specGl:query')")
  97. @GetMapping(value = "/{id}")
  98. public AjaxResult getInfo(@PathVariable("id") Long id)
  99. {
  100. return AjaxResult.success(tSpecdevGlService.selectTSpecdevGlById(id));
  101. }
  102. /**
  103. * 新增特种设备锅炉台账
  104. */
  105. @PreAuthorize("@ss.hasPermi('sems:specGl:add')")
  106. @Log(title = "特种设备锅炉台账", businessType = BusinessType.INSERT)
  107. @PostMapping
  108. public AjaxResult add(@RequestBody TSpecdevGl tSpecdevGl)
  109. {
  110. tSpecdevGl.setApproveStatus(22l);
  111. tSpecdevGlService.insertTSpecdevGl(tSpecdevGl);
  112. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  113. Long userid = getUserId();
  114. tApproveSpecModify.setUserId(userid);
  115. tApproveSpecModify.setApproveType(3l);
  116. tApproveSpecModify.setDevType(4l);
  117. tApproveSpecModify.setDevId(String.valueOf(tSpecdevGl.getId()));
  118. //审批编号
  119. Date dt = new Date();
  120. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  121. String data = sdf.format(dt) + userid;
  122. tApproveSpecModify.setApNo(data);
  123. //
  124. Authentication.setAuthenticatedUserId(userid.toString());
  125. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  126. long bussniseeKey = tApproveSpecModify.getId();
  127. //开始工作流、监听
  128. Map<String, Object> variables = new HashMap<>();
  129. variables.put("applyUser", userid.toString());
  130. variables.put("wxjlusers", tSpecdevGl.getWxjl());
  131. //采用key来启动流程定义并设置流程变量,返回流程实例
  132. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  133. logger.info("流程部署id:" + pi.getDeploymentId());
  134. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  135. logger.info("流程实例id:" + pi.getProcessInstanceId());
  136. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  137. new Thread(() -> {
  138. approveSpecModifyController.sendMail(tApproveSpecModify , tSpecdevGl.getWxjl());
  139. },"发送邮件").start();
  140. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  141. String userName =loginUser != null? loginUser.getUsername(): "";
  142. new Thread(() -> {
  143. tSpechiGlController.addOperLog(String.valueOf(tSpecdevGl.getId()),userName,new Date() , "新增申请" );
  144. },"特种设备操作日志").start();
  145. return AjaxResult.success();
  146. }
  147. /**
  148. * 修改特种设备锅炉台账
  149. */
  150. @PreAuthorize("@ss.hasPermi('sems:specGl:edit')")
  151. @Log(title = "特种设备锅炉台账", businessType = BusinessType.UPDATE)
  152. @PutMapping
  153. public AjaxResult edit(@RequestBody TSpecdevGl tSpecdevGl)
  154. {
  155. TSpecdevGl old = tSpecdevGlService.selectTSpecdevGlById(tSpecdevGl.getId());
  156. if (StringUtils.isNotEmpty(tSpecdevGl.getReportNo()) && !tSpecdevGl.getReportNo().equals(old.getReportNo())) {
  157. TSpecCheck tc = new TSpecCheck();
  158. tc.setDevType(4l);
  159. tc.setCheckUnit(tSpecdevGl.getCheckUnit());
  160. tc.setDevId(tSpecdevGl.getId());
  161. tc.setNextWarnDate(tSpecdevGl.getNextWarnDate());
  162. tc.setReportNo(tSpecdevGl.getReportNo());
  163. tc.setWarnDate(tSpecdevGl.getWarnDate());
  164. tc.setCheckConclusion(tSpecdevGl.getCheckConclusion());
  165. tc.setOutWarnDate(tSpecdevGl.getOutWarnDate());
  166. tc.setOutReportNo(tSpecdevGl.getOutReportNo());
  167. tc.setOutCheckConclusion(tSpecdevGl.getOutCheckConclusion());
  168. tc.setOutNextWarnDate(tSpecdevGl.getOutNextWarnDate());
  169. tSpecCheckService.insertTSpecCheck(tc);
  170. }
  171. tSpecdevGlService.updateTSpecdevGl(tSpecdevGl);
  172. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  173. String userName =loginUser != null? loginUser.getUsername(): "";
  174. new Thread(() -> {
  175. tSpechiGlController.addOperLog(String.valueOf(tSpecdevGl.getId()),userName,new Date() , "修改" );
  176. },"特种设备操作日志").start();
  177. return AjaxResult.success();
  178. }
  179. /**
  180. * 删除特种设备锅炉台账
  181. */
  182. @PreAuthorize("@ss.hasPermi('sems:specGl:remove')")
  183. @Log(title = "特种设备锅炉台账", businessType = BusinessType.DELETE)
  184. @DeleteMapping("/{ids}")
  185. public AjaxResult remove(@PathVariable Long[] ids)
  186. {
  187. return toAjax(tSpecdevGlService.deleteTSpecdevGlByIds(ids));
  188. }
  189. /**
  190. * 去重
  191. */
  192. @PreAuthorize("@ss.hasPermi('sems:plant:remove')")
  193. @Log(title = "特种设备锅炉台账去重", businessType = BusinessType.OTHER)
  194. @GetMapping("/duplicate")
  195. public AjaxResult duplicate()
  196. {
  197. tSpecdevGlService.duplicateTSpecdevGl();
  198. return AjaxResult.success();
  199. }
  200. /**
  201. * 批量导入
  202. */
  203. @PreAuthorize("@ss.hasPermi('sems:specGl:add')")
  204. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  205. @PostMapping("/importData")
  206. public AjaxResult importData(@RequestParam("file") MultipartFile file,@RequestParam("wxjl") String wxjl) throws IOException
  207. {
  208. //获取操作人员ID
  209. Long userId = getUserId();
  210. //报错行数统计
  211. List<Integer> failRow =new ArrayList<Integer>();
  212. Workbook workbook = ExcelUtils.getWorkBook(file);
  213. Sheet sheet = workbook.getSheetAt(0);
  214. List<TSpecdevGl> list = new ArrayList<TSpecdevGl>();
  215. //字典查询
  216. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  217. //部门查询
  218. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  219. int rowNum = sheet.getPhysicalNumberOfRows();
  220. int failNumber = 0;
  221. for (int i = 1; i < rowNum; i++) {
  222. try {
  223. logger.info("读取行数:" + i);
  224. Row row = sheet.getRow(i);
  225. int cellNum = row.getLastCellNum();
  226. TSpecdevGl entity = new TSpecdevGl();
  227. for (int j = 0; j < cellNum; j++) {
  228. Cell cell = row.getCell(j);
  229. if (cell == null) {
  230. continue;
  231. }
  232. String cellValue = ExcelUtils.getCellValue(cell);
  233. logger.info("cellValue:" + cellValue);
  234. if (j == 0) {
  235. //序号
  236. } else if (j == 1) {
  237. entity.setPlantCode(cellValue);//装置名称
  238. } else if (j == 2) {
  239. entity.setUnit(cellValue);//单元
  240. } else if (j == 3) {
  241. entity.setPlantMaint(cellValue);//装置维修组
  242. } else if (j == 4) {
  243. entity.setEngineer(cellValue);//装置维修工程师
  244. } else if (j == 5) {
  245. entity.setDevno(cellValue);//位号
  246. } else if (j == 6) {
  247. entity.setDevname(cellValue);//设备名称
  248. } else if (j == 7) {
  249. entity.setModel(cellValue);//型号
  250. } else if (j == 8) {
  251. entity.setUseno(cellValue);//使用证号
  252. } else if (j == 9) {
  253. entity.setRegno(cellValue);//注册编号
  254. } else if (j == 10) {
  255. entity.setCreateUnit(cellValue);//制造单位
  256. } else if (j == 11) {
  257. entity.setBurnMode(cellValue);//燃烧方式
  258. } else if (j == 12) {
  259. entity.setWaterMode(cellValue);//水处理方式
  260. } else if (j == 13) {
  261. entity.setBurnKind(cellValue);//燃烧种类
  262. } else if (j == 14) {
  263. entity.setRatedPower(cellValue);//额定出力
  264. } else if (j == 15) {
  265. entity.setDesTemp(cellValue);//设计温度
  266. } else if (j == 16) {
  267. entity.setOptTemp(cellValue);//操作温度
  268. } else if (j == 17) {
  269. entity.setDesPressure(cellValue);//设计压力
  270. } else if (j == 18) {
  271. entity.setOptPressure(cellValue);//操作压力
  272. } else if (j == 19) {
  273. if (cellValue.length() > 3) {//投用日期
  274. entity.setSubmitdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  275. }
  276. } else if (j == 20) {
  277. entity.setCheckUnit(cellValue);//检验单位
  278. } else if (j == 21) {
  279. if (cellValue.length() > 3) {//本次内部检验日期
  280. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  281. }
  282. } else if (j == 22) {
  283. entity.setCheckConclusion(cellValue);//内部检验结论
  284. } else if (j == 23) {
  285. entity.setReportNo(cellValue);//内部检验报告编号
  286. } else if (j == 24) {
  287. if (cellValue.length() > 3) {//下次内部检验日期
  288. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  289. }
  290. } else if (j == 25) {
  291. if (cellValue.length() > 3) {//本次外部检验日期
  292. entity.setOutWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  293. }
  294. } else if (j == 26) {
  295. entity.setOutCheckConclusion(cellValue);//外部检验结论
  296. } else if (j == 27) {
  297. entity.setOutReportNo(cellValue);//外部检验报告编号
  298. } else if (j == 28) {
  299. if (cellValue.length() > 3) {//下次外部检验日期
  300. entity.setOutNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  301. }
  302. } else if (j == 29) {
  303. entity.setRemarks(cellValue);//备注
  304. }/*else if (j == 30) {
  305. for (SysDept d : dept) {
  306. if (d.getDeptName().equals(cellValue)) {
  307. entity.setDeptId(d.getDeptId());//部门编号
  308. }
  309. }
  310. }*/
  311. }
  312. entity.setCreaterCode(userId.toString());
  313. logger.info("entity:" + entity);
  314. list.add(entity);
  315. }catch (Exception e){
  316. failNumber++;
  317. logger.info("e:" + JSON.toJSONString(e));
  318. failRow.add(i + 1);
  319. }
  320. }
  321. int successNumber = 0;
  322. int failNum = 0;
  323. CopyOnWriteArrayList<String> ids = new CopyOnWriteArrayList();
  324. for (TSpecdevGl t : list
  325. ) {
  326. failNum++;
  327. try {
  328. t.setApproveStatus(22l);
  329. tSpecdevGlService.insertTSpecdevGl(t);
  330. ids.add(t.getId().toString());
  331. successNumber++;
  332. }catch (Exception e){
  333. failNumber++;
  334. logger.info("e:" + e);
  335. failRow.add(failNum + 1);
  336. }
  337. }
  338. //申请流程
  339. String devIds = StringUtils.join(ids.toArray(),",");
  340. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  341. Long userid = getUserId();
  342. tApproveSpecModify.setUserId(userid);
  343. tApproveSpecModify.setApproveType(3l);
  344. tApproveSpecModify.setDevType(4l);
  345. tApproveSpecModify.setDevId(devIds);
  346. //审批编号
  347. Date dt = new Date();
  348. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  349. String data = sdf.format(dt) + userid;
  350. tApproveSpecModify.setApNo(data);
  351. //
  352. Authentication.setAuthenticatedUserId(userid.toString());
  353. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  354. long bussniseeKey = tApproveSpecModify.getId();
  355. //开始工作流、监听
  356. Map<String, Object> variables = new HashMap<>();
  357. variables.put("applyUser", userid.toString());
  358. variables.put("wxjlusers", wxjl);
  359. //采用key来启动流程定义并设置流程变量,返回流程实例
  360. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  361. logger.info("流程部署id:" + pi.getDeploymentId());
  362. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  363. logger.info("流程实例id:" + pi.getProcessInstanceId());
  364. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  365. new Thread(() -> {
  366. approveSpecModifyController.sendMail(tApproveSpecModify , wxjl);
  367. },"发送邮件").start();
  368. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  369. String userName =loginUser != null? loginUser.getUsername(): "";
  370. new Thread(() -> {
  371. tSpechiGlController.addOperLog(ids.toArray(),userName,new Date() , "新增申请" );
  372. },"特种设备操作日志").start();
  373. logger.info("list:" + JSON.toJSONString(list));
  374. logger.info("successNumber:" +String.valueOf(successNumber));
  375. logger.info("failNumber:" +String.valueOf(failNumber));
  376. logger.info("failRow:" +String.valueOf(failRow));
  377. return AjaxResult.success(String.valueOf(successNumber), failRow);
  378. }
  379. /**
  380. * 批量导入
  381. * 检验更新导入
  382. */
  383. @PreAuthorize("@ss.hasPermi('sems:specGl:add')")
  384. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  385. @PostMapping("/updateData")
  386. public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException
  387. {
  388. //获取操作人员ID
  389. Long userId = getUserId();
  390. //报错行数统计
  391. List<Integer> failRow =new ArrayList<Integer>();
  392. Workbook workbook = ExcelUtils.getWorkBook(file);
  393. Sheet sheet = workbook.getSheetAt(0);
  394. List<TSpecdevGl> list = new ArrayList<TSpecdevGl>();
  395. List<TSpecdevGl> oldList = new ArrayList<TSpecdevGl>();
  396. TSpecdevGl oldEntity = new TSpecdevGl();
  397. //字典查询
  398. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  399. //部门查询
  400. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  401. int rowNum = sheet.getPhysicalNumberOfRows();
  402. int failNumber = 0;
  403. for (int i = 1; i < rowNum; i++) {
  404. try {
  405. logger.info("读取行数:" + i);
  406. Row row = sheet.getRow(i);
  407. int cellNum = row.getLastCellNum();
  408. TSpecdevGl entity = new TSpecdevGl();
  409. for (int j = 0; j < cellNum; j++) {
  410. Cell cell = row.getCell(j);
  411. if (cell == null) {
  412. continue;
  413. }
  414. String cellValue = ExcelUtils.getCellValue(cell);
  415. logger.info("cellValue:" + cellValue);
  416. if (j == 0) {
  417. //序号
  418. Double d = Double.parseDouble(cellValue);
  419. long s = new Double(d).longValue();
  420. entity.setId(s);
  421. } else if (j == 1) {
  422. entity.setPlantCode(cellValue);//装置名称
  423. } else if (j == 2) {
  424. entity.setDevno(cellValue);//位号
  425. } else if (j == 3) {
  426. entity.setDevname(cellValue);//设备名称
  427. } else if (j == 4) {
  428. entity.setUseno(cellValue);//使用证号
  429. } else if (j == 5) {
  430. entity.setCheckUnit(cellValue);//检验单位
  431. } else if (j == 6) {
  432. logger.info("日期格式:" + cellValue);
  433. if (cellValue.length() > 3) {//本次内部检验日期
  434. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  435. }
  436. } else if (j == 7) {
  437. entity.setCheckConclusion(cellValue);//内部检验结论
  438. } else if (j == 8) {
  439. entity.setReportNo(cellValue);//内部检验报告编号
  440. } else if (j == 9) {
  441. logger.info("日期格式:" + cellValue);
  442. if (cellValue.length() > 3) {//下次内部检验日期
  443. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  444. }
  445. } else if (j == 10) {
  446. logger.info("日期格式:" + cellValue);
  447. if (cellValue.length() > 3) {//本次外部检验日期
  448. entity.setOutWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  449. }
  450. } else if (j == 11) {
  451. entity.setOutCheckConclusion(cellValue);//外部检验结论
  452. } else if (j == 12) {
  453. entity.setOutReportNo(cellValue);//外部检验报告编号
  454. } else if (j == 13) {
  455. logger.info("日期格式:" + cellValue);
  456. if (cellValue.length() > 3) {//下次外部检验日期
  457. entity.setOutNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  458. }
  459. }
  460. }
  461. logger.info("entity:" + JSON.toJSONString(entity));
  462. list.add(entity);
  463. oldEntity = entity;
  464. oldList.add(oldEntity);
  465. }catch (Exception e){
  466. failNumber++;
  467. logger.info("e:" + JSON.toJSONString(e));
  468. failRow.add(i + 1);
  469. }
  470. }
  471. int successNumber = 0;
  472. int failNum = 0;
  473. for (TSpecdevGl t : list) {
  474. failNum++;
  475. try {
  476. tSpecdevGlService
  477. .update(t,
  478. new QueryWrapper<TSpecdevGl>()
  479. .eq("USENO", t.getUseno())
  480. .eq("PLANT_CODE", t.getPlantCode())
  481. .eq("DEVNO" , t.getDevno())
  482. );
  483. successNumber++;
  484. }catch (Exception e){
  485. failNumber++;
  486. logger.info("e:" + e);
  487. failRow.add(failNum + 1);
  488. e.printStackTrace();
  489. }
  490. }
  491. for (TSpecdevGl t : oldList) {
  492. TSpecCheck tc = new TSpecCheck();
  493. tc.setDevType(4l);
  494. tc.setCheckUnit(t.getCheckUnit());
  495. tc.setDevId(t.getId());
  496. tc.setNextWarnDate(t.getNextWarnDate());
  497. tc.setReportNo(t.getReportNo());
  498. tc.setWarnDate(t.getWarnDate());
  499. tc.setCheckConclusion(t.getCheckConclusion());
  500. tc.setOutWarnDate(t.getOutWarnDate());
  501. tc.setOutReportNo(t.getOutReportNo());
  502. tc.setOutCheckConclusion(t.getOutCheckConclusion());
  503. tc.setOutNextWarnDate(t.getOutNextWarnDate());
  504. tSpecCheckService.insertTSpecCheck(tc);
  505. }
  506. logger.info("list:" + JSON.toJSONString(list));
  507. logger.info("successNumber:" +String.valueOf(successNumber));
  508. logger.info("failNumber:" +String.valueOf(failNumber));
  509. logger.info("failRow:" +String.valueOf(failRow));
  510. return AjaxResult.success(String.valueOf(successNumber), failRow);
  511. }
  512. @GetMapping("/exportDevList")
  513. public AjaxResult exportbmy(ParamData params) throws IOException {
  514. logger.info(JSON.toJSONString(params));
  515. String id = params.getIds();
  516. String[] ids = id.split(",");
  517. List<TSpecdevGl> list = new ArrayList<>();
  518. for (String i : ids
  519. ) {
  520. TSpecdevGl t = tSpecdevGlService.getById(i);
  521. list.add(t);
  522. }
  523. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  524. CellStyle wrapStyle = wb.createCellStyle();
  525. wrapStyle.setWrapText(true); //设置自动换行
  526. //创建sheet页
  527. Sheet sheet = wb.createSheet("sheet1");
  528. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  529. sheet.setColumnWidth(0, 12*256);
  530. sheet.setColumnWidth(1, 26*256);
  531. sheet.setColumnWidth(2, 26*256);
  532. sheet.setColumnWidth(3, 26*256);
  533. sheet.setColumnWidth(4, 26*256);
  534. sheet.setColumnWidth(5, 26*256);
  535. sheet.setColumnWidth(6, 26*256);
  536. sheet.setColumnWidth(7, 26*256);
  537. sheet.setColumnWidth(8, 40*256);
  538. sheet.setColumnWidth(9, 40*256);
  539. sheet.setColumnWidth(10, 26*256);
  540. sheet.setColumnWidth(11, 26*256);
  541. sheet.setColumnWidth(12, 40*256);
  542. sheet.setColumnWidth(13, 40*256);
  543. //设置开始行和开始列
  544. Row row0 = sheet.createRow(0);
  545. CellStyle style = wb.createCellStyle();
  546. style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
  547. style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  548. // Font headerFont = wb.createFont();
  549. // headerFont.setFontName("Arial");
  550. // headerFont.setFontHeightInPoints((short) 12);
  551. // headerFont.setBold(false);
  552. // headerFont.setColor(IndexedColors.BLACK.getIndex());
  553. // style.setFont(headerFont);
  554. Cell cell0 = row0.createCell(0);
  555. row0.createCell(0).setCellValue("序号");
  556. row0.createCell(1).setCellValue("装置");
  557. row0.createCell(2).setCellValue("设备位号");
  558. row0.createCell(3).setCellValue("设备名称");
  559. row0.createCell(4).setCellValue("使用证号码");
  560. row0.createCell(5).setCellValue("检验单位");row0.getCell(5).setCellStyle(style);
  561. row0.createCell(6).setCellValue("本次内部检验日期");row0.getCell(6).setCellStyle(style);
  562. row0.createCell(7).setCellValue("内部检验结论");row0.getCell(7).setCellStyle(style);
  563. row0.createCell(8).setCellValue("内部检验报告编号");row0.getCell(8).setCellStyle(style);
  564. row0.createCell(9).setCellValue("下次内部检验日期");row0.getCell(9).setCellStyle(style);
  565. row0.createCell(10).setCellValue("本次外部检验日期");row0.getCell(10).setCellStyle(style);
  566. row0.createCell(11).setCellValue("外部检验结论");row0.getCell(11).setCellStyle(style);
  567. row0.createCell(12).setCellValue("外部检验报告编号");row0.getCell(12).setCellStyle(style);
  568. row0.createCell(13).setCellValue("下次外部检验日期");row0.getCell(13).setCellStyle(style);
  569. //填充数据
  570. int rowIndex = 1;
  571. int columnIndex = 1;
  572. for (TSpecdevGl t: list
  573. ) {
  574. Row row = sheet.createRow(rowIndex);
  575. row.createCell(0).setCellValue(t.getId());
  576. row.createCell(1).setCellValue(t.getPlantCode());
  577. row.createCell(2).setCellValue(t.getDevno());
  578. row.createCell(3).setCellValue(t.getDevname());
  579. row.createCell(4).setCellValue(t.getUseno());
  580. row.createCell(5).setCellValue(t.getCheckUnit());
  581. if (t.getWarnDate()!= null){
  582. row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
  583. }
  584. row.createCell(7).setCellValue(t.getCheckConclusion());
  585. row.createCell(8).setCellValue(t.getReportNo());
  586. if (t.getNextWarnDate()!= null){
  587. row.createCell(9).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
  588. }
  589. if (t.getOutWarnDate()!= null){
  590. row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getOutWarnDate()));
  591. }
  592. row.createCell(11).setCellValue(t.getOutCheckConclusion());
  593. row.createCell(12).setCellValue(t.getOutReportNo());
  594. if (t.getOutNextWarnDate()!= null){
  595. row.createCell(13).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getOutNextWarnDate()));
  596. }
  597. rowIndex++;
  598. }
  599. OutputStream out = null;
  600. String filename = ExcelUtil.encodingFilename("锅炉批量更新");
  601. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  602. wb.write(out);
  603. wb.close();
  604. out.close();
  605. return AjaxResult.success(filename);
  606. }
  607. }