From 24c4b9dc96bcfd6a4096004d91816ac2e16a85a3 Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期二, 27 八月 2024 09:41:47 +0800 Subject: [PATCH] 2024-08-27 朱宝民 总账记录及明细账记录导出功能 --- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml | 2 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoGeneral.java | 33 +++- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoTradeDetails.java | 61 +++++-- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java | 61 +++++++- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralSv.java | 65 +++++++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ReportExportCellWriteHandler.java | 173 ++++++++++++++++++++++++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ExcelUtil.java | 22 +++ 7 files changed, 376 insertions(+), 41 deletions(-) diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ExcelUtil.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ExcelUtil.java new file mode 100644 index 0000000..6674095 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ExcelUtil.java @@ -0,0 +1,22 @@ +package com.dy.pipIrrGlobal.excel; + +import jakarta.servlet.http.HttpServletResponse; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +/** + * @author ZhuBaoMin + * @date 2024-08-26 10:28 + * @LastEditTime 2024-08-26 10:28 + * @Description 璁剧疆excel涓嬭浇鍝嶅簲澶村睘鎬� + */ +public class ExcelUtil { + public static void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { + String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + } + +} diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ReportExportCellWriteHandler.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ReportExportCellWriteHandler.java new file mode 100644 index 0000000..8f3ede8 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ReportExportCellWriteHandler.java @@ -0,0 +1,173 @@ +package com.dy.pipIrrGlobal.excel; + +import com.alibaba.excel.metadata.Head; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.write.handler.context.CellWriteHandlerContext; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteTableHolder; +import com.alibaba.excel.write.metadata.style.WriteCellStyle; +import com.alibaba.excel.write.metadata.style.WriteFont; +import com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap; +import org.apache.poi.xssf.usermodel.XSSFCellStyle; +import org.apache.poi.xssf.usermodel.XSSFColor; +import org.springframework.util.PropertyPlaceholderHelper; + +import java.util.List; +import java.util.Objects; +import java.util.Properties; + +/** + * @author ZhuBaoMin + * @date 2024-08-26 14:18 + * @LastEditTime 2024-08-26 14:18 + * @Description + */ + +public class ReportExportCellWriteHandler extends AbstractVerticalCellStyleStrategy { + private String title; + + PropertyPlaceholderHelper propertyPlaceholderHelper = new PropertyPlaceholderHelper("${", "}"); + + public ReportExportCellWriteHandler(String title) { + this.title = title; + } + + // 鍔ㄦ�佸鍏ユ爣棰� + @Override + public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, + Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) { + if (head != null) { + List<String> headNameList = head.getHeadNameList(); + if (CollectionUtils.isNotEmpty(headNameList)) { + Properties properties = new Properties(); + properties.setProperty("title", title); + headNameList.replaceAll(value -> propertyPlaceholderHelper.replacePlaceholders(value, properties)); + } + } + } + + // 璁剧疆鏍囬鏍峰紡锛屽寘鍚瓧浣撱�佽儗鏅� + @Override + protected void setHeadCellStyle(CellWriteHandlerContext context) { + // 鑾峰彇鍜屽垱寤篊ellStyle + WriteCellData<?> cellData = context.getFirstCellData(); + CellStyle originCellStyle = cellData.getOriginCellStyle(); + Cell cell = context.getCell(); + + if (Objects.isNull(originCellStyle)) { + originCellStyle = context.getWriteWorkbookHolder().getWorkbook().createCellStyle(); + } + + ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255), new DefaultIndexedColorMap())); + + // 璁剧疆鎸囧畾鍒楄儗鏅壊 + //if(cell.getColumnIndex() == 10 + //) { + // ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(237, 237, 237), new DefaultIndexedColorMap())); + //} + + // 璁剧疆鑳屾櫙棰滆壊 + originCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + // 鐢变簬鍦‵illStyleCellWriteHandler锛屼細鎶奜riginCellStyle鍜學riteCellStyle鍚堝苟锛屼細浠riteCellStyle鏍峰紡涓轰富锛屾墍鏈夊繀椤绘妸WriteCellStyle璁剧疆鐨勮儗鏅壊娓呯┖ + // 鍏蜂綋鍚堝苟瑙勫垯鐪媁riteWorkbookHolder.createCellStyle鏂规硶 + WriteCellStyle writeCellStyle = cellData.getWriteCellStyle(); + writeCellStyle.setFillForegroundColor(null); + // 蹇呴』璁剧疆OriginCellStyle + cellData.setOriginCellStyle(originCellStyle); + + WriteFont headWriteFont = new WriteFont(); + if (cell.getRowIndex() == 0) { + headWriteFont.setFontHeightInPoints((short)14); + headWriteFont.setFontName("Arial"); + headWriteFont.setBold(true); + }else if (cell.getRowIndex() == 1) { + headWriteFont.setFontHeightInPoints((short)12); + headWriteFont.setFontName("Arial"); + headWriteFont.setBold(false); + } + + cellData.getWriteCellStyle().setWriteFont(headWriteFont); + } + + // 璁剧疆鍐呭鍏ず銆佸唴瀹瑰瓧浣撴牱寮忋�佽儗鏅牱寮� + @Override + protected void setContentCellStyle(CellWriteHandlerContext context) { + + // 鑾峰彇鍜屽垱寤篊ellStyle + WriteCellData<?> cellData = context.getFirstCellData(); + CellStyle originCellStyle = cellData.getOriginCellStyle(); + Cell cell = context.getCell(); + + if (Objects.isNull(originCellStyle)) { + originCellStyle = context.getWriteWorkbookHolder().getWorkbook().createCellStyle(); + } + // 璁剧疆鑳屾櫙棰滆壊 + ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 192, 0), new DefaultIndexedColorMap())); + //System.out.println("Go to row: " + context.getCell().getRowIndex() + ", column: " + context.getCell().getColumnIndex()); + + if (cell.getRowIndex() >= 2){ + ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(237, 237, 237), new DefaultIndexedColorMap())); + // 绁ㄩ潰鎬讳环 + //if (cell.getColumnIndex() == 10){ + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("I" + actualCellRowNum +"+J" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "绁ㄩ潰鎬讳环鍐欏叆鍏紡瀹屾垚"); + //}else if (cell.getColumnIndex() == 12){ + // // 鏀粯绁ㄦ + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("K" + actualCellRowNum +"-L" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "鏀粯绁ㄦ鍐欏叆鍏紡瀹屾垚"); + //}else if (cell.getColumnIndex() == 15){ + // // 鏀粯鎬婚 + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("M" + actualCellRowNum +"+N" + actualCellRowNum +"+O" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "鏀粯鎬婚鍐欏叆鍏紡瀹屾垚"); + //}else if (cell.getColumnIndex() == 17){ + // // 瀹為檯鍒╂鼎 + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("L" + actualCellRowNum +"+Q" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "瀹為檯鍒╂鼎鍐欏叆鍏紡瀹屾垚"); + //}else if (cell.getColumnIndex() == 18){ + // // 搴旀敹娆� + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("P" + actualCellRowNum +"+R" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "搴旀敹娆惧啓鍏ュ叕寮忓畬鎴�"); + //}else if (cell.getColumnIndex() == 20){ + // // 鏈敹娆� + // int actualCellRowNum = context.getCell().getRowIndex() + 1; + // context.getCell().setCellFormula("S" + actualCellRowNum +"-T" + actualCellRowNum); + // System.out.println("绗�" + context.getCell().getRowIndex() + "琛�,绗�" + context.getCell().getColumnIndex() + "鏈敹娆惧啓鍏ュ叕寮忓畬鎴�"); + //}else if (cell.getColumnIndex() >= 2){ + // ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(189, 215, 238), new DefaultIndexedColorMap())); + //}else if (cell.getColumnIndex() < 2){ + // ((XSSFCellStyle) originCellStyle).setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 192, 0), new DefaultIndexedColorMap())); + //} + } + + originCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); + originCellStyle.setBorderLeft(BorderStyle.THIN); //宸﹁竟妗嗙嚎 + originCellStyle.setBorderTop(BorderStyle.THIN); //椤堕儴妗嗙嚎 + originCellStyle.setBorderRight(BorderStyle.THIN); //鍙宠竟妗嗙嚎 + originCellStyle.setBorderBottom(BorderStyle.THIN); //搴曢儴妗嗙嚎 + // 鐢变簬鍦‵illStyleCellWriteHandler锛屼細鎶奜riginCellStyle鍜學riteCellStyle鍚堝苟锛屼細浠riteCellStyle鏍峰紡涓轰富锛屾墍鏈夊繀椤绘妸WriteCellStyle璁剧疆鐨勮儗鏅壊娓呯┖ + // 鍏蜂綋鍚堝苟瑙勫垯鐪媁riteWorkbookHolder.createCellStyle鏂规硶 + WriteCellStyle writeCellStyle = cellData.getWriteCellStyle(); + writeCellStyle.setFillForegroundColor(null); + writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); + writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); + // 蹇呴』璁剧疆OriginCellStyle + cellData.setOriginCellStyle(originCellStyle); + + WriteFont headWriteFont = new WriteFont(); + headWriteFont.setFontHeightInPoints((short)12); + headWriteFont.setFontName("瀹嬩綋"); + headWriteFont.setBold(false); + headWriteFont.setColor(IndexedColors.BLACK.getIndex()); + + cellData.getWriteCellStyle().setWriteFont(headWriteFont); + } +} + diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoGeneral.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoGeneral.java index 49ef7bb..264803d 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoGeneral.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoGeneral.java @@ -1,5 +1,10 @@ package com.dy.pipIrrGlobal.voSe; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.ContentRowHeight; +import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.alibaba.fastjson2.annotation.JSONField; import com.alibaba.fastjson2.writer.ObjectWriterImplToString; import com.dy.common.po.BaseEntity; @@ -16,40 +21,50 @@ @Data @JsonPropertyOrder({ "generalId", "cashierId", "cashierName", "tradeAmount", "gift", "refundAmount", "totalAmount", "operateDate", "auditStatus"}) -@Schema(title = "璐㈠姟瀵硅处涔嬫�昏处瑙嗗浘瀵硅薄") +@HeadRowHeight(30) +@ContentRowHeight(20) public class VoGeneral implements BaseEntity { private static final long serialVersionUID = 202401241706001L; @Schema(title = "鎬昏处ID") @JSONField(serializeUsing= ObjectWriterImplToString.class) + @ExcelIgnore private Long generalId; @Schema(title = "鏀堕摱鍛業D") @JSONField(serializeUsing= ObjectWriterImplToString.class) + @ExcelIgnore private Long cashierId; - @Schema(title = "鏀堕摱鍛樺鍚�") + @ExcelProperty(value = {"${title}", "鏀堕摱鍛樺鍚�"}) + @ColumnWidth(18) private String cashierName; - @Schema(title = "瀹炴敹閲戦") + @ExcelProperty(value = {"${title}", "瀹炴敹閲戦"}) + @ColumnWidth(15) private Float tradeAmount; - @Schema(title = "璧犻�侀噾棰�") + @ExcelProperty(value = {"${title}", "璧犻�侀噾棰�"}) + @ColumnWidth(15) private Float gift; - @Schema(title = "杩旇繕閲戦") + @ExcelProperty(value = {"${title}", "杩旇繕閲戦"}) + @ColumnWidth(15) private Float refundAmount; /** - * 鎬婚 = 瀹炴敹閲戦 + 璧犻�侀噾棰� + 杩旇繕閲戦 + * 鎬婚 = 瀹炴敹閲戦 + 璧犻�侀噾棰� - 杩旇繕閲戦 */ - @Schema(title = "鎬婚") + @ExcelProperty(value = {"${title}", "鎬婚"}) + @ColumnWidth(10) private Float totalAmount; - @Schema(title = "浜ゆ槗鏃ユ湡") + @ExcelProperty(value = {"${title}", "浜ゆ槗鏃ユ湡"}) + @ColumnWidth(15) private String operateDate; - @Schema(title = "瀹℃牳鐘舵��") + @ExcelProperty(value = {"${title}", "瀹℃牳鐘舵��"}) + @ColumnWidth(15) private String auditStatus; } diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoTradeDetails.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoTradeDetails.java index 3caef8d..559f77e 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoTradeDetails.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voSe/VoTradeDetails.java @@ -1,7 +1,12 @@ package com.dy.pipIrrGlobal.voSe; +import com.alibaba.excel.annotation.ExcelIgnore; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.alibaba.excel.annotation.write.style.ContentRowHeight; +import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.dy.common.po.BaseEntity; -import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; @@ -16,51 +21,67 @@ */ @Data -@Schema(title = "璐㈠姟瀵硅处锛屼氦鏄撴槑缁嗚鍥惧璞�") +@JsonPropertyOrder({ "cashierId", "villageId", "clientNum", "districtTitle", "clientName", "phone", "operateType", "tradeAmount", "waterCost", "cardCost", "gift", "refundAmount", "paymentName", "tradeTime"}) +@HeadRowHeight(30) +@ContentRowHeight(20) public class VoTradeDetails implements BaseEntity { private static final long serialVersionUID = 202402012040001L; @Schema(title = "鏀堕摱鍛業D") + @ExcelIgnore private String cashierId; - @Schema(title = "鍖哄垝鍚嶇О涓�") - private String districtTitle; - @Schema(title = "鏉戝簞ID") + @ExcelIgnore private String villageId; - @Schema(title = "鍐滄埛濮撳悕") - private String clientName; - - @Schema(title = "鑱旂郴鐢佃瘽") - private String phone; - @Schema(title = "鍐滄埛缂栧彿") + @ExcelIgnore private String clientNum; - @Schema(title = "涓氬姟绫诲瀷") + @ExcelProperty(value = {"${title}", "鏉戝簞鍚嶇О"}) + @ColumnWidth(20) + private String districtTitle; + + @ExcelProperty(value = {"${title}", "鍐滄埛濮撳悕"}) + @ColumnWidth(15) + private String clientName; + + @ExcelProperty(value = {"${title}", "鑱旂郴鐢佃瘽"}) + @ColumnWidth(15) + private String phone; + + @ExcelProperty(value = {"${title}", "涓氬姟绫诲瀷"}) + @ColumnWidth(15) private String operateType; - @Schema(title = "浜ゆ槗閲戦") + @ExcelProperty(value = {"${title}", "浜ゆ槗閲戦"}) + @ColumnWidth(15) private Double tradeAmount; - @Schema(title = "璐按閲戦") + @ExcelProperty(value = {"${title}", "璐按閲戦"}) + @ColumnWidth(15) private Double waterCost; - @Schema(title = "璐崱閲戦") + @ExcelProperty(value = {"${title}", "璐崱閲戦"}) + @ColumnWidth(15) private Double cardCost; - @Schema(title = "璧犻�侀噾棰�") + @ExcelProperty(value = {"${title}", "璧犻�侀噾棰�"}) + @ColumnWidth(15) private Double gift; - @Schema(title = "杩斿洖閲戦") + @ExcelProperty(value = {"${title}", "杩旇繕閲戦"}) + @ColumnWidth(15) private Double refundAmount; - @Schema(title = "浠樻鏂瑰紡") + @ExcelProperty(value = {"${title}", "浠樻鏂瑰紡"}) + @ColumnWidth(15) private String paymentName; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") - @Schema(title = "浜ゆ槗鏃堕棿") + @ExcelProperty(value = {"${title}", "浜ゆ槗鏃堕棿"}) + @ColumnWidth(20) private Date tradeTime; + } diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml index 0a4eb71..9e7786d 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/resources/application-database.yml @@ -3,7 +3,7 @@ datasource: #閰嶇疆鏁版嵁婧� type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver - #url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull +# url: jdbc:mysql://192.168.40.166:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull #url: jdbc:mysql://8.130.130.233:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull #url: jdbc:mysql://8.140.179.55:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull url: jdbc:mysql://127.0.0.1:3306/pipIrr_ym?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java index f8f3b8b..94fdf5c 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralCtrl.java @@ -1,14 +1,18 @@ package com.dy.pipIrrSell.general; +import com.alibaba.excel.EasyExcel; import com.dy.common.aop.SsoAop; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import com.dy.common.webUtil.QueryResultVo; import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.excel.ExcelUtil; +import com.dy.pipIrrGlobal.excel.ReportExportCellWriteHandler; import com.dy.pipIrrGlobal.pojoBa.BaClient; import com.dy.pipIrrGlobal.pojoSe.SeAudits; import com.dy.pipIrrGlobal.pojoSe.SeGeneral; import com.dy.pipIrrGlobal.voSe.VoGeneral; +import com.dy.pipIrrGlobal.voSe.VoTradeDetails; import com.dy.pipIrrSell.general.dto.DtoGeneral; import com.dy.pipIrrSell.general.qo.QoGeneral; import com.dy.pipIrrSell.general.qo.QoSummary; @@ -20,14 +24,18 @@ 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.time.LocalDate; import java.util.*; /** @@ -66,15 +74,27 @@ try { add_general(); QueryResultVo<List<VoGeneral>> res = generalSv.getGenerals(vo); - if(res.itemTotal > 0) { - return BaseResponseUtils.buildSuccess(res); - }else { - return BaseResponseUtils.buildSuccess(SellResultCode.No_GENERALS.getMessage()); - } + return BaseResponseUtils.buildSuccess(res); } catch (Exception e) { log.error("鏌ヨ浜ゆ槗璁板綍寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; } + } + + /** + * 瀵煎嚭鎬昏处璁板綍 + * @param response + * @param vo + */ + @SneakyThrows(IOException.class) + @RequestMapping(value = "/export_general", method = RequestMethod.GET) + public void exportGeneral(HttpServletResponse response, QoGeneral vo) { + ExcelUtil.setExcelRespProp(response, "鎬昏处" + LocalDate.now()); + List<VoGeneral> generalList = generalSv.exportGenerals(vo).getObj(); + EasyExcel.write(response.getOutputStream(), VoGeneral.class) + .registerWriteHandler(new ReportExportCellWriteHandler("璐㈠姟瀵硅处-鎬昏处")) + .sheet("鎬昏处") + .doWrite(generalList); } /** @@ -218,15 +238,34 @@ @SsoAop() public BaseResponse<Map> getTradeDetails(QoToAudit vo){ try { - Map res = Optional.ofNullable(generalSv.getTradeDetails(vo)).orElse(new HashMap()); - if(res.size() > 0) { - return BaseResponseUtils.buildSuccess(res); - }else { - return BaseResponseUtils.buildFail(SellResultCode.No_TRADE_DETAILS.getMessage()); - } + return BaseResponseUtils.buildSuccess(generalSv.getTradeDetails(vo)); } catch (Exception e) { log.error("鏌ヨ浜ゆ槗璁板綍寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; } } + + /** + * 瀵煎嚭璐㈠姟瀵硅处_浜ゆ槗鏄庣粏 + * @param response + * @param vo + */ + @SneakyThrows(IOException.class) + @RequestMapping(value = "/export_trade_details", method = RequestMethod.GET) + public void exportTradeDetails(HttpServletResponse response, QoToAudit vo) { + ExcelUtil.setExcelRespProp(response, "浜ゆ槗鏄庣粏" + LocalDate.now()); + + Map map_result = generalSv.exportTradeDetails(vo); + Map map_record = (Map) map_result.get("records"); + List<VoTradeDetails> list = (List<VoTradeDetails>) map_record.get("list"); + Double totalTradeAmount = Double.parseDouble(map_result.get("totalTradeAmount").toString()); + VoTradeDetails po = new VoTradeDetails(); + po.setTradeAmount(totalTradeAmount); + list.add(po); + + EasyExcel.write(response.getOutputStream(), VoTradeDetails.class) + .registerWriteHandler(new ReportExportCellWriteHandler("璐㈠姟瀵硅处-浜ゆ槗鏄庣粏")) + .sheet("浜ゆ槗鏄庣粏") + .doWrite(list); + } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralSv.java index 7c6804d..49c1cce 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralSv.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/general/GeneralSv.java @@ -88,8 +88,25 @@ rsVo.pageSize = queryVo.pageSize ; rsVo.pageCurr = queryVo.pageCurr ; + rsVo.calculateAndSet(itemTotal, params); + rsVo.obj = seGeneralMapper.getGenerals(params); + return rsVo ; + } + + /** + * 瀵煎嚭鎸囧畾鏉′欢鐨勬�昏处璁板綍 + * @param queryVo + * @return + */ + public QueryResultVo<List<VoGeneral>> exportGenerals(QoGeneral queryVo) { + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + + Long itemTotal = seGeneralMapper.getRecordCount(params); + QueryResultVo<List<VoGeneral>> rsVo = new QueryResultVo<>() ; rsVo.calculateAndSet(itemTotal, params); + params.remove("start"); + params.remove("count"); rsVo.obj = seGeneralMapper.getGenerals(params); return rsVo ; } @@ -279,4 +296,52 @@ return map_result; } + + /** + * 瀵煎嚭浜ゆ槗鏄庣粏璁板綍 + * @param queryVo + * @return + */ + public Map exportTradeDetails(QoToAudit queryVo) { + DecimalFormat df = new DecimalFormat("0.00"); + Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); + + Long itemTotal = seGeneralMapper.getTradeDetailsRecordCount(params); + + QueryResultVo<List<VoTradeDetails>> rsVo = new QueryResultVo<>() ; + rsVo.pageSize = queryVo.pageSize ; + rsVo.pageCurr = queryVo.pageCurr ; + + rsVo.calculateAndSet(itemTotal, params); + params.remove("start"); + params.remove("count"); + List<VoTradeDetails> list = Optional.ofNullable(seGeneralMapper.getTradeDetails(params)).orElse(new ArrayList<>()); + if(list.size() == 0) { + return new HashMap(); + } + + // 閬嶅巻浜ゆ槗鏄庣粏璁板綍锛屾眹鎬讳氦鏄撻噾棰� + Double totalTradeAmount = 0.0; + JSONArray array= JSONArray.parseArray(JSON.toJSONString(list)); + for(int i = 0; i < array.size(); i++) { + JSONObject job = array.getJSONObject(i); + Double tradeAmount = Optional.ofNullable(job.getDouble("tradeAmount")).orElse(0.0); + totalTradeAmount = totalTradeAmount + tradeAmount; + } + + Map map_record = new HashMap(); + map_record.put("itemTotal", rsVo.itemTotal); + map_record.put("pageCurr", rsVo.pageCurr); + map_record.put("pageSize", rsVo.pageSize); + map_record.put("pageTotal", rsVo.pageTotal); + map_record.put("list", list); + + Map map_result = new HashMap(); + + map_result.put("totalTradeAmount", df.format(totalTradeAmount)); + map_result.put("records", map_record); + + return map_result; + + } } -- Gitblit v1.8.0