Commit 0fc3597f by zhoulm

refactor(对账服务): 优化重复校验逻辑,提取公共方法

将商品类型组关系的重复校验逻辑提取到公共方法validAllRepeat中
移除GoodsListingReconciliationRuleService和GoodsListingSettleRuleService中的重复代码
1 parent 7180c2d5
......@@ -3,6 +3,7 @@ package cn.com.glsx.dj.goods.listing.service;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
......@@ -13,6 +14,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.com.glsx.dj.goods.listing.dto.GoodsListingGoodsTypeGroupDTO;
import cn.com.glsx.dj.goods.listing.mapper.GoodsListingGoodsTypeGroupRelationMapper;
import cn.com.glsx.dj.goods.listing.model.CompareResult;
import cn.com.glsx.dj.goods.listing.model.GoodsListingGoodsTypeGroup;
......@@ -213,4 +215,31 @@ public class GoodsListingGoodsTypeGroupRelationService {
}
}
}
public void validAllRepeat(List<GoodsListingGoodsTypeGroupDTO> allGroupList,List<GoodsListingGoodsTypeGroupRelation> allRelationList) {
RpcAssert.assertNotEmpty(allGroupList, DefaultErrorEnum.SERVER_ERROR,"分账品类数据不能为空");
RpcAssert.assertNotEmpty(allRelationList, DefaultErrorEnum.SERVER_ERROR,"分账品类数据不能为空");
Map<Integer,List<GoodsListingGoodsTypeGroupRelation>> relationMap = allRelationList.stream()
.collect(Collectors.groupingBy(GoodsListingGoodsTypeGroupRelation::getGoodsTypeGroupId));
Set<Integer> goodsTypeSet = new HashSet<>();
Set<String> merchantGoodsCodeSet = new HashSet<>();
Set<String> packageCodeSet = new HashSet<>();
for(GoodsListingGoodsTypeGroup group:allGroupList) {
List<GoodsListingGoodsTypeGroupRelation> relationList = relationMap.get(group.getId());
for(GoodsListingGoodsTypeGroupRelation item:relationList) {
if(Objects.equals(group.getCategoryType(), GoodsGroupCategoryTypeEnum.GOODS_TYPE.getValue())) {
RpcAssert.assertIsTrue(!goodsTypeSet.contains(item.getGoodsType()), DefaultErrorEnum.PARAMETER_NULL,"按商品品类存在重复数据");
goodsTypeSet.add(item.getGoodsType());
}else if(Objects.equals(group.getCategoryType(), GoodsGroupCategoryTypeEnum.UPGRADE_GOODS.getValue())) {
RpcAssert.assertIsTrue(!merchantGoodsCodeSet.contains(item.getMerchantGoodsCode()), DefaultErrorEnum.PARAMETER_NULL,"按具体商品存在重复数据");
merchantGoodsCodeSet.add(item.getMerchantGoodsCode());
}else if(Objects.equals(group.getCategoryType(), GoodsGroupCategoryTypeEnum.GOODS_PACKAGE.getValue())) {
RpcAssert.assertIsTrue(!packageCodeSet.contains(item.getPackageCode()), DefaultErrorEnum.PARAMETER_NULL,"按具体套餐存在重复数据");
packageCodeSet.add(item.getPackageCode());
}else {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR,"分账品类错误");
}
}
}
}
}
\ No newline at end of file
......@@ -215,12 +215,9 @@ public class GoodsListingReconciliationRuleService {
RpcAssert.assertNotEmpty(allExpenseCategoryRuleList, DefaultErrorEnum.SERVER_ERROR,"对账配置不存在");
Map<Integer,List<GoodsListingExpenseCategoryRule>> expenseCategoryRuleMap = allExpenseCategoryRuleList.stream()
.collect(Collectors.groupingBy(GoodsListingExpenseCategoryRule::getGoodsTypeGroupId));
Map<Integer,List<GoodsListingGoodsTypeGroupRelation>> relationMap = allRelationList.stream()
.collect(Collectors.groupingBy(GoodsListingGoodsTypeGroupRelation::getGoodsTypeGroupId));
goodsListingGoodsTypeGroupRelationService.validAllRepeat(goodsTypeGroupList, allRelationList);
for(GoodsListingGoodsTypeGroup group:goodsTypeGroupList) {
List<GoodsListingGoodsTypeGroupRelation> relationList = relationMap.get(group.getId());
List<GoodsListingExpenseCategoryRule> expenseCategoryRuleList = expenseCategoryRuleMap.get(group.getId());
goodsListingGoodsTypeGroupRelationService.validRepeat(group, relationList);
RpcAssert.assertNotEmpty(expenseCategoryRuleList, DefaultErrorEnum.SERVER_ERROR,"对账配置不存在");
for(GoodsListingExpenseCategoryRule rule:expenseCategoryRuleList) {
RpcAssert.assertNotNull(rule.getExpenseCategoryValue(), DefaultErrorEnum.SERVER_ERROR,"对账配置[" + rule.getExpenseCategoryName() + "]数据未填写");
......
......@@ -585,14 +585,10 @@ public class GoodsListingSettleRuleService {
.collect(Collectors.groupingBy(GoodsListingExpenseCategoryRule::getGoodsTypeGroupId));
Map<Integer,List<GoodsListingDistributionRule>> distributionRuleMap = allDistributionRuleList.stream()
.collect(Collectors.groupingBy(GoodsListingDistributionRule::getGoodsTypeGroupId));
Map<Integer,List<GoodsListingGoodsTypeGroupRelation>> relationMap = allRelationList.stream()
.collect(Collectors.groupingBy(GoodsListingGoodsTypeGroupRelation::getGoodsTypeGroupId));
goodsListingGoodsTypeGroupRelationService.validAllRepeat(goodsTypeGroupList, allRelationList);
for(GoodsListingGoodsTypeGroup group:goodsTypeGroupList) {
List<GoodsListingGoodsTypeGroupRelation> relationList = relationMap.get(group.getId());
List<GoodsListingExpenseCategoryRule> expenseCategoryRuleList = expenseCategoryRuleMap.get(group.getId());
List<GoodsListingDistributionRule> distributionRuleList = distributionRuleMap.get(group.getId());
goodsListingGoodsTypeGroupRelationService.validRepeat(group, relationList);
RpcAssert.assertNotEmpty(expenseCategoryRuleList, DefaultErrorEnum.SERVER_ERROR,"分账类目配置不存在");
RpcAssert.assertNotEmpty(distributionRuleList, DefaultErrorEnum.SERVER_ERROR,"分账配置不存在");
for(GoodsListingExpenseCategoryRule rule:expenseCategoryRuleList) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!