Explorar el Código

fix 平台总规格分类同步

zoujiajian hace 3 años
padre
commit
7076b2c979

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/GoodsDonSpec.java

@@ -21,7 +21,7 @@ public class GoodsDonSpec extends BaseEntity {
     /**
      * 规格属性值最大id
      */
-    private Long maxId;
+    private Integer maxId;
 
     /**
      * 商品规格数量

+ 2 - 2
netflix-dao/src/main/java/com/cyksj/model/manage/request/ReqGoodsSkuSpec.java

@@ -13,7 +13,7 @@ import java.util.List;
 @Getter
 @Setter
 public class ReqGoodsSkuSpec {
-    private Long id;
+    private Integer id;
 
     private String key;
 
@@ -22,7 +22,7 @@ public class ReqGoodsSkuSpec {
     @Getter
     @Setter
     public static class Node {
-        private Long id;
+        private Integer id;
 
         private String value;
 

+ 3 - 3
netflix-dao/src/main/java/com/cyksj/model/manage/request/ReqGoodsSpecSingle.java

@@ -20,10 +20,10 @@ public class ReqGoodsSpecSingle {
     private Long goodsId;
 
     @NotNull(message = "缺少规格属性id")
-    private Long id;
+    private Integer id;
 
     @NotNull(message = "缺少总规格属性id")
-    private Long keyId;
+    private Integer keyId;
 
     @NotBlank(message = "缺少规格名")
     private String key;
@@ -31,5 +31,5 @@ public class ReqGoodsSpecSingle {
     @NotBlank(message = "缺少属性名.")
     private String name;
 
-    private Long maxId;
+    private Integer maxId;
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/CmsGoodsDonSpecService.java

@@ -17,7 +17,7 @@ public interface CmsGoodsDonSpecService extends IService<GoodsDonSpec> {
 	/**
 	 * 新增或编辑规格spec
 	 */
-	void insertOrUpdateSkuSpec(ReqGoodsSkuInsert insert) throws Exception;
+	void insertOrUpdateSkuSpec(ReqGoodsSkuInsert insert, Boolean isUpdate) throws Exception;
 
 	void skuAppend(ReqGoodsSkuInsert insert, GoodsDon goods) throws Exception;
 

+ 164 - 40
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonSpecServiceImpl.java

@@ -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) {
+					}
+				});
+			}
+		}
+	}
 }

+ 2 - 2
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/CmsGoodsDonSkuController.java

@@ -58,7 +58,7 @@ public class CmsGoodsDonSkuController {
     @PostMapping(value = "/post/spec-sku")
     @Log(module = "平台管理/新增商品sku&spec", businessType = BusinessType.POST, isSaveRequestData = true)
     public Result<String> skuInsert(@Validated @RequestBody ReqGoodsSkuInsert insert) throws Exception{
-        goodsDonSpecService.insertOrUpdateSkuSpec(insert);
+        goodsDonSpecService.insertOrUpdateSkuSpec(insert, false);
 
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
@@ -74,7 +74,7 @@ public class CmsGoodsDonSkuController {
         if (spec == null || !spec.getGoodsId().equals(insert.getGoodsId())) {
             throw BusinessRuntimeException.getInstance("规格不存在");
         }
-        goodsDonSpecService.insertOrUpdateSkuSpec(insert);
+        goodsDonSpecService.insertOrUpdateSkuSpec(insert, true);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/CmsGoodsDonSpecController.java

@@ -72,7 +72,7 @@ public class CmsGoodsDonSpecController {
         String specsJson = Jsons.toJson(specs);
 
         JavaType type = Jsons.javaType().constructMapType(HashMap.class, Integer.class, ReqGoodsSpecSingle.class);
-        Map<Long, ReqGoodsSpecSingle> map = Jsons.parseObject(v2spec.getSpecMapping(), type);
+        Map<Integer, ReqGoodsSpecSingle> map = Jsons.parseObject(v2spec.getSpecMapping(), type);
         map.put(specSingle.getId(), specSingle);
         String specMapping = Jsons.toJson(map);