Commit ad0abae2 by 崔彦峰

feat(goods): 添加精品场景成本类型设置逻辑

- 在商品上架审批服务中新增精品场景判断方法
- 根据场景类型区分升级产品成本样式和第三方成本样式
- 为精品场景添加升级产品成本样式的条件判断
- 为非精品场景添加第三方成本样式的条件判断
- 完善商品信息中的产品成本类型设置逻辑
1 parent 493d1fe9
...@@ -1040,9 +1040,12 @@ public class GoodsListingApprovalService { ...@@ -1040,9 +1040,12 @@ public class GoodsListingApprovalService {
goodsInfo.setThirdPartyCost(detail.getThirdPartyCost()); goodsInfo.setThirdPartyCost(detail.getThirdPartyCost());
goodsInfo.setPosition(detail.getPosition()); goodsInfo.setPosition(detail.getPosition());
goodsInfo.setServiceItemId(detail.getServiceItemId()); goodsInfo.setServiceItemId(detail.getServiceItemId());
if (detail.getUpgradeProductCostStyle() != null) { if (isSceneBoutique(context.baseSceneCode) && detail.getUpgradeProductCostStyle() != null) {
goodsInfo.setProductCostType((byte) (detail.getUpgradeProductCostStyle() == 1 ? 0 : 1)); goodsInfo.setProductCostType((byte) (detail.getUpgradeProductCostStyle() == 1 ? 0 : 1));
} }
if (!isSceneBoutique(context.baseSceneCode) && detail.getThirdPartyCostStyle() != null) {
goodsInfo.setProductCostType((byte) (detail.getThirdPartyCostStyle() == 1 ? 0 : 1));
}
fillApprovedGoodsDefaults(goodsInfo, detail, context, packageCode); fillApprovedGoodsDefaults(goodsInfo, detail, context, packageCode);
fillAuditFields(goodsInfo, context); fillAuditFields(goodsInfo, context);
...@@ -1064,6 +1067,13 @@ public class GoodsListingApprovalService { ...@@ -1064,6 +1067,13 @@ public class GoodsListingApprovalService {
return goodsInfo; return goodsInfo;
} }
/**
* 精品场景
*/
private boolean isSceneBoutique(String baseSceneCode) {
return BaseSceneEnum.QUALITY_UPGRADE.getBaseSceneCode().equals(baseSceneCode);
}
private MerchantPackageGoodsInfo buildMerchantPackageGoodsInfo(ApprovalPublishContext context, private MerchantPackageGoodsInfo buildMerchantPackageGoodsInfo(ApprovalPublishContext context,
GoodsListingProductBaseDTO product, GoodsListingProductBaseDTO product,
String packageCode) { String packageCode) {
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议,如果必要,给出代码示例(仅限 Top 3)

    1. 魔法值(Magic Numbers)降低了代码可读性与可维护性

    • 问题描述:代码中使用了硬编码的数字 1 和 0(如 detail.getUpgradeProductCostStyle() == 1 ? 0 : 1)。
    • 影响分析:缺乏业务语义的上下文,后续维护人员无法直观理解 1 和 0 分别代表何种成本类型(如:是免费/收费,还是比例/固定金额?)。这不仅增加了阅读认知负担,在未来需求变更时也容易引发修改遗漏。
    • 优化建议:建议使用枚举(Enum)或具有明确业务含义的常量来替换这些魔法值。 java // 示例:假设 1 代表类型A,0 代表类型B if (isSceneBoutique(context.getBaseSceneCode()) && detail.getUpgradeProductCostStyle() != null) { byte costType = Objects.equals(detail.getUpgradeProductCostStyle(), CostStyleEnum.TYPE_A.getCode()) ? ProductCostTypeEnum.TYPE_X.getValue() : ProductCostTypeEnum.TYPE_Y.getValue(); goodsInfo.setProductCostType(costType); }

    2. 破坏对象封装性(直接访问属性)

    • 问题描述:代码中使用了 context.baseSceneCode 直接访问对象的属性。
    • 影响分析:在 Java 工程实践中,直接暴露对象的内部属性破坏了面向对象的封装性原则。如果未来需要对 baseSceneCode 的获取逻辑进行拦截、格式化或兼容处理,直接访问属性的做法将导致重构困难。
    • 优化建议:建议使用标准的 Getter 方法获取属性值。 java // 建议修改为 if (isSceneBoutique(context.getBaseSceneCode()) && ...)

    二、评分明细

    • 功能实现的正确性与健壮性(40/40分) 理由:业务逻辑分支处理清晰。在新增的 isSceneBoutique 方法中,将常量 BaseSceneEnum.QUALITY_UPGRADE.getBaseSceneCode() 放在 equals 的左侧,这是一个很好的防御性编程习惯,有效避免了 baseSceneCode 为 null 时可能引发的 NullPointerException。未违反 MyBatis 和 Dubbo 相关的特殊规则。

    • 安全性与潜在风险(30/30分) 理由:本次变更为纯内存逻辑判断与对象赋值,不涉及数据库直接操作、外部输入反序列化或越权访问等场景,无安全隐患。

    • 最佳实践与可维护性(15/20分) 理由:扣除 5 分。主要原因是代码中存在未解释的魔法值(Magic Numbers)以及直接访问对象属性(未遵循 Getter 封装规范),在一定程度上降低了代码的可维护性。

    • 性能与资源利用(5/5分) 理由:逻辑判断简单高效,没有复杂的循环或高开销操作,不存在性能瓶颈或资源浪费。

    • 提交信息质量(5/5分) 理由:Commit 信息非常优秀。采用了 Angular 规范(feat(goods): ...),标题简明扼要,正文详细列出了修改的背景、具体改动点和逻辑分支,可追溯性极强。

    总分:95分

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