From 86e5bb4399d25e0a4ffa5188d6c0a5cc727efef1 Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期四, 21 十二月 2023 15:52:31 +0800 Subject: [PATCH] 2023-12-21 朱宝民 分水房导出 --- /dev/null | 402 -------------------------------------------- pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideSv.java | 13 + pipIrr-platform/pipIrr-global/pom.xml | 12 + pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java | 31 +++ pipIrr-platform/pipIrr-web/pipIrr-web-project/pom.xml | 1 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/LocalJsonUtil.java | 28 +++ pipIrr-platform/pipIrr-common/pom.xml | 7 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoDivide.java | 16 + 8 files changed, 100 insertions(+), 410 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/pom.xml b/pipIrr-platform/pipIrr-common/pom.xml index 2b86036..be19e3a 100644 --- a/pipIrr-platform/pipIrr-common/pom.xml +++ b/pipIrr-platform/pipIrr-common/pom.xml @@ -128,13 +128,6 @@ <artifactId>httpclient</artifactId> <version>4.5.14</version> </dependency> - <!-- apache poi --> - <dependency> - <groupId>org.apache.poi</groupId> - <artifactId>poi</artifactId> - <version>3.14</version> - </dependency> - <!-- quartz --> <dependency> <groupId>org.quartz-scheduler</groupId> diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/HSSF.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/HSSF.java deleted file mode 100644 index 430373f..0000000 --- a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/HSSF.java +++ /dev/null @@ -1,402 +0,0 @@ -package com.dy.common.util; - -import org.apache.poi.hssf.usermodel.*; -import org.apache.poi.hssf.util.HSSFColor; -import org.apache.poi.ss.usermodel.RichTextString; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.RegionUtil; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; - -public abstract class HSSF { - - public HSSFCellStyle createTitleStyle_1(HSSFWorkbook workbook, boolean hasForegroundColor, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - if(hasForegroundColor) { - style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);// The style settings - }else{ - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - } - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_NONE); - style.setBorderLeft(HSSFCellStyle.BORDER_NONE); - style.setBorderRight(HSSFCellStyle.BORDER_NONE); - style.setBorderTop(HSSFCellStyle.BORDER_NONE); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - font.setColor(HSSFColor.BLACK.index); - style.setFont(font); - return style ; - } - public HSSFCellStyle createTitleStyle_2(HSSFWorkbook workbook, boolean hasForegroundColor, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - if(hasForegroundColor) { - style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);// The style settings - }else{ - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - } - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_NONE); - style.setBorderLeft(HSSFCellStyle.BORDER_NONE); - style.setBorderRight(HSSFCellStyle.BORDER_NONE); - style.setBorderTop(HSSFCellStyle.BORDER_NONE); - style.setAlignment(HSSFCellStyle.ALIGN_LEFT); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - font.setColor(HSSFColor.BLACK.index); - style.setFont(font); - return style ; - } - public HSSFCellStyle createTitleStyle_3(HSSFWorkbook workbook, boolean hasForegroundColor, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - if(hasForegroundColor) { - style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);// The style settings - }else{ - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - } - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - //font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - font.setColor(HSSFColor.BLACK.index); - style.setFont(font); - return style ; - } - - - public HSSFCellStyle createTitleStyle(HSSFWorkbook workbook, boolean hasForegroundColor){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - if(hasForegroundColor) { - style.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);// The style settings - }else{ - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - } - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) 11); - font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - style.setFont(font); - return style ; - } - - public HSSFCellStyle createContentCenterStyle(HSSFWorkbook workbook){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontHeightInPoints((short) 10); - font.setFontName("瀹嬩綋"); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - - return style ; - } - - public HSSFCellStyle createContentCenterStyleBFH(HSSFWorkbook workbook){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontHeightInPoints((short) 10); - font.setFontName("瀹嬩綋"); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - - style.setDataFormat(workbook.createDataFormat().getFormat("0.00%")); - - return style ; - } - public HSSFCellStyle createContentCenterStyle_1(HSSFWorkbook workbook, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_CENTER); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - style.setFont(font); - - return style ; - } - - - public HSSFCellStyle createContentLeftStyle(HSSFWorkbook workbook){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_LEFT); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontHeightInPoints((short) 10); - font.setFontName("瀹嬩綋"); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - return style ; - } - - - public HSSFCellStyle createContentLeftStyle_1(HSSFWorkbook workbook, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_LEFT); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - return style ; - } - - - public HSSFCellStyle createContentRightStyle(HSSFWorkbook workbook){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontHeightInPoints((short) 10); - font.setFontName("瀹嬩綋"); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - return style ; - } - - public HSSFCellStyle createContentRightStyle_1(HSSFWorkbook workbook, int fontSize){ - HSSFCellStyle style = workbook.createCellStyle();// Create a style - style.setFillForegroundColor(HSSFColor.WHITE.index);// The style settings - style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); - style.setBorderBottom(HSSFCellStyle.BORDER_THIN); - style.setBorderLeft(HSSFCellStyle.BORDER_THIN); - style.setBorderRight(HSSFCellStyle.BORDER_THIN); - style.setBorderTop(HSSFCellStyle.BORDER_THIN); - style.setAlignment(HSSFCellStyle.ALIGN_RIGHT); - style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); - style.setWrapText(true);// 鑷姩鎹㈣ - - HSSFFont font = workbook.createFont();// Create a font - font.setFontName("瀹嬩綋"); - font.setFontHeightInPoints((short) fontSize); - font.setColor(HSSFColor.GREY_80_PERCENT.index); - - style.setFont(font); - return style ; - } - - public HSSFCell createTitleCell(HSSFSheet sheet, HSSFRow row, String name, int index, Integer width, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index);//Create first column cell - if(style != null){ - cell.setCellStyle(style); - } - cell.setCellType(HSSFCell.CELL_TYPE_STRING); - cell.setCellValue(new HSSFRichTextString(name)); - if(width != null){ - sheet.setColumnWidth(index, width * 1000); - } - return cell ; - } - public HSSFCell createTitleCell_1(HSSFSheet sheet, HSSFRow row, String name, int index, Double width, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index);//Create first column cell - if(style != null){ - cell.setCellStyle(style); - } - cell.setCellType(HSSFCell.CELL_TYPE_STRING); - cell.setCellValue(new HSSFRichTextString(name)); - if(width != null){ - sheet.setColumnWidth(index, (int)(width * 1000)); - } - return cell ; - } - - public void setMergedRegionStyle(HSSFSheet sheet, CellRangeAddress region, HSSFCellStyle style) { - for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) { - HSSFRow row = sheet.getRow(i); - if (row == null) { - row = sheet.createRow(i); - } - for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) { - HSSFCell cell = row.getCell(j); - if (cell == null) { - cell = row.createCell(j); - cell.setCellValue(""); - } - cell.setCellStyle(style); - } - } - } - public void setRegionBorder(int border, CellRangeAddress region, HSSFSheet sheet, HSSFWorkbook wb){ - RegionUtil.setBorderBottom(border,region, sheet, wb); - RegionUtil.setBorderLeft(border,region, sheet, wb); - RegionUtil.setBorderRight(border,region, sheet, wb); - RegionUtil.setBorderTop(border,region, sheet, wb); - } - - public HSSFCell createDataDouCell(HSSFRow row, int index, Double value, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index); - cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); - cell.setCellStyle(style); - if(value != null){ - cell.setCellValue(value); - } - return cell ; - } - - public HSSFCell createDataNumCell(HSSFRow row, int index, Integer value, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index); - cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC); - cell.setCellStyle(style); - if(value != null){ - cell.setCellValue(value); - } - return cell ; - } - - public HSSFCell createDataStrCell(HSSFRow row, int index, String value, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index); - cell.setCellType(HSSFCell.CELL_TYPE_STRING); - cell.setCellStyle(style); - if(value != null){ - cell.setCellValue(value); - } - return cell ; - } - - - public HSSFCell createDataStrCell(HSSFRow row, int index, RichTextString value, HSSFCellStyle style){ - HSSFCell cell = row.createCell(index); - cell.setCellType(HSSFCell.CELL_TYPE_STRING); - cell.setCellStyle(style); - if(value != null){ - cell.setCellValue(value); - } - return cell ; - } - - - public HSSFCell[] createTitleCells(int startColIndex, Object[][] tcs, HSSFSheet sheet, HSSFRow row, HSSFCellStyle style){ - HSSFCell[] cells = new HSSFCell[tcs.length] ; - for(int i = 0; i < tcs.length; i++){ - cells[i] = createTitleCell(sheet, row, (String)tcs[i][0], startColIndex+ i, (Integer)tcs[i][1], style); - } - return cells ; - } - public HSSFCell[] createTitleCells_1(int startColIndex, Object[][] tcs, HSSFSheet sheet, HSSFRow row, HSSFCellStyle style){ - HSSFCell[] cells = new HSSFCell[tcs.length] ; - for(int i = 0; i < tcs.length; i++){ - cells[i] = createTitleCell_1(sheet, row, (String)tcs[i][0], startColIndex+ i, (Double)tcs[i][1], style); - } - return cells ; - } - - public void createContentCells(Object[][] ccs, HSSFRow row){ - for(int i = 0; i < ccs.length; i++){ - createDataStrCell(row, i, (String)ccs[i][0], (HSSFCellStyle)ccs[i][1]) ; - } - } - - - - /** - * 杈撳叆EXCEL鏂囦欢 - * @param workbook - * @param fileName 鏂囦欢鍚� - */ - public boolean outputExcel(HSSFWorkbook workbook, String fileName) { - boolean flag = true ; - FileOutputStream fos = null; - try { - fos = new FileOutputStream(new File(fileName)); - workbook.write(fos); - fos.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - flag = false ; - } catch (IOException e) { - e.printStackTrace(); - flag = false ; - } - return flag ; - } -} diff --git a/pipIrr-platform/pipIrr-global/pom.xml b/pipIrr-platform/pipIrr-global/pom.xml index 1bc1879..a2dcd29 100644 --- a/pipIrr-platform/pipIrr-global/pom.xml +++ b/pipIrr-platform/pipIrr-global/pom.xml @@ -21,6 +21,12 @@ <groupId>com.dy</groupId> <artifactId>pipIrr-common</artifactId> <version>1.0.0</version> + <exclusions> + <exclusion> + <artifactId>spring-boot-starter-log4j2</artifactId> + <groupId>org.springframework.boot</groupId> + </exclusion> + </exclusions> </dependency> <dependency> @@ -122,6 +128,12 @@ <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> + <!--EasyExcel鐩稿叧渚濊禆--> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>easyexcel</artifactId> + <version>3.1.0</version> + </dependency> </dependencies> <build> diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/LocalJsonUtil.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/LocalJsonUtil.java new file mode 100644 index 0000000..718aaa9 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/LocalJsonUtil.java @@ -0,0 +1,28 @@ +package com.dy.pipIrrGlobal.util; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONUtil; +import java.nio.charset.Charset; +import java.util.List; + +/** + * @author ZhuBaoMin + * @date 2023/12/21 11:03 + * @LastEditTime 2023/12/21 11:03 + * @Description + */ +public class LocalJsonUtil { + /** + * 浠庢寚瀹氳矾寰勮幏鍙朖SON骞惰浆鎹负List + * @param path json鏂囦欢璺緞 + * @param elementType List鍏冪礌绫诲瀷 + */ + public static <T> List<T> getListFromJson(String path, Class<T> elementType) { + ClassPathResource resource = new ClassPathResource(path); + String jsonStr = IoUtil.read(resource.getStream(), Charset.forName("UTF-8")); + JSONArray jsonArray = new JSONArray(jsonStr); + return JSONUtil.toList(jsonArray, elementType); + } +} diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoDivide.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoDivide.java index 5973c5c..8ce97eb 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoDivide.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voPr/VoDivide.java @@ -1,5 +1,8 @@ package com.dy.pipIrrGlobal.voPr; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.dy.common.po.BaseEntity; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; @@ -21,25 +24,38 @@ private static final long serialVersionUID = 1L; @Schema(title = "ID") + @ExcelProperty("ID") + @ColumnWidth(10) private Long id; @Schema(title = "鍒嗘按鎴垮悕绉�") + @ExcelProperty("鍒嗘按鎴垮悕绉�") + @ColumnWidth(15) private String divideName; @Schema(title = "鎵�灞炵墖鍖�") + @ExcelProperty("鎵�灞炵墖鍖�") + @ColumnWidth(15) private String blockName; @Schema(title = "璐熻矗浜�") + @ExcelProperty("璐熻矗浜�") + @ColumnWidth(10) private String header; @Schema(title = "鑱旂郴鐢佃瘽") + @ExcelProperty("鑱旂郴鐢佃瘽") + @ColumnWidth(15) private String phone; @Schema(title = "褰掑睘鍦�") + @ExcelProperty("褰掑睘鍦�") + @ColumnWidth(25) private String address; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @Schema(title = "鎿嶄綔鏃堕棿") + @ExcelIgnore private Date operateDt; } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/pom.xml b/pipIrr-platform/pipIrr-web/pipIrr-web-project/pom.xml index c01d5cf..ef2e4e3 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/pom.xml +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/pom.xml @@ -15,7 +15,6 @@ <name>pipIrr-web-project</name> <description>web椤圭洰閰嶇疆绯荤粺</description> - <build> <plugins> <!-- 鐢熸垚涓嶅寘鍚緷璧杍ar鐨勫彲鎵цjar鍖� diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java index 66ef655..93193ff 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java @@ -1,5 +1,7 @@ package com.dy.pipIrrProject.divide; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.support.ExcelTypeEnum; import com.dy.common.aop.SsoAop; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; @@ -16,14 +18,19 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; @@ -93,4 +100,28 @@ return BaseResponseUtils.buildSuccess(true) ; } + + @SneakyThrows(IOException.class) + @RequestMapping(value = "/exportDivides", method = RequestMethod.GET) + public void exportDivides(HttpServletResponse response, QueryVo vo) { + setExcelRespProp(response, "鍒嗘按鎴垮垪琛�"); + //List<VoDivide> memberList = LocalJsonUtil.getListFromJson("json/members.json", VoDivide.class); + List<VoDivide> memberList = divideSv.exportDivides(vo); + + EasyExcel.write(response.getOutputStream()) + .head(VoDivide.class) + .excelType(ExcelTypeEnum.XLSX) + .sheet("鍒嗘按鎴垮垪琛�") + .doWrite(memberList); + } + + /** + * 璁剧疆excel涓嬭浇鍝嶅簲澶村睘鎬� + */ + private void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideSv.java index 9633b5f..5180d7a 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideSv.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -51,4 +52,16 @@ rsVo.obj = prDivideMapper.getDivides(params); return rsVo ; } + + /** + * 鏍规嵁鎸囧畾鏉′欢瀵煎嚭鍒嗘按鎴垮垪琛� + * @param queryVo + * @return + */ + public List<VoDivide> exportDivides(QueryVo queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + List<VoDivide> rsVo = new ArrayList<>(); + rsVo = prDivideMapper.getDivides(params); + return rsVo ; + } } -- Gitblit v1.8.0