From d7e72a37aa0e1c29db56cee822430c62dc698525 Mon Sep 17 00:00:00 2001 From: huangqizhen <15552608129@163.com> Date: Fri, 21 Nov 2025 15:58:30 +0800 Subject: [PATCH] =?UTF-8?q?11.21=20=E5=AF=BC=E5=87=BA=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/config/MarketConverter.java | 74 +++++++++++++++++++ .../example/demo/config/OrderStatusConverter.java | 82 ++++++++++++++++++++++ .../example/demo/config/RefundModelConverter.java | 60 ++++++++++++++++ .../example/demo/domain/vo/cash/CashRecordDTO.java | 21 +++--- src/main/resources/cashMapper/MessageMapper.xml | 2 +- 5 files changed, 229 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/example/demo/config/MarketConverter.java create mode 100644 src/main/java/com/example/demo/config/OrderStatusConverter.java create mode 100644 src/main/java/com/example/demo/config/RefundModelConverter.java diff --git a/src/main/java/com/example/demo/config/MarketConverter.java b/src/main/java/com/example/demo/config/MarketConverter.java new file mode 100644 index 0000000..3f46342 --- /dev/null +++ b/src/main/java/com/example/demo/config/MarketConverter.java @@ -0,0 +1,74 @@ +package com.example.demo.config; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import java.util.HashMap; +import java.util.Map; + +/** + * 所属地区转换器:Integer(地区ID)→ 地区名称(EasyExcel导出用) + */ +public class MarketConverter implements Converter { + + // 地区ID → 地区名称 映射表(从数据库表中提取) + private static final Map MARKET_MAP = new HashMap<>(); + + static { + // 初始化映射关系(严格对应数据库表中的id和name) + MARKET_MAP.put(1, "Capt"); + MARKET_MAP.put(2, "公司"); + MARKET_MAP.put(3, "市场部"); + MARKET_MAP.put(4, "新加坡"); + MARKET_MAP.put(5, "马来西亚"); + MARKET_MAP.put(9, "研发部"); + MARKET_MAP.put(999, "总部"); + MARKET_MAP.put(24016, "加拿大"); + MARKET_MAP.put(24018, "泰国"); + MARKET_MAP.put(24022, "越南HCM"); + MARKET_MAP.put(24027, "韩国"); + MARKET_MAP.put(24028, "深圳运营"); + MARKET_MAP.put(24030, "非网"); + MARKET_MAP.put(24031, "其他"); + MARKET_MAP.put(24032, "市场部"); + } + + /** + * 支持的Java类型(Integer,与market字段类型一致) + */ + @Override + public Class supportJavaTypeKey() { + return Integer.class; + } + + /** + * Excel单元格数据类型(字符串,显示地区名称) + */ + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; + } + + /** + * 导出时:Integer地区ID → 地区名称 + */ + @Override + public WriteCellData convertToExcelData(Integer marketId, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + // 未匹配到的ID,显示“未知地区(ID值)”,便于排查异常 + String marketName = MARKET_MAP.getOrDefault(marketId, "未知地区(" + marketId + ")"); + return new WriteCellData<>(marketName); + } + + /** + * 导入时:地区名称 → Integer地区ID(可选实现,如需导入可启用) + */ + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + // 若需支持导入,可实现反向映射;此处仅导出用,返回null即可 + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/config/OrderStatusConverter.java b/src/main/java/com/example/demo/config/OrderStatusConverter.java new file mode 100644 index 0000000..79748b3 --- /dev/null +++ b/src/main/java/com/example/demo/config/OrderStatusConverter.java @@ -0,0 +1,82 @@ +package com.example.demo.config; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import java.util.HashMap; +import java.util.Map; + +/** + * 订单状态转换器:Integer值 → 中文描述(EasyExcel导出用) + */ +public class OrderStatusConverter implements Converter { + + // 状态值 → 中文描述 映射表(严格对应注释中的状态) + private static final Map STATUS_MAP = new HashMap<>(); + + static { + // 初始化映射关系(复制注释中的状态,避免遗漏) + STATUS_MAP.put(0, "线下财务待审核"); + STATUS_MAP.put(1, "线下财务审核通过待填手续费"); + STATUS_MAP.put(2, "线下财务审核驳回"); + STATUS_MAP.put(5, "手动撤回待编辑提交"); + STATUS_MAP.put(3, "link线上财务复核待填手续费"); + STATUS_MAP.put(4, "收款流程全部结束"); + STATUS_MAP.put(6, "退款"); + STATUS_MAP.put(10, "地区财务待审核"); + STATUS_MAP.put(11, "地区财务手动撤回待编辑提交"); + STATUS_MAP.put(12, "地区财务驳回"); + STATUS_MAP.put(20, "地区负责人待审核"); + STATUS_MAP.put(22, "地区负责人驳回"); + STATUS_MAP.put(30, "总部财务待审核"); + STATUS_MAP.put(32, "总部财务驳回"); + STATUS_MAP.put(40, "执行人待处理"); + STATUS_MAP.put(41, "执行人已处理,退款结束"); + } + + /** + * 支持的Java类型(Integer,与status字段类型一致) + */ + @Override + public Class supportJavaTypeKey() { + return Integer.class; + } + + /** + * Excel单元格数据类型(字符串,显示中文描述) + */ + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; + } + + /** + * 导出时:Integer状态值 → 中文描述 + */ + @Override + public WriteCellData convertToExcelData(Integer status, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + // 未匹配到的状态,显示“未知状态”(避免导出空值) + String statusDesc = STATUS_MAP.getOrDefault(status, "未知状态(" + status + ")"); + return new WriteCellData<>(statusDesc); + } + + /** + * 导入时:中文描述 → Integer状态值(可选实现,如需导入可启用) + */ + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + String statusDesc = cellData.getStringValue(); + // 反向映射:根据中文描述找状态值(如果需要导入功能) + for (Map.Entry entry : STATUS_MAP.entrySet()) { + if (entry.getValue().equals(statusDesc)) { + return entry.getKey(); + } + } + // 未匹配到返回null或自定义默认值 + return null; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/config/RefundModelConverter.java b/src/main/java/com/example/demo/config/RefundModelConverter.java new file mode 100644 index 0000000..a0de61b --- /dev/null +++ b/src/main/java/com/example/demo/config/RefundModelConverter.java @@ -0,0 +1,60 @@ +package com.example.demo.config; + +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.data.ReadCellData; +import com.alibaba.excel.metadata.data.WriteCellData; +import com.alibaba.excel.metadata.property.ExcelContentProperty; + +import java.util.HashMap; +import java.util.Map; + +/** + * 退款方式转换器:0→全额,1→部分(EasyExcel导出用) + */ +public class RefundModelConverter implements Converter { + + // 退款方式映射表(严格对应:0=全额,1=部分) + private static final Map REFUND_MODEL_MAP = new HashMap<>(); + + static { + REFUND_MODEL_MAP.put(0, "全额"); + REFUND_MODEL_MAP.put(1, "部分"); + } + + @Override + public Class supportJavaTypeKey() { + return Integer.class; // 支持的Java类型(与refundModel字段类型一致) + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + return CellDataTypeEnum.STRING; // Excel显示为字符串(中文描述) + } + + /** + * 导出时:Integer值 → 中文描述 + */ + @Override + public WriteCellData convertToExcelData(Integer refundModel, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + // 未匹配到的异常值(如2、null等)显示“未知退款方式”,便于排查 + String desc = REFUND_MODEL_MAP.getOrDefault(refundModel, "未知退款方式(" + (refundModel == null ? "null" : refundModel) + ")"); + return new WriteCellData<>(desc); + } + + /** + * 导入时:中文描述 → Integer值(可选实现,如需导入可启用) + */ + @Override + public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { + String desc = cellData.getStringValue(); + // 反向映射:根据中文找对应数值 + for (Map.Entry entry : REFUND_MODEL_MAP.entrySet()) { + if (entry.getValue().equals(desc)) { + return entry.getKey(); + } + } + return null; // 未匹配返回null(可根据业务调整默认值) + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/domain/vo/cash/CashRecordDTO.java b/src/main/java/com/example/demo/domain/vo/cash/CashRecordDTO.java index 17d1e53..3b553e4 100644 --- a/src/main/java/com/example/demo/domain/vo/cash/CashRecordDTO.java +++ b/src/main/java/com/example/demo/domain/vo/cash/CashRecordDTO.java @@ -2,6 +2,9 @@ package com.example.demo.domain.vo.cash; import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; +import com.example.demo.config.MarketConverter; +import com.example.demo.config.OrderStatusConverter; +import com.example.demo.config.RefundModelConverter; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; import lombok.Data; @@ -26,11 +29,11 @@ import java.util.List; public class CashRecordDTO{ @ExcelIgnore private String activity;// 活动 - @ExcelProperty("商品名称") + @ExcelProperty("产品名称") private String goodsName;// 商品名称 - @ExcelProperty("商品数量") + @ExcelProperty("产品数量") private Integer goodsNum;// 商品数量 - @ExcelProperty("商品单位") + @ExcelProperty("产品单位") private String numUnit;// 商品单位 @ExcelIgnore private BigDecimal gold;//永久金币 @@ -93,15 +96,15 @@ public class CashRecordDTO{ /** * 姓名 */ - @ExcelProperty("姓名") - private String userName; @ExcelIgnore + private String userName; + @ExcelProperty("姓名") private String name; /** * 所属地区 */ - @ExcelProperty("所属地区") + @ExcelProperty(value = "所属地区",converter = MarketConverter.class) private Integer market; /** @@ -146,7 +149,7 @@ public class CashRecordDTO{ 30:总部财务待审核;32:总部财务驳回; 40:执行人待处理;41:执行人已处理,退款结束 */ - @ExcelProperty("订单状态") + @ExcelProperty(value="订单状态",converter = OrderStatusConverter.class) private Integer status; /** @@ -182,13 +185,13 @@ public class CashRecordDTO{ /** * 退款备注(理由),客服填写 */ - @ExcelProperty("退款备注") + @ExcelProperty("退款理由") private String refundReason; /** * 退款方式(0全额/1部分) */ - @ExcelProperty("退款方式") + @ExcelProperty(value = "退款方式",converter = RefundModelConverter.class) private Integer refundModel; /** diff --git a/src/main/resources/cashMapper/MessageMapper.xml b/src/main/resources/cashMapper/MessageMapper.xml index 724a078..602a9ba 100644 --- a/src/main/resources/cashMapper/MessageMapper.xml +++ b/src/main/resources/cashMapper/MessageMapper.xml @@ -24,7 +24,7 @@ ORDER BY ${sortField} ${sortOrder} - ORDER BY crr.create_time DESC + ORDER BY cz_time DESC