Commit 541843a9 by weijiguang

下单时校验订单中sku数量

parent cb6da3e2
package com.soss.system.service.impl; package com.soss.system.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.system.domain.Machine; import com.soss.system.domain.*;
import com.soss.system.domain.ShopGoods;
import com.soss.system.domain.Spec;
import com.soss.system.domain.SpecRule;
import com.soss.system.domain.vo.orderTaking.SkuVo; import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.mapper.*; import com.soss.system.mapper.*;
import com.soss.system.service.IShopGoodsService; import com.soss.system.service.IShopGoodsService;
...@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService { ...@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
return null; return null;
} }
Map<Long, SpecRule> selloutRules = new HashMap<>(); Set<Long> selloutRules = new HashSet<>();
Map<Long, SpecRule> sellinRules = new HashMap<>(); Set<Long> sellinRules = new HashSet<>();
List<SkuVo> selloutSkus = skuMap.get("2"); List<SkuVo> selloutSkus = skuMap.get("2");
if (!CollectionUtils.isEmpty(selloutSkus)) { if (!CollectionUtils.isEmpty(selloutSkus)) {
selloutSkus.forEach(skuVo -> { selloutSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class); List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) { if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> { rules.forEach(rule -> selloutRules.add(rule.getId()));
rule.setState(2);
selloutRules.put(rule.getId(), rule);
});
} }
}); });
} }
...@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService { ...@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
sellinSkus.forEach(skuVo -> { sellinSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class); List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) { if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> { rules.forEach(rule -> sellinRules.add(rule.getId()));
rule.setState(1);
sellinRules.put(rule.getId(), rule);
});
} }
}); });
} }
// 从售罄sku选项列表中删除 未售罄sku选项 // 从售罄sku选项列表中删除 未售罄sku选项
sellinRules.values().forEach(rule -> selloutRules.remove(rule.getId())); sellinRules.forEach(sellinId -> selloutRules.remove(sellinId));
Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId)); Goods goods = goodsMapper.selectGoodsById(goodsId);
Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId)); if (goods == null) {
List<Long> specIds = new ArrayList<>();
specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// 构建返回数据
List<Spec> specVos = specMapper.selectSpecByIds(specIds);
if (CollectionUtils.isEmpty(specVos)) {
return null; return null;
} }
specVos.forEach(spec -> { List<Spec> specs = JSONArray.parseArray(goods.getSpec(), Spec.class);
if (CollectionUtils.isEmpty(spec.getSpecRules())) { if (CollectionUtils.isEmpty(specs)) {
spec.setSpecRules(new ArrayList<>()); return specs;
} }
if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) { specs.forEach(spec -> {
spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId())); List<SpecRule> rules = spec.getSpecRules();
} if (CollectionUtils.isEmpty(rules)) {
if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) { return;
spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
} }
rules.forEach(rule -> {
if (sellinRules.contains(rule.getId())) {
rule.setState(1);
} else {
rule.setState(0);
}
});
}); });
return specVos;
// Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
// Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
//
// List<Long> specIds = new ArrayList<>();
// specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
//
// // 构建返回数据
// List<Spec> specVos = specMapper.selectSpecByIds(specIds);
// if (CollectionUtils.isEmpty(specVos)) {
// return null;
// }
// specVos.forEach(spec -> {
// if (CollectionUtils.isEmpty(spec.getSpecRules())) {
// spec.setSpecRules(new ArrayList<>());
// }
// if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
// }
// if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
// }
// });
return specs;
} }
public Boolean updateShopGoodsSpecState(Long shopId, Long goodsId, Long ruleId, Integer state) { public Boolean updateShopGoodsSpecState(Long shopId, Long goodsId, Long ruleId, Integer state) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment