package com.ruoyi.project.sems.controller; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.file.ExcelUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.interceptor.annotation.RepeatSubmit; import com.ruoyi.framework.security.LoginUser; import com.ruoyi.framework.security.service.TokenService; import com.ruoyi.project.sems.domain.ParamData; import com.ruoyi.project.sems.domain.TSpecCheck; import com.ruoyi.project.sems.domain.TSpecdevYlgd; import com.ruoyi.project.sems.his.controller.TApproveSpecModifyController; import com.ruoyi.project.sems.his.controller.TSpechiYlgdController; import com.ruoyi.project.sems.his.controller.TSpechiYlrqController; import com.ruoyi.project.sems.his.domain.TApproveSpecModify; import com.ruoyi.project.sems.his.service.ITApproveSpecModifyService; import com.ruoyi.project.sems.service.ITSpecCheckService; import com.ruoyi.project.system.domain.SysDept; import com.ruoyi.project.system.domain.SysDictData; import com.ruoyi.project.system.service.ISysDeptService; import com.ruoyi.project.system.service.ISysDictTypeService; import org.activiti.engine.RuntimeService; import org.activiti.engine.impl.identity.Authentication; import org.activiti.engine.runtime.ProcessInstance; import org.apache.commons.lang.StringUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.project.sems.domain.TSpecdevYlrq; import com.ruoyi.project.sems.service.ITSpecdevYlrqService; import com.ruoyi.framework.web.controller.BaseController; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.page.TableDataInfo; import org.springframework.web.multipart.MultipartFile; /** * 特种设备压力容器台账Controller * * @author ruoyi * @date 2021-06-30 */ @RestController @RequestMapping("/sems/specYlrq") public class TSpecdevYlrqController extends BaseController { @Autowired private ITSpecdevYlrqService tSpecdevYlrqService; @Autowired private ITSpecCheckService tSpecCheckService; @Autowired private ISysDeptService iSysDeptService; @Autowired private ISysDictTypeService iSysDictTypeService; @Autowired private ITApproveSpecModifyService tApproveSpecModifyService; @Autowired private RuntimeService runtimeService; @Autowired private TApproveSpecModifyController approveSpecModifyController; @Autowired private TSpechiYlrqController tSpechiYlrqController; /** * 查询特种设备压力容器台账列表 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:list')") @GetMapping("/list") public TableDataInfo list(TSpecdevYlrq tSpecdevYlrq) { startPage(); List list = tSpecdevYlrqService.selectTSpecdevYlrqList(tSpecdevYlrq); // // SpecOverLifeThead specOverLifeThead = new SpecOverLifeThead(tSpecdevYlrqService); // Thread t = new Thread(specOverLifeThead); // t.start(); // SpecDevYlrqThread specDevYlgdThread = new SpecDevYlrqThread(tSpecdevYlrqService); // Thread t2 = new Thread(specDevYlgdThread); // t2.start(); return getDataTable(list); } /** * 导出特种设备压力容器台账列表 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:export')") @Log(title = "特种设备压力容器台账", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(TSpecdevYlrq tSpecdevYlrq) { List list = tSpecdevYlrqService.selectTSpecdevYlrqList(tSpecdevYlrq); ExcelUtil util = new ExcelUtil(TSpecdevYlrq.class); return util.exportExcel(list, "specYlrq"); } /** * 获取特种设备压力容器台账详细信息 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return AjaxResult.success(tSpecdevYlrqService.selectTSpecdevYlrqById(id)); } /** * 新增特种设备压力容器台账 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')") @Log(title = "特种设备压力容器台账", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody TSpecdevYlrq tSpecdevYlrq) { tSpecdevYlrq.setApproveStatus(22l); tSpecdevYlrqService.insertTSpecdevYlrq(tSpecdevYlrq); TApproveSpecModify tApproveSpecModify = new TApproveSpecModify(); Long userid = getUserId(); tApproveSpecModify.setUserId(userid); tApproveSpecModify.setApproveType(3l); tApproveSpecModify.setDevType(1l); tApproveSpecModify.setDevId(String.valueOf(tSpecdevYlrq.getId())); //审批编号 Date dt = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); String data = sdf.format(dt) + userid; tApproveSpecModify.setApNo(data); // Authentication.setAuthenticatedUserId(userid.toString()); tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify); long bussniseeKey = tApproveSpecModify.getId(); //开始工作流、监听 Map variables = new HashMap<>(); variables.put("applyUser", userid.toString()); variables.put("wxjlusers", tSpecdevYlrq.getWxjl()); //采用key来启动流程定义并设置流程变量,返回流程实例 ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables); logger.info("流程部署id:" + pi.getDeploymentId()); logger.info("流程定义id:" + pi.getProcessDefinitionId()); logger.info("流程实例id:" + pi.getProcessInstanceId()); tApproveSpecModify.setProcessId(pi.getProcessInstanceId()); new Thread(() -> { approveSpecModifyController.sendMail(tApproveSpecModify , tSpecdevYlrq.getWxjl()); },"发送邮件").start(); LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); String userName =loginUser != null? loginUser.getUsername(): ""; new Thread(() -> { tSpechiYlrqController.addOperLog(String.valueOf(tSpecdevYlrq.getId()),userName,new Date() , "新增申请" ); },"特种设备操作日志").start(); return AjaxResult.success(); } /** * 修改特种设备压力容器台账 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:edit')") @Log(title = "特种设备压力容器台账", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody TSpecdevYlrq tSpecdevYlrq) { TSpecdevYlrq old = tSpecdevYlrqService.selectTSpecdevYlrqById(tSpecdevYlrq.getId()); if (StringUtils.isNotEmpty(tSpecdevYlrq.getReportNo()) && !tSpecdevYlrq.getReportNo().equals(old.getReportNo())) { TSpecCheck tc = new TSpecCheck(); tc.setDevType(1l); tc.setCheckUnit(tSpecdevYlrq.getCheckUnit()); tc.setDevId(tSpecdevYlrq.getId()); tc.setNextWarnDate(tSpecdevYlrq.getNextWarnDate()); tc.setReportNo(tSpecdevYlrq.getReportNo()); tc.setWarnDate(tSpecdevYlrq.getWarnDate()); tc.setYearNextWarnDate(tSpecdevYlrq.getYearNextWarnDate()); tc.setYearWarnDate(tSpecdevYlrq.getYearWarnDate()); tc.setYearReportNo(tSpecdevYlrq.getReportNo()); tc.setSafeClass(tSpecdevYlrq.getSafeClass()); tc.setCheckConclusion(tSpecdevYlrq.getCheckConclusion()); tSpecCheckService.insertTSpecCheck(tc); } tSpecdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq); LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); String userName =loginUser != null? loginUser.getUsername(): ""; new Thread(() -> { tSpechiYlrqController.addOperLog(String.valueOf(tSpecdevYlrq.getId()),userName,new Date() , "修改" ); },"特种设备操作日志").start(); return AjaxResult.success(); } /** * 修改特种设备压力容器台账 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:edit')") @Log(title = "特种设备压力容器台账", businessType = BusinessType.UPDATE) @PutMapping("/pre") public AjaxResult editPre(@RequestBody TSpecdevYlrq tSpecdevYlrq) { return toAjax(tSpecdevYlrqService.updateTSpecdevYlrq(tSpecdevYlrq)); } /** * 删除特种设备压力容器台账 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:remove')") @Log(title = "特种设备压力容器台账", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(tSpecdevYlrqService.deleteTSpecdevYlrqByIds(ids)); } /** * 去重 */ @PreAuthorize("@ss.hasPermi('sems:plant:remove')") @Log(title = "特种设备压力容器台账去重", businessType = BusinessType.OTHER) @GetMapping("/duplicate") public AjaxResult duplicate() { tSpecdevYlrqService.duplicateTSpecdevYlrq(); return AjaxResult.success(); } /** * 批量导入 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')") @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT) @PostMapping("/importData") public AjaxResult importData(@RequestParam("file") MultipartFile file,@RequestParam("wxjl") String wxjl) throws IOException, ParseException { //获取操作人员ID Long userId = getUserId(); //报错行数统计 List failRow = new ArrayList(); Workbook workbook = ExcelUtils.getWorkBook(file); Sheet sheet = workbook.getSheetAt(0); List list = new ArrayList(); //字典查询 List plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE"); //部门查询 List dept = iSysDeptService.selectDeptList(new SysDept()); int rowNum = sheet.getPhysicalNumberOfRows(); int failNumber = 0; for (int i = 1; i < rowNum; i++) { try { logger.info("读取行数:" + i); Row row = sheet.getRow(i); int cellNum = row.getLastCellNum(); TSpecdevYlrq entity = new TSpecdevYlrq(); for (int j = 0; j < cellNum; j++) { Cell cell = row.getCell(j); if (cell == null) { continue; } cell.getCellType(); String cellValue = ExcelUtils.getCellValue(cell); if (StringUtils.trim(cellValue) == "") { continue; } logger.info("cellValue:" + cellValue); if (j == 0) { //序号 } else if (j == 1) { entity.setPlantCode(cellValue);//装置名称 } else if (j == 2) { entity.setUnit(cellValue);//单元 } else if (j == 3) { entity.setPlantMaint(cellValue);//装置维修组 } else if (j == 4) { entity.setEngineer(cellValue);//装置维修工程师 } else if (j == 5) { entity.setDevno(cellValue);//位号 } else if (j == 6) { entity.setDevname(cellValue);//设备名称 } else if (j == 7) { entity.setFactoryNo(cellValue);//出厂编号 } else if (j == 8) { entity.setUseno(cellValue);//使用证编号 } else if (j == 9) { entity.setRegno(cellValue);//注册编号 } else if (j == 10) { entity.setVesselType(cellValue);//容器类别 } else if (j == 11) { entity.setCreateUnit(cellValue);//制造单位 } else if (j == 12) { entity.setNation(cellValue);//国家 } else if (j == 13) { entity.setOutSize(cellValue);//外形尺寸 } else if (j == 14) { entity.setMaterial(cellValue);//材料 } else if (j == 15) { entity.setMedium(cellValue);//介质 } else if (j == 16) { entity.setDesPressure(cellValue);//设计压力 } else if (j == 17) { entity.setOptPressure(cellValue);//操作压力 } else if (j == 18) { entity.setDesTemp(cellValue);//设计温度 } else if (j == 19) { entity.setOptTemp(cellValue);//操作温度 } else if (j == 20) { logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) {//投用日期 entity.setSubmitdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 21) { //是否涉危化品 entity.setIsDanger(cellValue); } else if (j == 22) { //是否涉危化品 entity.setDesYear(cellValue); } else if (j == 23) { //是否超设计使用寿命 entity.setIsOverlife(cellValue); } else if (j == 24) { entity.setCheckUnit(cellValue);//检验单位 } else if (j == 25) { logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) {//检验日期 entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 26) { entity.setSafeClass(cellValue);//安全状况等级 } else if (j == 27) { if (cellValue.length() > 3) {//下次检验日期 entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 28) { entity.setReportNo(cellValue);//报告编号 } else if (j == 29) { if (cellValue.length() > 3) {//检验日期 entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 30) { entity.setCheckConclusion(cellValue);//年度结论 } else if (j == 31) { if (cellValue.length() > 3) {//下次年度检验日期 entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 32) { entity.setYearReportNo(cellValue);//报告编号 } else if (j == 33) { entity.setRemarks(cellValue);//备注 }/*else if (j == 33) { for (SysDept d : dept) { if (d.getDeptName().equals(cellValue)) { entity.setDeptId(d.getDeptId());//部门编号 } } }*/ } entity.setCreaterCode(userId); logger.info("entity:" + entity); list.add(entity); } catch (Exception e) { failNumber++; logger.info("e:" + JSON.toJSONString(e)); failRow.add(i + 1); } } int successNumber = 0; int failNum = 0; CopyOnWriteArrayList ids = new CopyOnWriteArrayList(); for (TSpecdevYlrq t : list ) { failNum++; try { t.setApproveStatus(22l); tSpecdevYlrqService.insertTSpecdevYlrq(t); ids.add(t.getId().toString()); successNumber++; } catch (Exception e) { failNumber++; logger.info("e:" + e); failRow.add(failNum + 1); } } //申请流程 String devIds = StringUtils.join(ids.toArray(),","); TApproveSpecModify tApproveSpecModify = new TApproveSpecModify(); Long userid = getUserId(); tApproveSpecModify.setUserId(userid); tApproveSpecModify.setApproveType(3l); tApproveSpecModify.setDevType(1l); tApproveSpecModify.setDevId(devIds); //审批编号 Date dt = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss"); String data = sdf.format(dt) + userid; tApproveSpecModify.setApNo(data); // Authentication.setAuthenticatedUserId(userid.toString()); tApproveSpecModifyService.insertTApproveSpecModify(tApproveSpecModify); long bussniseeKey = tApproveSpecModify.getId(); //开始工作流、监听 Map variables = new HashMap<>(); variables.put("applyUser", userid.toString()); variables.put("wxjlusers", wxjl); //采用key来启动流程定义并设置流程变量,返回流程实例 ProcessInstance pi = runtimeService.startProcessInstanceByKey("semsAddDelProcess", String.valueOf(bussniseeKey), variables); logger.info("流程部署id:" + pi.getDeploymentId()); logger.info("流程定义id:" + pi.getProcessDefinitionId()); logger.info("流程实例id:" + pi.getProcessInstanceId()); tApproveSpecModify.setProcessId(pi.getProcessInstanceId()); new Thread(() -> { approveSpecModifyController.sendMail(tApproveSpecModify , wxjl); },"发送邮件").start(); LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest()); String userName =loginUser != null? loginUser.getUsername(): ""; new Thread(() -> { tSpechiYlrqController.addOperLog(ids.toArray(),userName,new Date() , "新增申请" ); },"特种设备操作日志").start(); logger.info("list:" + JSON.toJSONString(list)); logger.info("successNumber:" + String.valueOf(successNumber)); logger.info("failNumber:" + String.valueOf(failNumber)); logger.info("failRow:" + String.valueOf(failRow)); return AjaxResult.success(String.valueOf(successNumber), failRow); } /** * 批量导入 * 检验更新功能中的批量导入 */ @PreAuthorize("@ss.hasPermi('sems:specYlrq:add')") @Log(title = "特种设备批量导入", businessType = BusinessType.INSERT) @PostMapping("/updateData") public AjaxResult updateData(@RequestParam("file") MultipartFile file) throws IOException { //获取操作人员ID Long userId = getUserId(); //报错行数统计 List failRow = new ArrayList(); Workbook workbook = ExcelUtils.getWorkBook(file); Sheet sheet = workbook.getSheetAt(0); List list = new ArrayList(); List oldList = new ArrayList(); //字典查询 List plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE"); //部门查询 List dept = iSysDeptService.selectDeptList(new SysDept()); int rowNum = sheet.getPhysicalNumberOfRows(); int failNumber = 0; long devId = 0l; TSpecdevYlrq oldEntity = new TSpecdevYlrq(); for (int i = 1; i < rowNum; i++) { try { logger.info("读取行数:" + i); Row row = sheet.getRow(i); int cellNum = row.getLastCellNum(); TSpecdevYlrq entity = new TSpecdevYlrq(); for (int j = 0; j < cellNum; j++) { Cell cell = row.getCell(j); if (cell == null) { continue; } String cellValue = ExcelUtils.getCellValue(cell); logger.info("cellValue:" + cellValue); if (j == 0) { //序号 Double d = Double.parseDouble(cellValue); long s = new Double(d).longValue(); entity.setId(s); } else if (j == 1) { entity.setPlantCode(cellValue);//装置名称 } else if (j == 2) { entity.setDevno(cellValue);//位号 } else if (j == 3) { entity.setDevname(cellValue);//设备名称 } else if (j == 4) { entity.setUseno(cellValue);//使用证编号 } else if (j == 5) { entity.setCheckUnit(cellValue);//检验单位 } else if (j == 6) { logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) {//检验日期 entity.setWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 7) { entity.setSafeClass(cellValue);//安全状况等级 } else if (j == 8) { logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) {//下次检验日期 entity.setNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 9) { entity.setReportNo(cellValue);//报告编号 } else if (j == 10) { //年度检查日期 logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) { entity.setYearWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 11) {//年度检查结论 entity.setCheckConclusion(cellValue); } else if (j == 12) {//下次年度检查日期 logger.info("日期格式:" + cellValue); if (cellValue.length() > 3) { entity.setYearNextWarnDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue)); } } else if (j == 13) {//年度检查编号 entity.setYearReportNo(cellValue); } } logger.info("entity:" + entity); list.add(entity); oldEntity = entity; oldList.add(oldEntity); /*for (TSpecdevYlrq e :list){ e.setId(null); }*/ } catch (Exception e) { failNumber++; e.printStackTrace(); logger.info("e:" + JSON.toJSONString(e)); failRow.add(i + 1); } } int successNumber = 0; int failNum = 0; for (TSpecdevYlrq t : list ) { failNum++; try { tSpecdevYlrqService.update(t, new QueryWrapper().eq("USENO", t.getUseno()) .eq("PLANT_CODE", t.getPlantCode()) .eq("DEVNO", t.getDevno())); successNumber++; } catch (Exception e) { e.printStackTrace(); failNumber++; logger.info("e:" + e); failRow.add(failNum + 1); } } for (TSpecdevYlrq t : oldList) { // TSpecdevYlrq old = tSpecdevYlrqService.selectTSpecdevYlrqById(t.getId()); // if (!old.getReportNo().equals(t.getReportNo())) { TSpecCheck tc = new TSpecCheck(); tc.setDevType(1l); tc.setCheckUnit(t.getCheckUnit()); tc.setDevId(t.getId()); tc.setNextWarnDate(t.getNextWarnDate()); tc.setReportNo(t.getReportNo()); tc.setWarnDate(t.getWarnDate()); tc.setYearNextWarnDate(t.getYearNextWarnDate()); tc.setYearWarnDate(t.getYearWarnDate()); tc.setYearReportNo(t.getReportNo()); tc.setSafeClass(t.getSafeClass()); tc.setCheckConclusion(t.getCheckConclusion()); tSpecCheckService.insertTSpecCheck(tc); // } } logger.info("list:" + JSON.toJSONString(list)); logger.info("successNumber:" + String.valueOf(successNumber)); logger.info("failNumber:" + String.valueOf(failNumber)); logger.info("failRow:" + String.valueOf(failRow)); return AjaxResult.success(String.valueOf(successNumber), failRow); } @PostMapping("/exportDevList") @RepeatSubmit public AjaxResult exportDevList(@RequestBody ParamData params) throws IOException { logger.info(JSON.toJSONString(params)); String id = params.getIds(); String[] ids = id.split(","); CopyOnWriteArrayList list = new CopyOnWriteArrayList<>(); //线程池 ExecutorService executorService = Executors.newFixedThreadPool(40); final CountDownLatch latch = new CountDownLatch(ids.length); //相同线程数量的计数 for (String i : ids ) { executorService.execute(() -> { //-- 业务模块 try { TSpecdevYlrq t = tSpecdevYlrqService.getById(i); list.add(t); } catch (Exception e) { logger.info("e:" + e); } finally { latch.countDown(); //线程计数 } }); } try { latch.await(); //线程计数完毕后继续执行 } catch (InterruptedException e) { e.printStackTrace(); } executorService.shutdown(); SXSSFWorkbook wb = new SXSSFWorkbook(1000); CellStyle wrapStyle = wb.createCellStyle(); wrapStyle.setWrapText(true); //设置自动换行 //创建sheet页 Sheet sheet = wb.createSheet("sheet1"); //设置列的宽度,第一个参数为列的序号,从0开始,第二参数为列宽,单位1/256个字节 sheet.setColumnWidth(0, 12 * 256); sheet.setColumnWidth(1, 26 * 256); sheet.setColumnWidth(2, 26 * 256); sheet.setColumnWidth(3, 26 * 256); sheet.setColumnWidth(4, 26 * 256); sheet.setColumnWidth(5, 26 * 256); sheet.setColumnWidth(6, 26 * 256); sheet.setColumnWidth(7, 26 * 256); sheet.setColumnWidth(8, 40 * 256); sheet.setColumnWidth(9, 40 * 256); sheet.setColumnWidth(10, 26 * 256); sheet.setColumnWidth(11, 26 * 256); sheet.setColumnWidth(12, 40 * 256); sheet.setColumnWidth(13, 40 * 256); //设置开始行和开始列 Row row0 = sheet.createRow(0); CellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); // Font headerFont = wb.createFont(); // headerFont.setFontName("Arial"); // headerFont.setFontHeightInPoints((short) 12); // headerFont.setBold(false); // headerFont.setColor(IndexedColors.BLACK.getIndex()); // style.setFont(headerFont); Cell cell0 = row0.createCell(0); row0.createCell(0).setCellValue("序号"); row0.createCell(1).setCellValue("装置"); row0.createCell(2).setCellValue("位号"); row0.createCell(3).setCellValue("设备名称"); row0.createCell(4).setCellValue("使用证号码"); row0.createCell(5).setCellValue("检验单位"); row0.getCell(5).setCellStyle(style); row0.createCell(6).setCellValue("定期检验日期"); row0.getCell(6).setCellStyle(style); row0.createCell(7).setCellValue("安全状况等级"); row0.getCell(7).setCellStyle(style); row0.createCell(8).setCellValue("下次定期检验日期"); row0.getCell(8).setCellStyle(style); row0.createCell(9).setCellValue("定期检验报告编号"); row0.getCell(9).setCellStyle(style); row0.createCell(10).setCellValue("年度检查日期"); row0.getCell(10).setCellStyle(style); row0.createCell(11).setCellValue("年度检查结论"); row0.getCell(11).setCellStyle(style); row0.createCell(12).setCellValue("下次年度检查日期"); row0.getCell(12).setCellStyle(style); row0.createCell(13).setCellValue("年度检查报告编号"); row0.getCell(13).setCellStyle(style); //填充数据 int rowIndex = 1; int columnIndex = 1; for (TSpecdevYlrq t : list ) { Row row = sheet.createRow(rowIndex); row.createCell(0).setCellValue(t.getId()); row.createCell(1).setCellValue(t.getPlantCode()); row.createCell(2).setCellValue(t.getDevno()); row.createCell(3).setCellValue(t.getDevname()); row.createCell(4).setCellValue(t.getUseno()); row.createCell(5).setCellValue(t.getCheckUnit()); if (t.getWarnDate() != null) { row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate())); } row.createCell(7).setCellValue(t.getSafeClass()); if (t.getNextWarnDate() != null) { row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate())); } row.createCell(9).setCellValue(t.getReportNo()); if (t.getYearWarnDate() != null) { row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearWarnDate())); } row.createCell(11).setCellValue(t.getCheckConclusion()); if (t.getYearNextWarnDate() != null) { row.createCell(12).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearNextWarnDate())); } row.createCell(13).setCellValue(t.getYearReportNo()); rowIndex++; } OutputStream out = null; String filename = ExcelUtil.encodingFilename("压力容器批量更新"); out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename)); wb.write(out); wb.close(); out.close(); return AjaxResult.success(filename); } }