Commit 4b87b740 by zhoulm

refactor(商品上架服务): 优化套餐商品重复检查逻辑

将基于商品ID的重复检查改为基于商品ID和部位的组合键检查,提高太阳膜商品的重复判断准确性
1 parent de637cf7
......@@ -202,9 +202,9 @@ public class GoodsListingProductBaseService {
//延保类、权益类
extendedInsuranceTypeIdList.addAll(equityTypeIdList);
Set<String> upgradeGoodsIdStrSet = new HashSet<>();
Set<String> upgradeGoodsKeyStrSet = new HashSet<>();
productBaseList.forEach(record ->{
Set<Integer> upgradeGoodsIdSet = new HashSet<>();
Set<String> upgradeGoodsKeySet = new HashSet<>();
record.getDetailList().forEach(o->{
UpgradeGoodsDTO upgradeGoods = goodsListingProductDetailService.getUpgradeGoodsByUpgradeGoodsId(o.getUpgradeGoodsId());
RpcAssert.assertNotNull(upgradeGoods, DefaultErrorEnum.SERVER_ERROR, "升级商品不存在");
......@@ -215,10 +215,6 @@ public class GoodsListingProductBaseService {
}else {
RpcAssert.assertIsTrue(!extendedInsuranceTypeIdList.contains(upgradeGoods.getGoodsInfo().getGoodsType()), DefaultErrorEnum.SERVER_ERROR,"仅支持上架太阳膜、车衣、改色膜、精品类的商品");
}
if(Objects.equals(record.getProductType(), ProductTypeEnum.PACKAGE.getValue())) {
RpcAssert.assertIsTrue(!upgradeGoodsIdSet.contains(o.getUpgradeGoodsId()), DefaultErrorEnum.SERVER_ERROR,"套餐存在重复商品");
upgradeGoodsIdSet.add(o.getUpgradeGoodsId());
}
List<UpgradeGoodsAreaDTO> upgradeGoodsAreaList = upgradeGoods.getUpgradeGoodsAreaList();
RpcAssert.assertNotEmpty(upgradeGoodsAreaList, DefaultErrorEnum.SERVER_ERROR, "商品未配置适用区域");
List<String> upgradeGoodsCityCodeList = upgradeGoodsAreaList.stream().map(UpgradeGoodsAreaDTO::getCityCode).collect(Collectors.toList());
......@@ -232,12 +228,17 @@ public class GoodsListingProductBaseService {
if(isSolarFilmGoods) {
RpcAssert.assertNotNull(o.getPosition(), DefaultErrorEnum.SERVER_ERROR, "太阳膜商品需选择部位");
}
if(Objects.equals(record.getProductType(), ProductTypeEnum.PACKAGE.getValue())) {
String upgradeGoodsKey = buildUpgradeGoodsKey(o,isSolarFilmGoods);
RpcAssert.assertIsTrue(!upgradeGoodsKeySet.contains(upgradeGoodsKey), DefaultErrorEnum.SERVER_ERROR,"套餐存在重复商品");
upgradeGoodsKeySet.add(upgradeGoodsKey);
}
o.setUpgradeGoods(upgradeGoods);
});
if(Objects.equals(record.getProductType(), ProductTypeEnum.PACKAGE.getValue())) {
String upgradeGoodsIdStr = StringUtils.join(upgradeGoodsIdSet,",");
RpcAssert.assertIsTrue(!upgradeGoodsIdStrSet.contains(upgradeGoodsIdStr), DefaultErrorEnum.SERVER_ERROR,"存在重复套餐");
upgradeGoodsIdStrSet.add(upgradeGoodsIdStr);
String upgradeGoodsIdStr = StringUtils.join(upgradeGoodsKeySet,",");
RpcAssert.assertIsTrue(!upgradeGoodsKeyStrSet.contains(upgradeGoodsIdStr), DefaultErrorEnum.SERVER_ERROR,"存在重复套餐");
upgradeGoodsKeyStrSet.add(upgradeGoodsIdStr);
}
});
} catch (RpcServiceException rpcServiceException) {
......@@ -248,6 +249,14 @@ public class GoodsListingProductBaseService {
}
}
private String buildUpgradeGoodsKey(GoodsListingProductDetailDTO o,boolean isSolarFilmGoods) {
String upgradeGoodsKey = String.valueOf(o.getUpgradeGoodsId());
if(isSolarFilmGoods) {
upgradeGoodsKey = upgradeGoodsKey.concat("-").concat(String.valueOf(o.getPosition()));
}
return upgradeGoodsKey;
}
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = RpcServiceException.class)
public GoodsListingProductBaseDTO insertOrUpdate(GoodsListingProductBaseDTO record) {
RpcAssert.assertNotNull(record, DefaultErrorEnum.DATA_NULL, "record is null");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!