|
|
@@ -214,7 +214,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
return x.add(y.getPurchaseAmount().multiply(y.getOrderQuantity()));
|
|
|
},BigDecimal::add);//采购金额求和
|
|
|
BigDecimal amount = list.stream().map(OrderItems::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);//金额求和
|
|
|
- BigDecimal grossProfit = amount.subtract(reduce.add(order.getPredictOceanFreight())).subtract(order.getThisUsedProfit());
|
|
|
+ BigDecimal grossProfit = amount.subtract(reduce.add(order.getPredictOceanFreight())).subtract(order.getThisUsedProfit()==null?BigDecimal.ZERO:order.getThisUsedProfit());
|
|
|
BigDecimal grossProfitRate = new BigDecimal(BigInteger.ZERO);
|
|
|
if (amount.compareTo(BigDecimal.ZERO) > 0){
|
|
|
grossProfitRate = (grossProfit.divide(amount,2)).multiply(new BigDecimal(100));
|
|
|
@@ -623,6 +623,65 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
/**===========================end 审核通过修改销售订单信息==========================*/
|
|
|
|
|
|
|
|
|
+ /**===========================Start 审核通过锁定库存=============================*/
|
|
|
+ //获取此销售订单下,所有明细的库存
|
|
|
+ LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ orderItemsLambdaQueryWrapper
|
|
|
+ .eq(OrderItems::getPid,id)
|
|
|
+ .eq(OrderItems::getIsDeleted,0);
|
|
|
+ List<OrderItems> orderItems = orderItemsMapper.selectList(orderItemsLambdaQueryWrapper);
|
|
|
+ if(CollectionUtils.isNotEmpty(orderItems))
|
|
|
+ {
|
|
|
+ orderItems.forEach(e->{
|
|
|
+ StockGoods stockGoods=new StockGoods();
|
|
|
+ stockGoods.setCorpId(e.getCorpId());
|
|
|
+ stockGoods.setGoodsId(e.getItemId());
|
|
|
+ stockGoods.setTenantId(AuthUtil.getTenantId());
|
|
|
+ List<StockGoods> listStockGoods= stockGoodsClient.postListStockByCondition(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("锁定库存失败: 更新失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**===========================End 审核通过锁定库存=============================*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**===========================start 审核通过操作返利信息=============================*/
|
|
|
//不需要计算返利
|
|
|
@@ -698,62 +757,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
|
|
|
|
|
|
- /**===========================Start 审核通过锁定库存=============================*/
|
|
|
- //获取此销售订单下,所有明细的库存
|
|
|
- LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
- orderItemsLambdaQueryWrapper
|
|
|
- .eq(OrderItems::getPid,id)
|
|
|
- .eq(OrderItems::getIsDeleted,0);
|
|
|
- List<OrderItems> orderItems = orderItemsMapper.selectList(orderItemsLambdaQueryWrapper);
|
|
|
- if(CollectionUtils.isNotEmpty(orderItems))
|
|
|
- {
|
|
|
- orderItems.forEach(e->{
|
|
|
- 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("锁定库存失败: 更新失败");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**===========================End 审核通过锁定库存=============================*/
|
|
|
|
|
|
}
|
|
|
|