Commit d32c6c3d by chenxi

5.8.5 上架模块 新增销售模式字段,修复code review发现的问题

1 parent a63fc2a5
......@@ -83,6 +83,7 @@ public class MerchantGoodsInfoController {
}
rpcPagination.getCondition().setFilsterPackageGoods(1);
rpcPagination.getCondition().setProductCostType(request.getProductCostType());
rpcPagination.getCondition().setSaleMode(request.getSaleMode());
RpcResponse<RpcPagination<MerchantGoodsInfoDTO>> rpcPaginationRpcResponse = merchantGoodsInfoRmiRemote.listWithPage(rpcPagination);
if (rpcPaginationRpcResponse.hasResult()) {
RpcPagination<MerchantGoodsInfoDTO> result = rpcPaginationRpcResponse.getResult();
......
......@@ -7,27 +7,28 @@ import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
@Mapper(imports = {cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.ProductCostType.class})
@Mapper(imports = {cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.ProductCostType.class, cn.com.glsx.dj.smartcarlife.enums.SaleModeEnum.class})
public interface MerchantGoodsInfoConvert {
MerchantGoodsInfoConvert INSTANCE = Mappers.getMapper(MerchantGoodsInfoConvert.class);
MerchantGoodsInfoConvert INSTANCE = Mappers.getMapper(MerchantGoodsInfoConvert.class);
@Mappings({
@Mapping(target = "brandMerchantName", source = "goodsInfo.brandMerchantName"),
@Mapping(target = "supplierName", source = "goodsInfo.supplierName"),
@Mapping(target = "mixGoodsTypeName", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.getMixGoodsTypeName(source))"),
@Mapping(target = "upgradeGoodsName", source = "upgradeGoods.upgradeGoodsName"),
@Mapping(target = "upgradeCommodityCode", source = "upgradeGoods.commodityCode"),
@Mapping(target = "thirdPartyCode", source = "upgradeGoods.thirdPartyCode"),
@Mapping(target = "baseCommodityCode", source = "baseGoods.commodityCode"),
@Mapping(target = "sapCode", source = "goodsInfo.sapCode"),
@Mapping(target = "merchantNames", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setMerchantNames(source))"),
@Mapping(target = "inventoryTypeStr", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setMerchantInventoryTypeStr(source))"),
@Mapping(target = "yqMerchantNames", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setYqMerchantNames(source))"),
@Mapping(target = "specificationData", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.convertSpecification(source))"),
@Mapping(target = "sellPriceValidInfo", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.convertSellPriceValidInfo(source))"),
@Mapping(target = "productCostTypeStr", expression = "java(source.getProductCostType() != null ? cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.ProductCostType.getByValue(source.getProductCostType()).getDesc() : \"\")"),
@Mapping(target = "serviceItemDisplay", source = "serviceItemDisplay")
})
MerchantGoodsInfoExport toMerchantGoodsInfoExport(MerchantGoodsInfoDTO source);
@Mappings({
@Mapping(target = "brandMerchantName", source = "goodsInfo.brandMerchantName"),
@Mapping(target = "supplierName", source = "goodsInfo.supplierName"),
@Mapping(target = "mixGoodsTypeName", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.getMixGoodsTypeName(source))"),
@Mapping(target = "upgradeGoodsName", source = "upgradeGoods.upgradeGoodsName"),
@Mapping(target = "upgradeCommodityCode", source = "upgradeGoods.commodityCode"),
@Mapping(target = "thirdPartyCode", source = "upgradeGoods.thirdPartyCode"),
@Mapping(target = "baseCommodityCode", source = "baseGoods.commodityCode"),
@Mapping(target = "sapCode", source = "goodsInfo.sapCode"),
@Mapping(target = "merchantNames", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setMerchantNames(source))"),
@Mapping(target = "inventoryTypeStr", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setMerchantInventoryTypeStr(source))"),
@Mapping(target = "yqMerchantNames", expression = "java(cn.com.glsx.dj.smartcarlife.convert.helper.MerchantGoodsInfoDTOConverterHelper.setYqMerchantNames(source))"),
@Mapping(target = "specificationData", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.convertSpecification(source))"),
@Mapping(target = "sellPriceValidInfo", expression = "java(cn.com.glsx.dj.smartcarlife.convert.GoodsInfoConvertHelper.convertSellPriceValidInfo(source))"),
@Mapping(target = "productCostTypeStr", expression = "java(source.getProductCostType() != null ? cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.ProductCostType.getByValue(source.getProductCostType()).getDesc() : \"\")"),
@Mapping(target = "saleModeStr", expression = "java(source.getSaleMode() != null ? cn.com.glsx.dj.smartcarlife.enums.SaleModeEnum.getByValue(source.getSaleMode()).getDisplayName() : \"\")"),
@Mapping(target = "serviceItemDisplay", source = "serviceItemDisplay")
})
MerchantGoodsInfoExport toMerchantGoodsInfoExport(MerchantGoodsInfoDTO source);
}
......@@ -108,6 +108,9 @@ public class MerchantGoodsAddOrUpdateRequest extends AbstractRopRequest{
@ApiModelProperty(notes = "商品成本带入方式 0-自定义成本 1-默认带入产品成本")
private Byte productCostType;
@ApiModelProperty(notes = "销售模式 0-零售 1-批发")
private Byte saleMode;
@ApiModelProperty(notes = "上架商品凭证")
private List<MerchantGoodsVoucher> voucherList;
......
......@@ -100,4 +100,7 @@ public class MerchantGoodsPageRequest extends AbstractRopRequest {
@ApiModelProperty(notes = "商品成本带入方式 0-自定义成本 1-默认带入产品成本")
private Byte productCostType;
@ApiModelProperty(notes = "销售模式 0-零售 1-批发")
private Byte saleMode;
}
......@@ -13,6 +13,7 @@ import cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.MerchantShelfSource;
import cn.com.glsx.dj.smartcarlife.enums.CarLifeEnum.ShelfStatus;
import cn.com.glsx.dj.smartcarlife.enums.SceneTypeEnum;
import cn.com.glsx.dj.smartcarlife.enums.ProductCostTypeEnum;
import cn.com.glsx.dj.smartcarlife.enums.SaleModeEnum;
import cn.com.glsx.dj.smartcarlife.enums.SellPriceValidTypeEnum;
import cn.com.glsx.dj.smartcarlife.model.MerchantGoodsRef;
import cn.com.glsx.dj.smartcarlife.remote.MerchantGoodsInfoRemote;
......@@ -176,6 +177,15 @@ public class MerchantGoodsInfoImportService extends AbstractImportExcelTemplate<
return RopResponse.error("商品成本带入方式填写错误");
}
final Byte productCostType = productCostTypeEnum.getValue();
// 校验销售模式
Byte saleMode = null;
if (importVo.getSaleMode() != null && !importVo.getSaleMode().trim().isEmpty()) {
SaleModeEnum saleModeEnum = SaleModeEnum.getByDisplayName(importVo.getSaleMode());
if (saleModeEnum == null) {
return RopResponse.error("销售模式填写错误");
}
saleMode = saleModeEnum.getValue();
}
// 获取产品 SKU 信息
List<UpgradeGoodsDTO> upgradeGoodsList = goods.getUpgradeGoodsList();
......@@ -252,6 +262,7 @@ public class MerchantGoodsInfoImportService extends AbstractImportExcelTemplate<
.validMinSellPrice(StatusEnum.YES.getValue()).djCost(djCost)
.thirdPartyCost(thirdPartyCost)
.productCostType(productCostType)
.saleMode(saleMode)
.status(MerchantGoodsStatus.WAIT_AUDIT.getValue())
.upgradeProductFlag(StatusEnum.YES.getValue())
.sellPriceValidType(sellPriceValidType)
......
......@@ -41,6 +41,9 @@ public class MerchantGoodsInfoExport implements Serializable{/**
@ExcelProperty(value = "上架门店")
private String merchantNames;
@ExcelProperty(value = "销售模式")
private String saleModeStr;
@ExcelProperty(value = "库存模式")
private String inventoryTypeStr;
......
......@@ -62,14 +62,17 @@ public class MerchantGoodsInfoImportVo extends MergeExcelImportVo{
@ExcelProperty(index = 8,value = "上架门店")
private String merchantIds;
@ExcelProperty(index = 9,value = "销售模式")
private String saleMode;
@NotBlank(message = "售价有效期不能为空")
@ExcelProperty(index = 9,value = "售价有效期")
@ExcelProperty(index = 10,value = "售价有效期")
private String sellPriceValidType;
@ExcelProperty(index = 10,value = "开始日期")
@ExcelProperty(index = 11,value = "开始日期")
private String tempValidStartDate;
@ExcelProperty(index = 11,value = "结束日期")
@ExcelProperty(index = 12,value = "结束日期")
private String tempValidEndDate;
}
  • @wangxw1
    commented
    Master

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

    1. 安全性与健壮性:存在引发空指针异常(NPE)的高风险

    • 位置:MerchantGoodsInfoConvert.java
    • 问题描述:在 MapStruct 的 @Mapping 表达式中,获取枚举显示名称的代码为 SaleModeEnum.getByValue(source.getSaleMode()).getDisplayName()。如果数据库中存在非法值(如脏数据)或 getByValue 未匹配到对应枚举从而返回 null,紧接着调用 .getDisplayName() 将会抛出 NullPointerException,导致整个列表或详情查询接口崩溃。
    • 优化建议:增加对枚举对象是否为空的判断,或者将这部分转换逻辑抽离到 Helper 类中。 java // 建议在 Helper 类中实现,或者修改表达式为: expression = "java(source.getSaleMode() != null && cn.com.glsx.dj.smartcarlife.enums.SaleModeEnum.getByValue(source.getSaleMode()) != null ? cn.com.glsx.dj.smartcarlife.enums.SaleModeEnum.getByValue(source.getSaleMode()).getDisplayName() : \"\")"

    2. 功能健壮性:新增字段缺乏 API 参数校验

    • 位置:MerchantGoodsAddOrUpdateRequest.java
    • 问题描述:在 API 请求对象中新增了 saleMode 字段,但在 Excel 导入服务中做了校验,却没有在 API 请求对象上添加任何参数校验注解(Bean Validation)。如果前端或客户端传入非 0 或 1 的非法值(例如 99),该值将被直接入库,进而触发上述的 NPE 漏洞。
    • 优化建议:在相关 Request 类的 saleMode 字段上增加参数校验注解以限制取值范围。 java @ApiModelProperty(notes = "销售模式 0-零售 1-批发") @Range(min = 0, max = 1, message = "销售模式取值不合法") private Byte saleMode;

    3. 可维护性与规范:代码缩进混乱,违反阿里开发规范

    • 位置:MerchantGoodsInfoConvert.java 与 MerchantGoodsInfoImportService.java
    • 问题描述:在 MerchantGoodsInfoConvert 中,整个接口内部的代码均被无故向右增加了制表符(Tab)缩进,导致大面积无关的 Git Diff;在 MerchantGoodsInfoImportService 中,新增的 saleMode 校验代码块与上下文缩进层级不一致。这违反了《阿里巴巴 Java 开发手册》中“采用 4 个空格缩进,禁止使用 Tab 字符”的规定。
    • 优化建议:提交代码前,请使用 IDE 的代码格式化功能(如 IDEA 的 Reformat Code)统一格式,保持与原文件一致的代码风格,避免污染代码版本历史。

    二、评分明细

    评审项 权重 得分 扣分说明
    1. 功能实现的正确性与健壮性 40分 35分 核心功能实现正常;但 API 层缺乏参数边界校验,可能会导致脏数据入库(扣 5 分)。
    2. 安全性与潜在风险 30分 20分 MapStruct 表达式中存在未判空直接调用对象方法的问题,有明显的 NullPointerException 风险(扣 10 分)。
    3. 最佳实践与可维护性 20分 15分 代码缩进混乱,未遵守基本的格式化规范;MapStruct 表达式过于冗长,建议抽离到 Helper 类(扣 5 分)。
    4. 性能与资源利用 5分 5分 变更未引入性能瓶颈。
    5. 提交信息质量 5分 5分 提交信息清晰,准确描述了修改意图。

    总分:80分

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