|
|
@@ -607,12 +607,68 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if (order == null) {
|
|
|
throw new SecurityException("审批失败,未查到单据");
|
|
|
}
|
|
|
+ if (order.getStatus() != 0){
|
|
|
+ throw new SecurityException("订单已开启审核,请勿重复提交");
|
|
|
+ }
|
|
|
//判断是否有审批流,如果审批流已开启就进入审批流,否则直接走申请通过
|
|
|
Integer checkFlag = order.getCheckFlag();
|
|
|
AuditPathsActs pathsActs = null;
|
|
|
if (checkFlag == null) {
|
|
|
throw new SecurityException("请核失败:未配置请核标识");
|
|
|
}
|
|
|
+ //销售锁定库存
|
|
|
+ if (checkFlag == 2 && SecureUtil.getTenantId().equals("681169")){
|
|
|
+ if (salesOrder.getBillType().equals("XS")) {
|
|
|
+ /**===========================Start 审核通过锁定库存=============================*/
|
|
|
+ //获取此销售订单下,所有明细的库存
|
|
|
+ LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderItemsLambdaQueryWrapper
|
|
|
+ .eq(OrderItems::getGoodType, 0)
|
|
|
+ .eq(OrderItems::getPid, salesOrder.getId())
|
|
|
+ .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(SecureUtil.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("锁定库存失败: 更新失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
//判断是采购审批 还是 销售审批
|
|
|
if (checkFlag == 2) {
|
|
|
pathsActs = iCheckClient.getActsByActId(3, "status");
|
|
|
@@ -663,8 +719,22 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
} else if (checkFlag == 1) {
|
|
|
auditProecessDTO.setProcessType("采购审批");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderItemsLambdaQueryWrapper
|
|
|
+ .eq(OrderItems::getGoodType, 0)
|
|
|
+ .eq(OrderItems::getPid, salesOrder.getId())
|
|
|
+ .eq(OrderItems::getIsDeleted, 0);
|
|
|
+ List<OrderItems> orderItems = orderItemsMapper.selectList(orderItemsLambdaQueryWrapper);
|
|
|
+ if (CollectionUtils.isNotEmpty(orderItems)){
|
|
|
+ auditProecessDTO.setOrderQuantity(orderItems.stream().filter(e ->e.getOrderQuantity() != null).map(OrderItems::getOrderQuantity).reduce(BigDecimal.ZERO,BigDecimal::add));
|
|
|
+ auditProecessDTO.setAmount(orderItems.stream().filter(e ->e.getAmount() != null).map(OrderItems::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
|
|
|
+ }else {
|
|
|
+ auditProecessDTO.setOrderQuantity(BigDecimal.ZERO);
|
|
|
+ auditProecessDTO.setAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ auditProecessDTO.setOrderRemark(salesOrder.getOrderRemark());
|
|
|
+ auditProecessDTO.setGrossProfit(salesOrder.getGrossProfit());
|
|
|
+ auditProecessDTO.setGrossProfitRate(salesOrder.getGrossProfitRate());
|
|
|
auditProecessDTO.setCorpId(salesOrder.getCorpId());
|
|
|
auditProecessDTO.setCheckType(order.getCheckType());
|
|
|
auditProecessDTO.setPathsLevelsList(auditPathsLevels);
|
|
|
@@ -697,6 +767,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if (order == null) {
|
|
|
throw new SecurityException("审批通过失败");
|
|
|
}
|
|
|
+ if (order.getStatus() == 3){
|
|
|
+ throw new SecurityException("订单已审批通过请勿重复审批");
|
|
|
+ }
|
|
|
order.setStatus(3);
|
|
|
baseMapper.updateById(order);
|
|
|
/**===========================end 审核通过修改销售订单信息==========================*/
|
|
|
@@ -706,7 +779,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
if (order.getBillType().equals("XS")) {
|
|
|
/**===========================Start 审核通过锁定库存=============================*/
|
|
|
//获取此销售订单下,所有明细的库存
|
|
|
- LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ /*LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
orderItemsLambdaQueryWrapper
|
|
|
.eq(OrderItems::getGoodType, 0)
|
|
|
.eq(OrderItems::getPid, id)
|
|
|
@@ -751,7 +824,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
throw new SecurityException("锁定库存失败: 更新失败");
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
|
|
|
/**===========================End 审核通过锁定库存=============================*/
|
|
|
@@ -830,9 +903,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
public void underReview(Long id) {
|
|
|
Order order = baseMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
- throw new SecurityException("审批驳回失败");
|
|
|
+ throw new SecurityException("审批失败");
|
|
|
}
|
|
|
- order.setStatus(0);
|
|
|
+ order.setStatus(2);
|
|
|
baseMapper.updateById(order);
|
|
|
}
|
|
|
|
|
|
@@ -844,7 +917,132 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
.eq(Order::getTenantId, AuthUtil.getTenantId());
|
|
|
Order order = baseMapper.selectOne(orderLambdaQueryWrapper);
|
|
|
if (order == null) {
|
|
|
- throw new SecurityException("审批驳回失败");
|
|
|
+ throw new SecurityException("未找到单据");
|
|
|
+ }
|
|
|
+ if (order.getStatus() == 0){
|
|
|
+ throw new SecurityException("订单已驳回或未提交审批,请勿重复操作");
|
|
|
+ }
|
|
|
+ //销售审核不通过释放库存
|
|
|
+ if (order.getBillType().equals("XS") && SecureUtil.getTenantId().equals("681169")){
|
|
|
+ /**===========================Start 审核通过锁定库存=============================*/
|
|
|
+ //获取此销售订单下,所有明细的库存
|
|
|
+ LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderItemsLambdaQueryWrapper
|
|
|
+ .eq(OrderItems::getGoodType, 0)
|
|
|
+ .eq(OrderItems::getPid, order.getId())
|
|
|
+ .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(SecureUtil.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.add(orderQuantity == null ? new BigDecimal("0") : orderQuantity));
|
|
|
+ //减少锁定库存
|
|
|
+ oneStock.setLockingQuantity(lockingQuantity == null ? new BigDecimal("0") : lockingQuantity.subtract(orderQuantity));
|
|
|
+ //更新库存
|
|
|
+ R r = stockGoodsClient.updateStock(oneStock);
|
|
|
+ if (!r.isSuccess()) {
|
|
|
+ throw new SecurityException("锁定库存失败: 更新失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ order.setStatus(0);
|
|
|
+ baseMapper.updateById(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void repealCancel(Long id) {
|
|
|
+ LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderLambdaQueryWrapper
|
|
|
+ .eq(Order::getId, id)
|
|
|
+ .eq(Order::getTenantId, AuthUtil.getTenantId());
|
|
|
+ Order order = baseMapper.selectOne(orderLambdaQueryWrapper);
|
|
|
+ if (order == null) {
|
|
|
+ throw new SecurityException("未找到订单");
|
|
|
+ }
|
|
|
+ if (order.getStatus() == 0){
|
|
|
+ throw new SecurityException("订单未开启审批");
|
|
|
+ }
|
|
|
+ if (order.getStatus() == 1){
|
|
|
+ throw new SecurityException("订单已经开启审批不能撤销");
|
|
|
+ }
|
|
|
+ //销售审核不通过释放库存
|
|
|
+ if (order.getBillType().equals("XS") && SecureUtil.getTenantId().equals("681169")){
|
|
|
+ /**===========================Start 审核通过锁定库存=============================*/
|
|
|
+ //获取此销售订单下,所有明细的库存
|
|
|
+ LambdaQueryWrapper<OrderItems> orderItemsLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderItemsLambdaQueryWrapper
|
|
|
+ .eq(OrderItems::getGoodType, 0)
|
|
|
+ .eq(OrderItems::getPid, order.getId())
|
|
|
+ .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(SecureUtil.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.add(orderQuantity == null ? new BigDecimal("0") : orderQuantity));
|
|
|
+ //减少锁定库存
|
|
|
+ oneStock.setLockingQuantity(lockingQuantity == null ? new BigDecimal("0") : lockingQuantity.subtract(orderQuantity));
|
|
|
+ //更新库存
|
|
|
+ R r = stockGoodsClient.updateStock(oneStock);
|
|
|
+ if (!r.isSuccess()) {
|
|
|
+ throw new SecurityException("锁定库存失败: 更新失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
order.setStatus(0);
|
|
|
baseMapper.updateById(order);
|