|
@@ -200,39 +200,46 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods> implement
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void addGoods(GoodsWrapper.Goods goods, Integer operatorId) {
|
|
|
- if(StringUtils.isBlank(goods.getSn())){
|
|
|
- throw new BizException("请指定商品货号");
|
|
|
- }
|
|
|
- Goods existsGood = goodsDao.lockBySn(goods.getSn());
|
|
|
- if(Objects.nonNull(existsGood)){
|
|
|
+ public void addGoods(List<GoodsWrapper.Goods> goodsList, Integer operatorId) {
|
|
|
+ List<String> snList = goodsList.stream().map(GoodsWrapper.Goods::getSn).distinct().collect(Collectors.toList());
|
|
|
+ List<Goods> bySns = goodsDao.findBySns(snList);
|
|
|
+ if (!CollectionUtils.isEmpty(bySns)) {
|
|
|
throw new BizException("商品货号重复");
|
|
|
}
|
|
|
- List<GoodsWrapper.GoodsSub> goodsSubList = goods.getGoodsSubList();
|
|
|
- //获取最小的库存数
|
|
|
- String skuIds = goodsSubList.stream().map(e -> e.getSku().toString()).collect(Collectors.joining(","));
|
|
|
- PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
|
|
|
- paramDto.setSkuStockIds(skuIds);
|
|
|
+ for (GoodsWrapper.Goods goods : goodsList) {
|
|
|
+ if (StringUtils.isBlank(goods.getSn())) {
|
|
|
+ throw new BizException("请指定商品货号");
|
|
|
+ }
|
|
|
+ Goods existsGood = goodsDao.lockBySn(goods.getSn());
|
|
|
+ if (Objects.nonNull(existsGood)) {
|
|
|
+ throw new BizException("商品货号重复");
|
|
|
+ }
|
|
|
+ List<GoodsWrapper.GoodsSub> goodsSubList = goods.getGoodsSubList();
|
|
|
+ //获取最小的库存数
|
|
|
+ String skuIds = goodsSubList.stream().map(e -> e.getSku().toString()).collect(Collectors.joining(","));
|
|
|
+ PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
|
|
|
+ paramDto.setSkuStockIds(skuIds);
|
|
|
// paramDto.setPublishStatus(1);
|
|
|
- paramDto.setPageSize(1000);
|
|
|
- paramDto.setPageNum(1);
|
|
|
- paramDto.setJson(JSON.toJSONString(paramDto));
|
|
|
- List<PmsProductDto> productList = mallFeignService.getProductList(paramDto).getRows();
|
|
|
- if(CollectionUtils.isEmpty(productList)){
|
|
|
- throw new BizException("子商品不存在");
|
|
|
+ paramDto.setPageSize(1000);
|
|
|
+ paramDto.setPageNum(1);
|
|
|
+ paramDto.setJson(JSON.toJSONString(paramDto));
|
|
|
+ List<PmsProductDto> productList = mallFeignService.getProductList(paramDto).getRows();
|
|
|
+ if (CollectionUtils.isEmpty(productList)) {
|
|
|
+ throw new BizException("子商品不存在");
|
|
|
+ }
|
|
|
+ //获取最小库存数量
|
|
|
+ Integer stock = productList.stream().map(PmsProductDto::getStock).min(Integer::compareTo).get();
|
|
|
+ goods.setStockCount(stock);
|
|
|
+ goods.setSellCount(0);
|
|
|
+ Goods goodsRecord = JSON.parseObject(JSON.toJSONString(goods), Goods.class);
|
|
|
+ goodsRecord.setStatus(YesOrNoEnum.NO);
|
|
|
+ BigDecimal organCostPrice = goodsSubList.stream().map(GoodsWrapper.GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ goodsRecord.setOrganCostPrice(organCostPrice);
|
|
|
+ goodsDao.insert(goodsRecord);
|
|
|
+ List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
|
|
|
+ goodsSubs.forEach(next -> next.setGoodsId(goodsRecord.getId()));
|
|
|
+ goodsSubService.saveBatch(goodsSubs);
|
|
|
}
|
|
|
- //获取最小库存数量
|
|
|
- Integer stock = productList.stream().map(PmsProductDto::getStock).min(Integer::compareTo).get();
|
|
|
- goods.setStockCount(stock);
|
|
|
- goods.setSellCount(0);
|
|
|
- Goods goodsRecord = JSON.parseObject(JSON.toJSONString(goods), Goods.class);
|
|
|
- goodsRecord.setStatus(YesOrNoEnum.NO);
|
|
|
- BigDecimal organCostPrice = goodsSubList.stream().map(GoodsWrapper.GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- goodsRecord.setOrganCostPrice(organCostPrice);
|
|
|
- goodsDao.insert(goodsRecord);
|
|
|
- List<GoodsSub> goodsSubs = JSON.parseArray(JSON.toJSONString(goodsSubList), GoodsSub.class);
|
|
|
- goodsSubs.forEach(next -> next.setGoodsId(goodsRecord.getId()));
|
|
|
- goodsSubService.saveBatch(goodsSubs);
|
|
|
}
|
|
|
|
|
|
/*@Override
|