TSpecdevYlgdController.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. package com.ruoyi.project.sems.controller;
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.text.SimpleDateFormat;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.concurrent.CopyOnWriteArrayList;
  9. import java.util.concurrent.CountDownLatch;
  10. import java.util.concurrent.ExecutorService;
  11. import java.util.concurrent.Executors;
  12. import java.util.concurrent.atomic.AtomicInteger;
  13. import com.alibaba.fastjson.JSON;
  14. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  15. import com.ruoyi.common.utils.DateUtils;
  16. import com.ruoyi.common.utils.file.ExcelUtils;
  17. import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
  18. import com.ruoyi.project.sems.domain.*;
  19. import com.ruoyi.project.sems.service.ITSpecCheckService;
  20. import com.ruoyi.project.system.domain.SysDept;
  21. import com.ruoyi.project.system.domain.SysDictData;
  22. import com.ruoyi.project.system.service.ISysDeptService;
  23. import com.ruoyi.project.system.service.ISysDictTypeService;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.apache.poi.ss.usermodel.*;
  26. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  27. import org.springframework.security.access.prepost.PreAuthorize;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.web.bind.annotation.*;
  30. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  31. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  32. import com.ruoyi.project.sems.service.ITSpecdevYlgdService;
  33. import com.ruoyi.framework.web.controller.BaseController;
  34. import com.ruoyi.framework.web.domain.AjaxResult;
  35. import com.ruoyi.common.utils.poi.ExcelUtil;
  36. import com.ruoyi.framework.web.page.TableDataInfo;
  37. import org.springframework.web.multipart.MultipartFile;
  38. /**
  39. * 特种设备压力管道台账Controller
  40. *
  41. * @author ruoyi
  42. * @date 2021-07-22
  43. */
  44. @RestController
  45. @RequestMapping("/sems/specYlgd")
  46. public class TSpecdevYlgdController extends BaseController {
  47. @Autowired
  48. private ITSpecdevYlgdService tSpecdevYlgdService;
  49. @Autowired
  50. private ITSpecCheckService tSpecCheckService;
  51. @Autowired
  52. private ISysDeptService iSysDeptService;
  53. @Autowired
  54. private ISysDictTypeService iSysDictTypeService;
  55. /**
  56. * 查询特种设备压力管道台账列表
  57. */
  58. @PreAuthorize("@ss.hasPermi('sems:specYlgd:list')")
  59. @GetMapping("/list")
  60. public TableDataInfo list(TSpecdevYlgd tSpecdevYlgd) {
  61. startPage();
  62. List<TSpecdevYlgd> list = tSpecdevYlgdService.selectTSpecdevYlgdList(tSpecdevYlgd);
  63. return getDataTable(list);
  64. }
  65. /**
  66. * 导出特种设备压力管道台账列表
  67. */
  68. @PreAuthorize("@ss.hasPermi('sems:specYlgd:export')")
  69. @Log(title = "特种设备压力管道台账", businessType = BusinessType.EXPORT)
  70. @GetMapping("/export")
  71. public AjaxResult export(TSpecdevYlgd tSpecdevYlgd) {
  72. List<TSpecdevYlgd> list = tSpecdevYlgdService.selectTSpecdevYlgdList(tSpecdevYlgd);
  73. ExcelUtil<TSpecdevYlgd> util = new ExcelUtil<TSpecdevYlgd>(TSpecdevYlgd.class);
  74. return util.exportExcel(list, "specYlgd");
  75. }
  76. /**
  77. * 获取特种设备压力管道台账详细信息
  78. */
  79. @PreAuthorize("@ss.hasPermi('sems:specYlgd:query')")
  80. @GetMapping(value = "/{id}")
  81. public AjaxResult getInfo(@PathVariable("id") Long id) {
  82. return AjaxResult.success(tSpecdevYlgdService.selectTSpecdevYlgdById(id));
  83. }
  84. /**
  85. * 新增特种设备压力管道台账
  86. */
  87. @PreAuthorize("@ss.hasPermi('sems:specYlgd:add')")
  88. @Log(title = "特种设备压力管道台账", businessType = BusinessType.INSERT)
  89. @PostMapping
  90. public AjaxResult add(@RequestBody TSpecdevYlgd tSpecdevYlgd) {
  91. return toAjax(tSpecdevYlgdService.insertTSpecdevYlgd(tSpecdevYlgd));
  92. }
  93. /**
  94. * 修改特种设备压力管道台账
  95. */
  96. @PreAuthorize("@ss.hasPermi('sems:specYlgd:edit')")
  97. @Log(title = "特种设备压力管道台账", businessType = BusinessType.UPDATE)
  98. @PutMapping
  99. public AjaxResult edit(@RequestBody TSpecdevYlgd tSpecdevYlgd) {
  100. TSpecdevYlgd old = tSpecdevYlgdService.selectTSpecdevYlgdById(tSpecdevYlgd.getId());
  101. if (StringUtils.isNotEmpty(tSpecdevYlgd.getReportNo()) && !tSpecdevYlgd.getReportNo().equals(old.getReportNo())) {
  102. TSpecCheck tc = new TSpecCheck();
  103. tc.setDevType(2l);
  104. tc.setCheckUnit(tSpecdevYlgd.getCheckUnit());
  105. tc.setDevId(tSpecdevYlgd.getId());
  106. tc.setNextWarnDate(tSpecdevYlgd.getNextWarnDate());
  107. tc.setReportNo(tSpecdevYlgd.getReportNo());
  108. tc.setWarnDate(tSpecdevYlgd.getWarnDate());
  109. tc.setYearNextWarnDate(tSpecdevYlgd.getYearNextWarnDate());
  110. tc.setYearWarnDate(tSpecdevYlgd.getYearWarnDate());
  111. tc.setYearReportNo(tSpecdevYlgd.getReportNo());
  112. tc.setSafeClass(tSpecdevYlgd.getSafeClass());
  113. tc.setCheckConclusion(tSpecdevYlgd.getCheckConclusion());
  114. tSpecCheckService.insertTSpecCheck(tc);
  115. }
  116. return toAjax(tSpecdevYlgdService.updateTSpecdevYlgd(tSpecdevYlgd));
  117. }
  118. /**
  119. * 删除特种设备压力管道台账
  120. */
  121. @PreAuthorize("@ss.hasPermi('sems:specYlgd:remove')")
  122. @Log(title = "特种设备压力管道台账", businessType = BusinessType.DELETE)
  123. @DeleteMapping("/{ids}")
  124. public AjaxResult remove(@PathVariable Long[] ids) {
  125. return toAjax(tSpecdevYlgdService.deleteTSpecdevYlgdByIds(ids));
  126. }
  127. /**
  128. * 去重
  129. */
  130. @PreAuthorize("@ss.hasPermi('sems:plant:remove')")
  131. @Log(title = "特种设备压力管道台账去重", businessType = BusinessType.OTHER)
  132. @GetMapping("/duplicate")
  133. public AjaxResult duplicate() {
  134. tSpecdevYlgdService.duplicateTSpecdevYlgd();
  135. return AjaxResult.success();
  136. }
  137. /**
  138. * 批量导入
  139. */
  140. @PreAuthorize("@ss.hasPermi('sems:specYlgd:add')")
  141. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  142. @PostMapping("/importData")
  143. public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
  144. //获取操作人员ID
  145. Long userId = getUserId();
  146. //报错行数统计
  147. List<Integer> failRow = new ArrayList<Integer>();
  148. Workbook workbook = ExcelUtils.getWorkBook(file);
  149. Sheet sheet = workbook.getSheetAt(0);
  150. List<TSpecdevYlgd> list = new ArrayList<TSpecdevYlgd>();
  151. //字典查询
  152. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  153. //部门查询
  154. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  155. int rowNum = sheet.getPhysicalNumberOfRows();
  156. AtomicInteger failNumber = new AtomicInteger();
  157. for (int i = 1; i < rowNum; i++) {
  158. try {
  159. logger.info("读取行数:" + i);
  160. Row row = sheet.getRow(i);
  161. int cellNum = row.getLastCellNum();
  162. TSpecdevYlgd entity = new TSpecdevYlgd();
  163. for (int j = 0; j < cellNum; j++) {
  164. Cell cell = row.getCell(j);
  165. if (cell == null) {
  166. continue;
  167. }
  168. String cellValue = ExcelUtils.getCellValue(cell);
  169. logger.info("cellValue:" + cellValue);
  170. if (j == 0) {
  171. //序号
  172. } else if (j == 1) {
  173. entity.setPlantCode(cellValue);//装置名称
  174. } else if (j == 2) {
  175. entity.setUnit(cellValue);//单元
  176. } else if (j == 3) {
  177. entity.setPlantMaint(cellValue);//装置维修组
  178. } else if (j == 4) {
  179. entity.setEngineer(cellValue);//装置维修工程师
  180. } else if (j == 5) {
  181. entity.setDevname(cellValue);//管道名称
  182. } else if (j == 6) {
  183. entity.setDevno(cellValue);//管道编号
  184. } else if (j == 7) {
  185. entity.setRegno(cellValue);//压力管道工业代码
  186. } else if (j == 8) {
  187. entity.setUseno(cellValue);//使用登记表编号
  188. } else if (j == 9) {
  189. entity.setGrade(cellValue);//管道级别
  190. } else if (j == 10) {
  191. entity.setDesigner(cellValue);//设计单位
  192. } else if (j == 11) {
  193. entity.setInstaller(cellValue);//安装单位
  194. } else if (j == 12) {//安装年月
  195. logger.info("日期格式:" + cellValue);
  196. if (cellValue.length() > 3) {
  197. entity.setInstallDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  198. }
  199. } else if (j == 13) {//投用年月
  200. logger.info("日期格式:" + cellValue);
  201. if (cellValue.length() > 3) {
  202. entity.setSubmitdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  203. }
  204. } else if (j == 14) {
  205. entity.setMaterial(cellValue);//材质
  206. } else if (j == 15) {
  207. entity.setDia(cellValue);//管道外径(英寸)
  208. } else if (j == 16) {
  209. entity.setScheduleNo(cellValue);//厚度等级
  210. } else if (j == 17) {
  211. entity.setLength(cellValue);//长度
  212. } else if (j == 18) {
  213. entity.setWeldNumber(cellValue);//焊口数量
  214. } else if (j == 19) {
  215. entity.setStarting(cellValue);//起点
  216. } else if (j == 20) {
  217. entity.setEnding(cellValue);//终点
  218. } else if (j == 21) {
  219. entity.setLayingMethod(cellValue);//敷设方式
  220. } else if (j == 22) {
  221. entity.setMedium(cellValue);//介质
  222. } else if (j == 23) {
  223. entity.setDesPressure(cellValue);//设计压力
  224. } else if (j == 25) {
  225. entity.setDesTemp(cellValue);//设计温度
  226. } else if (j == 24) {
  227. entity.setOptPressure(cellValue);//工作压力
  228. } else if (j == 26) {
  229. entity.setOptTemp(cellValue);//工作温度
  230. } else if (j == 27) {
  231. entity.setAdiabatic(cellValue);//绝热层代码
  232. } else if (j == 28) {
  233. entity.setIsDanger(cellValue);
  234. } else if (j == 29) {
  235. entity.setCheckUnit(cellValue);//检验单位
  236. } else if (j == 30) {//检验日期
  237. if (cellValue.length() < 4) {
  238. continue;
  239. }
  240. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  241. } else if (j == 31) {
  242. entity.setSafeClass(cellValue);//安全状况等级
  243. } else if (j == 32) {
  244. //年度检查报告编号
  245. entity.setReportNo(cellValue);//报告编号
  246. } else if (j == 33) {//下次检验日期
  247. logger.info("日期格式:" + cellValue);
  248. if (cellValue.length() < 4) {
  249. continue;
  250. }
  251. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  252. } else if (j == 34) {
  253. if (cellValue.length() > 3) {//年度检查日期
  254. entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  255. }
  256. } else if (j == 35) {
  257. entity.setCheckConclusion(cellValue);//年度结论
  258. } else if (j == 36) {
  259. if (cellValue.length() > 3) {//下次年度检验日期
  260. entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  261. }
  262. } else if (j == 37) {
  263. entity.setYearReportNo(cellValue);
  264. } else if (j == 38) {
  265. entity.setRemarks(cellValue);//备注
  266. } /*else if (j == 39) {
  267. for (SysDept d : dept) {
  268. if (d.getDeptName().equals(cellValue)) {
  269. entity.setDeptId(d.getDeptId());//部门编号
  270. }
  271. }
  272. }*/
  273. }
  274. entity.setCreaterCode(userId);
  275. logger.info("entity:" + entity);
  276. list.add(entity);
  277. } catch (Exception e) {
  278. failNumber.getAndIncrement();
  279. logger.info("e:" + JSON.toJSONString(e));
  280. failRow.add(i + 1);
  281. }
  282. }
  283. AtomicInteger successNumber = new AtomicInteger();
  284. AtomicInteger failNum = new AtomicInteger();
  285. //线程池
  286. ExecutorService executorService = Executors.newFixedThreadPool(30);
  287. final CountDownLatch latch = new CountDownLatch(list.size()); //相同线程数量的计数
  288. for (TSpecdevYlgd t : list
  289. ) {
  290. executorService.execute(() -> {
  291. //续票列表 -- 业务模块
  292. failNum.getAndIncrement();
  293. try {
  294. tSpecdevYlgdService.insertTSpecdevYlgd(t);
  295. successNumber.getAndIncrement();
  296. } catch (Exception e) {
  297. failNumber.getAndIncrement();
  298. logger.info("e:" + e);
  299. failRow.add(failNum.get() + 1);
  300. } finally {
  301. latch.countDown(); //线程计数
  302. }
  303. });
  304. }
  305. try {
  306. latch.await(); //线程计数完毕后继续执行
  307. } catch (InterruptedException e) {
  308. e.printStackTrace();
  309. }
  310. executorService.shutdown();
  311. logger.info("list:" + JSON.toJSONString(list));
  312. logger.info("successNumber:" + String.valueOf(successNumber.get()));
  313. logger.info("failNumber:" + String.valueOf(failNumber.get()));
  314. logger.info("failRow:" + String.valueOf(failRow));
  315. return AjaxResult.success(String.valueOf(successNumber.get()), failRow);
  316. }
  317. /**
  318. * 批量导入
  319. * 检验更新中的批量导入
  320. */
  321. @PreAuthorize("@ss.hasPermi('sems:specYlgd:add')")
  322. @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT)
  323. @PostMapping("/updateData")
  324. public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException {
  325. //获取操作人员ID
  326. Long userId = getUserId();
  327. //报错行数统计
  328. List<Integer> failRow = new ArrayList<Integer>();
  329. Workbook workbook = ExcelUtils.getWorkBook(file);
  330. Sheet sheet = workbook.getSheetAt(0);
  331. List<TSpecdevYlgd> list = new ArrayList<TSpecdevYlgd>();
  332. List<TSpecdevYlgd> oldList = new ArrayList<TSpecdevYlgd>();
  333. TSpecdevYlgd oldEntity = new TSpecdevYlgd();
  334. //字典查询
  335. List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
  336. //部门查询
  337. List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
  338. int rowNum = sheet.getPhysicalNumberOfRows();
  339. int failNumber = 0;
  340. for (int i = 1; i < rowNum; i++) {
  341. try {
  342. logger.info("读取行数:" + i);
  343. Row row = sheet.getRow(i);
  344. int cellNum = row.getLastCellNum();
  345. TSpecdevYlgd entity = new TSpecdevYlgd();
  346. for (int j = 0; j < cellNum; j++) {
  347. Cell cell = row.getCell(j);
  348. if (cell == null) {
  349. continue;
  350. }
  351. String cellValue = ExcelUtils.getCellValue(cell);
  352. logger.info("cellValue:" + cellValue);
  353. if (j == 0) {
  354. //序号
  355. Double d = Double.parseDouble(cellValue);
  356. long s = new Double(d).longValue();
  357. entity.setId(s);
  358. } else if (j == 1) { //装置名称
  359. entity.setPlantCode(cellValue);
  360. } else if (j == 2) { //管道名称
  361. entity.setDevname(cellValue);
  362. } else if (j == 3) { //管道编号
  363. entity.setDevno(cellValue);
  364. } else if (j == 4) { //使用登记表编号
  365. entity.setUseno(cellValue);
  366. } else if (j == 5) { //检验单位
  367. entity.setCheckUnit(cellValue);
  368. } else if (j == 6) { //检验日期
  369. logger.info("日期格式:" + cellValue);
  370. if (cellValue.length() > 3) {
  371. entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  372. }
  373. } else if (j == 7) { //安全状况等级
  374. entity.setSafeClass(cellValue);
  375. } else if (j == 8) { //报告编号
  376. entity.setReportNo(cellValue);
  377. } else if (j == 9) { //下次检验日期
  378. logger.info("日期格式:" + cellValue);
  379. if (cellValue.length() > 3) {//检验日期
  380. entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  381. }
  382. } else if (j == 10) { //年度检查日期
  383. logger.info("日期格式:" + cellValue);
  384. if (cellValue.length() > 3) {//检验日期
  385. entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  386. }
  387. } else if (j == 11) { //年度检查结论
  388. entity.setCheckConclusion(cellValue);
  389. } else if (j == 12) { //下次年度检查日期
  390. logger.info("日期格式:" + cellValue);
  391. if (cellValue.length() > 3) {//检验日期
  392. entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
  393. }
  394. } else if (j == 13) { //年度检查报告编号
  395. entity.setYearReportNo(cellValue);
  396. }
  397. }
  398. logger.info("entity:" + JSON.toJSONString(entity));
  399. list.add(entity);
  400. oldEntity = entity;
  401. oldList.add(oldEntity);
  402. } catch (Exception e) {
  403. failNumber++;
  404. logger.info("e:" + JSON.toJSONString(e));
  405. failRow.add(i + 1);
  406. }
  407. }
  408. int successNumber = 0;
  409. int failNum = 0;
  410. for (TSpecdevYlgd t : list) {
  411. failNum++;
  412. try {
  413. tSpecdevYlgdService
  414. .update(t,
  415. new QueryWrapper<TSpecdevYlgd>()
  416. .eq("USENO", t.getUseno())
  417. .eq("PLANT_CODE", t.getPlantCode())
  418. .eq("DEVNO", t.getDevno())
  419. );
  420. successNumber++;
  421. } catch (Exception e) {
  422. failNumber++;
  423. logger.info("e:" + e);
  424. failRow.add(failNum + 1);
  425. }
  426. }
  427. for (TSpecdevYlgd t : oldList) {
  428. TSpecCheck tc = new TSpecCheck();
  429. tc.setDevType(2l);
  430. tc.setCheckUnit(t.getCheckUnit());
  431. tc.setDevId(t.getId());
  432. tc.setNextWarnDate(t.getNextWarnDate());
  433. tc.setReportNo(t.getReportNo());
  434. tc.setWarnDate(t.getWarnDate());
  435. tc.setYearNextWarnDate(t.getYearNextWarnDate());
  436. tc.setYearWarnDate(t.getYearWarnDate());
  437. tc.setYearReportNo(t.getReportNo());
  438. tc.setSafeClass(t.getSafeClass());
  439. tc.setCheckConclusion(t.getCheckConclusion());
  440. tSpecCheckService.insertTSpecCheck(tc);
  441. }
  442. logger.info("list:" + JSON.toJSONString(list));
  443. logger.info("successNumber:" + String.valueOf(successNumber));
  444. logger.info("failNumber:" + String.valueOf(failNumber));
  445. logger.info("failRow:" + String.valueOf(failRow));
  446. return AjaxResult.success(String.valueOf(successNumber), failRow);
  447. }
  448. @PostMapping("/exportDevList")
  449. @RepeatSubmit
  450. public AjaxResult exportDevList(@RequestBody ParamData params) throws IOException {
  451. logger.info(JSON.toJSONString(params));
  452. String id = params.getIds();
  453. String[] ids = id.split(",");
  454. CopyOnWriteArrayList<TSpecdevYlgd> list = new CopyOnWriteArrayList<>();
  455. //线程池
  456. ExecutorService executorService = Executors.newFixedThreadPool(40);
  457. final CountDownLatch latch = new CountDownLatch(ids.length); //相同线程数量的计数
  458. for (String i : ids
  459. ) {
  460. executorService.execute(() -> {
  461. //-- 业务模块
  462. try {
  463. TSpecdevYlgd t = tSpecdevYlgdService.getById(i);
  464. list.add(t);
  465. } catch (Exception e) {
  466. logger.info("e:" + e);
  467. } finally {
  468. latch.countDown(); //线程计数
  469. }
  470. });
  471. }
  472. try {
  473. latch.await(); //线程计数完毕后继续执行
  474. } catch (InterruptedException e) {
  475. e.printStackTrace();
  476. }
  477. executorService.shutdown();
  478. SXSSFWorkbook wb = new SXSSFWorkbook(1000);
  479. CellStyle wrapStyle = wb.createCellStyle();
  480. wrapStyle.setWrapText(true); //设置自动换行
  481. //创建sheet页
  482. Sheet sheet = wb.createSheet("sheet1");
  483. //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节
  484. sheet.setColumnWidth(0, 12 * 256);
  485. sheet.setColumnWidth(1, 26 * 256);
  486. sheet.setColumnWidth(2, 26 * 256);
  487. sheet.setColumnWidth(3, 26 * 256);
  488. sheet.setColumnWidth(4, 26 * 256);
  489. sheet.setColumnWidth(5, 26 * 256);
  490. sheet.setColumnWidth(6, 26 * 256);
  491. sheet.setColumnWidth(7, 26 * 256);
  492. sheet.setColumnWidth(8, 40 * 256);
  493. sheet.setColumnWidth(9, 40 * 256);
  494. sheet.setColumnWidth(10, 26 * 256);
  495. sheet.setColumnWidth(11, 26 * 256);
  496. sheet.setColumnWidth(12, 40 * 256);
  497. sheet.setColumnWidth(13, 40 * 256);
  498. //设置开始行和开始列
  499. Row row0 = sheet.createRow(0);
  500. CellStyle style = wb.createCellStyle();
  501. style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
  502. style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  503. // Font headerFont = wb.createFont();
  504. // headerFont.setFontName("Arial");
  505. // headerFont.setFontHeightInPoints((short) 12);
  506. // headerFont.setBold(false);
  507. // headerFont.setColor(IndexedColors.BLACK.getIndex());
  508. // style.setFont(headerFont);
  509. Cell cell0 = row0.createCell(0);
  510. row0.createCell(0).setCellValue("序号");
  511. row0.createCell(1).setCellValue("装置");
  512. row0.createCell(2).setCellValue("管道名称");
  513. row0.createCell(3).setCellValue("管道编号");
  514. row0.createCell(4).setCellValue("使用登记表编号");
  515. row0.createCell(5).setCellValue("检验单位");
  516. row0.getCell(5).setCellStyle(style);
  517. row0.createCell(6).setCellValue("定期检验日期");
  518. row0.getCell(6).setCellStyle(style);
  519. row0.createCell(7).setCellValue("安全状况等级");
  520. row0.getCell(7).setCellStyle(style);
  521. row0.createCell(8).setCellValue("定期检验报告编号");
  522. row0.getCell(8).setCellStyle(style);
  523. row0.createCell(9).setCellValue("下次定期检验日期");
  524. row0.getCell(9).setCellStyle(style);
  525. row0.createCell(10).setCellValue("年度检查日期");
  526. row0.getCell(10).setCellStyle(style);
  527. row0.createCell(11).setCellValue("年度检查结论");
  528. row0.getCell(11).setCellStyle(style);
  529. row0.createCell(12).setCellValue("下次年度检查日期");
  530. row0.getCell(12).setCellStyle(style);
  531. row0.createCell(13).setCellValue("年度检查报告编号");
  532. row0.getCell(13).setCellStyle(style);
  533. //填充数据
  534. int rowIndex = 1;
  535. int columnIndex = 1;
  536. for (TSpecdevYlgd t : list
  537. ) {
  538. Row row = sheet.createRow(rowIndex);
  539. row.createCell(0).setCellValue(t.getId());
  540. row.createCell(1).setCellValue(t.getPlantCode());
  541. row.createCell(2).setCellValue(t.getDevname());
  542. row.createCell(3).setCellValue(t.getDevno());
  543. row.createCell(4).setCellValue(t.getUseno());
  544. row.createCell(5).setCellValue(t.getCheckUnit());
  545. if (t.getWarnDate() != null) {
  546. row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
  547. }
  548. row.createCell(7).setCellValue(t.getSafeClass());
  549. row.createCell(8).setCellValue(t.getReportNo());
  550. if (t.getNextWarnDate() != null) {
  551. row.createCell(9).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
  552. }
  553. if (t.getYearWarnDate() != null) {
  554. row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearWarnDate()));
  555. }
  556. row.createCell(11).setCellValue(t.getCheckConclusion());
  557. if (t.getYearNextWarnDate() != null) {
  558. row.createCell(12).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearNextWarnDate()));
  559. }
  560. row.createCell(13).setCellValue(t.getYearReportNo());
  561. rowIndex++;
  562. }
  563. OutputStream out = null;
  564. String filename = ExcelUtil.encodingFilename("压力管道批量更新");
  565. out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
  566. wb.write(out);
  567. wb.close();
  568. out.close();
  569. return AjaxResult.success(filename);
  570. }
  571. }