Commit 85c7f05e by 王璐琦

1.修改主订单表保存时使用的方法,当为空时使用数据库默认值

2.增加支付和回调时对订单类型为null的判断
1 parent 0aef0776
...@@ -485,7 +485,8 @@ public class GoodsOrderService { ...@@ -485,7 +485,8 @@ public class GoodsOrderService {
.orderStatus(record.getStatus()).createdBy(record.getCreatedBy()).build(); .orderStatus(record.getStatus()).createdBy(record.getCreatedBy()).build();
orderStatusRecordService.add(orderStatusRecord); orderStatusRecordService.add(orderStatusRecord);
goodsOrderMapper.insertUseGeneratedKeys(record); //goodsOrderMapper.insertUseGeneratedKeys(record);
goodsOrderMapper.insertSelective(record);
return record; return record;
} catch (RpcServiceException e) { } catch (RpcServiceException e) {
throw e; throw e;
...@@ -568,7 +569,8 @@ public class GoodsOrderService { ...@@ -568,7 +569,8 @@ public class GoodsOrderService {
// 补充businessType字段 // 补充businessType字段
compileOrderBusinessType(record); compileOrderBusinessType(record);
// 存储主订单信息 // 存储主订单信息
goodsOrderMapper.insertUseGeneratedKeys(record); //goodsOrderMapper.insertUseGeneratedKeys(record);
goodsOrderMapper.insertSelective(record);
// 保存订单状态变更记录 // 保存订单状态变更记录
orderStatusRecordService.saveOrderStatusRecord(record); orderStatusRecordService.saveOrderStatusRecord(record);
// 后续处理-异步 // 后续处理-异步
...@@ -4309,7 +4311,8 @@ public class GoodsOrderService { ...@@ -4309,7 +4311,8 @@ public class GoodsOrderService {
// 保存客户信息 // 保存客户信息
goodsOrderCustomerService.insertByOrderInfo(record); goodsOrderCustomerService.insertByOrderInfo(record);
// 存储主订单信息 // 存储主订单信息
goodsOrderMapper.insertUseGeneratedKeys(record); //goodsOrderMapper.insertUseGeneratedKeys(record);
goodsOrderMapper.insertSelective(record);
// 保存订单状态变更记录 // 保存订单状态变更记录
orderStatusRecordService.saveOrderStatusRecord(record); orderStatusRecordService.saveOrderStatusRecord(record);
orderAfterWorkExecuteService.handleCreateOrder(record.getOrderCode()); orderAfterWorkExecuteService.handleCreateOrder(record.getOrderCode());
...@@ -4436,7 +4439,8 @@ public class GoodsOrderService { ...@@ -4436,7 +4439,8 @@ public class GoodsOrderService {
goodsOrderCustomerService.insertByOrderInfo(record); goodsOrderCustomerService.insertByOrderInfo(record);
//存储主订单信息 //存储主订单信息
if (oldOrder == null) { if (oldOrder == null) {
goodsOrderMapper.insertUseGeneratedKeys(record); //goodsOrderMapper.insertUseGeneratedKeys(record);
goodsOrderMapper.insertSelective(record);
} else { } else {
record.setId(oldOrder.getId()); record.setId(oldOrder.getId());
goodsOrderMapper.updateByPrimaryKeySelective(record); goodsOrderMapper.updateByPrimaryKeySelective(record);
...@@ -4951,7 +4955,8 @@ public class GoodsOrderService { ...@@ -4951,7 +4955,8 @@ public class GoodsOrderService {
goodsOrderCustomerService.insertByOrderInfo(record); goodsOrderCustomerService.insertByOrderInfo(record);
//存储主订单信息 //存储主订单信息
if (oldOrder == null) { if (oldOrder == null) {
goodsOrderMapper.insertUseGeneratedKeys(record); //goodsOrderMapper.insertUseGeneratedKeys(record);
goodsOrderMapper.insertSelective(record);
} else { } else {
record.setId(oldOrder.getId()); record.setId(oldOrder.getId());
goodsOrderMapper.updateByPrimaryKeySelective(record); goodsOrderMapper.updateByPrimaryKeySelective(record);
......
...@@ -291,7 +291,7 @@ public class PayOrderService { ...@@ -291,7 +291,7 @@ public class PayOrderService {
payOrder.setServiceCharge(BigDecimal.ZERO); payOrder.setServiceCharge(BigDecimal.ZERO);
payOrder.setActualIncomeMoney(payOrder.getActualMoney().subtract(payOrder.getServiceCharge())); payOrder.setActualIncomeMoney(payOrder.getActualMoney().subtract(payOrder.getServiceCharge()));
//特殊订单类型判断 //特殊订单类型判断
if(Objects.equals(DjOrderTypeEnum.NORMAL.getValue(), goodsOrder.getDjOrderType())){ if(ObjectUtil.isNull(goodsOrder.getDjOrderType()) || Objects.equals(DjOrderTypeEnum.NORMAL.getValue(), goodsOrder.getDjOrderType())){
if (Objects.equals(SceneTypeEnum.SCENE1_0.getValue(), goodsOrder.getSceneType()) if (Objects.equals(SceneTypeEnum.SCENE1_0.getValue(), goodsOrder.getSceneType())
&& Objects.equals(ZYVoucherStatusEnum.WAIT_TO_UPLOAD.getValue(), payOrder.getZyVoucherStatus())) { && Objects.equals(ZYVoucherStatusEnum.WAIT_TO_UPLOAD.getValue(), payOrder.getZyVoucherStatus())) {
o.setStatus(OrderStatus.WAIT_UPLOAD.getValue()); o.setStatus(OrderStatus.WAIT_UPLOAD.getValue());
...@@ -955,7 +955,7 @@ public class PayOrderService { ...@@ -955,7 +955,7 @@ public class PayOrderService {
o.setInstallUpgradeTime(now); o.setInstallUpgradeTime(now);
o.setOrderCode(orderCode); o.setOrderCode(orderCode);
o.setUpdatedBy(payOrder.getUpdatedBy()); o.setUpdatedBy(payOrder.getUpdatedBy());
if(Objects.equals(DjOrderTypeEnum.NORMAL.getValue(),goodsOrder.getDjOrderType())){ if(ObjectUtil.isNull(goodsOrder.getDjOrderType()) || Objects.equals(DjOrderTypeEnum.NORMAL.getValue(),goodsOrder.getDjOrderType())){
if (Objects.equals(SceneTypeEnum.SCENE1_0.getValue(), goodsOrder.getSceneType()) if (Objects.equals(SceneTypeEnum.SCENE1_0.getValue(), goodsOrder.getSceneType())
&& Objects.equals(ZYVoucherStatusEnum.WAIT_TO_UPLOAD.getValue(), p.getZyVoucherStatus())) { && Objects.equals(ZYVoucherStatusEnum.WAIT_TO_UPLOAD.getValue(), p.getZyVoucherStatus())) {
o.setStatus(OrderStatus.WAIT_UPLOAD.getValue()); o.setStatus(OrderStatus.WAIT_UPLOAD.getValue());
......
  • @wangxw1
    commented
    Master

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

    1. 严重功能隐患:替换为 insertSelective 后可能导致无法获取自增主键

    • 问题描述:在 GoodsOrderService.java 中,多处将 goodsOrderMapper.insertUseGeneratedKeys(record); 替换为了 goodsOrderMapper.insertSelective(record);。
    • 影响分析:原方法名 insertUseGeneratedKeys 明确表示插入后会将数据库生成的自增 ID 回写到 record 对象中。如果 insertSelective 在 Mapper 层的配置(XML 或注解)中没有显式开启 useGeneratedKeys="true" 和 keyProperty="id",那么插入后 record.getId() 将为空。由于后续逻辑(如直接 return record; 或异步处理)极有可能依赖此 ID,这将导致严重的 NullPointerException 或业务数据关联失败。
    • 优化建议:请务必检查 goodsOrderMapper.insertSelective 的底层实现是否支持主键回写。如果不支持,建议在 Mapper XML 中为 insertSelective 加上主键回写配置;或者保留原方法,在业务层手动处理空值默认逻辑。 xml <!-- 确保 Mapper.xml 中有类似如下配置 --> <insert id="insertSelective" parameterType="..." useGeneratedKeys="true" keyProperty="id"> ... </insert>

    2. 代码规范与可维护性:遗留被注释的废弃代码

    • 问题描述:在 GoodsOrderService.java 中,修改代码时使用了 //goodsOrderMapper.insertUseGeneratedKeys(record); 将旧代码注释掉,而不是直接删除。
    • 影响分析:将废弃代码注释并提交到代码库中是一种反模式(Anti-pattern)。这会降低代码的可读性,造成视觉干扰,并且随着时间推移,无用的注释代码会越来越多,形成“破窗效应”。版本控制系统(Git)已经承担了历史追溯的功能。
    • 优化建议:直接删除被注释的废弃代码。

    3. 可读性优化:对 Null 值的默认业务逻辑处理可以更优雅

    • 问题描述:在 PayOrderService.java 中,增加了对 goodsOrder.getDjOrderType() 为 null 的判断:ObjectUtil.isNull(goodsOrder.getDjOrderType()) || Objects.equals(DjOrderTypeEnum.NORMAL.getValue(), goodsOrder.getDjOrderType())。
    • 影响分析:当前的写法逻辑是正确的(将 null 视为 NORMAL 类型),但将默认值逻辑直接散落在 if 条件判断中,显得不够简洁,且如果多处使用会导致重复代码。
    • 优化建议:建议使用默认值赋予的方式来简化条件判断,使业务意图更加清晰。 java // 优化示例:利用 ObjectUtil.defaultIfNull 提供默认值进行比较 Integer currentOrderType = ObjectUtil.defaultIfNull(goodsOrder.getDjOrderType(), DjOrderTypeEnum.NORMAL.getValue()); if (Objects.equals(DjOrderTypeEnum.NORMAL.getValue(), currentOrderType)) { // ... 业务逻辑 }

    二、评分明细

    • 功能实现的正确性与健壮性(30/40分): 扣分原因:insertSelective 替换原有方法带来了极高的主键丢失风险。如果 Mapper 层未做对应的主键回写配置,将导致严重的线上 Bug。业务逻辑上对 null 的兼容处理是正确的。
    • 安全性与潜在风险(30/30分): 评分理由:本次变更主要涉及方法替换和空指针防御,未引入 SQL 注入、越权等安全漏洞。
    • 最佳实践与可维护性(15/20分): 扣分原因:提交了大量被注释的死代码(Dead Code),违反了整洁代码(Clean Code)原则;另外,条件判断中的默认值处理方式有进一步优化的空间。
    • 性能与资源利用(5/5分): 评分理由:使用 insertSelective 替代全量插入,可以让数据库层面去处理默认值,在字段较多时能微弱减少网络传输,无性能瓶颈。
    • 提交信息质量(4/5分): 评分理由:Commit 信息(“修改主订单表保存时使用的方法...”)清晰说明了做了什么以及为什么做,具有较好的可追溯性。若能附带相关的 Issue/Bug ID 会更完美。

    总分:84分

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