|
|
@@ -49,6 +49,8 @@ import org.springblade.purchase.sales.vo.OrderVO;
|
|
|
import org.springblade.purchase.sales.mapper.OrderMapper;
|
|
|
import org.springblade.purchase.sales.service.IOrderService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.stock.entity.StockGoods;
|
|
|
+import org.springblade.stock.feign.IStockGoodsClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -84,6 +86,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
private OrderItemsMapper orderItemsMapper;
|
|
|
private final ICheckClient iCheckClient;
|
|
|
private ICorpsProfitChangeClient corpsProfitChangeClient;
|
|
|
+ private IStockGoodsClient stockGoodsClient;
|
|
|
@Override
|
|
|
public IPage<OrderVO> selectOrderPage(IPage<OrderVO> page, OrderVO order) {
|
|
|
List<OrderVO> orderVOList = baseMapper.selectOrderPage(page, order);
|
|
|
@@ -705,7 +708,47 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if(CollectionUtils.isNotEmpty(orderItems))
|
|
|
{
|
|
|
orderItems.forEach(e->{
|
|
|
- //todo
|
|
|
+ StockGoods stockGoods=new StockGoods();
|
|
|
+ stockGoods.setCorpId(e.getCorpId());
|
|
|
+ stockGoods.setGoodsId(e.getItemId());
|
|
|
+ stockGoods.setTenantId(AuthUtil.getTenantId());
|
|
|
+ List<StockGoods> listStockGoods= stockGoodsClient.listStockByCondition(stockGoods);
|
|
|
+ if(listStockGoods.size()>1||CollectionUtils.isEmpty(listStockGoods))
|
|
|
+ {
|
|
|
+ throw new SecurityException("锁定库存失败:未查询到库存 或者 存在多条库存记录");
|
|
|
+ }
|
|
|
+ //开始锁定库存,减少可用
|
|
|
+ StockGoods oneStock = stockGoodsClient.getOneStock(stockGoods);
|
|
|
+ if(oneStock==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("锁定库存失败:未查询到库存信息");
|
|
|
+ }
|
|
|
+ //原单据的订货数量
|
|
|
+ BigDecimal orderQuantity = e.getOrderQuantity();
|
|
|
+ //可用库存
|
|
|
+ BigDecimal surplusRouteQuantity = oneStock.getSurplusRouteQuantity();
|
|
|
+ //锁定库存
|
|
|
+ BigDecimal lockingQuantity = oneStock.getLockingQuantity();
|
|
|
+
|
|
|
+ //判断比较大小
|
|
|
+ if(orderQuantity.compareTo(surplusRouteQuantity)==1)
|
|
|
+ {
|
|
|
+ throw new SecurityException("锁定库存失败:原单据的订货数量大于可用库存,无法锁定");
|
|
|
+ }
|
|
|
+ if(surplusRouteQuantity==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("锁定库存失败:可用库存为空,禁止操作");
|
|
|
+ }
|
|
|
+ //减少可用库存
|
|
|
+ oneStock.setSurplusRouteQuantity(surplusRouteQuantity.subtract(orderQuantity==null?new BigDecimal("0"):orderQuantity));
|
|
|
+ //增加锁定库存
|
|
|
+ oneStock.setLockingQuantity(lockingQuantity==null?new BigDecimal("0").add(orderQuantity):lockingQuantity.add(orderQuantity));
|
|
|
+ //更新库存
|
|
|
+ R r = stockGoodsClient.updateStock(oneStock);
|
|
|
+ if(!r.isSuccess())
|
|
|
+ {
|
|
|
+ throw new SecurityException("锁定库存失败: 更新失败");
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|