|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package cn.iocoder.yudao.module.erp.service.stock;
|
|
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
|
|
|
|
|
@ -42,12 +43,26 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ErpStockDO getStock(Long id) {
|
|
|
|
|
return stockMapper.selectById(id);
|
|
|
|
|
ErpStockDO stock = stockMapper.selectById(id);
|
|
|
|
|
if (stock != null && stock.getCategoryType() == null) {
|
|
|
|
|
ErpProductRespVO product = productService.getProduct(stock.getProductId());
|
|
|
|
|
if (product != null) {
|
|
|
|
|
stock.setCategoryType(product.getCategoryType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ErpStockDO getStock(Long productId, Long warehouseId) {
|
|
|
|
|
return stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
|
|
|
|
|
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
|
|
|
|
|
if (stock != null && stock.getCategoryType() == null) {
|
|
|
|
|
ErpProductRespVO product = productService.getProduct(productId);
|
|
|
|
|
if (product != null) {
|
|
|
|
|
stock.setCategoryType(product.getCategoryType());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return stock;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public List<ErpStockDO> getStockByProductId(Long productId) {
|
|
|
|
|
@ -67,12 +82,18 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BigDecimal updateStockCountIncrement(Long categoryId,Long productId, Long warehouseId, BigDecimal count) {
|
|
|
|
|
ErpProductRespVO product = productService.getProduct(productId);
|
|
|
|
|
Integer categoryType = product != null ? product.getCategoryType() : null;
|
|
|
|
|
// 1.1 查询当前库存
|
|
|
|
|
ErpStockDO stock = stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
|
|
|
|
|
if (stock == null) {
|
|
|
|
|
stock = new ErpStockDO().setProductId(productId).setWarehouseId(warehouseId).setCount(BigDecimal.ZERO);
|
|
|
|
|
stock = new ErpStockDO().setProductId(productId).setWarehouseId(warehouseId).setCount(BigDecimal.ZERO)
|
|
|
|
|
.setCategoryType(categoryType);
|
|
|
|
|
stock.setCategoryId(categoryId);
|
|
|
|
|
stockMapper.insert(stock);
|
|
|
|
|
} else if (stock.getCategoryType() == null) {
|
|
|
|
|
stock.setCategoryType(categoryType);
|
|
|
|
|
stockMapper.updateById(new ErpStockDO().setId(stock.getId()).setCategoryType(categoryType));
|
|
|
|
|
}
|
|
|
|
|
// 1.2 校验库存是否充足
|
|
|
|
|
if (!NEGATIVE_STOCK_COUNT_ENABLE && stock.getCount().add(count).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
@ -92,4 +113,4 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|
|
|
|
return stock.getCount().add(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|