Commit d8fd2088 by 章家宝

fixbug: 方案提交bug修复

1 parent 19cf3a13
......@@ -12,7 +12,7 @@ import java.math.BigDecimal;
@Getter
public enum CommissionTypeEnum {
BL("BL", "比例", BigDecimal.ZERO, BigDecimal.valueOf(100)),
XS("XS", "系数", BigDecimal.ONE, BigDecimal.valueOf(10)),
XS("XS", "系数", BigDecimal.ZERO, BigDecimal.valueOf(10)),
GDJE("GDJE", "固定金额", BigDecimal.ZERO, BigDecimal.valueOf(9999999));
private final String code;
......
......@@ -61,6 +61,11 @@ public class PerformanceConfigApprove implements Serializable {
@Column(name = "brands_names")
private String brandsNames;
@ApiModelProperty(notes = "审批时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@Column(name = "approve_date")
private Date approveDate;
@ApiModelProperty(notes = "创建人")
@Column(name = "created_by")
private String createdBy;
......
package cn.com.glsx.dj.staff.remote.performance;
import cn.com.glsx.dj.staff.dto.PerformanceConfigDTO;
import cn.com.glsx.dj.staff.dto.PerformanceConfigMerchantBrandRefDTO;
import cn.com.glsx.dj.staff.dto.performance.*;
import cn.com.glsx.framework.core.annotation.*;
import cn.com.glsx.framework.core.annotation.ApiParam.DataTypeEnum;
......@@ -54,8 +55,13 @@ public interface PerformanceConfigRemote {
@ApiResponse("提成方案")
RpcResponse<Boolean> hasEffectivePerformanceConfigForMerchant(@NotNull Integer merchantId);
@ApiMethod("查询门店是否有有效的提成方案")
@ApiMethod("查询配置详情接口(门店数据调整获取详情)")
@ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true)
@ApiResponse("提成方案")
RpcResponse<PerformanceConfigDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto);
@ApiMethod("通过门店id获取门店所有生效中的方案对应的品牌")
@ApiParam(name = "dto", notes = "门店id", dataType = DataTypeEnum.INT, required = true)
@ApiResponse("提成方案")
RpcResponse<List<PerformanceConfigDetailDTO>> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto);
RpcResponse<List<PerformanceConfigMerchantBrandRefDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto);
}
......@@ -14,4 +14,6 @@ public interface PerformanceConfigMerchantBrandRefMapper extends OreMapper<Perfo
List<PerformanceConfigMerchantBrandRefDTO> listByConfigId(Integer id);
void invalidByBusinessTypeAndMerchantBrand(PerformanceConfigMerchantBrandRefDTO merchantBrandRef);
List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto);
}
\ No newline at end of file
package cn.com.glsx.dj.staff.remote.performance;
import cn.com.glsx.dj.staff.dto.PerformanceConfigDTO;
import cn.com.glsx.dj.staff.dto.PerformanceConfigMerchantBrandRefDTO;
import cn.com.glsx.dj.staff.dto.performance.*;
import cn.com.glsx.dj.staff.service.staffPerformance.PerformanceConfigService;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
......@@ -62,9 +63,14 @@ public class PerformanceConfigRemoteImpl implements PerformanceConfigRemote {
}
@Override
public RpcResponse<List<PerformanceConfigDetailDTO>> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
public RpcResponse<PerformanceConfigDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
return RpcResponse.success(performanceConfigService.performanceConfigDetailWithMerchant(dto));
}
@Override
public RpcResponse<List<PerformanceConfigMerchantBrandRefDTO>> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return RpcResponse.success(performanceConfigService.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto));
}
}
......@@ -200,7 +200,7 @@ public class PerformanceConfigApproveService {
String agentId = env.getProperty("performance.approve.send.qw.notice.agentId", String.class,"1000024");
String titleEnv = env.getProperty("performance.approve.send.qw.notice.title", String.class, "门店提成方案%s审批提醒");
String descriptionEvn = env.getProperty("performance.approve.send.qw.notice.description", String.class, "%s#%s#发起内容%s申请,请相关领导审批查阅。");
String urlEvn = env.getProperty("performance.approve.send.qw.notice.url", String.class);
String urlEvn = env.getProperty("performance.approve.send.qw.notice.url", String.class, "https://scrm.test.glsx.com.cn/recruitment/#/salary/index?corpId=wwa55ffac1225eb25e&agentId=1000002&phone=%s&id=%s");
String userId = qwManager.getUserId(merchantId, performanceApproveConfigDTO.getApproverMobile());
if (StringUtils.isBlank(userId)) {
return false;
......@@ -215,7 +215,7 @@ public class PerformanceConfigApproveService {
String title = String.format(titleEnv, saveOrUpdate);
String description = String.format(descriptionEvn, dateStr, config.getSchemeName(), saveOrUpdate);
WorkWechatTextCardMessageDTO textCard = new WorkWechatTextCardMessageDTO();
String url = String.format(urlEvn, performanceConfigApproveId);
String url = String.format(urlEvn, performanceApproveConfigDTO.getApproverMobile(), performanceConfigApproveId);
textCard.setTitle(title);
textCard.setDescription(description);
textCard.setUrl(urlEvn);
......@@ -275,6 +275,8 @@ public class PerformanceConfigApproveService {
currRecord.setApproveOpinion(dto.getApproveOpinion());
currRecord.setStatus(dto.getStatus());
performanceConfigApproveOperationRecordService.updateApproveOpinionAndStatusById(currRecord);
approveDTO.setApproveDate(new Date());
performanceConfigApproveMapper.updateById(approveDTO);
if (Objects.equals(dto.getStatus(), PerformanceApproveOperatorStatusEnum.PASS.getCode()) && otherApproverPass) {
// 查询方案涉及到的商户和品牌,一个门店一个品牌下面一种类型的方案只能有一个生效中的方案
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService
......
......@@ -42,4 +42,8 @@ public class PerformanceConfigMerchantBrandRefService {
merchantBrandRef.setBusinessType(businessType);
performanceConfigMerchantBrandRefMapper.invalidByBusinessTypeAndMerchantBrand(merchantBrandRef);
}
public List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return performanceConfigMerchantBrandRefMapper.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto);
}
}
......@@ -15,7 +15,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.Date;
import java.util.List;
/**
* 提成配置Service
......@@ -178,41 +179,38 @@ public class PerformanceConfigService {
performanceConfigMapper.updateById(config);
}
public List<PerformanceConfigDetailDTO> performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
public PerformanceConfigDTO performanceConfigDetailWithMerchant(PerformanceConfigDTO dto) {
log.info("selectEffectiveConfig dto: {}", dto);
RpcAssert.assertNotNull(dto, DefaultErrorEnum.DATA_NULL, "dto不能为空");
RpcAssert.assertNotNull(dto.getMerchantId(), DefaultErrorEnum.DATA_NULL, "merchantId不能为空");
// 1 查询生效中的方案
List<PerformanceConfigDTO> performanceConfigDTOS = performanceConfigMapper.effectivePerformanceConfigByMerchantId(dto.getMerchantId());
List<PerformanceConfigDetailDTO> result = new ArrayList<>();
for (PerformanceConfigDTO performanceConfigDTO : performanceConfigDTOS) {
PerformanceConfigDetailDTO detailDTO = PerformanceConfigDetailDTO.builder()
.id(null)
.originPerformanceConfigId(performanceConfigDTO.getId())
.schemeName(performanceConfigDTO.getSchemeName())
.schemeType(2)
.businessType(performanceConfigDTO.getBusinessType())
.effectiveMonth(performanceConfigDTO.getEffectiveMonth())
.build();
// 查询rule
PerformanceConfigRuleDTO ruleDTO = performanceConfigRuleService
.listByConfigId(performanceConfigDTO.getId());
detailDTO.setPerformanceConfigRule(ruleDTO);
// 查询参数配置
List<PerformanceParamConfigDTO> performanceParamConfigs = performanceParamConfigService
.listByConfigId(performanceConfigDTO.getId());
detailDTO.setParamConfigList(performanceParamConfigs);
// 查询商户品牌
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService
.listByConfigId(performanceConfigDTO.getId());
merchantBrandRefs.removeIf(merchantBrandRef -> !merchantBrandRef.getMerchantId().equals(dto.getMerchantId()));
detailDTO.setMerchantBrandRefList(merchantBrandRefs);
result.add(detailDTO);
RpcAssert.assertNotNull(dto.getId(), DefaultErrorEnum.DATA_NULL, "id不能为空");
PerformanceConfigDTO performanceConfigDTO = performanceConfigMapper.selectById(dto.getId());
if (performanceConfigDTO == null) {
return null;
}
return result;
performanceConfigDTO.setOriginPerformanceConfigId(performanceConfigDTO.getId());
performanceConfigDTO.setSchemeType(2);
performanceConfigDTO.setId(null);
// 查询rule
PerformanceConfigRuleDTO ruleDTO = performanceConfigRuleService
.listByConfigId(dto.getId());
performanceConfigDTO.setPerformanceConfigRule(ruleDTO);
// 查询参数配置
List<PerformanceParamConfigDTO> performanceParamConfigs = performanceParamConfigService
.listByConfigId(dto.getId());
performanceConfigDTO.setPerformanceParamConfigs(performanceParamConfigs);
// 查询商户品牌
List<PerformanceConfigMerchantBrandRefDTO> merchantBrandRefs = performanceConfigMerchantBrandRefService
.listByConfigId(dto.getId());
merchantBrandRefs.removeIf(merchantBrandRef -> !merchantBrandRef.getMerchantId().equals(dto.getMerchantId()));
performanceConfigDTO.setMerchantBrandModelPageBrands(merchantBrandRefs);
return performanceConfigDTO;
}
public void enblePerformanceConfig() {
performanceConfigMapper.enblePerformanceConfig();
}
public List<PerformanceConfigMerchantBrandRefDTO> getMerchantBrandListByMerchantIdFromValidPerformanceConfig(PerformanceConfigMerchantBrandRefDTO dto) {
return performanceConfigMerchantBrandRefService.getMerchantBrandListByMerchantIdFromValidPerformanceConfig(dto);
}
}
......@@ -11,6 +11,7 @@
<result column="approve_status" property="approveStatus" jdbcType="TINYINT" />
<result column="merchant_names" property="merchantNames" jdbcType="VARCHAR" />
<result column="brands_names" property="brandsNames" jdbcType="VARCHAR" />
<result column="approve_date" property="approveDate" jdbcType="TIMESTAMP" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_date" property="createdDate" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
......@@ -22,7 +23,7 @@
</resultMap>
<sql id="Base_Column_List" >
id, performance_config_id, approve_remark, approve_attachments, attachment_imgs, submit_username,
approve_status, merchant_names, brands_names, created_by, created_date, updated_by, updated_date, deleted_flag
approve_status, merchant_names, brands_names, approve_date, created_by, created_date, updated_by, updated_date, deleted_flag
</sql>
<!-- 联表查询:审批主表 + 提成方案配置表 -->
<select id="listPerformanceConfig"
......@@ -36,8 +37,8 @@
c.status AS status,
a.merchant_names AS merchantNames,
a.brands_names AS brandsNames,
a.created_date AS createdDate,
a.updated_date AS updatedDate
a.created_date AS submitDate,
a.approve_date AS approveDate
FROM
dj_car_life_performance_config_approve a
LEFT JOIN dj_car_life_performance_config c
......@@ -185,6 +186,9 @@
<if test="updatedBy != null and updatedBy != ''">
updated_by = #{updatedBy},
</if>
<if test="approveDate != null and approveDate != ''">
approve_date = #{approveDate},
</if>
updated_date = NOW()
WHERE
deleted_flag = 'N'
......
......@@ -74,4 +74,20 @@
AND ref.child_id IS NULL
</if>
</update>
<select id="getMerchantBrandListByMerchantIdFromValidPerformanceConfig"
parameterType="cn.com.glsx.dj.staff.dto.PerformanceConfigMerchantBrandRefDTO"
resultMap="DTOResultMap">
SELECT
ref.*, config.business_type AS businessType
FROM dj_car_life_performance_config_merchant_brand_ref ref
INNER JOIN dj_car_life_performance_config config
ON ref.performance_config_id = config.id
WHERE
ref.merchant_id = #{merchantId}
AND ref.deleted_flag = 'N'
AND config.status = 2
AND config.enable_flag = 'Y'
AND config.deleted_flag = 'N'
</select>
</mapper>
\ No newline at end of file
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的资深软件开发工程师。我已仔细阅读了你提交的 rpc-dj-staff 模块代码变更。

    本次提交涉及 RPC 接口签名变更、MyBatis XML 逻辑修改以及业务逻辑调整。代码中存在严重的逻辑漏洞和MyBatis 语法错误,极大概率导致生产环境报错或数据异常。

    以下是本次审查的核心问题与优化建议:

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

    1. 严重逻辑缺陷:PerformanceConfigService 过滤逻辑导致数据丢失

    • 问题描述:在 performanceConfigDetailWithMerchant 方法中,你移除了对 dto.getMerchantId() 的非空校验(RpcAssert),但在后续代码中直接使用了该字段进行过滤: java merchantBrandRefs.removeIf(merchantBrandRef -> !merchantBrandRef.getMerchantId().equals(dto.getMerchantId()));
    • 影响分析:
      • 如果调用方仅传递了 id 而未传递 merchantId(根据新的校验逻辑这是合法的),dto.getMerchantId() 为 null。
      • merchantBrandRef.getMerchantId().equals(null) 返回 false。
      • !false 变为 true,导致 removeIf 条件恒成立。
      • 结果:该方法将返回一个 merchantBrandModelPageBrands 为空的配置对象,即使数据库中存在关联数据。这属于严重的功能性 Bug。
    • 优化建议: 必须恢复对 merchantId 的非空校验,或者在过滤前判断 dto.getMerchantId() 是否为空。 java // 建议方案:恢复断言 RpcAssert.assertNotNull(dto.getMerchantId(), DefaultErrorEnum.DATA_NULL, "merchantId不能为空");

    2. 代码错误:MyBatis XML 中 Date 类型错误的非空判断

    • 问题描述:在 PerformanceConfigApproveMapper.xml 中,对 Date 类型的 approveDate 字段进行了空字符串判断: xml <if test="approveDate != null and approveDate != ''"> approve_date = #{approveDate}, </if>
    • 影响分析:
      • 在 Java/MyBatis (OGNL) 中,将 java.util.Date 对象与空字符串 '' 进行比较会导致运行时异常(如 IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String),或者在某些版本中逻辑失效。
      • 这将导致更新 SQL 语句构建失败,审批流程无法完成。
    • 优化建议: 去除 and approveDate != '',仅保留 null 判断。 xml <if test="approveDate != null"> approve_date = #{approveDate}, </if>

    3. 稳定性风险:String.format 参数与配置项不匹配风险

    • 问题描述:在 PerformanceConfigApproveService 中,你修改了 url 的构建逻辑,增加了 phone 参数,现在的格式化需要 2 个占位符。 java // 代码中:期望 urlEvn 包含两个 %s String url = String.format(urlEvn, ..., ...);
    • 影响分析:
      • urlEvn 的值优先取自配置中心(env.getProperty)。如果生产环境的配置中心未同步更新 performance.approve.send.qw.notice.url 这个配置项(仍为旧版 1 个 %s 的格式),String.format 将抛出 MissingFormatArgumentException 或 IllegalFormatException。
      • 这会导致审批通过后的消息推送功能直接崩溃,阻断业务流程。
    • 优化建议: 增加参数数量校验,或使用更安全的字符串替换方式(如 MessageFormat 或具名占位符),并确保配置中心变更与代码发布同步。 java // 临时防御性编程示例 try { url = String.format(urlEvn, performanceApproveConfigDTO.getApproverMobile(), performanceConfigApproveId); } catch (Exception e) { log.error("URL格式化失败,请检查配置项", e); // 降级处理或抛出明确异常 }

    二、评分明细

    1. 功能实现的正确性与健壮性(40分):15分
      • 理由:存在两处阻断性 Bug。一是 Service 层逻辑会导致关联品牌数据被错误清空;二是 Mapper XML 中对 Date 类型的判断语法错误,必然导致 SQL 执行失败。
    2. 安全性与潜在风险(30分):20分
      • 理由:存在配置项与代码不一致导致服务崩溃的风险(String.format)。未发现明显的 SQL 注入风险。
    3. 最佳实践与可维护性(20分):10分
      • 理由:RPC 接口 performanceConfigDetailWithMerchant 的返回值从 List 修改为 Object,属于破坏性变更(Breaking Change)。如果客户端未同步升级,将导致反序列化失败或调用异常。通常应通过新增接口或版本号控制来处理此类变更。
    4. 性能与资源利用(5分):5分
      • 理由:未引入明显的性能问题。
    5. 提交信息质量(5分):2分
      • 理由:Commit message "fixbug: 方案提交bug修复" 过于笼统,未说明具体修复了什么 Bug,且本次提交包含了 RPC 接口签名修改等重大变更,描述严重不符。

    三、总分

    总分:52分

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