Commit d94e9621 by 张富康

fix(service): 修复业务审核服务中的数据类型错误

- 修改 handlerAllocateOrderInfo 方法参数,添加 PurchaseOrderAuditGoodsDTO 参数
- 将 StockAllocateRecordDTO 中的商户ID字段从 purchaseOrderGoods 改为使用 item 对象
- 将 PurchaseOrderAuditGoodsDTO 中的商户ID字段类型从 String 改为 Integer 类型
- 修复调拨单创建时商户信息传递的数据源问题
1 parent 7bd7d841
...@@ -39,7 +39,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable { ...@@ -39,7 +39,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable {
* 调出园区店id * 调出园区店id
*/ */
@ApiModelProperty(notes = "调出园区店id") @ApiModelProperty(notes = "调出园区店id")
private String callOutYqMerchantId; private Integer callOutYqMerchantId;
/** /**
* 调出园区店名称 * 调出园区店名称
...@@ -51,7 +51,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable { ...@@ -51,7 +51,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable {
* 调出门店商户号 * 调出门店商户号
*/ */
@ApiModelProperty(notes = "调出门店商户号") @ApiModelProperty(notes = "调出门店商户号")
private String callOutMerchantId; private Integer callOutMerchantId;
/** /**
* 调出门店商户名称 * 调出门店商户名称
...@@ -63,7 +63,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable { ...@@ -63,7 +63,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable {
* 调入园区店id * 调入园区店id
*/ */
@ApiModelProperty(notes = "调入园区店id") @ApiModelProperty(notes = "调入园区店id")
private String callInYqMerchantId; private Integer callInYqMerchantId;
/** /**
* 调入园区店名称 * 调入园区店名称
...@@ -75,7 +75,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable { ...@@ -75,7 +75,7 @@ public class PurchaseOrderAuditGoodsDTO implements Serializable {
* 调入门店商户号 * 调入门店商户号
*/ */
@ApiModelProperty(notes = "调入门店商户号") @ApiModelProperty(notes = "调入门店商户号")
private String callInMerchantId; private Integer callInMerchantId;
/** /**
* 调入门店商户名称 * 调入门店商户名称
......
...@@ -114,7 +114,7 @@ public class BusinessReviewService { ...@@ -114,7 +114,7 @@ public class BusinessReviewService {
String allocateCode = createAllocateCode(); String allocateCode = createAllocateCode();
allocateCodes.add(allocateCode); allocateCodes.add(allocateCode);
// 创建调拨单 // 创建调拨单
handlerAllocateOrderInfo(allocateCode, now, purchaseOrderGoods, purchaseOrder); handlerAllocateOrderInfo(allocateCode, now, purchaseOrderGoods, purchaseOrder, item);
} else { } else {
log.info("该商品已转为调拨单,跳过,采购商品id:{},调拨单号:{}", purchaseOrderGoods.getId(), purchaseOrderGoods.getAllocateCode()); log.info("该商品已转为调拨单,跳过,采购商品id:{},调拨单号:{}", purchaseOrderGoods.getId(), purchaseOrderGoods.getAllocateCode());
} }
...@@ -156,18 +156,18 @@ public class BusinessReviewService { ...@@ -156,18 +156,18 @@ public class BusinessReviewService {
} }
} }
private void handlerAllocateOrderInfo(String allocateCode, Date now, PurchaseOrderGoods purchaseOrderGoods, PurchaseOrder purchaseOrder) { private void handlerAllocateOrderInfo(String allocateCode, Date now, PurchaseOrderGoods purchaseOrderGoods, PurchaseOrder purchaseOrder, PurchaseOrderAuditGoodsDTO item) {
StockAllocateRecordDTO stockAllocateRecord = new StockAllocateRecordDTO(); StockAllocateRecordDTO stockAllocateRecord = new StockAllocateRecordDTO();
stockAllocateRecord.setAllocateCode(allocateCode); stockAllocateRecord.setAllocateCode(allocateCode);
stockAllocateRecord.setAllocateTime(now); stockAllocateRecord.setAllocateTime(now);
stockAllocateRecord.setCallOutYqMerchantId(purchaseOrderGoods.getCallOutYqMerchantId()); stockAllocateRecord.setCallOutYqMerchantId(item.getCallOutYqMerchantId());
stockAllocateRecord.setCallOutYqMerchantName(purchaseOrderGoods.getCallOutYqMerchantName()); stockAllocateRecord.setCallOutYqMerchantName(item.getCallOutYqMerchantName());
stockAllocateRecord.setCallOutMerchantId(purchaseOrderGoods.getCallOutMerchantId()); stockAllocateRecord.setCallOutMerchantId(item.getCallOutMerchantId());
stockAllocateRecord.setCallOutMerchantName(purchaseOrderGoods.getCallOutMerchantName()); stockAllocateRecord.setCallOutMerchantName(item.getCallOutMerchantName());
stockAllocateRecord.setCallInYqMerchantId(purchaseOrderGoods.getCallInYqMerchantId()); stockAllocateRecord.setCallInYqMerchantId(item.getCallInYqMerchantId());
stockAllocateRecord.setCallInYqMerchantName(purchaseOrderGoods.getCallInYqMerchantName()); stockAllocateRecord.setCallInYqMerchantName(item.getCallInYqMerchantName());
stockAllocateRecord.setCallInMerchantId(purchaseOrderGoods.getCallInMerchantId()); stockAllocateRecord.setCallInMerchantId(item.getCallInMerchantId());
stockAllocateRecord.setCallInMerchantName(purchaseOrderGoods.getCallInMerchantName()); stockAllocateRecord.setCallInMerchantName(item.getCallInMerchantName());
stockAllocateRecord.setDeliveryNumber(null); stockAllocateRecord.setDeliveryNumber(null);
stockAllocateRecord.setDeliveryCompany(null); stockAllocateRecord.setDeliveryCompany(null);
stockAllocateRecord.setRemark(null); stockAllocateRecord.setRemark(null);
......
  • @wangxw1
    commented
    Master

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

    1. 违反重要规则:Dubbo API 接口 DTO 字段类型变更(高危)

    • 问题描述:在 rpc-dj-smartcarlife-api 模块(API包)中,将 PurchaseOrderAuditGoodsDTO 的四个商户 ID 字段的类型从 String 直接修改为了 Integer。
    • 影响分析:触发了“dubbo服务提供者Remote接口中的已有请求参数变更视为危险实现”的重要规则。在 RPC(Dubbo)架构中,直接修改已发布 DTO 的字段类型属于破坏性变更(Breaking Change)。如果服务提供者(Provider)升级了该类型,而调用方(Consumer)仍使用旧版本的 Jar 包传递 String 类型,会导致底层序列化/反序列化(如 Hessian2 或 FastJSON)失败,直接引发线上 RPC 调用报错,阻断业务流程。
    • 优化建议:
      • 方案A(推荐,保持兼容):撤销类型修改,保持 String 类型。如果业务逻辑确实需要 Integer,请在 Service 内部进行 Integer.valueOf() 转换,而不是修改对外暴露的 API。
      • 方案B(平滑过渡):如果必须在 DTO 中使用 Integer,应新增字段(例如 callOutYqMerchantIdInt),并使用 @Deprecated 标记原 String 字段。在 Provider 端同时兼容解析新老字段,待所有 Consumer 升级完毕后,再在未来版本中移除老字段。

    2. 潜在的类型不匹配与编译/运行风险

    • 问题描述:在 BusinessReviewService.java 中,将数据源从 purchaseOrderGoods 切换到了 item(即 PurchaseOrderAuditGoodsDTO)。此时 item.getCallOutYqMerchantId() 返回的是 Integer 类型,并直接赋值给 stockAllocateRecord.setCallOutYqMerchantId(...)。
    • 影响分析:如果 StockAllocateRecordDTO 中的对应字段仍然是 String 类型,此处将发生编译错误。即使 StockAllocateRecordDTO 也同步修改为了 Integer,还需要确认数据库表结构中对应的商户 ID 字段是否为数值类型。如果数据库是 VARCHAR 且存在带前导零(如 0123)或包含字母的商户号,转为 Integer 会导致数据丢失或转换异常。
    • 优化建议:检查 StockAllocateRecordDTO 的字段类型,确保整个链路(API DTO -> 业务 DTO -> 数据库 Entity)的数据类型一致。若必须在此处进行类型转换,建议显式处理,例如 String.valueOf(item.getCallOutYqMerchantId())(假设目标端需要 String)。

    二、评分明细

    • 功能实现的正确性与健壮性(20/40分):
      • 扣分理由:修复了商户信息传递的数据源逻辑问题(逻辑修正正确),但引入了可能导致系统崩溃的 API 类型变更风险,且存在潜在的上下游对象属性类型不匹配问题。
    • 安全性与潜在风险(30/30分):
      • 评分理由:本次变更不涉及 SQL 编写(无子查询违规),未发现越权、注入或敏感信息泄露等安全漏洞。
    • 最佳实践与可维护性(10/20分):
      • 扣分理由:直接修改已发布的 RPC 接口 DTO 字段类型严重违背了分布式系统接口向后兼容的最佳实践原则。
    • 性能与资源利用(5/5分):
      • 评分理由:代码变更属于基础的赋值操作,无循环调用或资源浪费,性能表现正常。
    • 提交信息质量(5/5分):
      • 评分理由:使用了标准的 Conventional Commits 格式(fix(service): ...),清晰地列出了修改点和修复的目的,便于后续追溯。

    总分:70分

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