Commit 686aef7d by 崔彦峰

refactor(rpc-dj-goods-listing): 优化商品上架审核服务性能

- 将 expenseCategoryDTOS 重命名为 allExpenseCategoryDTOS
- 添加批量查询产品数据避免循环查询数据库
- 新增多个分组方法用于按不同维度缓存数据
- 重构商品详情、费用规则、分配规则等数据的查询方式
- 优化套餐商品发布流程中的数据处理逻辑
- 统一商户商品引用和库存类型引用的插入方式
- 使用缓存映射替代重复查询提升性能
- 修改场景类型解析逻辑并增强错误处理
- 更新审核上下文类结构以支持批量数据处理
1 parent cca1dc82
...@@ -404,9 +404,19 @@ public class GoodsListingApprovalService { ...@@ -404,9 +404,19 @@ public class GoodsListingApprovalService {
context.merchantRefs = merchantRefs; context.merchantRefs = merchantRefs;
context.baseSceneCode = approval == null ? null : approval.getBaseSceneCode(); context.baseSceneCode = approval == null ? null : approval.getBaseSceneCode();
context.sceneType = resolveSceneType(context.baseSceneCode); context.sceneType = resolveSceneType(context.baseSceneCode);
context.expenseCategoryDTOS = expenseCategoryDTOS; context.allExpenseCategoryDTOS = expenseCategoryDTOS;
// 审核发布阶段先按 businessCode 批量读取中间表,避免后续按品类组循环查询。
context.products = goodsListingProductBaseService.listByBusinessCode(businessCode);
context.details = goodsListingProductDetailService.listByBusinessCode(businessCode); context.details = goodsListingProductDetailService.listByBusinessCode(businessCode);
context.detailsByProductBaseIdMap = groupProductDetailsByProductBaseId(context.details);
context.settleGroups = goodsListingGoodsTypeGroupService.listBase(businessCode, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue());
context.reconciliationGroups = goodsListingGoodsTypeGroupService.listBase(businessCode, RuleTypeEnum.RECONCILIATION_RULE.getValue());
context.relationsByGroupIdMap = groupRelationsByGroupId(goodsListingGoodsTypeGroupRelationService.listByBusinessCode(businessCode));
context.expenseRulesByGroupIdMap = groupExpenseRulesByGroupId(goodsListingExpenseCategoryRuleService.listByBusinessCode(businessCode));
context.distributionRulesByGroupIdMap = groupDistributionRulesByGroupId(goodsListingDistributionRuleService.listByBusinessCode(businessCode));
context.divisionRuleAutos = goodsListingDivisionRuleAutoService.listByBusinessCode(businessCode);
context.upgradeGoodsDTOS = listUpgradeGoods(context.details); context.upgradeGoodsDTOS = listUpgradeGoods(context.details);
context.upgradeGoodsMap = buildUpgradeGoodsMap(context.upgradeGoodsDTOS);
context.allServiceItemIdList = goodsListingProductBaseService.getAllServiceItemIdList (); context.allServiceItemIdList = goodsListingProductBaseService.getAllServiceItemIdList ();
return context; return context;
} }
...@@ -434,17 +444,69 @@ public class GoodsListingApprovalService { ...@@ -434,17 +444,69 @@ public class GoodsListingApprovalService {
return null; return null;
} }
private Map<Integer, List<GoodsListingProductDetailDTO>> groupProductDetailsByProductBaseId(List<GoodsListingProductDetailDTO> details) {
if (CollectionUtils.isEmpty(details)) {
return Collections.emptyMap();
}
return details.stream()
.filter(detail -> detail != null && detail.getProductBaseId() != null)
.collect(Collectors.groupingBy(GoodsListingProductDetailDTO::getProductBaseId, LinkedHashMap::new, Collectors.toList()));
}
private Map<Integer, UpgradeGoodsDTO> buildUpgradeGoodsMap(List<UpgradeGoodsDTO> upgradeGoodsDTOS) {
if (CollectionUtils.isEmpty(upgradeGoodsDTOS)) {
return Collections.emptyMap();
}
Map<Integer, UpgradeGoodsDTO> upgradeGoodsMap = new HashMap<>();
for (UpgradeGoodsDTO upgradeGoodsDTO : upgradeGoodsDTOS) {
if (upgradeGoodsDTO != null && upgradeGoodsDTO.getId() != null) {
upgradeGoodsMap.putIfAbsent(upgradeGoodsDTO.getId(), upgradeGoodsDTO);
}
}
return upgradeGoodsMap;
}
private Map<Integer, List<GoodsListingGoodsTypeGroupRelation>> groupRelationsByGroupId(List<GoodsListingGoodsTypeGroupRelation> relations) {
if (CollectionUtils.isEmpty(relations)) {
return Collections.emptyMap();
}
return relations.stream()
.filter(relation -> relation != null && relation.getGoodsTypeGroupId() != null)
.collect(Collectors.groupingBy(GoodsListingGoodsTypeGroupRelation::getGoodsTypeGroupId, LinkedHashMap::new, Collectors.toList()));
}
private Map<Integer, List<GoodsListingExpenseCategoryRule>> groupExpenseRulesByGroupId(List<GoodsListingExpenseCategoryRule> expenses) {
if (CollectionUtils.isEmpty(expenses)) {
return Collections.emptyMap();
}
return expenses.stream()
.filter(expense -> expense != null && expense.getGoodsTypeGroupId() != null)
.collect(Collectors.groupingBy(GoodsListingExpenseCategoryRule::getGoodsTypeGroupId, LinkedHashMap::new, Collectors.toList()));
}
private Map<Integer, List<GoodsListingDistributionRule>> groupDistributionRulesByGroupId(List<GoodsListingDistributionRule> distributions) {
if (CollectionUtils.isEmpty(distributions)) {
return Collections.emptyMap();
}
return distributions.stream()
.filter(distribution -> distribution != null && distribution.getGoodsTypeGroupId() != null)
.collect(Collectors.groupingBy(GoodsListingDistributionRule::getGoodsTypeGroupId, LinkedHashMap::new, Collectors.toList()));
}
private <T> List<T> getCachedList(Map<Integer, List<T>> cacheMap, Integer key) {
if (cacheMap == null || key == null) {
return Collections.emptyList();
}
return cacheMap.getOrDefault(key, Collections.emptyList());
}
private void publishApprovedProducts(ApprovalPublishContext context) { private void publishApprovedProducts(ApprovalPublishContext context) {
List<GoodsListingProductBaseDTO> products = goodsListingProductBaseService.listByBusinessCode(context.businessCode); List<GoodsListingProductBaseDTO> products = context.products;
if (CollectionUtils.isEmpty(products)) { if (CollectionUtils.isEmpty(products)) {
return; return;
} }
List<GoodsListingProductDetailDTO> details = context.details;
Map<Integer, List<GoodsListingProductDetailDTO>> detailMap = CollectionUtils.isEmpty(details)
? new HashMap<>()
: details.stream().collect(Collectors.groupingBy(GoodsListingProductDetailDTO::getProductBaseId));
for (GoodsListingProductBaseDTO product : products) { for (GoodsListingProductBaseDTO product : products) {
List<GoodsListingProductDetailDTO> productDetails = detailMap.get(product.getId()); List<GoodsListingProductDetailDTO> productDetails = getCachedList(context.detailsByProductBaseIdMap, product.getId());
if (Objects.equals(product.getProductType(), ProductTypeEnum.PACKAGE.getValue())) { if (Objects.equals(product.getProductType(), ProductTypeEnum.PACKAGE.getValue())) {
publishPackageProduct(context, product, productDetails); publishPackageProduct(context, product, productDetails);
} else { } else {
...@@ -484,21 +546,23 @@ public class GoodsListingApprovalService { ...@@ -484,21 +546,23 @@ public class GoodsListingApprovalService {
if (CollectionUtils.isEmpty(details) || CollectionUtils.isEmpty(context.merchantRefs)) { if (CollectionUtils.isEmpty(details) || CollectionUtils.isEmpty(context.merchantRefs)) {
return; return;
} }
List<MerchantGoodsRef> refs = new ArrayList<>();
List<MerchantGoodsInventoryTypeRef> inventoryTypeRefs = new ArrayList<>();
for (GoodsListingProductDetailDTO detail : details) { for (GoodsListingProductDetailDTO detail : details) {
MerchantGoodsInfo goodsInfo = buildMerchantGoodsInfo(context, product, detail, null); MerchantGoodsInfo goodsInfo = buildMerchantGoodsInfo(context, detail, null);
smartcarMerchantGoodsInfoMapper.insertUseGeneratedKeys(goodsInfo); smartcarMerchantGoodsInfoMapper.insertUseGeneratedKeys(goodsInfo);
insertGoodsRefsByMerchantGoodsId(context, goodsInfo.getId()); refs.addAll(buildGoodsRefsByMerchantGoodsId(context, goodsInfo.getId()));
List<MerchantGoodsInventoryTypeRef> inventoryTypeRefs = new ArrayList<>();
for (GoodsListingMerchantRef merchantRef : context.merchantRefs) { for (GoodsListingMerchantRef merchantRef : context.merchantRefs) {
putGoodsCodeMapping(context, merchantRef, detail, goodsInfo.getMerchantGoodsCode()); putGoodsCodeMapping(context, merchantRef, detail, goodsInfo.getMerchantGoodsCode());
inventoryTypeRefs.add(buildMerchantGoodsInventoryTypeRef(product, detail, goodsInfo.getId(), context, merchantRef.getMerchantId())); inventoryTypeRefs.add(buildMerchantGoodsInventoryTypeRef(product, detail, goodsInfo.getId(), context, merchantRef.getMerchantId()));
} }
insertInventoryTypeRefs(inventoryTypeRefs);
} }
insertMerchantGoodsRefs(refs);
insertInventoryTypeRefs(inventoryTypeRefs);
} }
private void publishPackageProduct(ApprovalPublishContext context, GoodsListingProductBaseDTO product, private void publishPackageProduct(ApprovalPublishContext context,
GoodsListingProductBaseDTO product,
List<GoodsListingProductDetailDTO> details) { List<GoodsListingProductDetailDTO> details) {
if (CollectionUtils.isEmpty(details) || CollectionUtils.isEmpty(context.merchantRefs)) { if (CollectionUtils.isEmpty(details) || CollectionUtils.isEmpty(context.merchantRefs)) {
return; return;
...@@ -507,24 +571,23 @@ public class GoodsListingApprovalService { ...@@ -507,24 +571,23 @@ public class GoodsListingApprovalService {
MerchantPackageGoodsInfo packageInfo = buildMerchantPackageGoodsInfo(context, product, realPackageCode); MerchantPackageGoodsInfo packageInfo = buildMerchantPackageGoodsInfo(context, product, realPackageCode);
smartcarMerchantPackageGoodsInfoMapper.insertUseGeneratedKeys(packageInfo); smartcarMerchantPackageGoodsInfoMapper.insertUseGeneratedKeys(packageInfo);
putPackageCodeMapping(context, product, realPackageCode); putPackageCodeMapping(context, product, realPackageCode);
insertPackageRefsByPackageCode(context, realPackageCode); List<MerchantGoodsInventoryTypeRef> inventoryTypeRefs = new ArrayList<>();
List<MerchantGoodsRef> refs = buildPackageRefsByPackageCode(context, realPackageCode);
for (GoodsListingProductDetailDTO detail : details) { for (GoodsListingProductDetailDTO detail : details) {
MerchantGoodsInfo goodsInfo = buildMerchantGoodsInfo(context, product, detail, realPackageCode); MerchantGoodsInfo goodsInfo = buildMerchantGoodsInfo(context, detail, realPackageCode);
smartcarMerchantGoodsInfoMapper.insertUseGeneratedKeys(goodsInfo); smartcarMerchantGoodsInfoMapper.insertUseGeneratedKeys(goodsInfo);
insertGoodsRefsByMerchantGoodsId(context, goodsInfo.getId()); refs.addAll(buildGoodsRefsByMerchantGoodsId(context, goodsInfo.getId()));
List<MerchantGoodsInventoryTypeRef> inventoryTypeRefs = new ArrayList<>();
for (GoodsListingMerchantRef merchantRef : context.merchantRefs) { for (GoodsListingMerchantRef merchantRef : context.merchantRefs) {
putGoodsCodeMapping(context, merchantRef, detail, goodsInfo.getMerchantGoodsCode()); putGoodsCodeMapping(context, merchantRef, detail, goodsInfo.getMerchantGoodsCode());
inventoryTypeRefs.add(buildMerchantGoodsInventoryTypeRef(product, detail, goodsInfo.getId(), context, merchantRef.getMerchantId())); inventoryTypeRefs.add(buildMerchantGoodsInventoryTypeRef(product, detail, goodsInfo.getId(), context, merchantRef.getMerchantId()));
} }
insertInventoryTypeRefs(inventoryTypeRefs);
} }
insertMerchantGoodsRefs(refs);
insertInventoryTypeRefs(inventoryTypeRefs);
} }
private MerchantGoodsInfo buildMerchantGoodsInfo(ApprovalPublishContext context, private MerchantGoodsInfo buildMerchantGoodsInfo(ApprovalPublishContext context,
GoodsListingProductBaseDTO product,
GoodsListingProductDetailDTO detail, GoodsListingProductDetailDTO detail,
String packageCode) { String packageCode) {
MerchantGoodsInfo goodsInfo = new MerchantGoodsInfo(); MerchantGoodsInfo goodsInfo = new MerchantGoodsInfo();
...@@ -563,25 +626,34 @@ public class GoodsListingApprovalService { ...@@ -563,25 +626,34 @@ public class GoodsListingApprovalService {
} }
private void insertGoodsRefsByMerchantGoodsId(ApprovalPublishContext context, Integer merchantGoodsId) { private void insertGoodsRefsByMerchantGoodsId(ApprovalPublishContext context, Integer merchantGoodsId) {
// 单品商品主表和门店关系是 1:N,通过 merchant_goods_id 挂载多个门店,避免按门店重复生成商品主表。 insertMerchantGoodsRefs(buildGoodsRefsByMerchantGoodsId(context, merchantGoodsId));
}
private List<MerchantGoodsRef> buildGoodsRefsByMerchantGoodsId(ApprovalPublishContext context, Integer merchantGoodsId) {
List<MerchantGoodsRef> refs = new ArrayList<>(); List<MerchantGoodsRef> refs = new ArrayList<>();
for (GoodsListingMerchantRef merchantRef : context.merchantRefs) { for (GoodsListingMerchantRef merchantRef : context.merchantRefs) {
refs.add(buildMerchantGoodsRef(context, merchantRef, merchantGoodsId, null)); refs.add(buildMerchantGoodsRef(context, merchantRef, merchantGoodsId, null));
} }
if (CollectionUtils.isNotEmpty(refs)) { return refs;
smartcarMerchantGoodsRefMapper.insertList(refs);
}
} }
private void insertPackageRefsByPackageCode(ApprovalPublishContext context, String packageCode) { private void insertPackageRefsByPackageCode(ApprovalPublishContext context, String packageCode) {
// 套餐门店关系按 package_code 维护,套餐内子商品不再额外写 merchant_goods_id 维度的门店关系。 insertMerchantGoodsRefs(buildPackageRefsByPackageCode(context, packageCode));
}
private List<MerchantGoodsRef> buildPackageRefsByPackageCode(ApprovalPublishContext context, String packageCode) {
List<MerchantGoodsRef> refs = new ArrayList<>(); List<MerchantGoodsRef> refs = new ArrayList<>();
for (GoodsListingMerchantRef merchantRef : context.merchantRefs) { for (GoodsListingMerchantRef merchantRef : context.merchantRefs) {
refs.add(buildMerchantGoodsRef(context, merchantRef, null, packageCode)); refs.add(buildMerchantGoodsRef(context, merchantRef, null, packageCode));
} }
if (CollectionUtils.isNotEmpty(refs)) { return refs;
smartcarMerchantGoodsRefMapper.insertList(refs); }
private void insertMerchantGoodsRefs(List<MerchantGoodsRef> refs) {
if (CollectionUtils.isEmpty(refs)) {
return;
} }
smartcarMerchantGoodsRefMapper.insertList(refs);
} }
private MerchantGoodsRef buildMerchantGoodsRef(ApprovalPublishContext context, GoodsListingMerchantRef merchantRef, private MerchantGoodsRef buildMerchantGoodsRef(ApprovalPublishContext context, GoodsListingMerchantRef merchantRef,
...@@ -602,17 +674,16 @@ public class GoodsListingApprovalService { ...@@ -602,17 +674,16 @@ public class GoodsListingApprovalService {
if (CollectionUtils.isEmpty(allServiceItemIdList)) { if (CollectionUtils.isEmpty(allServiceItemIdList)) {
throw new RuntimeException("未找到升级商品服务项"); throw new RuntimeException("未找到升级商品服务项");
} }
if (CollectionUtils.isEmpty(context.upgradeGoodsDTOS)) { if (context.upgradeGoodsMap == null || context.upgradeGoodsMap.isEmpty()) {
throw new RuntimeException("未找到升级商品"); throw new RuntimeException("未找到升级商品");
} }
List<UpgradeGoodsDTO> upgradeGoodsDTOS = context.upgradeGoodsDTOS.stream().filter(upgradeGoods -> upgradeGoods.getId().equals(detail.getUpgradeGoodsId())).collect(Collectors.toList()); UpgradeGoodsDTO upgradeGoodsDTO = context.upgradeGoodsMap.get(detail.getUpgradeGoodsId());
log.info("upgradeGoodsDTOS:{}",upgradeGoodsDTOS); log.info("upgradeGoodsDTO:{}", upgradeGoodsDTO);
if (CollectionUtils.isEmpty(upgradeGoodsDTOS)) { if (upgradeGoodsDTO == null) {
log.info("context.upgradeGoodsDTOS:{},detail.getUpgradeGoodsId:{}",JSON.toJSONString(context.upgradeGoodsDTOS),detail.getUpgradeGoodsId()); log.info("context.upgradeGoodsDTOS:{},detail.getUpgradeGoodsId:{}", JSON.toJSONString(context.upgradeGoodsDTOS), detail.getUpgradeGoodsId());
throw new RuntimeException("未找到该升级商品"); throw new RuntimeException("未找到该升级商品");
} }
UpgradeGoodsDTO upgradeGoodsDTO = upgradeGoodsDTOS.get(0);
// 这里补齐旧链路审核通过后的最终默认值。 // 这里补齐旧链路审核通过后的最终默认值。
if (StringUtils.isBlank(packageCode)) { if (StringUtils.isBlank(packageCode)) {
goodsInfo.setBaseProductFlag(detail.getGiftCost() == null ? StatusEnum.NO.getValue() : StatusEnum.YES.getValue()); goodsInfo.setBaseProductFlag(detail.getGiftCost() == null ? StatusEnum.NO.getValue() : StatusEnum.YES.getValue());
...@@ -638,8 +709,7 @@ public class GoodsListingApprovalService { ...@@ -638,8 +709,7 @@ public class GoodsListingApprovalService {
} }
private void publishApprovedSettleRules(ApprovalPublishContext context) { private void publishApprovedSettleRules(ApprovalPublishContext context) {
List<GoodsListingGoodsTypeGroupDTO> groups = goodsListingGoodsTypeGroupService.listBase( List<GoodsListingGoodsTypeGroupDTO> groups = context.settleGroups;
context.businessCode, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue());
if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(context.merchantRefs)) { if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(context.merchantRefs)) {
return; return;
} }
...@@ -663,12 +733,12 @@ public class GoodsListingApprovalService { ...@@ -663,12 +733,12 @@ public class GoodsListingApprovalService {
private void publishApprovedSettleGroup(ApprovalPublishContext context, GoodsListingMerchantRef merchantRef, private void publishApprovedSettleGroup(ApprovalPublishContext context, GoodsListingMerchantRef merchantRef,
GoodsListingGoodsTypeGroup group, Integer settleRuleId, Integer divisionRuleId) { GoodsListingGoodsTypeGroup group, Integer settleRuleId, Integer divisionRuleId) {
GoodsTypeGroup oldGroup = insertOldGoodsTypeGroup(context); GoodsTypeGroup oldGroup = insertOldGoodsTypeGroup(context);
List<GoodsListingGoodsTypeGroupRelation> relations = goodsListingGoodsTypeGroupRelationService.listByGoodsTypeGroupId(group.getId()); List<GoodsListingGoodsTypeGroupRelation> relations = getCachedList(context.relationsByGroupIdMap, group.getId());
insertOldGoodsTypeGroupRelations(context, merchantRef, oldGroup.getId(), RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), group.getCategoryType(), relations); insertOldGoodsTypeGroupRelations(context, merchantRef, oldGroup.getId(), RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), group.getCategoryType(), relations);
MerchantGoodsTypeGroupSettleRule settleGroupRule = buildMerchantGoodsTypeGroupSettleRule(context, settleRuleId, oldGroup.getId(), group.getGroupType()); MerchantGoodsTypeGroupSettleRule settleGroupRule = buildMerchantGoodsTypeGroupSettleRule(context, settleRuleId, oldGroup.getId(), group.getGroupType());
smartcarMerchantGoodsTypeGroupSettleRuleMapper.insertUseGeneratedKeys(settleGroupRule); smartcarMerchantGoodsTypeGroupSettleRuleMapper.insertUseGeneratedKeys(settleGroupRule);
List<GoodsListingExpenseCategoryRule> expenses = goodsListingExpenseCategoryRuleService.listByGoodsTypeGroupId(group.getId()); List<GoodsListingExpenseCategoryRule> expenses = getCachedList(context.expenseRulesByGroupIdMap, group.getId());
// 默认费用类目只在审核通过发布旧表时补齐,不回写商品上架草稿中间表。 // 默认费用类目只在审核通过发布旧表时补齐,不回写商品上架草稿中间表。
List<GoodsListingExpenseCategoryRule> defaultExpenses = buildDefaultSettleExpenseRules(context, group.getId(), expenses); List<GoodsListingExpenseCategoryRule> defaultExpenses = buildDefaultSettleExpenseRules(context, group.getId(), expenses);
insertExpenseCategoryRules(context, merchantRef, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), settleGroupRule.getId(), insertExpenseCategoryRules(context, merchantRef, RuleTypeEnum.SETTLE_ACCOUNT_RULE.getValue(), settleGroupRule.getId(),
...@@ -676,7 +746,7 @@ public class GoodsListingApprovalService { ...@@ -676,7 +746,7 @@ public class GoodsListingApprovalService {
MerchantGoodsTypeGroupDivisionRule divisionGroupRule = buildMerchantGoodsTypeGroupDivisionRule(context, divisionRuleId, oldGroup.getId(), group.getGroupType()); MerchantGoodsTypeGroupDivisionRule divisionGroupRule = buildMerchantGoodsTypeGroupDivisionRule(context, divisionRuleId, oldGroup.getId(), group.getGroupType());
smartcarMerchantGoodsTypeGroupDivisionRuleMapper.insertUseGeneratedKeys(divisionGroupRule); smartcarMerchantGoodsTypeGroupDivisionRuleMapper.insertUseGeneratedKeys(divisionGroupRule);
List<GoodsListingDistributionRule> distributions = goodsListingDistributionRuleService.listByGoodsTypeGroupId(group.getId()); List<GoodsListingDistributionRule> distributions = getCachedList(context.distributionRulesByGroupIdMap, group.getId());
insertOldDistributionRules(context, merchantRef, divisionGroupRule.getId(), insertOldDistributionRules(context, merchantRef, divisionGroupRule.getId(),
appendDefaultSettleDistributionRules(context, group.getId(), distributions, expenses)); appendDefaultSettleDistributionRules(context, group.getId(), distributions, expenses));
} }
...@@ -808,8 +878,7 @@ public class GoodsListingApprovalService { ...@@ -808,8 +878,7 @@ public class GoodsListingApprovalService {
} }
private void publishApprovedReconciliationRules(ApprovalPublishContext context) { private void publishApprovedReconciliationRules(ApprovalPublishContext context) {
List<GoodsListingGoodsTypeGroupDTO> groups = goodsListingGoodsTypeGroupService.listBase( List<GoodsListingGoodsTypeGroupDTO> groups = context.reconciliationGroups;
context.businessCode, RuleTypeEnum.RECONCILIATION_RULE.getValue());
if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(context.merchantRefs)) { if (CollectionUtils.isEmpty(groups) || CollectionUtils.isEmpty(context.merchantRefs)) {
return; return;
} }
...@@ -830,9 +899,9 @@ public class GoodsListingApprovalService { ...@@ -830,9 +899,9 @@ public class GoodsListingApprovalService {
MerchantGoodsTypeGroupReconciliationRule reconciliationGroupRule = buildMerchantGoodsTypeGroupReconciliationRule( MerchantGoodsTypeGroupReconciliationRule reconciliationGroupRule = buildMerchantGoodsTypeGroupReconciliationRule(
context, reconciliationRuleId, group.getGroupType()); context, reconciliationRuleId, group.getGroupType());
smartcarMerchantGoodsTypeGroupReconciliationRuleMapper.insertUseGeneratedKeys(reconciliationGroupRule); smartcarMerchantGoodsTypeGroupReconciliationRuleMapper.insertUseGeneratedKeys(reconciliationGroupRule);
List<GoodsListingGoodsTypeGroupRelation> relations = goodsListingGoodsTypeGroupRelationService.listByGoodsTypeGroupId(group.getId()); List<GoodsListingGoodsTypeGroupRelation> relations = getCachedList(context.relationsByGroupIdMap, group.getId());
insertOldGoodsTypeGroupRelations(context, merchantRef, reconciliationGroupRule.getId(), RuleTypeEnum.RECONCILIATION_RULE.getValue(), group.getCategoryType(), relations); insertOldGoodsTypeGroupRelations(context, merchantRef, reconciliationGroupRule.getId(), RuleTypeEnum.RECONCILIATION_RULE.getValue(), group.getCategoryType(), relations);
List<GoodsListingExpenseCategoryRule> expenses = goodsListingExpenseCategoryRuleService.listByGoodsTypeGroupId(group.getId()); List<GoodsListingExpenseCategoryRule> expenses = getCachedList(context.expenseRulesByGroupIdMap, group.getId());
// 对账默认费用类目也只在审核通过发布旧表时补齐,不回写商品上架草稿中间表。 // 对账默认费用类目也只在审核通过发布旧表时补齐,不回写商品上架草稿中间表。
List<GoodsListingExpenseCategoryRule> defaultExpenses = buildDefaultReconciliationExpenseRules(context, group.getId(), expenses); List<GoodsListingExpenseCategoryRule> defaultExpenses = buildDefaultReconciliationExpenseRules(context, group.getId(), expenses);
List<GoodsListingExpenseCategoryRule> publishExpenses = appendSunshineReconciliationExpenseRules(context, group.getId(), List<GoodsListingExpenseCategoryRule> publishExpenses = appendSunshineReconciliationExpenseRules(context, group.getId(),
...@@ -962,10 +1031,10 @@ public class GoodsListingApprovalService { ...@@ -962,10 +1031,10 @@ public class GoodsListingApprovalService {
} }
private ExpenseCategoryDTO findExpenseCategoryDTO(ApprovalPublishContext context, Integer expenseCategoryId) { private ExpenseCategoryDTO findExpenseCategoryDTO(ApprovalPublishContext context, Integer expenseCategoryId) {
if (expenseCategoryId == null || CollectionUtils.isEmpty(context.expenseCategoryDTOS)) { if (expenseCategoryId == null || CollectionUtils.isEmpty(context.allExpenseCategoryDTOS)) {
return null; return null;
} }
for (ExpenseCategoryDTO categoryDTO : context.expenseCategoryDTOS) { for (ExpenseCategoryDTO categoryDTO : context.allExpenseCategoryDTOS) {
if (categoryDTO != null && Objects.equals(categoryDTO.getExpenseCategoryId(), expenseCategoryId)) { if (categoryDTO != null && Objects.equals(categoryDTO.getExpenseCategoryId(), expenseCategoryId)) {
return categoryDTO; return categoryDTO;
} }
...@@ -1033,7 +1102,7 @@ public class GoodsListingApprovalService { ...@@ -1033,7 +1102,7 @@ public class GoodsListingApprovalService {
if (CollectionUtils.isEmpty(expenses)) { if (CollectionUtils.isEmpty(expenses)) {
return; return;
} }
Map<Integer, ExpenseCategoryDTO> expenseCategoryDTOMap = buildExpenseCategoryDTOMap(context.expenseCategoryDTOS); Map<Integer, ExpenseCategoryDTO> expenseCategoryDTOMap = buildExpenseCategoryDTOMap(context.allExpenseCategoryDTOS);
List<MerchantExpenseCategoryRule> childExpenses = new ArrayList<>(); List<MerchantExpenseCategoryRule> childExpenses = new ArrayList<>();
Map<Integer, MerchantExpenseCategoryRule> insertedParentRuleMap = new HashMap<>(); Map<Integer, MerchantExpenseCategoryRule> insertedParentRuleMap = new HashMap<>();
for (GoodsListingExpenseCategoryRule expense : expenses) { for (GoodsListingExpenseCategoryRule expense : expenses) {
...@@ -1352,7 +1421,7 @@ public class GoodsListingApprovalService { ...@@ -1352,7 +1421,7 @@ public class GoodsListingApprovalService {
} }
private void insertDivisionRuleAutos(ApprovalPublishContext context, Integer divisionRuleId) { private void insertDivisionRuleAutos(ApprovalPublishContext context, Integer divisionRuleId) {
List<GoodsListingDivisionRuleAuto> autos = goodsListingDivisionRuleAutoService.listByBusinessCode(context.businessCode); List<GoodsListingDivisionRuleAuto> autos = context.divisionRuleAutos;
if (CollectionUtils.isEmpty(autos)) { if (CollectionUtils.isEmpty(autos)) {
return; return;
} }
...@@ -1525,13 +1594,10 @@ public class GoodsListingApprovalService { ...@@ -1525,13 +1594,10 @@ public class GoodsListingApprovalService {
private Byte resolveSceneType(String baseSceneCode) { private Byte resolveSceneType(String baseSceneCode) {
BaseSceneEnum baseSceneEnum = BaseSceneEnum.fromCode(baseSceneCode); BaseSceneEnum baseSceneEnum = BaseSceneEnum.fromCode(baseSceneCode);
if (baseSceneEnum != null) { if (baseSceneEnum == null) {
return baseSceneEnum.getSceneType(); throw new RpcServiceException("无效的场景编码:" + baseSceneCode);
}
if (StringUtils.startsWith(baseSceneCode, "110")) {
return SceneTypeEnum.SCENE1_0.getValue();
} }
return SceneTypeEnum.SCENE1_1.getValue(); return baseSceneEnum.getSceneType();
} }
private Byte defaultGroupType(Byte groupType) { private Byte defaultGroupType(Byte groupType) {
...@@ -1684,14 +1750,23 @@ public class GoodsListingApprovalService { ...@@ -1684,14 +1750,23 @@ public class GoodsListingApprovalService {
private List<GoodsListingMerchantRef> merchantRefs; private List<GoodsListingMerchantRef> merchantRefs;
private String baseSceneCode; private String baseSceneCode;
private Byte sceneType; private Byte sceneType;
private List<ExpenseCategoryDTO> expenseCategoryDTOS; private List<ExpenseCategoryDTO> allExpenseCategoryDTOS;
private List<ExpenseCategoryDTO> systemSettleExpenseCategoryDTOS; private List<ExpenseCategoryDTO> systemSettleExpenseCategoryDTOS;
private List<ExpenseCategoryDTO> systemReconciliationExpenseCategoryDTOS; private List<ExpenseCategoryDTO> systemReconciliationExpenseCategoryDTOS;
private Map<String, String> goodsCodeMap = new LinkedHashMap<>(); private Map<String, String> goodsCodeMap = new LinkedHashMap<>();
private Map<String, String> packageCodeMap = new LinkedHashMap<>(); private Map<String, String> packageCodeMap = new LinkedHashMap<>();
private Map<Integer, ApprovalRuleIds> ruleIdMap = new HashMap<>(); private Map<Integer, ApprovalRuleIds> ruleIdMap = new HashMap<>();
private List<GoodsListingProductBaseDTO> products;
private List<GoodsListingProductDetailDTO> details; private List<GoodsListingProductDetailDTO> details;
private Map<Integer, List<GoodsListingProductDetailDTO>> detailsByProductBaseIdMap = Collections.emptyMap();
private List<GoodsListingGoodsTypeGroupDTO> settleGroups;
private List<GoodsListingGoodsTypeGroupDTO> reconciliationGroups;
private Map<Integer, List<GoodsListingGoodsTypeGroupRelation>> relationsByGroupIdMap = Collections.emptyMap();
private Map<Integer, List<GoodsListingExpenseCategoryRule>> expenseRulesByGroupIdMap = Collections.emptyMap();
private Map<Integer, List<GoodsListingDistributionRule>> distributionRulesByGroupIdMap = Collections.emptyMap();
private List<GoodsListingDivisionRuleAuto> divisionRuleAutos;
private List<UpgradeGoodsDTO> upgradeGoodsDTOS; private List<UpgradeGoodsDTO> upgradeGoodsDTOS;
private Map<Integer, UpgradeGoodsDTO> upgradeGoodsMap = Collections.emptyMap();
private List<Integer> allServiceItemIdList; private List<Integer> allServiceItemIdList;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!