TSpecdevCcController.java 25 KB

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