|
@@ -240,6 +240,20 @@ public class WebsitSalesLogic {
|
|
|
|
|
|
Map<String, WebsitGoods> goodsMap = goodsList.stream().collect(Collectors.toMap(WebsitGoods::getGoodsId, Function.identity()));
|
|
|
|
|
|
+ // 获取网点辅材库存
|
|
|
+ final List<WebsitStock> websitStockList = websitStockService.lambdaQuery()
|
|
|
+ .eq(WebsitStock::getCompanyWechatId, sales.getCompanyWechatId())
|
|
|
+ .eq(WebsitStock::getWebsitId, sales.getWebsitId())
|
|
|
+ .eq(WebsitStock::getStorageId, sales.getStorageId())
|
|
|
+ .eq(WebsitStock::getGoodsType, WebsitGoodsTypeEnum.M.getKey())
|
|
|
+ .in(WebsitStock::getGoodsId, itemList.stream()
|
|
|
+ .map(WebsitSalesItem::getGoodsId)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+
|
|
|
+ Map<String, WebsitStock> stockMap = websitStockList.stream()
|
|
|
+ .collect(Collectors.toMap(WebsitStock::getGoodsId, Function.identity()));
|
|
|
+
|
|
|
for (WebsitSalesItem item : itemList) {
|
|
|
if (!goodsMap.containsKey(item.getGoodsId())) {
|
|
|
throw new RemoteServiceException("找不到商品信息:" + item.getGoodsName());
|
|
@@ -252,6 +266,16 @@ public class WebsitSalesLogic {
|
|
|
.setConvertBitScale(1)
|
|
|
.setManageWorkerStock(goods.getManageWorkerStock());
|
|
|
|
|
|
+ // 检查辅材库存
|
|
|
+ if (!stockMap.containsKey(item.getGoodsId())) {
|
|
|
+ throw new RemoteServiceException("仓库 " + sales.getStorageName() + " 没有”" + item.getGoodsName() + "”库存信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getSalesQty().compareTo(stockMap.get(item.getGoodsId()).getQty()) > 0) {
|
|
|
+ throw new RemoteServiceException("仓库 " + sales.getStorageName() + " 的“" + item.getGoodsName() + "“库存数量" + stockMap.get(item.getGoodsId()).getQty() + "少于销售数量");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 商品类型为配件时单价要先乘倍率
|
|
|
if (sales.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())) {
|
|
|
final MaterialConfig config = materialConfigService.lambdaQuery()
|
|
@@ -310,23 +334,23 @@ public class WebsitSalesLogic {
|
|
|
item.setConvertQty(convertQty)
|
|
|
.setConvertPrice(convertPrice);
|
|
|
// 检查数量是否大于当前库存数
|
|
|
- final List<WebsitStock> websitStocks = websitStockService.lambdaQuery()
|
|
|
- .eq(WebsitStock::getCompanyWechatId, sales.getCompanyWechatId())
|
|
|
- .eq(WebsitStock::getWebsitId, sales.getWebsitId())
|
|
|
- .eq(WebsitStock::getGoodsType, WebsitGoodsTypeEnum.P.getKey())
|
|
|
- .eq(WebsitStock::getStorageId, sales.getStorageId())
|
|
|
- .in(WebsitStock::getGoodsId, itemList.stream().map(WebsitSalesItem::getGoodsId).collect(Collectors.toList()))
|
|
|
- .list();
|
|
|
- if (CollectionUtil.isNotEmpty(websitStocks)) {
|
|
|
- final Map<String, WebsitStock> stockMap = websitStocks.stream()
|
|
|
- .collect(Collectors.toMap(WebsitStock::getGoodsId, Function.identity()));
|
|
|
- for (WebsitSalesItem salesItem : itemList) {
|
|
|
- final WebsitStock stock = stockMap.get(salesItem.getGoodsId());
|
|
|
- if (Objects.nonNull(stock) && salesItem.getSalesQty().compareTo(stock.getQty()) > 0) {
|
|
|
- throw new RemoteServiceException(salesItem.getGoodsName() + " 销售数量不能大于库存数量");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+// final List<WebsitStock> websitStocks = websitStockService.lambdaQuery()
|
|
|
+// .eq(WebsitStock::getCompanyWechatId, sales.getCompanyWechatId())
|
|
|
+// .eq(WebsitStock::getWebsitId, sales.getWebsitId())
|
|
|
+// .eq(WebsitStock::getGoodsType, WebsitGoodsTypeEnum.P.getKey())
|
|
|
+// .eq(WebsitStock::getStorageId, sales.getStorageId())
|
|
|
+// .in(WebsitStock::getGoodsId, itemList.stream().map(WebsitSalesItem::getGoodsId).collect(Collectors.toList()))
|
|
|
+// .list();
|
|
|
+// if (CollectionUtil.isNotEmpty(websitStocks)) {
|
|
|
+// final Map<String, WebsitStock> stockMap = websitStocks.stream()
|
|
|
+// .collect(Collectors.toMap(WebsitStock::getGoodsId, Function.identity()));
|
|
|
+// for (WebsitSalesItem salesItem : itemList) {
|
|
|
+// final WebsitStock stock = stockMap.get(salesItem.getGoodsId());
|
|
|
+// if (Objects.nonNull(stock) && salesItem.getSalesQty().compareTo(stock.getQty()) > 0) {
|
|
|
+// throw new RemoteServiceException(salesItem.getGoodsName() + " 销售数量不能大于库存数量");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
}
|