From e543d213d65bc82c0823ffd38e4292de1ac2a267 Mon Sep 17 00:00:00 2001 From: wangzhijiang <12345678> Date: Fri, 19 Aug 2022 16:31:43 +0800 Subject: [PATCH] =?UTF-8?q?58420=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/LawsComplianceBoardServiceImpl.java | 110 +++++++++--------- 1 file changed, 54 insertions(+), 56 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/impl/LawsComplianceBoardServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/impl/LawsComplianceBoardServiceImpl.java index 4bebaed12..d060a5ebe 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/impl/LawsComplianceBoardServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/project/service/impl/LawsComplianceBoardServiceImpl.java @@ -360,66 +360,64 @@ public class LawsComplianceBoardServiceImpl implements ILawsComplianceBoardServi String cut = (String) params.get("cut"); List> exportData = this.lawsComplianceBoardMapper.queryComplianceResultList(params); this.disposeComplianceResult(exportData,cut); - if(CollectionUtils.isNotEmpty(exportData)){ - String title = ""; - String fileName = ""; - if(StringUtils.equals(cut, CutEnum.CN.getValue())){ - title = "责任领域,相关项目,设计符合性,Pre-Homo确认,验证符合性"; - fileName = "符合性结果" + ".xlsx"; - }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ - title = "Responsible Field,Relevant Project,Design Compliance Confirmation,Pre-Homo Confirmation,Validation Compliance Confirmation"; - fileName = "Compliance results" + ".xlsx"; + String title = ""; + String fileName = ""; + if(StringUtils.equals(cut, CutEnum.CN.getValue())){ + title = "责任领域,相关项目,设计符合性,Pre-Homo确认,验证符合性"; + fileName = "符合性结果" + ".xlsx"; + }else if(StringUtils.equals(cut,CutEnum.EN.getValue())){ + title = "Responsible Field,Relevant Project,Design Compliance Confirmation,Pre-Homo Confirmation,Validation Compliance Confirmation"; + fileName = "Compliance results" + ".xlsx"; + } + OutputStream os = null; + HSSFWorkbook workbook = new HSSFWorkbook(); + + try { + response.setHeader("Content-Disposition", + "attachment; filename=" + fileName); + response.setContentType("application/force-download"); + + HSSFSheet sheet = workbook.createSheet("sheet1"); + + CellStyle titleCellStyle = workbook.createCellStyle(); + titleCellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中 + titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中 + titleCellStyle.setWrapText(true);//自动换行 + + //创建表头 + String[] firstLineTitleArr = title.split(","); + Row firstRow = sheet.createRow(0); + + //设置居中、表头值。 + for (int i = 0; i < firstLineTitleArr.length; i++){ + sheet.setColumnWidth(i,8000); + Cell cell = firstRow.createCell(i); + cell.setCellStyle(titleCellStyle); + cell.setCellValue(firstLineTitleArr[i]); } - OutputStream os = null; - HSSFWorkbook workbook = new HSSFWorkbook(); - try { - response.setHeader("Content-Disposition", - "attachment; filename=" + fileName); - response.setContentType("application/force-download"); - - HSSFSheet sheet = workbook.createSheet("sheet1"); - - CellStyle titleCellStyle = workbook.createCellStyle(); - titleCellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中 - titleCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//水平居中 - titleCellStyle.setWrapText(true);//自动换行 - - //创建表头 - String[] firstLineTitleArr = title.split(","); - Row firstRow = sheet.createRow(0); - - //设置居中、表头值。 - for (int i = 0; i < firstLineTitleArr.length; i++){ - sheet.setColumnWidth(i,8000); - Cell cell = firstRow.createCell(i); - cell.setCellStyle(titleCellStyle); - cell.setCellValue(firstLineTitleArr[i]); - } - - //设置导出数据 - if(CollectionUtils.isNotEmpty(exportData)) { - int rowIndex = 1; - for (int dataIndex = 0; dataIndex < exportData.size(); dataIndex++) { - Row dataRow = sheet.createRow(rowIndex); - dataRow.createCell(0).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("dutyTerritory_dicText"))); - dataRow.createCell(1).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("projectName"))); - dataRow.createCell(2).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("designFlowTaskStatus_dicText"))); - dataRow.createCell(3).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("prehomoFlowTaskStatus_dicText"))); - dataRow.createCell(4).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("verifyFlowTaskStatus_dicText"))); - rowIndex ++; - } - } - os = response.getOutputStream(); - workbook.write(os); - os.flush(); - }catch (IOException ex){ - if(CutEnum.CN.getValue().equals(cut)){ - throw new JeroBootException("下载文件失败"); - }else{ - throw new JeroBootException("Failed to download file"); + //设置导出数据 + if(CollectionUtils.isNotEmpty(exportData)) { + int rowIndex = 1; + for (int dataIndex = 0; dataIndex < exportData.size(); dataIndex++) { + Row dataRow = sheet.createRow(rowIndex); + dataRow.createCell(0).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("dutyTerritory_dicText"))); + dataRow.createCell(1).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("projectName"))); + dataRow.createCell(2).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("designFlowTaskStatus_dicText"))); + dataRow.createCell(3).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("prehomoFlowTaskStatus_dicText"))); + dataRow.createCell(4).setCellValue(checkValueIsNotNull(exportData.get(dataIndex).get("verifyFlowTaskStatus_dicText"))); + rowIndex ++; } } + os = response.getOutputStream(); + workbook.write(os); + os.flush(); + }catch (IOException ex){ + if(CutEnum.CN.getValue().equals(cut)){ + throw new JeroBootException("下载文件失败"); + }else{ + throw new JeroBootException("Failed to download file"); + } } }