|
@@ -10,6 +10,7 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
import com.fjhx.item.service.product.ProductClassifyService;
|
|
@@ -35,6 +36,7 @@ import com.fjhx.wms.entity.stock.vo.StockWaitDetailsVo;
|
|
|
import com.fjhx.wms.entity.warehouse.po.Warehouse;
|
|
|
import com.fjhx.wms.mapper.stock.StockMapper;
|
|
|
import com.fjhx.wms.service.PurService;
|
|
|
+import com.fjhx.wms.service.WmsService;
|
|
|
import com.fjhx.wms.service.stock.StockJournalDetailsService;
|
|
|
import com.fjhx.wms.service.stock.StockJournalService;
|
|
|
import com.fjhx.wms.service.stock.StockService;
|
|
@@ -86,6 +88,8 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
private StockWaitService stockWaitService;
|
|
|
@Autowired
|
|
|
private DictTenantDataService dictTenantDataService;
|
|
|
+ @Autowired
|
|
|
+ private WmsService wmsService;
|
|
|
|
|
|
@Override
|
|
|
public Page<StockVo> getPage(StockSelectDto dto) {
|
|
@@ -546,6 +550,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
oldStocks.setProductId(stock.getProductId());
|
|
|
oldStocks.setWarehouseId(warehouseId);
|
|
|
oldStocks.setQuantity(BigDecimal.ZERO);
|
|
|
+ this.save(oldStocks);
|
|
|
}
|
|
|
|
|
|
if (type == 1) {
|
|
@@ -560,7 +565,42 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
|
|
|
}
|
|
|
BigDecimal quantity = oldStocks.getQuantity().subtract(stock.getQuantity());
|
|
|
if (quantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw new ServiceException("以下商品库存不足,无法出库:" + productInfo.getName());
|
|
|
+ //库存不足判断是否是组合
|
|
|
+ String victoriatouristJson = productInfo.getVictoriatouristJson();
|
|
|
+ JSONObject json = ObjectUtil.isNotEmpty(victoriatouristJson) ? JSONObject.parseObject(victoriatouristJson) : new JSONObject();
|
|
|
+ Integer combination = json.getInteger("combination");
|
|
|
+ if (combination != 1) {
|
|
|
+ //不是组合直接报错
|
|
|
+ throw new ServiceException("以下商品库存不足,无法出库:" + productInfo.getName());
|
|
|
+ }
|
|
|
+ //计算差多少 自动组合差的那部分
|
|
|
+ BigDecimal differenceQuantity = stock.getQuantity().subtract(oldStocks.getQuantity());
|
|
|
+ //获取产品组合信息
|
|
|
+ JSONArray productCombinationListArr = json.getJSONArray("productCombinationList");
|
|
|
+ Assert.notEmpty(productCombinationListArr, "产品组合信息为空");
|
|
|
+ List<JSONObject> productCombinationList = productCombinationListArr.toJavaList(JSONObject.class);
|
|
|
+ List<Long> linkProductIds = productCombinationList.stream().map(item -> item.getLong("linkProductId")).collect(Collectors.toList());
|
|
|
+ Map<Long, Stock> combinationStockMap = this.mapKEntity(Stock::getProductId, q -> q
|
|
|
+ .eq(Stock::getWarehouseId, warehouseId)
|
|
|
+ .in(Stock::getProductId, linkProductIds));
|
|
|
+ //检查是否满足自动组合条件
|
|
|
+ for (JSONObject jsonObject : productCombinationList) {
|
|
|
+ Stock stockInfo = combinationStockMap.get(jsonObject.getLong("linkProductId"));
|
|
|
+ BigDecimal requiredQuantity = jsonObject.getBigDecimal("linkQuantity").multiply(differenceQuantity);
|
|
|
+ if (ObjectUtil.isEmpty(stockInfo) || stockInfo.getQuantity().compareTo(requiredQuantity) < 0) {
|
|
|
+ throw new ServiceException("该组合产品,子产品库存不足无法自动组合出库:" + productInfo.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建组合信息
|
|
|
+ wmsService.autoCombination(productInfo.getId(), differenceQuantity, warehouseId);
|
|
|
+
|
|
|
+ //组合完成 再次尝试出库
|
|
|
+ oldStocks = this.getOne(q -> q.eq(Stock::getProductId, productInfo.getId()).eq(Stock::getWarehouseId, warehouseId));
|
|
|
+ quantity = oldStocks.getQuantity().subtract(stock.getQuantity());
|
|
|
+ oldStocks.setQuantity(quantity);
|
|
|
+ if (quantity.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new ServiceException("以下商品库存不足,无法出库:" + productInfo.getName());
|
|
|
+ }
|
|
|
}
|
|
|
oldStocks.setQuantity(quantity);
|
|
|
} else if (type == 3) {
|