Commit ccfca7e3 by chenxi

refactor(export): 调整套餐商品导出结构及字段索引

- 废弃 MerchantPackageGoodsExportVO 中列索引4,门店中间层相关字段移至索引17
- MerchantPackageGoodsMerchantExportVO 中新增 yqMerchantName 字段,调整 merchantName 列索引为16
- 导出服务对接信息由套餐层聚合移至门店层,为园区店对应字段赋值
- MerchantGoodsRefDTO 增加 yqMerchantName 字段用于导出映射
- 更新 MyBatis 映射及查询语句,支持园区店名称字段查询及映射
- 修正相关注解及转换器的列索引,保证导出字段顺序正确
1 parent cc7b5386
...@@ -111,15 +111,8 @@ public class MerchantPackageGoodsInfoService { ...@@ -111,15 +111,8 @@ public class MerchantPackageGoodsInfoService {
MerchantPackageGoodsExportVO exportDataVO = MerchantPackageGoodsExportVO exportDataVO =
MerchantPackageGoodsInfoDTOConvert.INSTANCE.toMerchantPackageGoodsExportVO(packageGoodsInfo); MerchantPackageGoodsInfoDTOConvert.INSTANCE.toMerchantPackageGoodsExportVO(packageGoodsInfo);
// 服务对接(套餐层聚合)
String yqMerchantName = org.apache.commons.collections.CollectionUtils.isEmpty(
packageGoodsInfo.getYqMerchantGoodsRefList()) ? ""
: packageGoodsInfo.getYqMerchantGoodsRefList().stream()
.map(ServiceMerchant::getMerchantName)
.collect(Collectors.joining("/"));
exportDataVO.setYqMerchantName(yqMerchantName);
exportDataVO.setIndexNum(index++); exportDataVO.setIndexNum(index++);
// 获取该套餐对应的 (merchantId_merchantGoodsId) -> inventoryType map // 获取该套餐对应的 (merchantId_merchantGoodsId) -> inventoryType map
Map<String, Byte> invMap = packageInvTypeMap.getOrDefault( Map<String, Byte> invMap = packageInvTypeMap.getOrDefault(
packageGoodsInfo.getPackageCode(), Collections.emptyMap()); packageGoodsInfo.getPackageCode(), Collections.emptyMap());
...@@ -135,7 +128,7 @@ public class MerchantPackageGoodsInfoService { ...@@ -135,7 +128,7 @@ public class MerchantPackageGoodsInfoService {
for (MerchantGoodsRefDTO merchantRef : merchantGoodsRefList) { for (MerchantGoodsRefDTO merchantRef : merchantGoodsRefList) {
MerchantPackageGoodsMerchantExportVO merchantVO = new MerchantPackageGoodsMerchantExportVO(); MerchantPackageGoodsMerchantExportVO merchantVO = new MerchantPackageGoodsMerchantExportVO();
merchantVO.setMerchantName(merchantRef.getMerchantName()); merchantVO.setMerchantName(merchantRef.getMerchantName());
merchantVO.setYqMerchantName(merchantRef.getYqMerchantName() != null ? merchantRef.getYqMerchantName() : "");
// 每个门店复制一份商品列表,并回填该门店对应的 inventoryType // 每个门店复制一份商品列表,并回填该门店对应的 inventoryType
List<MerchantGoodsInfoExportVO> goodsListForMerchant = new ArrayList<>(); List<MerchantGoodsInfoExportVO> goodsListForMerchant = new ArrayList<>();
for (MerchantGoodsInfoExportVO baseGoods : baseGoodsList) { for (MerchantGoodsInfoExportVO baseGoods : baseGoodsList) {
......
...@@ -43,56 +43,52 @@ public class MerchantPackageGoodsExportVO implements Serializable { ...@@ -43,56 +43,52 @@ public class MerchantPackageGoodsExportVO implements Serializable {
@ExcelProperty(value = "套餐别名") @ExcelProperty(value = "套餐别名")
private String packageAlias; private String packageAlias;
// 列索引4留给门店中间层(MerchantPackageGoodsMerchantExportVO.merchantName) // 列索引4已废弃(门店中间层移至columIndex=17)
@ExcelMergeRow(columIndex = 5) @ExcelMergeRow(columIndex = 5)
@ExcelProperty(value="服务对接")
private String yqMerchantName;
@ExcelMergeRow(columIndex = 6)
@ExcelProperty(value="业务场景",converter= ReplaceByteToStringConvert.class) @ExcelProperty(value="业务场景",converter= ReplaceByteToStringConvert.class)
@ExcelValueReplace(replace={"会员/权益升级_0","精品升级_1","次新车转化_2","售后众筹_3","积分商城_4"},repeatValue=true) @ExcelValueReplace(replace={"会员/权益升级_0","精品升级_1","次新车转化_2","售后众筹_3","积分商城_4"},repeatValue=true)
private Byte sceneType; private Byte sceneType;
@ExcelMergeRow(columIndex = 7) @ExcelMergeRow(columIndex = 6)
@ExcelProperty(value = "状态",converter= ReplaceByteToStringConvert.class) @ExcelProperty(value = "状态",converter= ReplaceByteToStringConvert.class)
@ExcelValueReplace(replace={"草稿_3","待审核_4","已上架_1","已下架_0"},repeatValue=true) @ExcelValueReplace(replace={"草稿_3","待审核_4","已上架_1","已下架_0"},repeatValue=true)
private Byte status; private Byte status;
@ExcelMergeRow(columIndex = 8) @ExcelMergeRow(columIndex = 7)
@ExcelProperty(value = "财务校验",converter= ReplaceStringToStringConvert.class) @ExcelProperty(value = "财务校验",converter= ReplaceStringToStringConvert.class)
@ExcelValueReplace(replace={"开启_Y","关闭_N"},repeatValue=true) @ExcelValueReplace(replace={"开启_Y","关闭_N"},repeatValue=true)
private String financeCheckFlag; private String financeCheckFlag;
@ExcelMergeRow(columIndex = 9) @ExcelMergeRow(columIndex = 8)
@ExcelProperty(value="售价/元") @ExcelProperty(value="售价/元")
private BigDecimal sellPrice; private BigDecimal sellPrice;
@ExcelMergeRow(columIndex = 10) @ExcelMergeRow(columIndex = 9)
@ExcelProperty(value="最低售价/元") @ExcelProperty(value="最低售价/元")
private BigDecimal minSellPrice; private BigDecimal minSellPrice;
@ExcelMergeRow(columIndex = 11) @ExcelMergeRow(columIndex = 10)
@ExcelProperty(value = "升级/产品成本") @ExcelProperty(value = "升级/产品成本")
private BigDecimal upgradeProductCost; private BigDecimal upgradeProductCost;
@ExcelMergeRow(columIndex = 12) @ExcelMergeRow(columIndex = 11)
@ExcelProperty(value="回收成本") @ExcelProperty(value="回收成本")
private BigDecimal recoveryCost; private BigDecimal recoveryCost;
@ExcelMergeRow(columIndex = 13) @ExcelMergeRow(columIndex = 12)
@ExcelProperty(value="虚拟对账成本") @ExcelProperty(value="虚拟对账成本")
private BigDecimal virtualAccountCost; private BigDecimal virtualAccountCost;
@ExcelMergeRow(columIndex = 14) @ExcelMergeRow(columIndex = 13)
@ExcelProperty(value = "嘀加成本") @ExcelProperty(value = "嘀加成本")
private BigDecimal djCost; private BigDecimal djCost;
@ExcelMergeRow(columIndex = 15) @ExcelMergeRow(columIndex = 14)
@ExcelProperty(value="第三方成本") @ExcelProperty(value="第三方成本")
private BigDecimal thirdPartyCost; private BigDecimal thirdPartyCost;
@ExcelMergeRow(columIndex = 16) @ExcelMergeRow(columIndex = 15)
@ExcelProperty(value="创建时间") @ExcelProperty(value="创建时间")
@DateTimeFormat("yyyy-MM-dd HH:mm:ss") @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
private Date createdDate; private Date createdDate;
......
...@@ -16,12 +16,18 @@ public class MerchantPackageGoodsMerchantExportVO implements Serializable { ...@@ -16,12 +16,18 @@ public class MerchantPackageGoodsMerchantExportVO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* 上架门店名称(门店级合并,columIndex 对应模板第4列) * 上架门店名称(门店级合并,columIndex=16)
*/ */
@ExcelMergeRow(columIndex = 4) @ExcelMergeRow(columIndex = 16)
private String merchantName; private String merchantName;
/** /**
* 服务对接(园区店,columIndex=18)
*/
@ExcelMergeRow(columIndex = 4)
private String yqMerchantName;
/**
* 套餐下所有商品列表(每个门店共享同一套商品) * 套餐下所有商品列表(每个门店共享同一套商品)
*/ */
private List<MerchantGoodsInfoExportVO> merchantGoodsInfoList; private List<MerchantGoodsInfoExportVO> merchantGoodsInfoList;
......
  • @wangxw1
    commented
    Master

    作为资深 Java 开发工程师,我针对本次代码变更进行审查,结果如下:

    一、关键问题与优化建议(仅限 Top 3)

    1. Excel 列索引定义冲突与逻辑不一致

      • 风险点:在 MerchantPackageGoodsMerchantExportVO 中,代码注释提到 merchantName 对应 columIndex=16,但新增的 yqMerchantName 却占用了 columIndex=4。而在 MerchantPackageGoodsExportVO 的注释中提到“门店中间层移至 columIndex=17”。
      • 后果:这会导致 Excel 导出时列顺序极度混乱,甚至出现数据覆盖。多层级对象(套餐-门店-商品)共享同一个 Excel 表格时,列索引必须严格递增且不重叠。目前 columIndex 4、16、17 的对应关系在代码和注释中存在明显矛盾。
      • 建议:统一梳理 Excel 模板列定义,建议使用常量类定义列索引,确保 MerchantPackageGoodsExportVO(外层)、MerchantPackageGoodsMerchantExportVO(中层)和 MerchantGoodsInfoExportVO(内层)的索引区间互不交叉且逻辑连续。
    2. 硬编码索引带来的维护性风险

      • 风险点:代码中大量使用了 @ExcelMergeRow(columIndex = X) 硬编码。本次修改手动将 6-16 的索引全部向前移动一位(因为删除了原有的 yqMerchantName)。
      • 后果:这种“牵一发而动全身”的修改极易出错(例如漏改某一行导致两列数据挤在同一列)。这违反了阿里巴巴开发手册中关于“魔法值”和“易维护性”的原则。
      • 建议:若框架支持,建议使用自动列排序;若必须硬编码,应在类头部定义 private static final int COL_INDEX_STATUS = 6; 等常量,通过常量引用来减少手动修改错误。
    3. 空值处理与健壮性问题

      • 风险点:在 MerchantPackageGoodsInfoService 第 131 行,对 merchantRef.getYqMerchantName() 进行了三元运算符判空处理。但 merchantRef 本身来源于 merchantGoodsRefList,该列表若为 null,第 128 行的 for 循环会直接抛出 NullPointerException。
      • 后果:线上数据若存在异常(如套餐未关联门店),导出功能将直接崩溃。
      • 建议:在进入 for (MerchantGoodsRefDTO merchantRef : merchantGoodsRefList) 循环前,必须使用 CollectionUtils.isEmpty() 进行前置检查。

    二、评分明细

    评分项目 分数 评价
    功能实现正确性与健壮性 30/40 核心逻辑调整基本完成,但列索引定义存在逻辑冲突,且缺乏必要的集合判空保护。
    安全性与潜在风险 25/30 无明显 SQL 注入或越权风险,但索引错位可能导致业务数据展示错误。
    最佳实践与可维护性 12/20 存在大量硬编码(魔法值),索引重排维护成本高,不符合整洁代码规范。
    性能与资源利用 5/5 转换逻辑在内存中完成,对性能无显著负面影响。
    提交信息质量 5/5 Commit Message 格式规范,清晰描述了变更内容和原因。

    总分:77分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!