Commit 0b3584c3 by 范富荣

优化修改查询客户档案逻辑

1 parent a869f36d
...@@ -12,6 +12,7 @@ import cn.com.glsx.dj.mindworkplate.model.ReceptionCustomerInfo; ...@@ -12,6 +12,7 @@ import cn.com.glsx.dj.mindworkplate.model.ReceptionCustomerInfo;
import cn.com.glsx.dj.mindworkplate.service.MerchantService; import cn.com.glsx.dj.mindworkplate.service.MerchantService;
import cn.com.glsx.dj.mindworkplate.service.customer.QWManager; import cn.com.glsx.dj.mindworkplate.service.customer.QWManager;
import cn.com.glsx.dj.mindworkplate.util.ExcelExportUtils; import cn.com.glsx.dj.mindworkplate.util.ExcelExportUtils;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.scrm.proxy.dto.merchant.ListMerchantRequest; import cn.com.glsx.scrm.proxy.dto.merchant.ListMerchantRequest;
import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse; import cn.com.glsx.scrm.proxy.model.merchant.MerchantRopResponse;
...@@ -36,6 +37,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -36,6 +37,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.oreframework.boot.autoconfigure.alioss.entity.AliOssUploadClient; import org.oreframework.boot.autoconfigure.alioss.entity.AliOssUploadClient;
import org.oreframework.distribute.lock.annotation.GlsxDistributeLockable;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -161,10 +163,11 @@ public class ReceptionCustomerFileGenerateService { ...@@ -161,10 +163,11 @@ public class ReceptionCustomerFileGenerateService {
return phone.substring(0, 3) + "****" + phone.substring(7); return phone.substring(0, 3) + "****" + phone.substring(7);
} }
@GlsxDistributeLockable(name="'ReceptionCustomerFileGenerateService_updateCustomerFile_' + #request.receptionId", timeoutException=Exception.class)
@Transactional @Transactional
public boolean updateCustomerFile(ReceptionCustomerFileUpdateRequestDTO request) { public boolean updateCustomerFile(ReceptionCustomerFileUpdateRequestDTO request) {
if (request == null || request.getReceptionId() == null) { if (request == null || request.getReceptionId() == null) {
throw new RpcServiceException(MindWorkplateServiceErrorEnum.DATA_NOT_FULL_ERROR); throw new RpcServiceException(DefaultErrorEnum.PARAMETER_NULL);
} }
ReceptionCustomerFile existingFile = receptionCustomerFileMapper.selectByReceptionId(request.getReceptionId()); ReceptionCustomerFile existingFile = receptionCustomerFileMapper.selectByReceptionId(request.getReceptionId());
...@@ -172,7 +175,7 @@ public class ReceptionCustomerFileGenerateService { ...@@ -172,7 +175,7 @@ public class ReceptionCustomerFileGenerateService {
if (existingFile != null) { if (existingFile != null) {
// 记录存在,执行更新 // 记录存在,执行更新
if (existingFile.getSubmitStatus() != null && existingFile.getSubmitStatus() == 1) { if (existingFile.getSubmitStatus() != null && existingFile.getSubmitStatus() == 1) {
throw new RpcServiceException(MindWorkplateServiceErrorEnum.COMMON_ERROR, "该客户档案已提交,不可重复提交"); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, "该客户档案已提交,不可重复提交");
} }
receptionCustomerFileMapper.updateByReceptionId(request); receptionCustomerFileMapper.updateByReceptionId(request);
} else { } else {
......
...@@ -149,11 +149,29 @@ ...@@ -149,11 +149,29 @@
<select id="selectByReceptionId" resultType="cn.com.glsx.dj.mindworkplate.model.ReceptionCustomerFile"> <select id="selectByReceptionId" resultType="cn.com.glsx.dj.mindworkplate.model.ReceptionCustomerFile">
select select
id, submit_status, reception_id, reception_result, deal_attribution, id,
lose_reason, car_user_type, customer_background, easy_communication, is_mortgage, submit_status as submitStatus,
down_payment_ratio, purchase_background, is_local_use, purchase_purpose, reception_id as receptionId,
install_items, gift_items, film_brand, know_other_brand_goods, reception_result as receptionResult,
created_by, created_date, updated_by, updated_date, deleted_flag deal_attribution as dealAttribution,
lose_reason as loseReason,
car_user_type as carUserType,
customer_background as customerBackground,
easy_communication as easyCommunication,
is_mortgage as isMortgage,
down_payment_ratio as downPaymentRatio,
purchase_background as purchaseBackground,
is_local_use as isLocalUse,
purchase_purpose as purchasePurpose,
install_items as installItems,
gift_items as giftItems,
film_brand as filmBrand,
know_other_brand_goods as knowOtherBrandGoods,
created_by as createdBy,
created_date as createdDate,
updated_by as updatedBy,
updated_date as updatedDate,
deleted_flag as deletedFlag
from reception_customer_file from reception_customer_file
where reception_id = #{receptionId} where reception_id = #{receptionId}
and deleted_flag = 'N' and deleted_flag = 'N'
...@@ -161,4 +179,4 @@ ...@@ -161,4 +179,4 @@
</select> </select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
  • @wangxw1
    commented
    Master

    你好,我是本次的代码审查工程师。针对你提交的关于“优化修改查询客户档案逻辑”的代码变更,以下是我的审查意见:

    一、关键问题与优化建议

    问题 1:分布式锁与事务嵌套顺序不当(安全性/稳定性)

    • 问题描述:在 updateCustomerFile 方法上,@GlsxDistributeLockable(分布式锁)被置于 @Transactional(数据库事务)之上。这意味着锁的释放早于事务的提交。
    • 影响分析:在高并发场景下,线程 A 释放分布式锁后,其事务可能尚未提交。此时线程 B 获取到锁并进入方法,读取到的仍是线程 A 修改前的旧数据(不可重复读/幻读),从而导致逻辑判断失效(如重复提交检查失效)或数据覆盖。
    • 优化建议:应确保“锁的范围大于事务的范围”。如果是通过 AOP 实现,需确保分布式锁切面的优先级(Order)高于事务切面,或者将事务逻辑封装在内部私有方法中,由带锁的公有方法调用。

    问题 2:SQL 返回值映射建议使用 ResultMap(最佳实践/可维护性)

    • 问题描述:在 ReceptionCustomerFileMapper.xml 中,代码通过 as 别名的方式手动映射数据库字段到 Java 驼峰命名。
    • 影响分析:这种方式会导致 SQL 语句冗长且难以维护。当字段增多或多个查询复用时,重复的别名定义增加了出错概率。
    • 优化建议:建议在 XML 中定义 <resultMap>,或者在 MyBatis 全局配置中开启 mapUnderscoreToCamelCase。这样可以保持 SQL 简洁,并提高代码的可读性。

    问题 3:异常枚举替换的语义准确性(功能正确性)

    • 问题描述:代码将业务特定的错误码 MindWorkplateServiceErrorEnum.DATA_NOT_FULL_ERROR 替换为了通用错误码 DefaultErrorEnum.PARAMETER_NULL。
    • 影响分析:虽然功能上可行,但丢失了业务语义。DATA_NOT_FULL_ERROR 通常暗示数据不完整(可能包含非空但逻辑不全),而 PARAMETER_NULL 仅指参数为空,这可能影响前端或调用方对错误原因的精准捕获和提示。
    • 优化建议:除非是为了统一框架级异常规范,否则建议保留具有明确业务含义的错误码,或确保 DefaultErrorEnum 能覆盖所有业务边界场景。

    二、评分明细

    评分维度 分数 理由
    功能实现正确性与健壮性 35分 逻辑基本正确,但分布式锁与事务的嵌套顺序存在并发安全隐患。
    安全性与潜在风险 28分 引入分布式锁防止并发冲突是好的,但因切面顺序问题可能导致锁失效风险。无 SQL 注入风险。
    最佳实践与可维护性 15分 SQL 别名映射方式不够优雅;异常处理由具体转向通用,略微降低了语义清晰度。
    性能与资源利用 5分 无明显性能瓶颈,SQL 查询简单高效。
    提交信息质量 4分 commit 信息简练,但未能全面涵盖“引入分布式锁”这一重大变更。

    总分:87分

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