Commit 5b36a8f2 by zhoulm

更新流量方分账方

1 parent 9836b8a4
package cn.com.glsx.dj.smartcarlife.remote; package cn.com.glsx.dj.smartcarlife.remote;
import javax.validation.constraints.NotNull;
import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO;
import cn.com.glsx.dj.smartcarlife.model.MerchantDivisionRule;
import cn.com.glsx.framework.core.annotation.*; import cn.com.glsx.framework.core.annotation.*;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
...@@ -25,4 +28,9 @@ public interface MerchantDivisionRuleRemote { ...@@ -25,4 +28,9 @@ public interface MerchantDivisionRuleRemote {
@ApiParams({@ApiParam(name="merchantId",notes="商户号",dataType= ApiParam.DataTypeEnum.INTEGER,required=true)}) @ApiParams({@ApiParam(name="merchantId",notes="商户号",dataType= ApiParam.DataTypeEnum.INTEGER,required=true)})
@ApiResponse("返回商户分账规则") @ApiResponse("返回商户分账规则")
RpcResponse<MerchantDivisionRuleDTO> getLatestByMerchantId(Integer merchantId, Byte sceneType); RpcResponse<MerchantDivisionRuleDTO> getLatestByMerchantId(Integer merchantId, Byte sceneType);
@ApiMethod("获取当前商户分账规则")
@ApiParams({@ApiParam(name="divisionRuleId",notes="分账规则id",dataType= ApiParam.DataTypeEnum.INTEGER,required=true)})
@ApiResponse("返回商户分账规则")
RpcResponse<MerchantDivisionRule> getBaseById(@NotNull Integer divisionRuleId);
} }
...@@ -18,4 +18,6 @@ public interface MerchantDistributionRuleMapper extends OreMapper<MerchantDistri ...@@ -18,4 +18,6 @@ public interface MerchantDistributionRuleMapper extends OreMapper<MerchantDistri
List<MerchantDistributionRuleDTO> selectByRuleType1(Integer goodsTypeGroupRuleId); List<MerchantDistributionRuleDTO> selectByRuleType1(Integer goodsTypeGroupRuleId);
List<MerchantDistributionRuleDTO> selectByRuleType2(Integer goodsTypeGroupRuleId); List<MerchantDistributionRuleDTO> selectByRuleType2(Integer goodsTypeGroupRuleId);
int updateShopInfo(MerchantDistributionRuleDTO dto);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.smartcarlife.remote; package cn.com.glsx.dj.smartcarlife.remote;
import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO;
import cn.com.glsx.dj.smartcarlife.model.MerchantDivisionRule;
import cn.com.glsx.dj.smartcarlife.service.merchantSettleDistribution.MerchantDivisionRuleService; import cn.com.glsx.dj.smartcarlife.service.merchantSettleDistribution.MerchantDivisionRuleService;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import javax.validation.constraints.NotNull;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -35,4 +39,14 @@ public class MerchantDivisionRuleRemoteImpl implements MerchantDivisionRuleRemot ...@@ -35,4 +39,14 @@ public class MerchantDivisionRuleRemoteImpl implements MerchantDivisionRuleRemot
} }
} }
@Override
public RpcResponse<MerchantDivisionRule> getBaseById(@NotNull Integer divisionRuleId) {
try{
return RpcResponse.success(merchantDivisionRuleService.getBaseById(divisionRuleId));
}catch(RpcServiceException e){
logger.error(e.getMessage(),e);
return RpcResponse.error(e);
}
}
} }
...@@ -279,7 +279,7 @@ public class CreateBusinessApproveSettleRuleService { ...@@ -279,7 +279,7 @@ public class CreateBusinessApproveSettleRuleService {
try { try {
CreateBusinessApproveMerchantDTO merchant = createBusinessApproveMerchantService.getSaveRuleMerchant(businessCode); CreateBusinessApproveMerchantDTO merchant = createBusinessApproveMerchantService.getSaveRuleMerchant(businessCode);
record.setId(merchant.getDivisionRuleId()); record.setId(merchant.getDivisionRuleId());
return merchantDivisionRuleService.saveDivisionRuleAuto(record); return merchantDivisionRuleService.saveDivisionRuleAuto(merchant,record);
} catch (Exception e) { } catch (Exception e) {
log.info(e.getMessage(), e); log.info(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage()); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
......
...@@ -62,6 +62,16 @@ public class MerchantDistributionRuleService { ...@@ -62,6 +62,16 @@ public class MerchantDistributionRuleService {
); );
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void updateShopInfo(MerchantDistributionRuleDTO dto){
try{
merchantDistributionRuleMapper.updateShopInfo(dto);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void deleteByGoodsTypeGroupRuleId(Integer goodsTypeGroupRuleId,String updatedBy){ public void deleteByGoodsTypeGroupRuleId(Integer goodsTypeGroupRuleId,String updatedBy){
try{ try{
MerchantDistributionRule record = MerchantDistributionRule.builder() MerchantDistributionRule record = MerchantDistributionRule.builder()
......
...@@ -21,7 +21,9 @@ import com.github.pagehelper.Page; ...@@ -21,7 +21,9 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import cn.com.glsx.dj.smartcarlife.converter.DivisionRuleAutoDTOConvert; import cn.com.glsx.dj.smartcarlife.converter.DivisionRuleAutoDTOConvert;
import cn.com.glsx.dj.smartcarlife.dto.CreateBusinessApproveMerchantDTO;
import cn.com.glsx.dj.smartcarlife.dto.DivisionRuleEffectRecordDTO; import cn.com.glsx.dj.smartcarlife.dto.DivisionRuleEffectRecordDTO;
import cn.com.glsx.dj.smartcarlife.dto.MerchantDistributionRuleDTO;
import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantDivisionRuleDTO;
import cn.com.glsx.dj.smartcarlife.dto.MerchantGoodsTypeGroupDivisionRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantGoodsTypeGroupDivisionRuleDTO;
import cn.com.glsx.dj.smartcarlife.dto.MerchantSettleDistributeRuleDTO; import cn.com.glsx.dj.smartcarlife.dto.MerchantSettleDistributeRuleDTO;
...@@ -727,7 +729,7 @@ public class MerchantDivisionRuleService { ...@@ -727,7 +729,7 @@ public class MerchantDivisionRuleService {
} }
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantDivisionRuleDTO saveDivisionRuleAuto(MerchantDivisionRuleDTO record) { public MerchantDivisionRuleDTO saveDivisionRuleAuto(CreateBusinessApproveMerchantDTO merchant,MerchantDivisionRuleDTO record) {
RpcAssert.assertNotNull(record.getId(), DefaultErrorEnum.DATA_NULL,"record.id not be null"); RpcAssert.assertNotNull(record.getId(), DefaultErrorEnum.DATA_NULL,"record.id not be null");
RpcAssert.assertNotNull(record.getUpdatedBy(), DefaultErrorEnum.DATA_NULL,"record.updatedBy not be null"); RpcAssert.assertNotNull(record.getUpdatedBy(), DefaultErrorEnum.DATA_NULL,"record.updatedBy not be null");
RpcAssert.assertNotEmpty(record.getDivisionRuleAutos(), DefaultErrorEnum.DATA_NULL,"record.getDivisionRuleAutos() not be empty"); RpcAssert.assertNotEmpty(record.getDivisionRuleAutos(), DefaultErrorEnum.DATA_NULL,"record.getDivisionRuleAutos() not be empty");
...@@ -753,6 +755,15 @@ public class MerchantDivisionRuleService { ...@@ -753,6 +755,15 @@ public class MerchantDivisionRuleService {
}else{ }else{
record.setDivisionType(CarLifeEnum.DivisionType.OFFLINE.getValue()); record.setDivisionType(CarLifeEnum.DivisionType.OFFLINE.getValue());
} }
if (Objects.equals(TargetMerchantLevelEnum.SUPERIOR.getValue(), record.getRealityShopLevel())) {
record.setRealityShopMerchantId(merchant.getParentMerchantId());
record.setRealityShopMerchantName(merchant.getParentMerchantName());
}else{
record.setRealityShopMerchantId(merchant.getMerchantId());
record.setRealityShopMerchantName(merchant.getMerchantName());
}
MerchantDivisionRule updateRecord = MerchantDivisionRule.builder().id(record.getId()) MerchantDivisionRule updateRecord = MerchantDivisionRule.builder().id(record.getId())
.realityShopLevel(record.getRealityShopLevel()) .realityShopLevel(record.getRealityShopLevel())
.realityShopMerchantId(record.getRealityShopMerchantId()) .realityShopMerchantId(record.getRealityShopMerchantId())
...@@ -761,6 +772,12 @@ public class MerchantDivisionRuleService { ...@@ -761,6 +772,12 @@ public class MerchantDivisionRuleService {
.divisionType(record.getDivisionType()) .divisionType(record.getDivisionType())
.updatedBy(record.getUpdatedBy()).updatedDate(new Date()).build(); .updatedBy(record.getUpdatedBy()).updatedDate(new Date()).build();
merchantDivisionRuleMapper.updateByPrimaryKeySelective(updateRecord); merchantDivisionRuleMapper.updateByPrimaryKeySelective(updateRecord);
merchantDistributionRuleService.updateShopInfo(MerchantDistributionRuleDTO.builder()
.divisionRuleId(record.getId())
.targetMerchantLevel(record.getRealityShopLevel())
.merchantId(record.getRealityShopMerchantId()).merchantName(record.getRealityShopMerchantName())
.updatedBy(record.getUpdatedBy())
.build());
divisionRuleAutoService.updateBatch(record.getDivisionRuleAutos(), record.getId(), record.getUpdatedBy()); divisionRuleAutoService.updateBatch(record.getDivisionRuleAutos(), record.getId(), record.getUpdatedBy());
return record; return record;
} catch (Exception e) { } catch (Exception e) {
......
...@@ -73,6 +73,15 @@ ...@@ -73,6 +73,15 @@
</if> </if>
</where> </where>
</select> </select>
<update id="updateShopInfo" parameterType="cn.com.glsx.dj.smartcarlife.dto.MerchantDistributionRuleDTO">
update dj_car_life_merchant_distribution_rule a,dj_car_life_merchant_goods_type_group_division_rule b
set a.target_merchant_level = #{targetMerchantLevel},a.merchant_id=#{merchantId}, a.merchant_name=#{merchantName},
a.updated_by = #{updatedBy},a.updated_date=now()
where a.deleted_flag='N' and b.id=a.goods_type_group_rule_id and b.deleted_flag='N'
and a.target_merchant_type=3 and b.division_rule_id=#{divisionRuleId}
</update>
<select id="getTypeRuleByExpenseCategoryRuleId" resultMap="DTOResultMap"> <select id="getTypeRuleByExpenseCategoryRuleId" resultMap="DTOResultMap">
select dclmdr.id, select dclmdr.id,
dclmdr.goods_type_group_rule_id, dclmdr.goods_type_group_rule_id,
......
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议

    • 问题 1:SQL 更新操作缺乏影响行数校验,存在逻辑静默失败风险

      • 问题描述:在 MerchantDistributionRuleMapper.xml 中的 updateShopInfo 关联更新 SQL 以及 MerchantDivisionRuleService.java 中调用 updateByPrimaryKeySelective 时,均未校验返回值(影响行数)。
      • 影响分析:如果 divisionRuleId 不存在或关联条件 a.target_merchant_type=3 不匹配,SQL 会执行成功但实际未修改任何数据。业务层会误以为更新成功并继续后续操作,导致数据不一致。
      • 优化建议:在 Service 层校验 Mapper 返回的 int 值,若为 0 则根据业务需求抛出异常或进行补偿处理。 java int rows = merchantDivisionRuleMapper.updateByPrimaryKeySelective(updateRecord); RpcAssert.assertTrue(rows > 0, DefaultErrorEnum.DATA_NOT_EXIST, "更新分账规则主表失败");
    • 问题 2:RPC 接口暴露内部 Entity 对象(Model),违反领域隔离原则

      • 问题描述:在 MerchantDivisionRuleRemote.java 中新增的 getBaseById 接口直接返回了 MerchantDivisionRule(MyBatis Generator 生成的数据库实体模型)。
      • 影响分析:1. 耦合性:数据库表结构的任何变动会直接影响外部调用方;2. 安全性:Entity 可能包含敏感字段(如逻辑删除位、内部状态等)被无意暴露。
      • 优化建议:应统一使用 DTO 对象作为 RPC 接口的返回值,通过 BeanUtils 或 Converter 进行转换。 java // 建议修改为 RpcResponse<MerchantDivisionRuleDTO> getBaseById(@NotNull Integer divisionRuleId);
    • 问题 3:事务内异常捕获过于宽泛,导致原始堆栈信息丢失风险

      • 问题描述:在 MerchantDivisionRuleService.saveDivisionRuleAuto 等多个方法中,使用了 catch (Exception e) 并手动抛出 RpcServiceException。
      • 影响分析:虽然通过 e.getMessage() 传递了信息,但在某些框架实现中,若不将原始 e 作为 cause 传入新异常,会导致上层拦截器无法获取完整的异常链,增加排查问题的难度。此外,部分非受检异常可能被错误包装。
      • 优化建议:建议使用统一的异常处理拦截器,或者在包装异常时保留原始异常引用。 java } catch (Exception e) { log.error("保存分账规则失败: " + e.getMessage(), e); throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e); // 传入 e 保持异常链 }

    二、评分明细

    • 功能实现的正确性与健壮性(35/40分): 逻辑实现基本正确,符合业务变更需求。未发现子查询。扣分项在于对 SQL 执行结果缺乏校验,存在静默失败风险。
    • 安全性与潜在风险(28/30分): 使用了预编译 SQL,无注入风险。扣分项在于 RPC 接口直接返回数据库 Model 实体,存在过度暴露内部数据的风险。
    • 最佳实践与可维护性(16/20分): 代码结构清晰,使用了 Builder 模式。但接口层返回对象类型不统一(DTO 与 Model 混用),且 Mapper XML 中 No newline at end of file 说明格式规范有待加强。
    • 性能与资源利用(5/5分): SQL 更新使用了关联索引字段,暂无明显性能瓶颈。
    • 提交信息质量(4/5分): Commit 信息“更新流量方分账方”描述了业务意图,较为清晰,但若能加上关联的任务 ID 会更好。

    总分:88分

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