Browse Source

Merge branch 'real_goods_sku'

# Conflicts:
#	netflix-dao/src/main/java/com/cyksj/model/entity/GoodsDonSku.java
#	netflix-dao/src/main/java/com/cyksj/model/manage/views/OrderDonSearchView.java
#	netflix-dao/src/main/java/com/cyksj/model/request/CombinationSkuReq.java
#	netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonSkuFrontView.java
#	netflix-service/src/main/java/com/cyksj/service/mange/CmsGoodsDonSpecService.java
#	netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonServiceImpl.java
#	netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonSpecServiceImpl.java
#	netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java
#	netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/CmsGoodsDonSkuController.java
zoujiajian 3 years ago
parent
commit
2ab8ac1d35

+ 17 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GoodsDonSku.java

@@ -7,6 +7,7 @@ import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.DbIgnore;
 import com.ejlchina.searcher.bean.SearchBean;
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -129,4 +130,20 @@ public class GoodsDonSku extends BaseEntity {
     @DbIgnore
     @TableField(exist = false)
     private List<GoodsDiscountPlusPurchaseRelationFrontView> dpSkuViews;
+
+    /**
+     * 前端展示
+     */
+    @DbIgnore
+    @TableField(exist = false)
+    @JsonProperty("gname")
+    private String gName;
+
+    /**
+     * 前端展示
+     */
+    @DbIgnore
+    @TableField(exist = false)
+    @JsonProperty("sname")
+    private String sName;
 }

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

@@ -25,6 +25,9 @@ public class ReqGoodsSpecSingle {
     @NotNull(message = "缺少总规格属性id")
     private Long keyId;
 
+    @NotNull(message = "缺少总规格属性id")
+    private Integer keyId;
+
     @NotBlank(message = "缺少规格名")
     private String key;
 

+ 0 - 2
netflix-dao/src/main/java/com/cyksj/model/request/CombinationSkuReq.java

@@ -15,8 +15,6 @@ import java.util.List;
 @Getter
 @Setter
 public class CombinationSkuReq {
-	private Long id;
-
 	private String key;
 
 	private List<ReqGoodsSkuSpec.Node> values;

+ 0 - 96
netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonSkuFrontView.java

@@ -1,96 +0,0 @@
-package com.cyksj.model.views;
-
-import com.ejlchina.searcher.bean.DbField;
-import com.ejlchina.searcher.bean.DbIgnore;
-import com.ejlchina.searcher.bean.SearchBean;
-import lombok.Getter;
-import lombok.Setter;
-
-import java.math.BigDecimal;
-import java.util.List;
-
-/*
- *项目名: netflix
- *文件名: GoodsDonSkuFrontView
- *创建者: JavaZou
- *创建时间:2023/4/6 17:58
- */
-@Getter
-@Setter
-@SearchBean(tables = "goods_don_sku")
-public class GoodsDonSkuFrontView {
-
-	private Long id;
-
-	private Long goodsId;
-
-
-	private String subTitle;
-
-	/**
-	 * 商品规格 ids
-	 */
-	private String specIds;
-
-	/**
-	 * 商品规格 value
-	 */
-	private String specVal;
-
-	/**
-	 * 商品规格 json
-	 */
-	private String specJson;
-
-	/**
-	 * 规格说明信息
-	 */
-	private String notifyText;
-
-	/**
-	 * 商品预览图
-	 */
-	private String picture;
-
-	/**
-	 * 商品详情图
-	 */
-	private String detail;
-
-	/**
-	 * 标签
-	 */
-	private String tags;
-
-
-	/**
-	 * true 上架 / false 下架
-	 */
-	private Boolean status;
-
-	/**
-	 * 价格
-	 */
-	private BigDecimal price;
-
-	/**
-	 * 月数
-	 */
-	private Integer months;
-
-	/**
-	 * 天数
-	 */
-	private Integer days;
-
-	@DbField("case when spec_val like '%月%' and spec_val not like '%年%' then 0 when spec_val like '%季%' then 1 when spec_val like '%半年%' then 2 when spec_val like '%年%' then 3 else 66 end")
-	private Integer orderBy;
-
-	private Boolean isDp;
-
-	/**
-	 * 优惠加购商品
-	 */
-	@DbIgnore
-	private List<GoodsDiscountPlusPurchaseRelationFrontView> dpSkuViews;
-}

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonSkuView.java

@@ -35,6 +35,9 @@ public class GoodsDonSkuView {
 	@DbField("gdk.spec_val")
 	private String specVal;
 
+	@DbField("gdk.spec_json")
+	private String specJson;
+
 	@DbField("gdk.days")
 	private Integer days;
 

+ 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;
 

+ 162 - 37
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsGoodsDonSpecServiceImpl.java

@@ -27,6 +27,8 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -44,14 +46,21 @@ public class CmsGoodsDonSpecServiceImpl extends ServiceImpl<GoodsDonSpecMapper,
 	private final GoodsDonSkuMapper goodsDonSkuMapper;
 
 	@Override
-	public void insertOrUpdateSkuSpec(ReqGoodsSkuInsert insert) throws Exception {
+	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 +69,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 +91,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 +99,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 +127,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 +227,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 +257,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 +281,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 +307,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 +322,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 +332,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 +348,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 +358,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) {
+					}
+				});
+			}
+		}
+	}
 }

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

@@ -1,22 +1,23 @@
 package com.cyksj.web.controller.manage.goods;
 
-import com.baomidou.mybatisplus.core.toolkit.Assert;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.annotation.Log;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.Jsons;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.BusinessType;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.model.entity.GoodsDon;
 import com.cyksj.model.entity.GoodsDonSku;
-import com.cyksj.model.entity.GoodsDonSpec;
 import com.cyksj.model.manage.request.ReqGoodsSkuInsert;
 import com.cyksj.model.request.CombinationSkuReq;
-import com.cyksj.model.views.GoodsDonSkuView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.mange.CmsGoodsDonService;
 import com.cyksj.service.mange.CmsGoodsDonSkuService;
 import com.cyksj.service.mange.CmsGoodsDonSpecService;
 import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.SearchResult;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -58,7 +59,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();
     }
@@ -68,13 +69,7 @@ public class CmsGoodsDonSkuController {
      */
     @PutMapping("/update/spec")
     public Result<String> updateGoodsSpec(@Validated @RequestBody ReqGoodsSkuInsert insert) throws Exception {
-        Long id = insert.getId();
-        Assert.notNull(id, "规格属性id不存在");
-        GoodsDonSpec spec = goodsDonSpecService.getById(id);
-        if (spec == null || !spec.getGoodsId().equals(insert.getGoodsId())) {
-            throw BusinessRuntimeException.getInstance("规格不存在");
-        }
-        goodsDonSpecService.insertOrUpdateSkuSpec(insert);
+        goodsDonSpecService.insertOrUpdateSkuSpec(insert, true);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
 
@@ -104,7 +99,7 @@ public class CmsGoodsDonSkuController {
     @Transactional(rollbackFor = Throwable.class)
     @PutMapping(value = "/update")
     @Log(module = "平台管理/编辑规格", businessType = BusinessType.PUT, isSaveRequestData = true)
-    public Result<String> skuUpdate(@RequestBody GoodsDonSku sku){
+    public Result<String> skuUpdate(@RequestBody GoodsDonSku sku) throws Exception {
         Long goodsId = sku.getGoodsId();
         GoodsDon goods = goodsDonService.getById(goodsId);
         if (goods.getType() == 1) {
@@ -121,6 +116,12 @@ public class CmsGoodsDonSkuController {
         }
         //优惠加购
         goodsDonSkuService.handleDiscountPurchaseGoods(sku, sku.getDpSku());
+
+        String benefitsList = sku.getBenefitsList();
+        if (StrUtil.isNotBlank(benefitsList)) {
+            Set<GoodsDonSku> benefitsSkuIds = Jsons.parseSet(benefitsList, GoodsDonSku.class);
+            sku.setBenefitsList(Jsons.toJson(benefitsSkuIds));
+        }
         goodsDonSkuService.saveOrUpdate(sku);
         //给平台更新额外属性
         goodsDonService.updateGoodsSkuPrice(sku.getGoodsId(), null);
@@ -161,8 +162,30 @@ public class CmsGoodsDonSkuController {
      * 获取平台规格列表
      */
     @GetMapping("/get/list")
-    public Result<List<GoodsDonSkuView>> getGoodsSkuList() {
-        List<GoodsDonSkuView> skuViewList = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
+    public Result<SearchResult<GoodsDonSku>> getGoodsSkuList() {
+        SearchResult<GoodsDonSku> skuViewList = beanSearcher.search(GoodsDonSku.class, MapUtils.flatBuilder(request.getParameterMap()).build());
         return GatewayResponse.SUCCESS.newBuilder().toResult(skuViewList);
     }
+
+    /**
+     * 批量上架
+     */
+    @PutMapping("/batch/update/status/{goodsId}")
+    public Result<String> batchUpdateStatus(@PathVariable Long goodsId, @RequestBody List<Long> skuIds) {
+        GoodsDon goodsDon = goodsDonService.getById(goodsId);
+        if (goodsDon == null || !goodsDon.getDeleted()) {
+            throw BusinessRuntimeException.getInstance("商品不存在");
+        }
+        boolean update = goodsDonSkuService.update(null, Wrappers.lambdaUpdate(GoodsDonSku.class)
+                .set(GoodsDonSku::getStatus, true)
+                .eq(GoodsDonSku::getGoodsId, goodsId)
+                .in(GoodsDonSku::getId, skuIds)
+                .eq(GoodsDonSku::getStatus, false));
+        if (update) {
+            goodsDonService.updateGoodsSkuPrice(goodsId, null);
+            Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
+            redisService.del(keys.toArray(String[]::new));
+        }
+        return GatewayResponse.SUCCESS.newBuilder().toResult();
+    }
 }