Commit adc0a234 by 章家宝

feat:优加门店审批通过之后需要更新门店成本

1 parent 8927ca24
package cn.com.glsx.dj.smartcarlife.dto.merchant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@ApiModel(value = "MerchantCostUpdateDTO", description = "商户成本更新请求")
public class MerchantCostUpdateDTO implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "商户ID(traffic_party_id)", required = true)
private Integer merchantId;
@ApiModelProperty(value = "场景code", required = true)
private String baseSceneCode;
@ApiModelProperty(value = "装修、设备总投入")
private BigDecimal renovationEquipmentCost;
@ApiModelProperty(value = "其他费用/月(房租、水电、耗材等)")
private BigDecimal otherCostPerMonth;
@ApiModelProperty(value = "操作人")
private String updatedBy;
}
package cn.com.glsx.dj.smartcarlife.dto.merchant; package cn.com.glsx.dj.smartcarlife.dto.merchant;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantGuaranteeConfigDTO;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
......
...@@ -4,6 +4,7 @@ import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailBatchQueryDTO; ...@@ -4,6 +4,7 @@ import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailBatchQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailQueryDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailResponseDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailResponseDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantEditDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantEditDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantCostUpdateDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantHistoryResponseDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantHistoryResponseDTO;
import cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefUpd; import cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefUpd;
import cn.com.glsx.framework.core.annotation.ApiMethod; import cn.com.glsx.framework.core.annotation.ApiMethod;
...@@ -71,4 +72,15 @@ public interface MerchantStoreInfoRemote { ...@@ -71,4 +72,15 @@ public interface MerchantStoreInfoRemote {
@ApiParam(name = "queryDTO", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true) @ApiParam(name = "queryDTO", notes = "查询参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("商户详情响应,包含商户信息和产品列表") @ApiResponse("商户详情响应,包含商户信息和产品列表")
RpcResponse<List<MerchantDetailResponseDTO>> MerchantDetailBatchQueryDTO(@NotNull MerchantDetailBatchQueryDTO queryDTO); RpcResponse<List<MerchantDetailResponseDTO>> MerchantDetailBatchQueryDTO(@NotNull MerchantDetailBatchQueryDTO queryDTO);
/**
* 更新商户成本(装修、设备总投入 和 其他费用/月)
*
* @param costDTO 成本更新参数
* @return 是否更新成功
*/
@ApiMethod("更新商户成本")
@ApiParam(name = "costDTO", notes = "成本更新参数", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("是否更新成功")
RpcResponse<Boolean> updateMerchantCost(@NotNull MerchantCostUpdateDTO costDTO);
} }
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailBatchQueryDTO; ...@@ -4,6 +4,7 @@ import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailBatchQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailQueryDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailQueryDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailResponseDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantDetailResponseDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantEditDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantEditDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantCostUpdateDTO;
import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantHistoryResponseDTO; import cn.com.glsx.dj.smartcarlife.dto.merchant.MerchantHistoryResponseDTO;
import cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefUpd; import cn.com.glsx.dj.smartcarlife.model.SceneMerchantRefUpd;
import cn.com.glsx.dj.smartcarlife.service.MerchantStoreInfoQueryService; import cn.com.glsx.dj.smartcarlife.service.MerchantStoreInfoQueryService;
...@@ -93,4 +94,26 @@ public class MerchantStoreInfoRemoteImpl implements MerchantStoreInfoRemote { ...@@ -93,4 +94,26 @@ public class MerchantStoreInfoRemoteImpl implements MerchantStoreInfoRemote {
} }
} }
@Override
public RpcResponse<Boolean> updateMerchantCost(@NotNull MerchantCostUpdateDTO costDTO) {
try {
Assert.notNull(costDTO.getMerchantId(), "商户ID不能为空");
Assert.notNull(costDTO.getBaseSceneCode(), "场景code不能为空");
log.info("更新商户成本,参数:{}", costDTO);
Boolean result = merchantStoreInfoService.updateMerchantCost(
costDTO.getMerchantId(),
costDTO.getBaseSceneCode(),
costDTO.getRenovationEquipmentCost(),
costDTO.getOtherCostPerMonth(),
costDTO.getUpdatedBy());
return RpcResponse.success(result);
} catch (RpcServiceException e) {
log.error("更新商户成本失败:{}", e.getMessage());
return RpcResponse.error(e);
} catch (Exception e) {
log.error("更新商户成本异常", e);
return RpcResponse.error(e);
}
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -469,4 +469,37 @@ public class MerchantStoreInfoService { ...@@ -469,4 +469,37 @@ public class MerchantStoreInfoService {
} }
} }
/**
* 更新商户门店成本信息(装修、设备总投入 和 其他费用/月)
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public Boolean updateMerchantCost(Integer merchantId, String baseSceneCode,
java.math.BigDecimal renovationEquipmentCost,
java.math.BigDecimal otherCostPerMonth,
String updatedBy) {
log.info("更新商户成本,merchantId: {}, baseSceneCode: {}, renovationEquipmentCost: {}, otherCostPerMonth: {}",
merchantId, baseSceneCode, renovationEquipmentCost, otherCostPerMonth);
if (merchantId == null || org.apache.commons.lang.StringUtils.isBlank(baseSceneCode)) {
throw new RpcServiceException("merchantId 和 baseSceneCode 不能为空");
}
MerchantStoreInfo merchantStoreInfo = merchantStoreInfoMapper.findByMerchantIdAndBaseSceneCode(merchantId, baseSceneCode);
if (merchantStoreInfo == null) {
log.warn("商户门店信息不存在,merchantId: {}, baseSceneCode: {}", merchantId, baseSceneCode);
throw new RpcServiceException("商户门店信息不存在");
}
Date updateDate = new Date();
merchantStoreInfo.setRenovationEquipmentCost(renovationEquipmentCost);
merchantStoreInfo.setOtherCostPerMonth(otherCostPerMonth);
merchantStoreInfo.setUpdatedBy(updatedBy);
merchantStoreInfo.setUpdatedDate(updateDate);
merchantStoreInfoMapper.updateByPrimaryKeySelective(merchantStoreInfo);
log.info("更新商户成本成功,merchantId: {}, baseSceneCode: {}", merchantId, baseSceneCode);
return true;
}
} }
  • @wangxw1
    commented
    Master

    代码审查报告

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

    1. 并发更新导致的数据丢失风险(功能正确性与健壮性)

    • 问题描述:在 MerchantStoreInfoService.updateMerchantCost 方法中,采用了典型的“读-改-写”(Read-Modify-Write)模式更新商户成本。该过程没有加锁或使用乐观锁机制。
    • 影响分析:如果存在多个人员同时操作,或者前端发生重复提交,并发执行该方法会导致后提交的数据直接覆盖先提交的数据(Lost Update),对于涉及金额、成本等敏感字段,这属于高危逻辑缺陷。
    • 优化建议:建议在数据库表设计中引入 version 字段实现乐观锁,或者在 SQL 层面直接进行条件更新。 (代码示例 - 乐观锁方式): java // Mapper XML 中应配合:UPDATE table SET cost = #{cost}, version = version + 1 WHERE id = #{id} AND version = #{version} int updateCount = merchantStoreInfoMapper.updateCostWithVersion(merchantStoreInfo); if (updateCount == 0) { throw new RpcServiceException("商户成本信息已被他人修改,请刷新后重试"); }

    2. 事务回滚异常类型配置不当(功能正确性与健壮性)

    • 问题描述:@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class) 仅显式指定了 RpcServiceException 触发回滚。
    • 影响分析:虽然 Spring 默认会对 RuntimeException 触发回滚,但显式指定具体的业务异常会导致其他非 RuntimeException(如某些特定的受检异常)发生时,事务无法正常回滚。这不符合工程最佳实践,容易在后续维护中埋下隐患。
    • 优化建议:将回滚异常类型扩大到 Exception.class,确保所有异常都能触发事务回滚。 (代码示例): java @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public Boolean updateMerchantCost(...) { ... }

    3. 缺乏声明式参数校验与服务层参数冗余(最佳实践与可维护性)

    • 问题描述:
      1. MerchantCostUpdateDTO 中的校验仅使用了 Swagger 的 @ApiModelProperty(required = true),这仅用于文档生成,无实际校验约束作用。
      2. MerchantStoreInfoRemoteImpl 和 Service 层充斥着手动的 Assert.notNull 和 if 判断。
      3. Service 层方法 updateMerchantCost 接收了 5 个零散参数,而不是封装好的对象。
    • 影响分析:手动校验容易遗漏边界情况(如空字符串、负数金额等),且导致代码臃肿;方法参数过多降低了代码的可扩展性和可读性。
    • 优化建议:在 DTO 中引入 JSR-303 校验注解,并在接口处使用 @Validated 或 @Valid。Service 层直接接收 DTO(或转换为 BO)。 (代码示例): ```java // 1. DTO 增加校验注解 public class MerchantCostUpdateDTO implements Serializable { @NotNull(message = "商户ID不能为空") private Integer merchantId; @NotBlank(message = "场景code不能为空") private String baseSceneCode; @DecimalMin(value = "0.0", message = "成本金额不能为负数") private BigDecimal renovationEquipmentCost; // ... }

    // 2. Service 层直接传递对象 public Boolean updateMerchantCost(MerchantCostUpdateDTO costDTO) { // 内部直接使用 costDTO.getMerchantId() 等 }

    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性 (32/40分)**
      - **理由**:基础业务逻辑连贯,未发现违反“MyBatis子查询”及“Dubbo接口参数变更”的红线规则(本次为新增方法,未破坏已有接口)。但由于涉及金额/成本更新的逻辑缺乏并发控制(乐观锁),且事务注解配置存在一定局限性,扣除 8 分。
    - **安全性与潜在风险 (28/30分)**
      - **理由**:未发现 SQL 注入、越权等严重安全漏洞。但由于参数校验依赖手动断言,未对金额字段的合法性(如负数)进行严格限制,存在极小概率的脏数据风险,扣除 2 分。
    - **最佳实践与可维护性 (15/20分)**
      - **理由**:清理了无用的 import 语句,表现良好。但未采用 JSR-303 标准校验,且 Service 层方法参数列表过长(未传递对象),不符合主流的整洁代码规范,扣除 5 分。
    - **性能与资源利用 (5/5分)**
      - **理由**:资源利用合理,数据库操作使用了 `updateByPrimaryKeySelective` 按需更新,无明显的性能瓶颈,得满分。
    - **提交信息质量 (4/5分)**
      - **理由**:Commit 信息 `feat:优加门店审批通过之后需要更新门店成本 (by jiabao)` 清晰说明了业务背景和变动内容。若能附带对应的需求/缺陷管理工具的 Issue ID(如 Jira 编号)会更利于追溯,扣除 1 分。
    
    总分:84分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!