Commit 97217dfd by chenxi

对于折扣订单,开发票金额取值有订单总额改为实付金额

1 parent 60887ffc
...@@ -129,21 +129,21 @@ public class GoodsOrderInvoinceService { ...@@ -129,21 +129,21 @@ public class GoodsOrderInvoinceService {
List<Integer> extendedInsuranceTypeIdList = CommonUtil.convert2Integer(OrePropertyConfigurer.getString("smartcarlife.goodsType.extendedInsurance", "155").split(","));//延保类 List<Integer> extendedInsuranceTypeIdList = CommonUtil.convert2Integer(OrePropertyConfigurer.getString("smartcarlife.goodsType.extendedInsurance", "155").split(","));//延保类
List<Integer> equityTypeIdList = CommonUtil.convert2Integer(OrePropertyConfigurer.getString("smartcarlife.goodsType.equity", "104,126").split(","));//权益类 List<Integer> equityTypeIdList = CommonUtil.convert2Integer(OrePropertyConfigurer.getString("smartcarlife.goodsType.equity", "104,126").split(","));//权益类
for(GoodsSubOrder gso:goodsOrder.getSubOrderList()) { for(GoodsSubOrder gso:goodsOrder.getSubOrderList()) {
if(Objects.equals(gso.getStatus(), RefundGoodsSubOrderStatusEnum.REFUNDED.getValue()) || gso.getTotalPrice().compareTo(BigDecimal.ZERO) <= 0){ if(Objects.equals(gso.getStatus(), RefundGoodsSubOrderStatusEnum.REFUNDED.getValue()) || gso.getFinalPrice().compareTo(BigDecimal.ZERO) <= 0){
continue; continue;
} }
if(equityTypeIdList.contains(gso.getUpgradeGoodsType())) { if(equityTypeIdList.contains(gso.getUpgradeGoodsType())) {
itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("qy.invoice.item.name","权益服务费"),gso.getTotalPrice())); itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("qy.invoice.item.name","权益服务费"),gso.getFinalPrice()));
}else if(extendedInsuranceTypeIdList.contains(gso.getUpgradeGoodsType())) { }else if(extendedInsuranceTypeIdList.contains(gso.getUpgradeGoodsType())) {
itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("yb.invoice.item.name","延保营销服务费"),gso.getTotalPrice())); itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("yb.invoice.item.name","延保营销服务费"),gso.getFinalPrice()));
}else if((gso.getUpgradeGoodsName() != null && gso.getUpgradeGoodsName().contains("膜")) || }else if((gso.getUpgradeGoodsName() != null && gso.getUpgradeGoodsName().contains("膜")) ||
(gso.getUpgradeGoodsTypeName() != null && gso.getUpgradeGoodsTypeName().contains("膜")) || (gso.getUpgradeGoodsTypeName() != null && gso.getUpgradeGoodsTypeName().contains("膜")) ||
(gso.getUpgradeSecondaryGoodsTypeName() != null && gso.getUpgradeSecondaryGoodsTypeName().contains("膜")) || (gso.getUpgradeSecondaryGoodsTypeName() != null && gso.getUpgradeSecondaryGoodsTypeName().contains("膜")) ||
(gso.getUpgradeThirdLevelGoodsTypeName() != null && gso.getUpgradeThirdLevelGoodsTypeName().contains("膜")) (gso.getUpgradeThirdLevelGoodsTypeName() != null && gso.getUpgradeThirdLevelGoodsTypeName().contains("膜"))
) { ) {
itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("tm.invoice.item.name","贴膜服务费"),gso.getTotalPrice())); itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("tm.invoice.item.name","贴膜服务费"),gso.getFinalPrice()));
}else { }else {
itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("other.invoice.item.name","营销服务费"),gso.getTotalPrice())); itemList.add(new InvoiceIssueItem(OrePropertyConfigurer.getString("other.invoice.item.name","营销服务费"),gso.getFinalPrice()));
} }
} }
return itemList; return itemList;
......
  • @wangxw1
    commented
    Master

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

    1. 潜在的空指针异常(NPE)风险

    • 问题描述:代码将 getTotalPrice() 替换为了 getFinalPrice(),并直接调用了 gso.getFinalPrice().compareTo(BigDecimal.ZERO)。如果由于历史脏数据或上游业务异常导致 getFinalPrice() 返回 null,此处将抛出 NullPointerException。
    • 影响分析:一旦触发空指针异常,将导致整个订单的开票流程中断,直接影响用户的开票体验和核心业务链路的稳定性。
    • 优化建议:在进行金额比较前,增加对 getFinalPrice() 的非空校验,进行防御性编程。
    • 代码示例: java if(Objects.equals(gso.getStatus(), RefundGoodsSubOrderStatusEnum.REFUNDED.getValue()) || gso.getFinalPrice() == null || gso.getFinalPrice().compareTo(BigDecimal.ZERO) <= 0){ continue; }

    2. 业务逻辑判断依赖硬编码(原有代码优化建议)

    • 问题描述:代码中通过 contains("膜") 的方式对商品名称或类型进行模糊匹配,以此来判断是否为“贴膜服务费”。这种基于魔法字符串的硬编码判断方式非常脆弱。
    • 影响分析:如果未来新增了名称中带“膜”字但非贴膜服务的商品(例如“手机膜”或某种带有“膜”字的配件),会导致开票类目归属错误;或者商品命名规范发生改变,也会导致该逻辑失效。可维护性较差。
    • 优化建议:建议在商品类别表或商品属性中增加“开票类目”的标识字段,或通过明确的枚举/字典值进行映射匹配,避免在代码中使用字符串模糊匹配处理核心财务逻辑。

    3. 提交信息(Commit Message)存在错别字与规范性不足

    • 问题描述:提交信息为“对于折扣订单,开发票金额取值有订单总额改为实付金额 (by chenxi);”,其中“有”字为错别字,应为“由”。
    • 影响分析:虽然不影响代码运行,但错别字会降低代码库的严谨性。此外,缺少标准化的前缀(如 fix:, feat: 等),不利于自动生成 Changelog 或快速识别变更类型。
    • 优化建议:修正错别字,并建议遵循 Angular 提交规范。例如优化为:fix: 修复折扣订单开票金额错误,金额取值由订单总额改为实付金额。

    二、评分明细

    • 功能实现的正确性与健壮性(35/40分):修改逻辑正确,符合“开票金额取实付金额”的财务规则。但缺少对 getFinalPrice 的非空校验,健壮性略有不足,扣除5分。
    • 安全性与潜在风险(30/30分):本次变更属于纯内部业务逻辑计算修改,未引入 SQL 注入、越权、敏感信息泄露等安全漏洞。
    • 最佳实践与可维护性(15/20分):未进行防御性编程,且原有逻辑存在明显的硬编码和魔法字符串依赖(模糊匹配“膜”字),不利于后续维护,扣除5分。
    • 性能与资源利用(5/5分):无明显性能瓶颈或不必要的资源浪费。
    • 提交信息质量(4/5分):提交信息清楚地说明了业务背景和修改点,但存在错别字且未遵循业界通用的 Commit 规范,扣除1分。

    总分:89分

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