Commit 5d365d6c by 崔彦峰

refactor(goods-listing): 优化商品上架审批发布流程支持单店修改型原地更新

- 移除废弃的 publishApprovedSettleRules 方法
- 新增 prepareModifyRulePublishMode 方法用于判断修改型发布模式
- 实现财务和对账规则的原地更新逻辑,复用原有规则ID进行更新
- 添加 deleteOldDivisionRuleAutos 方法清理旧自动分账配置
- 扩展 settle 和 reconciliation 规则服务支持按规则ID批量删除子表数据
- 新增商家商品类型组对账规则服务的按规则ID删除功能
- 重构商品类型组结算规则服务支持按结算规则ID清理相关数据
- 为单店修改型发布场景添加商户映射标识字段
1 parent e551b5c7
...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -189,6 +190,88 @@ public class GoodsListingReconciliationRuleService { ...@@ -189,6 +190,88 @@ public class GoodsListingReconciliationRuleService {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,e); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,e);
} }
} }
/**
* 单店修改型原地更新时复用对账主规则ID,旧对账品类、费用类目和商品关系先逻辑删除再重建。
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public void deleteByReconciliationRuleId(Integer reconciliationRuleId, String updatedBy) {
RpcAssert.assertNotNull(reconciliationRuleId, DefaultErrorEnum.DATA_NULL, "reconciliationRuleId is null");
RpcAssert.assertNotEmpty(updatedBy, DefaultErrorEnum.DATA_NULL, "updatedBy is null");
try {
Date now = new Date();
List<MerchantGoodsTypeGroupReconciliationRule> reconciliationGroupRules = listOldReconciliationGroupRules(reconciliationRuleId);
List<Integer> reconciliationGroupRuleIds = collectIds(reconciliationGroupRules, MerchantGoodsTypeGroupReconciliationRule::getId);
deleteExpenseCategoryRules(reconciliationGroupRuleIds, updatedBy, now);
deleteGoodsTypeGroupRelations(reconciliationGroupRuleIds, updatedBy, now);
deleteReconciliationGroupRules(reconciliationGroupRuleIds, updatedBy, now);
} catch (RpcServiceException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e);
}
}
private List<MerchantGoodsTypeGroupReconciliationRule> listOldReconciliationGroupRules(Integer reconciliationRuleId) {
List<MerchantGoodsTypeGroupReconciliationRule> list = smartcarMerchantGoodsTypeGroupReconciliationRuleMapper
.select(MerchantGoodsTypeGroupReconciliationRule.builder()
.reconciliationRuleId(reconciliationRuleId)
.deletedFlag(DeletedFlagEnum.N.name())
.build());
return CollectionUtils.isEmpty(list) ? Collections.emptyList() : list;
}
private <T> List<Integer> collectIds(List<T> list, java.util.function.Function<T, Integer> mapper) {
if(CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
}
private void deleteExpenseCategoryRules(List<Integer> goodsTypeGroupRuleIds, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(goodsTypeGroupRuleIds)) {
return;
}
MerchantExpenseCategoryRule record = new MerchantExpenseCategoryRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantExpenseCategoryRule.class);
example.createCriteria().andIn("goodsTypeGroupRuleId", goodsTypeGroupRuleIds)
.andEqualTo("ruleType", RuleTypeEnum.RECONCILIATION_RULE.getValue())
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantExpenseCategoryRuleMapper.updateByExampleSelective(record, example);
}
private void deleteGoodsTypeGroupRelations(List<Integer> goodsTypeGroupRuleIds, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(goodsTypeGroupRuleIds)) {
return;
}
GoodsTypeGroupRelation record = new GoodsTypeGroupRelation();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(GoodsTypeGroupRelation.class);
example.createCriteria().andIn("goodsTypeGroupRuleId", goodsTypeGroupRuleIds)
.andEqualTo("ruleType", RuleTypeEnum.RECONCILIATION_RULE.getValue())
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarGoodsTypeGroupRelationMapper.updateByExampleSelective(record, example);
}
private void deleteReconciliationGroupRules(List<Integer> ids, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(ids)) {
return;
}
MerchantGoodsTypeGroupReconciliationRule record = new MerchantGoodsTypeGroupReconciliationRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantGoodsTypeGroupReconciliationRule.class);
example.createCriteria().andIn("id", ids)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantGoodsTypeGroupReconciliationRuleMapper.updateByExampleSelective(record, example);
}
public void validConfirmStep(GoodsListingApproval goodsListingApproval) { public void validConfirmStep(GoodsListingApproval goodsListingApproval) {
try { try {
...@@ -215,4 +298,4 @@ public class GoodsListingReconciliationRuleService { ...@@ -215,4 +298,4 @@ public class GoodsListingReconciliationRuleService {
throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG, e.getMessage()); throw new RpcServiceException(RpcErrorEnum.DATA_INVALID_WITH_SPECIFIC_MSG, e.getMessage());
} }
} }
}
\ No newline at end of file \ No newline at end of file
}
...@@ -150,6 +150,129 @@ public class GoodsListingSettleRuleService { ...@@ -150,6 +150,129 @@ public class GoodsListingSettleRuleService {
} }
/** /**
* 单店修改型原地更新时复用财务/分账主规则ID,旧子表必须先逻辑删除,再由审批发布链路按新导入数据重建。
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public void deleteBySettleRuleId(Integer settleRuleId, Integer divisionRuleId, String updatedBy) {
RpcAssert.assertNotNull(settleRuleId, DefaultErrorEnum.DATA_NULL, "settleRuleId is null");
RpcAssert.assertNotNull(divisionRuleId, DefaultErrorEnum.DATA_NULL, "divisionRuleId is null");
RpcAssert.assertNotEmpty(updatedBy, DefaultErrorEnum.DATA_NULL, "updatedBy is null");
try {
Date now = new Date();
List<MerchantGoodsTypeGroupSettleRule> settleGroupRules = listOldSettleGroupRules(settleRuleId);
List<MerchantGoodsTypeGroupDivisionRule> divisionGroupRules = listOldDivisionGroupRules(divisionRuleId);
List<Integer> settleGroupRuleIds = collectIds(settleGroupRules, MerchantGoodsTypeGroupSettleRule::getId);
List<Integer> divisionGroupRuleIds = collectIds(divisionGroupRules, MerchantGoodsTypeGroupDivisionRule::getId);
Set<Integer> goodsTypeGroupIds = collectOldGoodsTypeGroupIds(settleGroupRules, divisionGroupRules);
deleteExpenseCategoryRules(settleGroupRuleIds, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), updatedBy, now);
deleteDistributionRules(divisionGroupRuleIds, updatedBy, now);
deleteGoodsTypeGroupRelations(goodsTypeGroupIds, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), updatedBy, now);
deleteSettleGroupRules(settleGroupRuleIds, updatedBy, now);
deleteDivisionGroupRules(divisionGroupRuleIds, updatedBy, now);
deleteGoodsTypeGroups(goodsTypeGroupIds, updatedBy, now);
} catch (RpcServiceException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.DATABASE_ERROR, e);
}
}
private <T> List<Integer> collectIds(List<T> list, java.util.function.Function<T, Integer> mapper) {
if(CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
}
private void deleteExpenseCategoryRules(List<Integer> goodsTypeGroupRuleIds, Byte ruleType, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(goodsTypeGroupRuleIds)) {
return;
}
MerchantExpenseCategoryRule record = new MerchantExpenseCategoryRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantExpenseCategoryRule.class);
example.createCriteria().andIn("goodsTypeGroupRuleId", goodsTypeGroupRuleIds)
.andEqualTo("ruleType", ruleType)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantExpenseCategoryRuleMapper.updateByExampleSelective(record, example);
}
private void deleteDistributionRules(List<Integer> goodsTypeGroupRuleIds, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(goodsTypeGroupRuleIds)) {
return;
}
MerchantDistributionRule record = new MerchantDistributionRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantDistributionRule.class);
example.createCriteria().andIn("goodsTypeGroupRuleId", goodsTypeGroupRuleIds)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantDistributionRuleMapper.updateByExampleSelective(record, example);
}
private void deleteGoodsTypeGroupRelations(Collection<Integer> goodsTypeGroupRuleIds, Byte ruleType, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(goodsTypeGroupRuleIds)) {
return;
}
GoodsTypeGroupRelation record = new GoodsTypeGroupRelation();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(GoodsTypeGroupRelation.class);
example.createCriteria().andIn("goodsTypeGroupRuleId", goodsTypeGroupRuleIds)
.andEqualTo("ruleType", ruleType)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarGoodsTypeGroupRelationMapper.updateByExampleSelective(record, example);
}
private void deleteSettleGroupRules(List<Integer> ids, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(ids)) {
return;
}
MerchantGoodsTypeGroupSettleRule record = new MerchantGoodsTypeGroupSettleRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantGoodsTypeGroupSettleRule.class);
example.createCriteria().andIn("id", ids)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantGoodsTypeGroupSettleRuleMapper.updateByExampleSelective(record, example);
}
private void deleteDivisionGroupRules(List<Integer> ids, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(ids)) {
return;
}
MerchantGoodsTypeGroupDivisionRule record = new MerchantGoodsTypeGroupDivisionRule();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(MerchantGoodsTypeGroupDivisionRule.class);
example.createCriteria().andIn("id", ids)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarMerchantGoodsTypeGroupDivisionRuleMapper.updateByExampleSelective(record, example);
}
private void deleteGoodsTypeGroups(Collection<Integer> ids, String updatedBy, Date now) {
if(CollectionUtils.isEmpty(ids)) {
return;
}
GoodsTypeGroup record = new GoodsTypeGroup();
record.setDeletedFlag(DeletedFlagEnum.D.name());
record.setUpdatedBy(updatedBy);
record.setUpdatedDate(now);
Example example = new Example(GoodsTypeGroup.class);
example.createCriteria().andIn("id", ids)
.andEqualTo("deletedFlag", DeletedFlagEnum.N.name());
smartcarGoodsTypeGroupMapper.updateByExampleSelective(record, example);
}
/**
* 查询旧财务规则下的品类规则主记录,供后续复制到新财务规则。 * 查询旧财务规则下的品类规则主记录,供后续复制到新财务规则。
*/ */
private List<MerchantGoodsTypeGroupSettleRule> listOldSettleGroupRules(Integer oldSettleRuleId) { private List<MerchantGoodsTypeGroupSettleRule> listOldSettleGroupRules(Integer oldSettleRuleId) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!