Browse Source

更新库存

yuanliang 1 year ago
parent
commit
4ecc9efc52

+ 19 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/GoodsServiceImpl.java

@@ -1124,6 +1124,10 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 		}
 		GoodsWrapper.Goods detail = JSON.parseObject(JSON.toJSONString(goods), GoodsWrapper.Goods.class);
 		detail.setGoodsSubList(queryGoodsSubByGoodId(goodsId));
+
+		List<ProductCategoryDto> productCategoryDtos = treeToList(queryGoodsCategoryList());
+		Map<Long, String> IdNamemap = productCategoryDtos.stream().collect(Collectors.toMap(ProductCategoryDto::getId, ProductCategoryDto::getName));
+		detail.setGoodsCategoryName(IdNamemap.getOrDefault(Long.valueOf(detail.getGoodsCategoryId()), ""));
 		return detail;
 	}
 
@@ -1163,6 +1167,21 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 
 			BigDecimal organCostPrice = goodsSubList.stream().map(GoodsWrapper.GoodsSub::getGoodsPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 			goodsInfo.setOrganCostPrice(organCostPrice);
+
+			//获取最小的库存数
+			String skuIds = goodsSubList.stream().map(e -> e.getSku().toString()).collect(Collectors.joining(","));
+			PmsProductQueryParamDto paramDto = new PmsProductQueryParamDto();
+			paramDto.setSkuStockIds(skuIds);
+			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();
+			goodsInfo.setStockCount(stock);
 		}
 		update(goodsInfo);
 	}