Commit 427eb4cc by 周立明

refactor(merchant-settle): 统一添加分账测试开关参数changeAddNew

调整多个分账相关服务的方法签名,新增changeAddNew参数控制是否触发规则复制生效逻辑,统一各处调用传参
1 parent ad16de52
......@@ -28,7 +28,7 @@ public class DivisionRuleTestRemoteImpl implements DivisionRuleTestRemote {
@Override
public RpcResponse<DivisionRuleTestDTO> getLastByMerchantId(Integer goodsTypeGroupDivisionId, String paymentChannelId) {
try{
return RpcResponse.success(divisionRuleTestService.getLastByGoodsTypeGroupDivisionId(goodsTypeGroupDivisionId, paymentChannelId,false));
return RpcResponse.success(divisionRuleTestService.getLastByGoodsTypeGroupDivisionId(goodsTypeGroupDivisionId, paymentChannelId,false,true));
}catch(RpcServiceException e){
logger.error(e.getMessage(), e);
return RpcResponse.error(e);
......
......@@ -4183,7 +4183,7 @@ public class CreateBusinessApproveService {
}
merchantSettleAccountRuleService.validSettleAccountRuleDeletedFlag(merchant.getSettleRuleId(), CommonConstants.DEFAULT_UPDATE_BY,StatusEnum.YES.getValue());
merchantDivisionRuleService.validDivisionRuleDeletedFlag(merchant.getDivisionRuleId(), CommonConstants.DEFAULT_UPDATE_BY,StatusEnum.YES.getValue());
merchantDivisionRuleService.refreshRuleTest(merchant.getDivisionRuleId());
merchantDivisionRuleService.refreshRuleTest(merchant.getDivisionRuleId(),true);
DivisionRuleEffectRecord ruleEffectRecord = DivisionRuleEffectRecord.builder().merchantId(settleAccountRuleDTO.getMerchantId())
.merchantName(merchant.getMerchantName()).sceneType(settleAccountRuleDTO.getSceneType()).ruleType(RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue())
.ruleId(merchant.getSettleRuleId()).divisionRuleId(merchant.getDivisionRuleId()).effectStartDate(new Date()).updatedBy(CommonConstants.DEFAULT_UPDATE_BY).build();
......
......@@ -138,7 +138,7 @@ public class GoodsListingProfitRateService {
merchants.parallelStream().forEach(m ->{
try {
if(m.getDivisionRuleId() != null) {
merchantDivisionRuleService.refreshRuleTest(m.getDivisionRuleId());
merchantDivisionRuleService.refreshRuleTest(m.getDivisionRuleId(),false);
log.info("分账规则ID:{}刷新分账测试完成",m.getDivisionRuleId());
}
}catch(Exception e){
......
......@@ -552,7 +552,7 @@ public class YseMerchantRefBatchService {
// 更新商户信息分账测试通过标志
merchantPaymentChannelAccountService.resetTestFlag(removedMerchantIds, paymentChannelId, CommonConstants.DEFAULT_UPDATE_BY);
// 重置分账测试标志位
merchantDivisionRuleService.resetTestFlag(removedMerchantIds, paymentChannelId, CommonConstants.DEFAULT_UPDATE_BY);
merchantDivisionRuleService.resetTestFlag(removedMerchantIds, paymentChannelId, CommonConstants.DEFAULT_UPDATE_BY,true);
}
}
}
......
......@@ -251,7 +251,7 @@ public class DivisionRuleAutoService {
}
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantDivisionRuleProcessDTO refreshTestProcess(MerchantDivisionRuleDTO record) {
public MerchantDivisionRuleProcessDTO refreshTestProcess(MerchantDivisionRuleDTO record,boolean changeAddNew) {
if (record == null || CollectionUtils.isEmpty(record.getDivisionRuleAutos()) || CollectionUtils.isEmpty(record.getGoodsTypeGroupDivisionRules())) {
log.warn("record is null or divisionRuleAutos is empty or goodsTypeGroupDivisionRules is empty");
return null;
......@@ -265,7 +265,7 @@ public class DivisionRuleAutoService {
MerchantDivisionRuleProcessDTO processDTO = MerchantDivisionRuleProcessDTO.builder().notInForceAccountMerchantMap(new HashMap<>()).divisionRuleTestMap(new TreeMap<>()).build();
return processDTO;
}
return groupDivisionRuleTestService.refreshTestProcess(record.getGoodsTypeGroupDivisionRules());
return groupDivisionRuleTestService.refreshTestProcess(record.getGoodsTypeGroupDivisionRules(),changeAddNew);
}
}
......@@ -79,13 +79,13 @@ public class DivisionRuleTestService {
RpcAssert.assertNotEmpty(record.getPaymentChannelId(), DefaultErrorEnum.DATA_NULL,"re not be empty");
RpcAssert.assertNotNull(record.getUpdatedBy(), DefaultErrorEnum.DATA_NULL, "DivisionRuleTest.updatedBy not be null");
try {
DivisionRuleTestDTO oldRecord = thiz.getLastByGoodsTypeGroupDivisionId(record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId(), true);
DivisionRuleTestDTO oldRecord = thiz.getLastByGoodsTypeGroupDivisionId(record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId(), true,true);
record.setOrderCode(oldRecord.getOrderCode());
record.setId(oldRecord.getId());
record.setMerchantId(oldRecord.getMerchantId());
record.setPaymentChannelName(oldRecord.getPaymentChannelName());
record.setDivisionRuleId(oldRecord.getDivisionRuleId());
thiz.updateProcess(record);
thiz.updateProcess(record,true);
return record;
} catch (Exception e) {
log.info(e.getMessage(), e);
......@@ -184,7 +184,7 @@ public class DivisionRuleTestService {
@Transactional(propagation=Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void setProgress(DivisionRuleTestDTO record){
public void setProgress(DivisionRuleTestDTO record,boolean changeAddNew){
try{
List<MerchantPaymentChannelAccountDTO> distributeMerchants = thiz.getDistributeMerchants(record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId());
Boolean allPassTest = true;
......@@ -208,7 +208,7 @@ public class DivisionRuleTestService {
record.setSubProgress(DivisionTestSubProgress.NOT_NEED_DIVISION_TEST.getValue());
log.info("分账测试进度更新,所有商户都已通过测试,groupRuleId:{}, paymentChannelId:{},更新groupDivisionRuleTest为已测试", record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId());
// 更新分账规则分组为已测试
groupDivisionRuleTestService.markTested(record.getDivisionRuleId(), record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId());
groupDivisionRuleTestService.markTested(record.getDivisionRuleId(), record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId(),changeAddNew);
return;
}
// 3.测试订单
......@@ -239,7 +239,7 @@ public class DivisionRuleTestService {
List<Integer> ids = distributeMerchants.stream().map(MerchantPaymentChannelAccountDTO::getId).collect(Collectors.toList());
merchantPaymentChannelAccountService.markTested(ids, CommonConstants.DEFAULT_UPDATE_BY);
// 更新分账规则分组对应支付渠道为已测试
groupDivisionRuleTestService.markTested(record.getDivisionRuleId(), record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId());
groupDivisionRuleTestService.markTested(record.getDivisionRuleId(), record.getGoodsTypeGroupDivisionId(), record.getPaymentChannelId(),changeAddNew);
record.setSubProgress(DivisionTestSubProgress.FINISHED.getValue());
}else{
// 测试订单已支付,但还未分账成功
......@@ -257,10 +257,10 @@ public class DivisionRuleTestService {
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void updateProcess(DivisionRuleTestDTO record){
public void updateProcess(DivisionRuleTestDTO record,boolean changeAddNew){
RpcAssert.assertNotEmpty(record.getUpdatedBy(), DefaultErrorEnum.DATA_NULL,"record.getUpdatedBy() not be empty");
try{
thiz.setProgress(record);
thiz.setProgress(record,changeAddNew);
record.setUpdatedDate(new Date());
divisionRuleTestMapper.updateByPrimaryKeySelective(record);
if (CollectionUtils.isNotEmpty(record.getTestMerchantDivisions())) {
......@@ -453,7 +453,7 @@ public class DivisionRuleTestService {
@GlsxDistributeLockable(name="'DivisionRuleTestService_' + #goodsTypeGroupSettleId",timeoutException=RpcServiceException.class)
public DivisionRuleTestDTO getLastByGoodsTypeGroupDivisionId(Integer goodsTypeGroupDivisionId, String paymentChannelId, boolean isBase){
public DivisionRuleTestDTO getLastByGoodsTypeGroupDivisionId(Integer goodsTypeGroupDivisionId, String paymentChannelId, boolean isBase,boolean changeAddNew){
RpcAssert.assertNotNull(goodsTypeGroupDivisionId, DefaultErrorEnum.DATA_NULL, "goodsTypeGroupSettleId not be null");
RpcAssert.assertNotEmpty(paymentChannelId, DefaultErrorEnum.DATA_NULL,"paymentChannelId not be empty");
try {
......@@ -479,7 +479,7 @@ public class DivisionRuleTestService {
return r;
}
r.setUpdatedBy(CommonConstants.DEFAULT_UPDATE_BY);
thiz.updateProcess(r);
thiz.updateProcess(r,changeAddNew);
return r;
} catch (Exception e) {
log.info(e.getMessage(), e);
......
......@@ -55,7 +55,7 @@ public class GroupDivisionRuleTestService {
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantDivisionRuleProcessDTO refreshTestProcess(List<MerchantGoodsTypeGroupDivisionRuleDTO> goodsTypeGroupDivisionRules) {
public MerchantDivisionRuleProcessDTO refreshTestProcess(List<MerchantGoodsTypeGroupDivisionRuleDTO> goodsTypeGroupDivisionRules,boolean changeAddNew) {
RpcAssert.assertNotEmpty(goodsTypeGroupDivisionRules, DefaultErrorEnum.DATA_NULL,"goodsTypeGroupDivisionRules not be empty");
log.info("divisionRule groupRule paymentChannel refreshTestProcess, goodsTypeGroupDivisionRules size:{}", goodsTypeGroupDivisionRules.size());
RpcAssert.assertIsTrue(goodsTypeGroupDivisionRules.stream().noneMatch(o->o == null || CollectionUtils.isEmpty(o.getMerchantDistributionRules())), DefaultErrorEnum.DATA_NULL, "goodsTypeGroupDivisionRules.getMerchantDistributionRules() not be empty");
......@@ -89,7 +89,7 @@ public class GroupDivisionRuleTestService {
}
for (MerchantGoodsTypeGroupDivisionRuleDTO goodsTypeGroupDivisionRule : groupDivisionRuleDTOMap.values()) {
// 聚合各个分组的测试进度
MerchantDivisionRuleProcessDTO groupProcessDTO = thiz.refreshGroupTestProcess(goodsTypeGroupDivisionRule);
MerchantDivisionRuleProcessDTO groupProcessDTO = thiz.refreshGroupTestProcess(goodsTypeGroupDivisionRule,changeAddNew);
if (groupProcessDTO != null) {
if (MapUtils.isNotEmpty(groupProcessDTO.getNotInForceAccountMerchantMap())) {
for (Map.Entry<String, List<MerchantPaymentChannelAccountDTO>> entry : groupProcessDTO.getNotInForceAccountMerchantMap().entrySet()) {
......@@ -122,7 +122,7 @@ public class GroupDivisionRuleTestService {
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantDivisionRuleProcessDTO refreshGroupTestProcess(Integer groupRuleId, Boolean compileTestSubOrderAndCategory) {
MerchantGoodsTypeGroupDivisionRuleDTO groupDivisionRule = merchantGoodsTypeGroupDivisionRuleService.getDetail(groupRuleId);
MerchantDivisionRuleProcessDTO processDTO = thiz.refreshGroupTestProcess(groupDivisionRule);
MerchantDivisionRuleProcessDTO processDTO = thiz.refreshGroupTestProcess(groupDivisionRule,true);
if (processDTO != null && MapUtils.isNotEmpty(processDTO.getDivisionRuleTestMap())
&& compileTestSubOrderAndCategory != null && compileTestSubOrderAndCategory) {
for (Map<String, DivisionRuleTestDTO> divisionRuleTestDTOMap : processDTO.getDivisionRuleTestMap().values()) {
......@@ -144,7 +144,7 @@ public class GroupDivisionRuleTestService {
}
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public MerchantDivisionRuleProcessDTO refreshGroupTestProcess(MerchantGoodsTypeGroupDivisionRuleDTO goodsTypeGroupDivisionRule) {
public MerchantDivisionRuleProcessDTO refreshGroupTestProcess(MerchantGoodsTypeGroupDivisionRuleDTO goodsTypeGroupDivisionRule,boolean changeAddNew) {
RpcAssert.assertNotNull(goodsTypeGroupDivisionRule, DefaultErrorEnum.DATA_NULL,"goodsTypeGroupDivisionRule not be null");
final Integer groupRuleId = goodsTypeGroupDivisionRule.getId();
log.info("divisionRule groupRuleTest refreshGroupTestProcess, 刷新测试进度, groupRuleId:{}", groupRuleId);
......@@ -164,7 +164,7 @@ public class GroupDivisionRuleTestService {
Map<String, Map<Integer, MerchantPaymentChannelAccountDTO>> notInForceAccountMerchantMap = new HashMap<>();
for (String paymentChannelId : paymentChannelIds) {
log.info("divisionRule groupRuleTest refreshGroupTestProcess, 刷新分账测试进度, groupRuleId:{}, paymentChannelId:{}", groupRuleId, paymentChannelId);
DivisionRuleTestDTO divisionRuleTestDTO = divisionRuleTestService.getLastByGoodsTypeGroupDivisionId(groupRuleId, paymentChannelId, false);
DivisionRuleTestDTO divisionRuleTestDTO = divisionRuleTestService.getLastByGoodsTypeGroupDivisionId(groupRuleId, paymentChannelId, false,changeAddNew);
if (CollectionUtils.isNotEmpty(divisionRuleTestDTO.getAccountValidMerchants())) {
notInForceAccountMerchantMap.computeIfAbsent(paymentChannelId, k -> new HashMap<>());
for (MerchantPaymentChannelAccountDTO accountValidMerchant : divisionRuleTestDTO.getAccountValidMerchants()) {
......@@ -195,7 +195,7 @@ public class GroupDivisionRuleTestService {
}
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void markTested(Integer divisionRuleId, Integer goodsTypeGroupDivisionId, String paymentChannelId) {
public void markTested(Integer divisionRuleId, Integer goodsTypeGroupDivisionId, String paymentChannelId,boolean changeAddNew) {
log.info("groupDivisionRuleTest markTested, 测试完成, goodsTypeGroupDivisionId:{}, paymentChannelId:{},更新groupDivisionRuleTest", goodsTypeGroupDivisionId, paymentChannelId);
GroupDivisionRuleTest record = GroupDivisionRuleTest.builder()
.groupDivisionRuleId(goodsTypeGroupDivisionId).paymentChannelId(paymentChannelId)
......@@ -213,7 +213,7 @@ public class GroupDivisionRuleTestService {
List<GroupDivisionRuleTestDTO> notTestedGroupDivisionRuleTestDTOS = groupDivisionRuleTestMapper.listGroupDivisionRuleTest(dto);
if (CollectionUtils.isEmpty(notTestedGroupDivisionRuleTestDTOS)) {
log.info("groupDivisionRuleTest markTested, 测试完成,divisionRule该支付渠道所有测试完成,更新divisionAuto为已测试, divisionRuleId:{}, paymentChannelId:{}", divisionRuleId, paymentChannelId);
merchantDivisionRuleService.updateTestFlag(divisionRuleId, paymentChannelId, CarLifeEnum.Flag.Y.name(), CommonConstants.DEFAULT_UPDATE_BY);
merchantDivisionRuleService.updateTestFlag(divisionRuleId, paymentChannelId, CarLifeEnum.Flag.Y.name(), CommonConstants.DEFAULT_UPDATE_BY,changeAddNew);
}
}
......
......@@ -131,7 +131,7 @@ public class MerchantDivisionRuleService {
}
if (!isSaveSingleGoodsTypeRule && !Objects.equals(record.getSaveDraft(), Boolean.TRUE)
&& !Objects.equals(record.getSource(), RuleSourceTypeEnum.DJ_ON_SHELVE.getValue())) {
divisionRuleAutoService.refreshTestProcess(record);
divisionRuleAutoService.refreshTestProcess(record,true);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
......@@ -177,7 +177,7 @@ public class MerchantDivisionRuleService {
divisionRuleAutoService.updateBatch(record.getDivisionRuleAutos(), record.getId(), record.getUpdatedBy());
if (!Objects.equals(record.getSaveDraft(), Boolean.TRUE)
&& !Objects.equals(record.getSource(), RuleSourceTypeEnum.DJ_ON_SHELVE.getValue())) {
divisionRuleAutoService.refreshTestProcess(record);
divisionRuleAutoService.refreshTestProcess(record,true);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
......@@ -533,7 +533,7 @@ public class MerchantDivisionRuleService {
* @date 2023年11月20日 14:12:28
*/
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void resetTestFlag(List<Integer> merchantIds, String paymentChannelId, String updatedBy){
public void resetTestFlag(List<Integer> merchantIds, String paymentChannelId, String updatedBy,boolean changeAddNew){
log.info("resetTestFlag, merchantIds:{}, updatedBy:{}", merchantIds, updatedBy);
RpcAssert.assertNotEmpty(updatedBy, DefaultErrorEnum.DATA_NULL,"updatedBy not be empty");
try {
......@@ -542,7 +542,7 @@ public class MerchantDivisionRuleService {
List<Integer> divisionRuleIds = thiz.listEnabledMerchantRelatedDivisionRuleIds(merchantIds, sceneTypes, new Date());
if (CollectionUtils.isNotEmpty(divisionRuleIds)) {
for (Integer divisionRuleId : divisionRuleIds) {
thiz.updateTestFlag(divisionRuleId, paymentChannelId, CarLifeEnum.Flag.N.name(), updatedBy);
thiz.updateTestFlag(divisionRuleId, paymentChannelId, CarLifeEnum.Flag.N.name(), updatedBy,changeAddNew);
}
}
}
......@@ -564,7 +564,7 @@ public class MerchantDivisionRuleService {
* @date 2023年12月18日 10:54:18
*/
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void updateTestFlag(Integer divisionRuleId, String paymentChannelId, String testFlag, String updatedBy){
public void updateTestFlag(Integer divisionRuleId, String paymentChannelId, String testFlag, String updatedBy,boolean changeAddNew){
try {
log.info("divisionRule 某支付渠道 updateTestFlag, divisionRuleId:{}, paymentChannelId:{}, testFlag:{}, updatedBy:{}", divisionRuleId, paymentChannelId, testFlag, updatedBy);
RpcAssert.assertNotNull(divisionRuleId, DefaultErrorEnum.DATA_NULL,"divisionRuleId not be null");
......@@ -577,24 +577,26 @@ public class MerchantDivisionRuleService {
if (divisionRule == null) {
throw new RpcServiceException(DefaultErrorEnum.DATA_NULL, "分账规则不存在, id:"+divisionRuleId);
}
DivisionRuleEffectRecord lastEffect = divisionRuleEffectRecordService.getLastest(divisionRule.getMerchantId(), divisionRule.getBaseSceneCode(), RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue());
// 如果会导致当前商户分账方式会发生变化,则需要复制当前商户的财务、分账规则修改分账测试通过标志位,保存为新规则,并且立即生效
if (lastEffect != null
&& Objects.equals(lastEffect.getDivisionRuleId(), divisionRuleId)) {
Map<String, DivisionRuleAutoDTO> divisionRuleAutoDTOMap = divisionRuleAutoService.listDivisionRuleAutoByDivisionRuleId(divisionRuleId)
.stream().collect(Collectors.toMap(DivisionRuleAutoDTO::getPaymentChannelId, o -> o, (v1, v2) -> v1));
DivisionRuleAutoDTO divisionRuleAutoDTO = divisionRuleAutoDTOMap.get(paymentChannelId);
if (Objects.equals(CarLifeEnum.Flag.Y.name(), divisionRuleAutoDTO.getAutoFlag())
&& !Objects.equals(divisionRuleAutoDTO.getTestFlag(), testFlag)) {
divisionRuleAutoDTO.setTestFlag(testFlag);
byte divisionType = StringUtils.equals(testFlag, CarLifeEnum.Flag.Y.name()) ?
CarLifeEnum.DivisionType.ONLINE.getValue() : CarLifeEnum.DivisionType.OFFLINE.getValue();
divisionRuleAutoDTO.setDivisionType(divisionType);
List<DivisionRuleAutoDTO> divisionRuleAutoDTOS = divisionRuleAutoDTOMap.values().stream()
.map(DivisionRuleAutoDTOConvert.INSTANCE::buildWithClearId).collect(Collectors.toList());
log.info("divisionRule 某支付渠道 updateTestFlag, 当期生效中的分账规则该支付渠道测试状态变更,需要复制当前商户的财务、分账规则修改分账测试通过标志位,保存为新规则,并且立即生效,, divisionRuleId:{}, paymentChannelId:{}, testFlag:{}, divisionType:{}", divisionRuleId, paymentChannelId, testFlag, divisionType);
thiz.copyNewTestStatusSettleDistributionRule(divisionRuleAutoDTOS, updatedBy, lastEffect, divisionRule.getRuleAuditId());
return;
if(changeAddNew) {
DivisionRuleEffectRecord lastEffect = divisionRuleEffectRecordService.getLastest(divisionRule.getMerchantId(), divisionRule.getBaseSceneCode(), RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue());
// 如果会导致当前商户分账方式会发生变化,则需要复制当前商户的财务、分账规则修改分账测试通过标志位,保存为新规则,并且立即生效
if (lastEffect != null
&& Objects.equals(lastEffect.getDivisionRuleId(), divisionRuleId)) {
Map<String, DivisionRuleAutoDTO> divisionRuleAutoDTOMap = divisionRuleAutoService.listDivisionRuleAutoByDivisionRuleId(divisionRuleId)
.stream().collect(Collectors.toMap(DivisionRuleAutoDTO::getPaymentChannelId, o -> o, (v1, v2) -> v1));
DivisionRuleAutoDTO divisionRuleAutoDTO = divisionRuleAutoDTOMap.get(paymentChannelId);
if (Objects.equals(CarLifeEnum.Flag.Y.name(), divisionRuleAutoDTO.getAutoFlag())
&& !Objects.equals(divisionRuleAutoDTO.getTestFlag(), testFlag)) {
divisionRuleAutoDTO.setTestFlag(testFlag);
byte divisionType = StringUtils.equals(testFlag, CarLifeEnum.Flag.Y.name()) ?
CarLifeEnum.DivisionType.ONLINE.getValue() : CarLifeEnum.DivisionType.OFFLINE.getValue();
divisionRuleAutoDTO.setDivisionType(divisionType);
List<DivisionRuleAutoDTO> divisionRuleAutoDTOS = divisionRuleAutoDTOMap.values().stream()
.map(DivisionRuleAutoDTOConvert.INSTANCE::buildWithClearId).collect(Collectors.toList());
log.info("divisionRule 某支付渠道 updateTestFlag, 当期生效中的分账规则该支付渠道测试状态变更,需要复制当前商户的财务、分账规则修改分账测试通过标志位,保存为新规则,并且立即生效,, divisionRuleId:{}, paymentChannelId:{}, testFlag:{}, divisionType:{}", divisionRuleId, paymentChannelId, testFlag, divisionType);
thiz.copyNewTestStatusSettleDistributionRule(divisionRuleAutoDTOS, updatedBy, lastEffect, divisionRule.getRuleAuditId());
return;
}
}
}
DivisionRuleEffectRecordDTO dto = DivisionRuleEffectRecordDTO.builder().merchantId(divisionRule.getMerchantId())
......@@ -707,9 +709,9 @@ public class MerchantDivisionRuleService {
}
@Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class)
public void refreshRuleTest(Integer divisionRuleId) {
public void refreshRuleTest(Integer divisionRuleId,boolean changeAddNew) {
MerchantDivisionRuleDTO divisionRuleDTO = getById(divisionRuleId);
divisionRuleAutoService.refreshTestProcess(divisionRuleDTO);
divisionRuleAutoService.refreshTestProcess(divisionRuleDTO,changeAddNew);
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
......
  • @wangxw1
    commented
    Master

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

    1. 破坏现有方法签名,存在编译失败与兼容性风险(稳定性与最佳实践)

    • 问题描述:本次提交直接修改了大量 Service 层公共方法(如 refreshRuleTest、resetTestFlag、getLastByGoodsTypeGroupDivisionId 等)的签名,强行加入了一个 boolean changeAddNew 参数。
    • 影响分析:直接修改公共方法的签名会破坏向后兼容性。如果代码库中存在其他未在此次 PR 中修改的调用方(或者有其他正在开发的分支依赖这些旧签名),将直接导致编译失败。
    • 优化建议:强烈建议使用方法重载(Method Overloading)来代替直接修改签名。保留原方法,并在内部调用新方法,赋予默认值。 代码示例: ```java // 保留原方法,保证兼容性 @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) public void refreshRuleTest(Integer divisionRuleId) { this.refreshRuleTest(divisionRuleId, true); // 假设默认行为是 true }

    // 新增带参数的方法 @Transactional(propagation= Propagation.REQUIRED,rollbackFor=RpcServiceException.class) public void refreshRuleTest(Integer divisionRuleId, boolean changeAddNew) { MerchantDivisionRuleDTO divisionRuleDTO = getById(divisionRuleId); divisionRuleAutoService.refreshTestProcess(divisionRuleDTO, changeAddNew); }

    
    **2. 严重的“游街数据(Tramp Data)”与布尔值盲点(架构设计与可维护性)**
    - **问题描述**:为了控制最底层 `MerchantDivisionRuleService.updateTestFlag` 方法中的一段逻辑,`changeAddNew` 参数被当作“接力棒”,穿透了多达 7-8 层的方法调用(`refreshRuleTest` -> `refreshTestProcess` -> `refreshGroupTestProcess` -> `getLastBy...` -> `updateProcess` -> `setProgress` -> `markTested` -> `updateTestFlag`)。
    - **影响分析**:这是典型的“控制耦合”和“游街数据”反模式。中间层的方法根本不需要关心这个参数,却被迫修改签名并传递它。这不仅导致代码可读性极差(布尔值盲点,调用方看到一堆 `true/false` 不知其意),也严重违反了开闭原则(OCP),未来若新增控制条件,又需修改整条链路。
    - **优化建议**:
      1. **短期**:引入上下文对象(Context Object)代替基本类型传参。例如定义 `DivisionRuleProcessContext` 包含业务所需的所有控制开关,链路传递该对象。
      2. **长期**:重新审视领域设计。底层是否应该直接负责“复制新规则”这种高层业务决策?可以考虑通过事件发布(Event Publisher)或策略模式,将“状态更新”与“规则复制生效”解耦。
    
    **3. `updateTestFlag` 方法中隐藏的逻辑穿透风险(功能正确性)**
    - **问题描述**:在 `MerchantDivisionRuleService.updateTestFlag` 中,原逻辑在满足条件时会执行规则复制并**提前 `return`**。修改后,这部分逻辑被包裹在 `if(changeAddNew)` 中。
    - **影响分析**:当 `changeAddNew == false` 且满足原拦截条件时,代码将跳过 `if` 块,**继续向下执行**后续的 `DivisionRuleEffectRecordDTO dto = ...` 等逻辑。这部分后续逻辑在旧版本中是被 `return` 截断的。这种隐式的“逻辑穿透”极易引发未知的副作用(例如错误地更新了不该更新的生效记录)。
    - **优化建议**:需仔细确认当 `changeAddNew == false` 时,是否应该阻断后续逻辑。如果不需要阻断,请在注释中显式说明;如果需要阻断,应补充 `else` 分支或调整 `return` 的位置。
    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(32/40分)**:
      核心业务逻辑实现基本满足需求,且未触犯 MyBatis 子查询及 Dubbo 接口变更的红线(仅修改了 RemoteImpl 的内部调用,未改动 Remote 接口签名)。但 `updateTestFlag` 中引入了潜在的逻辑穿透风险,扣除 8 分。
    - **安全性与潜在风险(30/30分)**:
      本次修改主要集中在内部业务逻辑的流转控制,未引入 SQL 注入、越权等常见的安全漏洞,满分。
    - **最佳实践与可维护性(10/20分)**:
      使用极长的调用链路传递 Boolean 标志位(控制耦合),且直接破坏了大量核心 Service 的方法签名,未采用重载等平滑过渡手段,导致代码可维护性大幅下降。扣除 10 分。
    - **性能与资源利用(5/5分)**:
      新增的布尔参数传递对内存和 CPU 的消耗微乎其微,未发现明显的性能瓶颈或锁粒度扩大的问题,满分。
    - **提交信息质量(5/5分)**:
      Commit 包含了清晰的 `refactor` 标签,准确描述了修改的内容(统一添加分账测试开关参数)及目的,具备良好的可追溯性,满分。
    
    总分:82分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!