Commit 33b13786 by 崔彦峰

refactor(goods): 优化套餐商品处理逻辑

- 将套餐相关索引列表作为参数传递给验证方法
- 使用新的套餐领导者行判断逻辑替代原有的套餐产品判断
- 移除基于单行套餐名称的套餐识别逻辑
- 新增套餐行和套餐领导者行的判断方法
- 优化套餐名称非空验证仅在套餐领导者行执行
- 调整产品键构建逻辑避免通过单行套餐名称反推套餐
1 parent d20bf8dc
......@@ -606,8 +606,9 @@ public class GoodsListingSubmitService {
&& org.apache.commons.lang.StringUtils.isBlank(createBusinessApproveImportVo.getRecoveryCost()));
}
Set<Integer> packageRelatedGoodsIndexSet = collectPackageRelatedGoodsIndexSet(globalContext.getPackageGoodsIndexList());
Map<Integer, Integer> baseLeaderIndexMap = buildBaseLeaderIndexMap(list, globalContext.getPackageGoodsIndexList());
List<List<Integer>> packageGoodsIndexList = globalContext.getPackageGoodsIndexList();
Set<Integer> packageRelatedGoodsIndexSet = collectPackageRelatedGoodsIndexSet(packageGoodsIndexList);
Map<Integer, Integer> baseLeaderIndexMap = buildBaseLeaderIndexMap(list, packageGoodsIndexList);
Map<Integer, UpgradeGoodsDTO> legalGoodsIndexMap = new LinkedHashMap<>();
......@@ -627,7 +628,7 @@ public class GoodsListingSubmitService {
continue;
}
if (!validateRequiredGoodsFields(row, i, list, baseLeaderIndexMap, submitDTO.getBaseSceneCode(), errorList)) {
if (!validateRequiredGoodsFields(row, i, list, baseLeaderIndexMap, packageGoodsIndexList, submitDTO.getBaseSceneCode(), errorList)) {
continue;
}
......@@ -752,7 +753,7 @@ public class GoodsListingSubmitService {
}
}
boolean packageProduct = isPackageProduct(packageName);
boolean packageProduct = isPackageLeaderRow(leaderIndex, packageGoodsIndexList);
// 套餐编码先写入产品基础信息,后续套餐品类关系复用同一编码。
String packageCode = packageProduct ? resolvePackageCode(globalContext, packageName, leaderIndex) : null;
String commodityCode = upgradeGoodsDTO == null ? null : upgradeGoodsDTO.getCommodityCode();
......@@ -938,6 +939,7 @@ public class GoodsListingSubmitService {
int rowIndex,
List<CreateBusinessApproveAllImportVo> list,
Map<Integer, Integer> baseLeaderIndexMap,
List<List<Integer>> packageGoodsIndexList,
String baseSceneCode,
List<StringBuilder> errorList) {
Integer leaderIndex = baseLeaderIndexMap.getOrDefault(rowIndex, rowIndex);
......@@ -948,11 +950,13 @@ public class GoodsListingSubmitService {
valid = false;
}
String packageName = resolveBaseMergedText(list, leaderIndex, baseLeaderIndexMap, CreateBusinessApproveAllImportVo::getPackageName);
if (StringUtils.isBlank(packageName)) {
boolean packageLeaderRow = isPackageLeaderRow(rowIndex, packageGoodsIndexList);
// 套餐身份只来自套餐列合并范围;普通商品行不校验套餐名称。
if (packageLeaderRow && StringUtils.isBlank(packageName)) {
setLineError(errorList, "套餐名称不能为空", rowIndex);
valid = false;
}
if (!validateTextMaxLength(errorList, rowIndex, "套餐名称", packageName, GOODS_TEXT_MAX_LENGTH)) {
if (packageLeaderRow && !validateTextMaxLength(errorList, rowIndex, "套餐名称", packageName, GOODS_TEXT_MAX_LENGTH)) {
valid = false;
}
if (!validateTextMaxLength(errorList, rowIndex, "商品别名", row.getUpgradeGoodsNameAlias(), GOODS_TEXT_MAX_LENGTH)) {
......@@ -2084,7 +2088,7 @@ public class GoodsListingSubmitService {
continue;
}
String packageName = normalize(list.get(rowIndex).getPackageName());
if (StringUtils.isNotBlank(packageName) && !"/".equals(packageName) && !"\\".equals(packageName)) {
if (StringUtils.isNotBlank(packageName)) {
return packageName;
}
}
......@@ -2569,6 +2573,31 @@ public class GoodsListingSubmitService {
return result;
}
/**
* 新链路与旧链路保持一致:套餐身份只来自套餐列合并范围,不用单行套餐名称反推套餐。
*/
private boolean isPackageRow(Integer rowIndex, List<List<Integer>> packageGoodsIndexList) {
if (rowIndex == null || CollectionUtils.isEmpty(packageGoodsIndexList)) {
return false;
}
return packageGoodsIndexList.stream()
.filter(CollectionUtils::isNotEmpty)
.anyMatch(indexList -> indexList.contains(rowIndex));
}
/**
* 只有套餐合并范围首行生成套餐产品基础记录,子行只作为套餐内商品参与关系。
*/
private boolean isPackageLeaderRow(Integer rowIndex, List<List<Integer>> packageGoodsIndexList) {
if (rowIndex == null || CollectionUtils.isEmpty(packageGoodsIndexList)) {
return false;
}
return packageGoodsIndexList.stream()
.filter(CollectionUtils::isNotEmpty)
.map(indexList -> indexList.get(0))
.anyMatch(firstIndex -> Objects.equals(firstIndex, rowIndex));
}
private UpgradeGoodsDTO findUpgradeGoodsByCommodityCode(List<UpgradeGoodsDTO> goodsList, String commodityCode) {
if (CollectionUtils.isEmpty(goodsList) || StringUtils.isBlank(commodityCode)) {
return null;
......@@ -3609,14 +3638,6 @@ public class GoodsListingSubmitService {
return firstRow == null ? null : normalize(extractor.apply(firstRow));
}
private boolean isPackageProduct(String packageName) {
String value = normalize(packageName);
if (StringUtils.isBlank(value)) {
return false;
}
return !Objects.equals(value, "\\") && !Objects.equals(value, "/");
}
private boolean isCostTargetPlaceholder(String value) {
String target = normalize(value);
return Objects.equals(target, "\\") || Objects.equals(target, "/");
......@@ -3739,10 +3760,7 @@ public class GoodsListingSubmitService {
}
private String buildProductKey(CreateBusinessApproveAllImportVo row, int index) {
String packageName = normalize(row.getPackageName());
if (StringUtils.isNotBlank(packageName)) {
return "P|" + packageName;
}
// 不能通过单行套餐名称反推套餐;套餐去重应使用已构建产品中的productType/packageCode。
return "G|" + defaultIfBlank(normalize(row.getUpgradeCommodityCode()), String.valueOf(index + 1));
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!