TSpecdevDzsbController.java 25 KB

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