|
|
@@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
-import com.cyksj.common.snowflake.Sequence;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.mapper.GoodsDonMapper;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
@@ -24,9 +23,12 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -37,21 +39,27 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper, GoodsDonSpec> implements CmsGoodsDonSpecService {
|
|
|
- private final static Sequence SEQUENCE = new Sequence(0);
|
|
|
-
|
|
|
private final GoodsDonMapper goodsDonMapper;
|
|
|
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void insertOrUpdateSkuSpec(ReqGoodsSkuInsert insert) throws Exception {
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public void insertOrUpdateSkuSpec(ReqGoodsSkuInsert insert, Boolean isUpdate) throws Exception {
|
|
|
GoodsDon goods = goodsDonMapper.selectById(insert.getGoodsId());
|
|
|
if (null == goods) {
|
|
|
throw new RuntimeException("找不到商品spu.");
|
|
|
}
|
|
|
GoodsDonSpec loveSpec = this.getOne(Wrappers.lambdaQuery(GoodsDonSpec.class).eq(GoodsDonSpec::getGoodsId, insert.getGoodsId()));
|
|
|
+ Map<String, List<ReqGoodsSkuSpec>> dbSpecMap = null;
|
|
|
+ Map<Integer, ReqGoodsSkuSpec.Node> dbNodeMap = null;
|
|
|
if (null != loveSpec) {
|
|
|
- throw new RuntimeException("该商品已新增总规格, 请点击编辑并追加该商品的sku.");
|
|
|
+ insert.setId(loveSpec.getId());
|
|
|
+ String specsJson = loveSpec.getSpecsJson();
|
|
|
+ dbSpecMap = Jsons.parseList(specsJson, ReqGoodsSkuSpec.class).stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec::getKey));
|
|
|
+ }
|
|
|
+ if (isUpdate && loveSpec == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("所更新的平台id:{0}属性不存在", insert.getGoodsId());
|
|
|
}
|
|
|
|
|
|
List<ReqGoodsSkuSpec> specs = insert.getSpecs();
|
|
|
@@ -60,18 +68,17 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
}
|
|
|
|
|
|
// 属性最大id
|
|
|
- Long maxId = 0l;
|
|
|
+ Integer maxId = 0;
|
|
|
// 统计总属性数
|
|
|
- Long total = 0l;
|
|
|
+ Integer total = 0;
|
|
|
// 判断id是否有重复
|
|
|
- Map<Long, ReqGoodsSpecSingle> map = null;
|
|
|
+ Map<Integer, ReqGoodsSpecSingle> map = null;
|
|
|
// 规格数量
|
|
|
int specNumber = specs.size();
|
|
|
|
|
|
+ dbNodeMap = checkUpdateGoodsSpec(goods.getId(), dbSpecMap, dbNodeMap, specs);
|
|
|
+
|
|
|
for (ReqGoodsSkuSpec spec : specs) {
|
|
|
- if (spec.getId() == null) {
|
|
|
- spec.setId(SEQUENCE.nextId());
|
|
|
- }
|
|
|
if (StringUtils.isBlank(spec.getKey())) {
|
|
|
throw new RuntimeException("存在空白规格名.");
|
|
|
}
|
|
|
@@ -83,7 +90,7 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
total += values.size();
|
|
|
for (ReqGoodsSkuSpec.Node e : values) {
|
|
|
if (null == e.getId() || e.getId() < 0) {
|
|
|
- e.setId(SEQUENCE.nextId());
|
|
|
+ e.setId(maxId + 1);
|
|
|
}
|
|
|
if (StringUtils.isBlank(e.getValue())) {
|
|
|
throw new RuntimeException("规格[" + spec.getKey() + "]中存在空白属性.");
|
|
|
@@ -91,18 +98,23 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
if (e.getId() > maxId) {
|
|
|
maxId = e.getId();
|
|
|
}
|
|
|
-
|
|
|
- if (goods.getType() == 2 && (e.getPrice() == null || e.getPrice().compareTo(BigDecimal.ZERO) < 0)) {
|
|
|
- throw BusinessRuntimeException.getInstance("实物规格:{0}对应价格错误", e.getValue());
|
|
|
+ //新增时 实物价格要填入
|
|
|
+ if (goods.getType() == 2 && insert.getId() == null && (e.getPrice() == null || e.getPrice().compareTo(BigDecimal.ZERO) < 0)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("实物规格:{0}对应价格请输入", e.getValue());
|
|
|
}
|
|
|
|
|
|
if (null == map) {
|
|
|
map = new HashMap<>(16);
|
|
|
}
|
|
|
+ String benefitsList = e.getBenefitsList();
|
|
|
+ if (StrUtil.isNotBlank(benefitsList)) {
|
|
|
+ Set<GoodsDonSku> benefitsSkuIds = Jsons.parseSet(benefitsList, GoodsDonSku.class);
|
|
|
+ e.setBenefitsList(Jsons.toJson(benefitsSkuIds));
|
|
|
+ }
|
|
|
+ syncSpecNodeSku(goods.getId(), dbNodeMap, e);
|
|
|
|
|
|
ReqGoodsSpecSingle single = new ReqGoodsSpecSingle();
|
|
|
single.setId(e.getId());
|
|
|
- single.setKeyId(spec.getId());
|
|
|
single.setKey(spec.getKey());
|
|
|
single.setName(e.getValue());
|
|
|
map.put(e.getId(), single);
|
|
|
@@ -114,6 +126,7 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
}
|
|
|
|
|
|
GoodsDonSpec spec = new GoodsDonSpec();
|
|
|
+ spec.setId(insert.getId());
|
|
|
spec.setGoodsId(insert.getGoodsId());
|
|
|
spec.setMaxId(maxId);
|
|
|
spec.setSpecsJson(Jsons.toJson(specs));
|
|
|
@@ -213,6 +226,12 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
goodsDonSku.setDupSpecIds(dupSpecIds);
|
|
|
goodsDonSku.setSpecVal(specVal);
|
|
|
goodsDonSku.setSpecJson(specJson);
|
|
|
+ String benefitsList = goodsDonSku.getBenefitsList();
|
|
|
+ if (StrUtil.isNotBlank(benefitsList)) {
|
|
|
+ Set<GoodsDonSku> benefitsSkuIds = Jsons.parseSet(benefitsList, GoodsDonSku.class);
|
|
|
+ goodsDonSku.setIsBenefits(true);
|
|
|
+ goodsDonSku.setBenefitsList(Jsons.toJson(benefitsSkuIds));
|
|
|
+ }
|
|
|
if (goods.getType() == 1) {
|
|
|
if (sku.getMonths() != null && sku.getMonths() > 0 && sku.getDays() != null && sku.getDays() > 0)
|
|
|
throw BusinessRuntimeException.getInstance("续费天数和续费月数不能同时存在");
|
|
|
@@ -237,23 +256,20 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
}
|
|
|
String specsJson = loveSpec.getSpecsJson();
|
|
|
List<ReqGoodsSkuSpec> specsList = Jsons.parseList(specsJson, ReqGoodsSkuSpec.class);
|
|
|
- Map<Long, List<ReqGoodsSkuSpec>> specValueMap = specsList.stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec::getId));
|
|
|
+ Map<String, List<ReqGoodsSkuSpec>> specValueMap = specsList.stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec::getKey));
|
|
|
if (combinations.isEmpty()) {
|
|
|
throw BusinessRuntimeException.getInstance("请选择对应的规格组合");
|
|
|
}
|
|
|
List<ReqGoodsSkuInsert.Sku> skus = new LinkedList<>();
|
|
|
ReqGoodsSkuInsert reqGoodsSkuInsert = new ReqGoodsSkuInsert();
|
|
|
reqGoodsSkuInsert.setGoodsId(goodsId);
|
|
|
- List<List<Long>> specIdLists = new LinkedList<>();
|
|
|
+ List<List<Integer>> specIdLists = new LinkedList<>();
|
|
|
CombinationSkuReq request = combinations.get(0);
|
|
|
- if (request.getId() == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("传入的总规格属性id不存在");
|
|
|
- }
|
|
|
- List<ReqGoodsSkuSpec> reqGoodsSkuSpecs = specValueMap.get(request.getId());
|
|
|
+ List<ReqGoodsSkuSpec> reqGoodsSkuSpecs = specValueMap.get(request.getKey());
|
|
|
if (reqGoodsSkuSpecs == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("传入的id:{0}总规格属性不存在", request.getId());
|
|
|
+ throw BusinessRuntimeException.getInstance("传入的总规格属性:{0}不存在", request.getKey());
|
|
|
}
|
|
|
- Map<Long, List<ReqGoodsSkuSpec.Node>> nodeIdMap = reqGoodsSkuSpecs.get(0).getValues().stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec.Node::getId));
|
|
|
+ Map<Integer, List<ReqGoodsSkuSpec.Node>> nodeIdMap = reqGoodsSkuSpecs.get(0).getValues().stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec.Node::getId));
|
|
|
if (CollUtil.isNotEmpty(request.getValues())) {
|
|
|
unifiedHandleCombinationSku(combinations, request.getValues(), specValueMap, nodeIdMap, specIdLists, skus);
|
|
|
} else {
|
|
|
@@ -264,18 +280,18 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
skuAppend(reqGoodsSkuInsert, goodsDon);
|
|
|
}
|
|
|
|
|
|
- public void unifiedHandleCombinationSku(List<CombinationSkuReq> combinations, List<ReqGoodsSkuSpec.Node> values, Map<Long, List<ReqGoodsSkuSpec>> specValueMap, Map<Long, List<ReqGoodsSkuSpec.Node>> nodeIdMap, List<List<Long>> specIdLists, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
+ public void unifiedHandleCombinationSku(List<CombinationSkuReq> combinations, List<ReqGoodsSkuSpec.Node> values, Map<String, List<ReqGoodsSkuSpec>> specValueMap, Map<Integer, List<ReqGoodsSkuSpec.Node>> nodeIdMap, List<List<Integer>> specIdLists, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
for (ReqGoodsSkuSpec.Node node_value : values) {
|
|
|
ReqGoodsSkuInsert.Sku sku = new ReqGoodsSkuInsert.Sku();
|
|
|
sku.setPrice(BigDecimal.ZERO);
|
|
|
- List<Long> specIds = new LinkedList<>();
|
|
|
+ List<Integer> specIds = new LinkedList<>();
|
|
|
unifiedHandleSecondCombinationSku(node_value, nodeIdMap, sku, specIds);
|
|
|
recurCombinationSku(combinations, combinations.size(), 1, 1, specIds, specIdLists, sku, specValueMap, skus);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void unifiedHandleSecondCombinationSku(ReqGoodsSkuSpec.Node temp_node, Map<Long, List<ReqGoodsSkuSpec.Node>> nodeIdMap, ReqGoodsSkuInsert.Sku sku, List<Long> specIds) {
|
|
|
+ public void unifiedHandleSecondCombinationSku(ReqGoodsSkuSpec.Node temp_node, Map<Integer, List<ReqGoodsSkuSpec.Node>> nodeIdMap, ReqGoodsSkuInsert.Sku sku, List<Integer> specIds) {
|
|
|
List<ReqGoodsSkuSpec.Node> nodes = nodeIdMap.get(temp_node.getId());
|
|
|
if (CollUtil.isEmpty(nodes)) {
|
|
|
throw BusinessRuntimeException.getInstance("{0}规格不存在", temp_node.getValue());
|
|
|
@@ -290,11 +306,9 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
}
|
|
|
sku.setPrice(sku.getPrice().add(price));
|
|
|
specIds.add(temp_node.getId());
|
|
|
- if (node.getValue().contains("套餐")) {
|
|
|
- if (StrUtil.isNotEmpty(node.getBenefitsList())) {
|
|
|
- sku.setIsBenefits(true);
|
|
|
- sku.setBenefitsList(node.getBenefitsList());
|
|
|
- }
|
|
|
+ if (StrUtil.isNotEmpty(node.getBenefitsList())) {
|
|
|
+ sku.setIsBenefits(true);
|
|
|
+ sku.setBenefitsList(node.getBenefitsList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -307,7 +321,7 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
* @param sku 待插入库中的sku
|
|
|
* @param specValueMap 总规格库中对应values
|
|
|
*/
|
|
|
- private void recurCombinationSku(List<CombinationSkuReq> combinations, Integer total, Integer has, Integer start, List<Long> specIds, List<List<Long>> specIdLists, ReqGoodsSkuInsert.Sku sku, Map<Long, List<ReqGoodsSkuSpec>> specValueMap, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
+ private void recurCombinationSku(List<CombinationSkuReq> combinations, Integer total, Integer has, Integer start, List<Integer> specIds, List<List<Integer>> specIdLists, ReqGoodsSkuInsert.Sku sku, Map<String, List<ReqGoodsSkuSpec>> specValueMap, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
if (has == total) {
|
|
|
if (specIdLists.contains(specIds)) {
|
|
|
return;
|
|
|
@@ -317,15 +331,12 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
return;
|
|
|
}
|
|
|
CombinationSkuReq request = combinations.get(start);
|
|
|
- if (request.getId() == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("总规格属性id不存在");
|
|
|
- }
|
|
|
- List<ReqGoodsSkuSpec> reqGoodsSkuSpecs = specValueMap.get(request.getId());
|
|
|
+ List<ReqGoodsSkuSpec> reqGoodsSkuSpecs = specValueMap.get(request.getKey());
|
|
|
if (reqGoodsSkuSpecs == null) {
|
|
|
- throw BusinessRuntimeException.getInstance("{0}总规格属性不存在", request.getKey());
|
|
|
+ throw BusinessRuntimeException.getInstance("总规格属性{0}不存在", request.getKey());
|
|
|
}
|
|
|
ReqGoodsSkuSpec reqGoodsSkuSpec = reqGoodsSkuSpecs.get(0);
|
|
|
- Map<Long, List<ReqGoodsSkuSpec.Node>> nodeIdMap = reqGoodsSkuSpec.getValues().stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec.Node::getId));
|
|
|
+ Map<Integer, List<ReqGoodsSkuSpec.Node>> nodeIdMap = reqGoodsSkuSpec.getValues().stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec.Node::getId));
|
|
|
if (CollUtil.isNotEmpty(request.getValues())) {
|
|
|
createNewSkuAndRecurCombination(combinations, request.getValues(), nodeIdMap, has, start, specIds, specIdLists, sku, specValueMap, skus);
|
|
|
return;
|
|
|
@@ -336,7 +347,7 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
/**
|
|
|
* 新的规格 递归
|
|
|
*/
|
|
|
- public void createNewSkuAndRecurCombination(List<CombinationSkuReq> combinations, List<ReqGoodsSkuSpec.Node> values, Map<Long, List<ReqGoodsSkuSpec.Node>> nodeIdMap, Integer has, Integer start, List<Long> specIds, List<List<Long>> specIdLists, ReqGoodsSkuInsert.Sku sku, Map<Long, List<ReqGoodsSkuSpec>> specValueMap, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
+ public void createNewSkuAndRecurCombination(List<CombinationSkuReq> combinations, List<ReqGoodsSkuSpec.Node> values, Map<Integer, List<ReqGoodsSkuSpec.Node>> nodeIdMap, Integer has, Integer start, List<Integer> specIds, List<List<Integer>> specIdLists, ReqGoodsSkuInsert.Sku sku, Map<String, List<ReqGoodsSkuSpec>> specValueMap, List<ReqGoodsSkuInsert.Sku> skus) throws Exception {
|
|
|
for (ReqGoodsSkuSpec.Node node_value : values) {
|
|
|
BigDecimal last_price = sku.getPrice();
|
|
|
unifiedHandleSecondCombinationSku(node_value, nodeIdMap, sku, specIds);
|
|
|
@@ -346,4 +357,117 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
|
|
|
sku.setPrice(last_price);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新删除总属性 一级分类 校验
|
|
|
+ */
|
|
|
+ public Map<Integer, ReqGoodsSkuSpec.Node> checkUpdateGoodsSpec(Long goodsId, Map<String, List<ReqGoodsSkuSpec>> dbSpecMap, Map<Integer, ReqGoodsSkuSpec.Node> dbNodeMap, List<ReqGoodsSkuSpec> specs) {
|
|
|
+ if (CollUtil.isNotEmpty(dbSpecMap)) {
|
|
|
+ Map<String, List<ReqGoodsSkuSpec>> updateSpecMap = specs.stream().collect(Collectors.groupingBy(ReqGoodsSkuSpec::getKey));
|
|
|
+ dbNodeMap = new ConcurrentHashMap<>();
|
|
|
+ for (String key : dbSpecMap.keySet()) {
|
|
|
+ List<ReqGoodsSkuSpec> reqGoodsSkuSpecs = updateSpecMap.get(key);
|
|
|
+ if (CollUtil.isNotEmpty(reqGoodsSkuSpecs)) {
|
|
|
+ ReqGoodsSkuSpec reqGoodsSkuSpec = reqGoodsSkuSpecs.get(0);
|
|
|
+ if (CollUtil.isEmpty(reqGoodsSkuSpec.getValues())) {
|
|
|
+ //删除整个一级分类key
|
|
|
+ String specFirstKey = reqGoodsSkuSpec.getKey();
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsId)
|
|
|
+ .like(GoodsDonSku::getSpecJson, specFirstKey).last("limit 1"));
|
|
|
+ if (sku != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("删除总规格分类,存在使用该总规格分类的规格");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Map<Integer, List<ReqGoodsSkuSpec.Node>> updateSecondMap = reqGoodsSkuSpec.getValues().stream().filter(node -> node.getId() != null).collect(Collectors.groupingBy(ReqGoodsSkuSpec.Node::getId));
|
|
|
+ ReqGoodsSkuSpec dbReqGoodsSkuSpec = dbSpecMap.get(key).get(0);
|
|
|
+ for (ReqGoodsSkuSpec.Node dbSecondValue : dbReqGoodsSkuSpec.getValues()) {
|
|
|
+ if (updateSecondMap.get(dbSecondValue.getId()) == null) {
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsId)
|
|
|
+ .like(GoodsDonSku::getSpecVal, dbSecondValue.getValue()).last("limit 1"));
|
|
|
+ if (sku != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("删除总规格分类,存在使用该总规格分类的规格");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dbNodeMap.put(dbSecondValue.getId(), dbSecondValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //去除总规格分类时
|
|
|
+ //校验是否已引用该属性规格
|
|
|
+ if (CollUtil.isEmpty(reqGoodsSkuSpecs)) {
|
|
|
+ ReqGoodsSkuSpec dbReqGoodsSkuSpec = dbSpecMap.get(key).get(0);
|
|
|
+ //删除整个一级分类key
|
|
|
+ String specFirstKey = dbReqGoodsSkuSpec.getKey();
|
|
|
+ GoodsDonSku sku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsId)
|
|
|
+ .like(GoodsDonSku::getSpecJson, specFirstKey).last("limit 1"));
|
|
|
+ if (sku != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("删除总规格分类,存在使用该总规格分类的规格");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dbNodeMap;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新二级分类标题价格等 同步库中sku
|
|
|
+ */
|
|
|
+ public void syncSpecNodeSku(Long goodsId, Map<Integer, ReqGoodsSkuSpec.Node> dbNodeMap, ReqGoodsSkuSpec.Node e) {
|
|
|
+ if (CollUtil.isNotEmpty(dbNodeMap)) {
|
|
|
+ ReqGoodsSkuSpec.Node dbNode = dbNodeMap.get(e.getId());
|
|
|
+ if (dbNode == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ AtomicBoolean isUpdateTitle = new AtomicBoolean(false);
|
|
|
+ AtomicBoolean isUpdatePrice = new AtomicBoolean(false);
|
|
|
+ AtomicBoolean isUpdateBenefits = new AtomicBoolean(false);
|
|
|
+ if (!StrUtil.equals(dbNode.getValue(), e.getValue())) {
|
|
|
+ isUpdateTitle.set(true);
|
|
|
+ }
|
|
|
+ if (e.getPrice() == null) {
|
|
|
+ e.setPrice(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ if (dbNode.getPrice() != null && e.getPrice().compareTo(dbNode.getPrice()) != 0) {
|
|
|
+ isUpdatePrice.set(true);
|
|
|
+ }
|
|
|
+ if (!StrUtil.equals(dbNode.getBenefitsList(), e.getBenefitsList())) {
|
|
|
+ isUpdateBenefits.set(true);
|
|
|
+ }
|
|
|
+ if (isUpdateTitle.get() || isUpdatePrice.get() || isUpdateBenefits.get()) {
|
|
|
+ List<GoodsDonSku> goodsDonSkus = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, goodsId));
|
|
|
+
|
|
|
+ goodsDonSkus.forEach(sku -> {
|
|
|
+ try {
|
|
|
+ List<Integer> specIdsList = Jsons.parseList(sku.getSpecIds(), Integer.class);
|
|
|
+ if (specIdsList.contains(dbNode.getId())) {
|
|
|
+ if (isUpdateTitle.get()) {
|
|
|
+ sku.setSpecJson(sku.getSpecJson().replaceAll(dbNode.getValue(), e.getValue()));
|
|
|
+ sku.setSpecVal(sku.getSpecVal().replaceAll(dbNode.getValue(), e.getValue()));
|
|
|
+ }
|
|
|
+ if (isUpdatePrice.get()) {
|
|
|
+ sku.setPrice(sku.getPrice().subtract(dbNode.getPrice()).add(e.getPrice()));
|
|
|
+ }
|
|
|
+ if (isUpdateBenefits.get()) {
|
|
|
+ if (StrUtil.isEmpty(e.getBenefitsList())) {
|
|
|
+ sku.setBenefitsList(StrUtil.EMPTY);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ sku.setBenefitsList(e.getBenefitsList());
|
|
|
+ } catch (Exception exception) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goodsDonSkuMapper.updateById(sku);
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|