TSpecdevDtController.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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.TSpechiDtController;
  19. import com.ruoyi.project.sems.his.domain.TApproveSpecModify;
  20. import com.ruoyi.project.sems.his.service.ITApproveSpecModifyService;
  21. import com.ruoyi.project.sems.mapper.TSpecdevDtMapper;
  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.domain.SysPlant;
  26. import com.ruoyi.project.system.domain.TAlarmtype;
  27. import com.ruoyi.project.system.mapper.SysPlantMapper;
  28. import com.ruoyi.project.system.service.ISysDeptService;
  29. import com.ruoyi.project.system.service.ISysDictTypeService;
  30. import com.ruoyi.project.system.service.ITAlarmtypeService;
  31. import org.activiti.engine.RuntimeService;
  32. import org.activiti.engine.impl.identity.Authentication;
  33. import org.activiti.engine.runtime.ProcessInstance;
  34. import org.apache.commons.lang.StringUtils;
  35. import org.apache.poi.ss.usermodel.*;
  36. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  37. import org.springframework.security.access.prepost.PreAuthorize;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.web.bind.annotation.*;
  40. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  41. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  42. import com.ruoyi.project.sems.domain.TSpecdevDt;
  43. import com.ruoyi.project.sems.service.ITSpecdevDtService;
  44. import com.ruoyi.framework.web.controller.BaseController;
  45. import com.ruoyi.framework.web.domain.AjaxResult;
  46. import com.ruoyi.common.utils.poi.ExcelUtil;
  47. import com.ruoyi.framework.web.page.TableDataInfo;
  48. import org.springframework.web.multipart.MultipartFile;
  49. import javax.annotation.Resource;
  50. /**
  51. * 特种设备电梯台账Controller
  52. *
  53. * @author ruoyi
  54. * @date 2021-07-26
  55. */
  56. @RestController
  57. @RequestMapping("/sems/specDt")
  58. public class TSpecdevDtController extends BaseController {
  59. @Autowired
  60. private ITSpecdevDtService tSpecdevDtService;
  61. @Autowired
  62. private ITSpecCheckService tSpecCheckService;
  63. @Autowired
  64. private ISysDeptService iSysDeptService;
  65. @Autowired
  66. private ISysDictTypeService iSysDictTypeService;
  67. @Autowired
  68. private ITApproveSpecModifyService tApproveSpecModifyService;
  69. @Autowired
  70. private RuntimeService runtimeService;
  71. @Autowired
  72. private TApproveSpecModifyController approveSpecModifyController;
  73. @Autowired
  74. private TSpechiDtController tSpechiDtController;
  75. //注入特种设备预警接口
  76. @Autowired
  77. private ITAlarmtypeService tAlarmtypeService;
  78. @Resource
  79. private SysPlantMapper sysPlantMapper;
  80. @Resource
  81. private TSpecdevDtMapper tSpecdevDtMapper;
  82. /**
  83. * 查询特种设备电梯台账列表
  84. */
  85. @PreAuthorize("@ss.hasPermi('sems:specDt:list')")
  86. @GetMapping("/list")
  87. public TableDataInfo list(TSpecdevDt tSpecdevDt) {
  88. startPage();
  89. List<TSpecdevDt> list = tSpecdevDtService.selectTSpecdevDtList(tSpecdevDt);
  90. return getDataTable(list);
  91. }
  92. /**
  93. * 导出特种设备电梯台账列表
  94. */
  95. @PreAuthorize("@ss.hasPermi('sems:specDt:export')")
  96. @Log(title = "特种设备电梯台账", businessType = BusinessType.EXPORT)
  97. @GetMapping("/export")
  98. public AjaxResult export(TSpecdevDt tSpecdevDt) {
  99. List<TSpecdevDt> list = tSpecdevDtService.selectTSpecdevDtList(tSpecdevDt);
  100. ExcelUtil<TSpecdevDt> util = new ExcelUtil<TSpecdevDt>(TSpecdevDt.class);
  101. return util.exportExcel(list, "specDt");
  102. }
  103. /**
  104. * 获取特种设备电梯台账详细信息
  105. */
  106. @PreAuthorize("@ss.hasPermi('sems:specDt:query')")
  107. @GetMapping(value = "/{id}")
  108. public AjaxResult getInfo(@PathVariable("id") Long id) {
  109. return AjaxResult.success(tSpecdevDtService.selectTSpecdevDtById(id));
  110. }
  111. /**
  112. * 新增特种设备电梯台账
  113. */
  114. @PreAuthorize("@ss.hasPermi('sems:specDt:add')")
  115. @Log(title = "特种设备电梯台账", businessType = BusinessType.INSERT)
  116. @PostMapping
  117. public AjaxResult add(@RequestBody TSpecdevDt tSpecdevDt) {
  118. tSpecdevDt.setApproveStatus(22l);
  119. tSpecdevDtService.insertTSpecdevDt(tSpecdevDt);
  120. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  121. Long userid = getUserId();
  122. tApproveSpecModify.setUserId(userid);
  123. tApproveSpecModify.setApproveType(3l);
  124. tApproveSpecModify.setDevType(5l);
  125. tApproveSpecModify.setDevId(String.valueOf(tSpecdevDt.getId()));
  126. //审批编号
  127. Date dt = new Date();
  128. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  129. String data = sdf.format(dt) + userid;
  130. tApproveSpecModify.setApNo(data);
  131. //
  132. Authentication.setAuthenticatedUserId(userid.toString());
  133. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  134. long bussniseeKey = tApproveSpecModify.getId();
  135. //开始工作流、监听
  136. Map<String, Object> variables = new HashMap<>();
  137. variables.put("applyUser", userid.toString());
  138. variables.put("wxjlusers", tSpecdevDt.getWxjl());
  139. //采用key来启动流程定义并设置流程变量,返回流程实例
  140. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  141. logger.info("流程部署id:" + pi.getDeploymentId());
  142. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  143. logger.info("流程实例id:" + pi.getProcessInstanceId());
  144. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  145. new Thread(() -> {
  146. approveSpecModifyController.sendMail(tApproveSpecModify , tSpecdevDt.getWxjl());
  147. },"发送邮件").start();
  148. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  149. String userName =loginUser != null? loginUser.getUsername(): "";
  150. new Thread(() -> {
  151. tSpechiDtController.addOperLog(String.valueOf(tSpecdevDt.getId()),userName,new Date() , "新增申请" );
  152. },"特种设备操作日志").start();
  153. return AjaxResult.success();
  154. }
  155. /**
  156. * 修改特种设备电梯台账
  157. */
  158. @PreAuthorize("@ss.hasPermi('sems:specDt:edit')")
  159. @Log(title = "特种设备电梯台账", businessType = BusinessType.UPDATE)
  160. @PutMapping
  161. public AjaxResult edit(@RequestBody TSpecdevDt tSpecdevDt) {
  162. TSpecdevDt old = tSpecdevDtService.selectTSpecdevDtById(tSpecdevDt.getId());
  163. if (StringUtils.isNotEmpty(tSpecdevDt.getReportNo()) && !tSpecdevDt.getReportNo().equals(old.getReportNo())) {
  164. TSpecCheck tc = new TSpecCheck();
  165. tc.setDevType(5l);
  166. tc.setCheckUnit(tSpecdevDt.getCheckUnit());
  167. tc.setDevId(tSpecdevDt.getId());
  168. tc.setNextWarnDate(tSpecdevDt.getNextWarnDate());
  169. tc.setReportNo(tSpecdevDt.getReportNo());
  170. tc.setWarnDate(tSpecdevDt.getWarnDate());
  171. tc.setCheckConclusion(tSpecdevDt.getPerTestConclusion());
  172. tSpecCheckService.insertTSpecCheck(tc);
  173. }
  174. tSpecdevDtService.updateTSpecdevDt(tSpecdevDt);
  175. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  176. String userName =loginUser != null? loginUser.getUsername(): "";
  177. new Thread(() -> {
  178. tSpechiDtController.addOperLog(String.valueOf(tSpecdevDt.getId()),userName,new Date() , "修改" );
  179. },"特种设备操作日志").start();
  180. new Thread(() -> {
  181. this.checkWarnflag();
  182. },"特种设备warnflag更新").start();
  183. return AjaxResult.success();
  184. }
  185. /**
  186. * 修改特种设备电梯台账
  187. */
  188. @PreAuthorize("@ss.hasPermi('sems:specDt:edit')")
  189. @Log(title = "特种设备电梯台账", businessType = BusinessType.UPDATE)
  190. @PutMapping("/editBatch")
  191. public AjaxResult editBatch(@RequestBody TSpecdevDt tSpecdevDt) {
  192. tSpecdevDtMapper.updateTSpecdevDtByIds(tSpecdevDt);
  193. return AjaxResult.success();
  194. }
  195. /**
  196. * 删除特种设备电梯台账
  197. */
  198. @PreAuthorize("@ss.hasPermi('sems:specDt:remove')")
  199. @Log(title = "特种设备电梯台账", businessType = BusinessType.DELETE)
  200. @DeleteMapping("/{ids}")
  201. public AjaxResult remove(@PathVariable Long[] ids) {
  202. return toAjax(tSpecdevDtService.deleteTSpecdevDtByIds(ids));
  203. }
  204. /**
  205. * 去重
  206. */
  207. @PreAuthorize("@ss.hasRole('admin')")
  208. @Log(title = "特种设备电梯台账去重", businessType = BusinessType.OTHER)
  209. @GetMapping("/duplicate")
  210. public AjaxResult duplicate() {
  211. tSpecdevDtService.duplicateTSpecdevDt();
  212. return AjaxResult.success();
  213. }
  214. /**
  215. * 批量导入
  216. */
  217. @PreAuthorize("@ss.hasPermi('sems:specDt:add')")
  218. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  219. @PostMapping("/importData")
  220. public AjaxResult importData(@RequestParam("file") MultipartFile file,@RequestParam("wxjl") String wxjl) throws IOException {
  221. //获取操作人员ID
  222. Long userId = getUserId();
  223. //报错行数统计
  224. List<Integer> failRow = new ArrayList<Integer>();
  225. Workbook workbook = ExcelUtils.getWorkBook(file);
  226. Sheet sheet = workbook.getSheetAt(0);
  227. List<TSpecdevDt> list = new ArrayList<TSpecdevDt>();
  228. //字典查询
  229. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  230. List<SysPlant> plants = sysPlantMapper.selectSysPlantList(new SysPlant());
  231. //部门查询
  232. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  233. int rowNum = sheet.getPhysicalNumberOfRows();
  234. int failNumber = 0;
  235. for (int i = 1; i < rowNum; i++) {
  236. try {
  237. logger.info("读取行数:" + i);
  238. Row row = sheet.getRow(i);
  239. int cellNum = row.getPhysicalNumberOfCells();
  240. TSpecdevDt entity = new TSpecdevDt();
  241. for (int j = 0; j < cellNum; j++) {
  242. Cell cell = row.getCell(j);
  243. if (cell == null) {
  244. continue;
  245. }
  246. String cellValue = ExcelUtils.getCellValue(cell);
  247. logger.info("cellValue:" + cellValue);
  248. if (j == 0) {
  249. //序号
  250. } else if (j == 1) {
  251. entity.setPlantCode(cellValue);//装置名称
  252. //判断是否存在的plant
  253. boolean found = false;
  254. for (SysPlant p : plants) {
  255. if (p.getName().equals(cellValue)) {
  256. found = true;
  257. break;
  258. }
  259. }
  260. if (!found) {
  261. //未发现plant
  262. throw new Exception("未发现plant");
  263. }
  264. } else if (j == 2) {
  265. entity.setUnit(cellValue);//单元
  266. } else if (j == 3) {
  267. entity.setDocno(cellValue);//档案号
  268. } else if (j == 4) {
  269. entity.setUseDept(cellValue);// 使用部门
  270. } else if (j == 5) {
  271. entity.setPlantMaint(cellValue);// 装置维修组
  272. } else if (j == 6) {
  273. entity.setDevname(cellValue);//名称
  274. } else if (j == 7) {
  275. entity.setRegno(cellValue);//设备注册编号
  276. } else if (j == 8) {
  277. entity.setModel(cellValue);//型号
  278. } else if (j == 9) {
  279. entity.setCapacity(cellValue);//额定载重
  280. } else if (j == 10) {
  281. entity.setFloor(cellValue);//层站数
  282. } else if (j == 11) {
  283. entity.setCreateUnit(cellValue);//制造单位
  284. } else if (j == 12) {
  285. entity.setLocation(cellValue);//使用地点
  286. } else if (j == 13) {
  287. if (cellValue.length() > 3) {//初检日期
  288. entity.setFirstWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  289. }
  290. } else if (j == 14) {
  291. if (cellValue.length() > 3) {//检验日期
  292. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  293. }
  294. } else if (j == 15) {
  295. entity.setCheckUnit(cellValue);//检验单位
  296. } else if (j == 16) {
  297. entity.setReportNo(cellValue);//报告编号
  298. } else if (j == 17) {
  299. if (cellValue.length() > 3) {//下次年检日期
  300. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  301. }
  302. } else if (j == 18) {
  303. entity.setPerTestConclusion(cellValue);//备注
  304. } else if (j == 19) {
  305. entity.setRemarks(cellValue);//备注
  306. }else if (j == 20) {
  307. entity.setRemarks2(cellValue);//备注2
  308. }/*else if (j == 17) {
  309. for (SysDept d : dept) {
  310. if (d.getDeptName().equals(cellValue)) {
  311. entity.setDeptId(d.getDeptId());//部门编号
  312. }
  313. }
  314. }*/
  315. }
  316. entity.setCreaterCode(userId);
  317. logger.info("entity:" + entity);
  318. list.add(entity);
  319. } catch (Exception e) {
  320. failNumber++;
  321. logger.info("e:" + JSON.toJSONString(e));
  322. failRow.add(i + 1);
  323. }
  324. }
  325. int successNumber = 0;
  326. int failNum = 0;
  327. CopyOnWriteArrayList<String> ids = new CopyOnWriteArrayList();
  328. for (TSpecdevDt t : list
  329. ) {
  330. failNum++;
  331. try {
  332. t.setApproveStatus(22l);
  333. tSpecdevDtService.insertTSpecdevDt(t);
  334. ids.add(t.getId().toString());
  335. successNumber++;
  336. } catch (Exception e) {
  337. failNumber++;
  338. logger.info("e:" + e);
  339. failRow.add(failNum + 1);
  340. }
  341. }
  342. //申请流程
  343. String devIds = StringUtils.join(ids.toArray(),",");
  344. TApproveSpecModify tApproveSpecModify = new TApproveSpecModify();
  345. Long userid = getUserId();
  346. tApproveSpecModify.setUserId(userid);
  347. tApproveSpecModify.setApproveType(3l);
  348. tApproveSpecModify.setDevType(5l);
  349. tApproveSpecModify.setDevId(devIds);
  350. //审批编号
  351. Date dt = new Date();
  352. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
  353. String data = sdf.format(dt) + userid;
  354. tApproveSpecModify.setApNo(data);
  355. //
  356. Authentication.setAuthenticatedUserId(userid.toString());
  357. tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify);
  358. long bussniseeKey = tApproveSpecModify.getId();
  359. //开始工作流、监听
  360. Map<String, Object> variables = new HashMap<>();
  361. variables.put("applyUser", userid.toString());
  362. variables.put("wxjlusers", wxjl);
  363. //采用key来启动流程定义并设置流程变量,返回流程实例
  364. ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables);
  365. logger.info("流程部署id:" + pi.getDeploymentId());
  366. logger.info("流程定义id:" + pi.getProcessDefinitionId());
  367. logger.info("流程实例id:" + pi.getProcessInstanceId());
  368. tApproveSpecModify.setProcessId(pi.getProcessInstanceId());
  369. new Thread(() -> {
  370. approveSpecModifyController.sendMail(tApproveSpecModify , wxjl);
  371. },"发送邮件").start();
  372. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  373. String userName =loginUser != null? loginUser.getUsername(): "";
  374. new Thread(() -> {
  375. tSpechiDtController.addOperLog(ids.toArray(),userName,new Date() , "新增申请" );
  376. },"特种设备操作日志").start();
  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. /**
  384. * 批量导入
  385. * 检验更新中的批量导入
  386. */
  387. @PreAuthorize("@ss.hasPermi('sems:specDt:add')")
  388. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  389. @PostMapping("/updateData")
  390. public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException {
  391. //获取操作人员ID
  392. Long userId = getUserId();
  393. //报错行数统计
  394. List<Integer> failRow = new ArrayList<Integer>();
  395. Workbook workbook = ExcelUtils.getWorkBook(file);
  396. Sheet sheet = workbook.getSheetAt(0);
  397. List<TSpecdevDt> list = new ArrayList<TSpecdevDt>();
  398. List<TSpecdevDt> oldList = new ArrayList<TSpecdevDt>();
  399. TSpecdevDt oldEntity = new TSpecdevDt();
  400. //字典查询
  401. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  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.getLastCellNum();
  411. TSpecdevDt entity = new TSpecdevDt();
  412. for (int j = 0; j < cellNum; j++) {
  413. Cell cell = row.getCell(j);
  414. if (cell == null) {
  415. continue;
  416. }
  417. String cellValue = ExcelUtils.getCellValue(cell);
  418. logger.info("cellValue:" + cellValue);
  419. if (j == 0) {
  420. //序号
  421. Double d = Double.parseDouble(cellValue);
  422. long s = new Double(d).longValue();
  423. entity.setId(s);
  424. } else if (j == 1) { //装置名称
  425. entity.setPlantCode(cellValue);
  426. } else if (j == 2) { //档案号
  427. entity.setDocno(cellValue);
  428. } else if (j == 3) { //型号
  429. entity.setModel(cellValue);
  430. } else if (j == 4) { //使用地点
  431. entity.setLocation(cellValue);
  432. } else if (j == 5) { //检验日期
  433. logger.info("日期格式:" + cellValue);
  434. if (cellValue.length() > 3) {
  435. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  436. }
  437. } else if (j == 6) { //检验单位
  438. entity.setCheckUnit(cellValue);
  439. } else if (j == 7) { //报告编号
  440. entity.setReportNo(cellValue);
  441. } else if (j == 8) { //下次年度检查日期
  442. logger.info("日期格式:" + cellValue);
  443. if (cellValue.length() > 3) {
  444. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  445. }
  446. } else if (j == 9) { //定期结论
  447. entity.setPerTestConclusion(cellValue);
  448. }else if (j == 10) { //备注
  449. entity.setRemarks(cellValue);
  450. }else if (j == 11) { //备注2
  451. entity.setRemarks2(cellValue);
  452. }
  453. }
  454. logger.info("entity:" + JSON.toJSONString(entity));
  455. list.add(entity);
  456. oldEntity = entity;
  457. oldList.add(oldEntity);
  458. } catch (Exception e) {
  459. failNumber++;
  460. logger.info("e:" + JSON.toJSONString(e));
  461. failRow.add(i + 1);
  462. }
  463. }
  464. int successNumber = 0;
  465. int failNum = 0;
  466. List<String> ids = new ArrayList<>();
  467. for (TSpecdevDt t : list) {
  468. failNum++;
  469. try {
  470. tSpecdevDtService
  471. .update(t,
  472. new QueryWrapper<TSpecdevDt>()
  473. .eq("DOCNO", t.getDocno())
  474. .eq("PLANT_CODE", t.getPlantCode())
  475. );
  476. successNumber++;
  477. ids.add(t.getId().toString());
  478. } catch (Exception e) {
  479. failNumber++;
  480. logger.info("e:" + e);
  481. failRow.add(failNum + 1);
  482. e.printStackTrace();
  483. }
  484. }
  485. for (TSpecdevDt t : oldList) {
  486. try {
  487. TSpecCheck tc = new TSpecCheck();
  488. tc.setDevType(5l);
  489. tc.setCheckUnit(t.getCheckUnit());
  490. tc.setDevId(t.getId());
  491. tc.setNextWarnDate(t.getNextWarnDate());
  492. tc.setReportNo(t.getReportNo());
  493. tc.setWarnDate(t.getWarnDate());
  494. tc.setCheckConclusion(t.getPerTestConclusion());
  495. tSpecCheckService.insertTSpecCheck(tc);
  496. }catch (Exception e) {
  497. logger.info("e:" + e);
  498. e.printStackTrace();
  499. }
  500. }
  501. LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
  502. String userName =loginUser != null? loginUser.getUsername(): "";
  503. new Thread(() -> {
  504. tSpechiDtController.addOperLog(ids.toArray(),userName,new Date() , "批量更新" );
  505. },"特种设备操作日志").start();
  506. new Thread(() -> {
  507. this.checkWarnflag();
  508. },"特种设备warnflag更新").start();
  509. logger.info("list:" + JSON.toJSONString(list));
  510. logger.info("successNumber:" + String.valueOf(successNumber));
  511. logger.info("failNumber:" + String.valueOf(failNumber));
  512. logger.info("failRow:" + String.valueOf(failRow));
  513. return AjaxResult.success(String.valueOf(successNumber), failRow);
  514. }
  515. @GetMapping("/exportDevList")
  516. public AjaxResult exportbmy(ParamData params) throws IOException {
  517. logger.info(JSON.toJSONString(params));
  518. String id = params.getIds();
  519. String[] ids = id.split(",");
  520. List<TSpecdevDt> list = new ArrayList<>();
  521. for (String i : ids
  522. ) {
  523. TSpecdevDt t = tSpecdevDtService.getById(i);
  524. list.add(t);
  525. }
  526. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  527. CellStyle wrapStyle = wb.createCellStyle();
  528. wrapStyle.setWrapText(true); //设置自动换行
  529. //创建sheet页
  530. Sheet sheet = wb.createSheet("sheet1");
  531. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  532. sheet.setColumnWidth(0, 12 * 256);
  533. sheet.setColumnWidth(1, 26 * 256);
  534. sheet.setColumnWidth(2, 26 * 256);
  535. sheet.setColumnWidth(3, 26 * 256);
  536. sheet.setColumnWidth(4, 26 * 256);
  537. sheet.setColumnWidth(5, 26 * 256);
  538. sheet.setColumnWidth(6, 26 * 256);
  539. sheet.setColumnWidth(7, 26 * 256);
  540. sheet.setColumnWidth(8, 40 * 256);
  541. sheet.setColumnWidth(9, 40 * 256);
  542. sheet.setColumnWidth(10, 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("检验日期");
  561. row0.getCell(5).setCellStyle(style);
  562. row0.createCell(6).setCellValue("检验单位");
  563. row0.getCell(6).setCellStyle(style);
  564. row0.createCell(7).setCellValue("报告编号");
  565. row0.getCell(7).setCellStyle(style);
  566. row0.createCell(8).setCellValue("下次检验日期");
  567. row0.getCell(8).setCellStyle(style);
  568. row0.createCell(9).setCellValue("定期检验结论");
  569. row0.getCell(9).setCellStyle(style);
  570. row0.createCell(10).setCellValue("备注");
  571. row0.getCell(10).setCellStyle(style);
  572. row0.createCell(11).setCellValue("备注2(如报告未到备注在此处)");
  573. row0.getCell(11).setCellStyle(style);
  574. //填充数据
  575. int rowIndex = 1;
  576. int columnIndex = 1;
  577. for (TSpecdevDt t : list
  578. ) {
  579. Row row = sheet.createRow(rowIndex);
  580. row.createCell(0).setCellValue(t.getId());
  581. row.createCell(1).setCellValue(t.getPlantCode());
  582. row.createCell(2).setCellValue(t.getDocno());
  583. row.createCell(3).setCellValue(t.getModel());
  584. row.createCell(4).setCellValue(t.getLocation());
  585. if (t.getWarnDate() != null) {
  586. row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
  587. }
  588. row.createCell(6).setCellValue(t.getCheckUnit());
  589. row.createCell(7).setCellValue(t.getReportNo());
  590. if (t.getNextWarnDate() != null) {
  591. row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
  592. }
  593. row.createCell(9).setCellValue(t.getPerTestConclusion());
  594. row.createCell(10).setCellValue(t.getRemarks());
  595. row.createCell(11).setCellValue(t.getRemarks2());
  596. rowIndex++;
  597. }
  598. OutputStream out = null;
  599. String filename = ExcelUtil.encodingFilename("电梯批量更新");
  600. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  601. wb.write(out);
  602. wb.close();
  603. out.close();
  604. return AjaxResult.success(filename);
  605. }
  606. public void checkWarnflag(){
  607. //获取动态处理预警级别
  608. TAlarmtype tAlarmtype = this.tAlarmtypeService.selectTAlarmtypeById(1080L);
  609. if (tAlarmtype.getIsOpen() == 0) {
  610. logger.info("特种设备预警标识定时任务未启用");
  611. return;
  612. }
  613. Long firstlevel = tAlarmtype.getFirstlevel();//1级
  614. Long secondlevel = tAlarmtype.getSecondlevel();//2级
  615. Long thirdlevel = tAlarmtype.getThirdlevel();//3级
  616. List<TSpecdevDt> list = tSpecdevDtService.list(new QueryWrapper<TSpecdevDt>()
  617. .eq("del_flag", 0).eq("status", "1"));
  618. List<TSpecdevDt> firstList = new ArrayList<>();
  619. List<TSpecdevDt> secondList = new ArrayList<>();
  620. List<TSpecdevDt> thirdList = new ArrayList<>();
  621. for (TSpecdevDt tSpecdevDt : list) {
  622. if (tSpecdevDt.getNextWarnDate() != null) {
  623. long now = System.currentTimeMillis();
  624. long diff = tSpecdevDt.getNextWarnDate().getTime() - now;
  625. long nd = 1000 * 24 * 60 * 60;
  626. long day = diff / nd;
  627. // 半年内 预警标识为2级
  628. if (day > 0 && day <= secondlevel) {
  629. this.updateForDt(2L, tSpecdevDt);
  630. //只在当天发送邮件
  631. if (day == secondlevel) {
  632. firstList.add(tSpecdevDt);
  633. }
  634. continue;
  635. }
  636. // 半年-一年 预警标识为1级
  637. if (day > secondlevel && day <= thirdlevel) {
  638. this.updateForDt(1L, tSpecdevDt);
  639. //只在当天发送邮件
  640. if (day == thirdlevel) {
  641. secondList.add(tSpecdevDt);
  642. }
  643. continue;
  644. }
  645. // 超时 预警标识为3级
  646. if (day <= firstlevel) {
  647. this.updateForDt(3L, tSpecdevDt);
  648. //只在当天发送邮件
  649. if (day == firstlevel) {
  650. thirdList.add(tSpecdevDt);
  651. }
  652. continue;
  653. }
  654. if (day > thirdlevel ) {
  655. this.updateForDt(0L, tSpecdevDt);
  656. continue;
  657. }
  658. }
  659. }
  660. }
  661. private void updateForDt(Long flag, TSpecdevDt tSpecdevDt) {
  662. tSpecdevDt.setWarnFlag(flag);
  663. this.tSpecdevDtService.updateTSpecdevDt(tSpecdevDt);
  664. }
  665. }