Commit 541843a9 by weijiguang

下单时校验订单中sku数量

parent cb6da3e2
package com.soss.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.soss.common.exception.ServiceException;
import com.soss.system.domain.Machine;
import com.soss.system.domain.ShopGoods;
import com.soss.system.domain.Spec;
import com.soss.system.domain.SpecRule;
import com.soss.system.domain.*;
import com.soss.system.domain.vo.orderTaking.SkuVo;
import com.soss.system.mapper.*;
import com.soss.system.service.IShopGoodsService;
......@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
return null;
}
Map<Long, SpecRule> selloutRules = new HashMap<>();
Map<Long, SpecRule> sellinRules = new HashMap<>();
Set<Long> selloutRules = new HashSet<>();
Set<Long> sellinRules = new HashSet<>();
List<SkuVo> selloutSkus = skuMap.get("2");
if (!CollectionUtils.isEmpty(selloutSkus)) {
selloutSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> {
rule.setState(2);
selloutRules.put(rule.getId(), rule);
});
rules.forEach(rule -> selloutRules.add(rule.getId()));
}
});
}
......@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
sellinSkus.forEach(skuVo -> {
List<SpecRule> rules = JSON.parseArray(skuVo.getRulesString(), SpecRule.class);
if (!CollectionUtils.isEmpty(rules)) {
rules.forEach(rule -> {
rule.setState(1);
sellinRules.put(rule.getId(), rule);
});
rules.forEach(rule -> sellinRules.add(rule.getId()));
}
});
}
// 从售罄sku选项列表中删除 未售罄sku选项
sellinRules.values().forEach(rule -> selloutRules.remove(rule.getId()));
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));
sellinRules.forEach(sellinId -> selloutRules.remove(sellinId));
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)) {
Goods goods = goodsMapper.selectGoodsById(goodsId);
if (goods == null) {
return null;
}
specVos.forEach(spec -> {
if (CollectionUtils.isEmpty(spec.getSpecRules())) {
spec.setSpecRules(new ArrayList<>());
List<Spec> specs = JSONArray.parseArray(goods.getSpec(), Spec.class);
if (CollectionUtils.isEmpty(specs)) {
return specs;
}
if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
specs.forEach(spec -> {
List<SpecRule> rules = spec.getSpecRules();
if (CollectionUtils.isEmpty(rules)) {
return;
}
if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
rules.forEach(rule -> {
if (sellinRules.contains(rule.getId())) {
rule.setState(1);
} else {
rule.setState(0);
}
});
});
// 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 specVos;
return specs;
}
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