Browse Source

作废问题处理

yzc 1 year ago
parent
commit
56ab7f7ad3

+ 41 - 4
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -71,6 +71,7 @@ import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.entity.sale.vo.SaleQuotationVo;
+import com.fjhx.sale.flow.ContractFlow;
 import com.fjhx.sale.mapper.contract.ContractMapper;
 import com.fjhx.sale.mapper.contract.ContractProductBomMapper;
 import com.fjhx.sale.service.claim.ClaimContractService;
@@ -212,9 +213,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     private SubscribeDetailMapper subscribeDetailMapper;
     @Autowired
     private ContractProductBomMapper contractProductBomMapper;
-//
+    //
 //    @Autowired
 //    private ProduceOrderService produceOrderService;
+    @Autowired
+    private ContractFlow contractFlow;
 
     /**
      * 合同和样品单 下拉分页
@@ -1277,15 +1280,49 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     @DSTransactional
     @Override
     public void cancellation(ContractDto contractDto) {
+        Long id = contractDto.getId();
+        Contract contract = getById(id);
+        Assert.notEmpty(contract, "查询不到合同信息");
+
+        //修改流程审批状态
+        flowExampleService.update(q -> q
+                .eq(FlowExample::getId, contract.getFlowId())
+                .in(FlowExample::getStatus, 0, 1)
+                .set(FlowExample::getStatus, FlowStatusEnum.CANCELLATION.getKey())
+                .set(BasePo::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+        //如果审批中作废
+        if (Objects.equals(FlowStatusEnum1.UNDER_REVIEW.getKey(), contract.getStatus())) {
+            contractService.update(q -> q
+                    .eq(Contract::getId, id)
+                    .set(Contract::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
+                    .set(BasePo::getUpdateTime, new Date())
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+
+            //恢复原合同
+            Long oldContractId = contract.getOldContractId();
+            if (ObjectUtil.isNotEmpty(oldContractId)) {
+                contractService.update(q -> q
+                        .eq(Contract::getId, contract.getOldContractId())
+                        .set(Contract::getStatus, FlowStatusEnum1.PASS.getKey())
+                        .set(Contract::getUpdateTime, new Date())
+                        .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                );
+            }
+            return;
+        }
+
+
         contractService.update(q -> q
-                .eq(Contract::getId, contractDto.getId())
+                .eq(Contract::getId, id)
                 .set(Contract::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
                 .set(BasePo::getUpdateTime, new Date())
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
 
-        Contract contract = getById(contractDto.getId());
-        Assert.notEmpty(contract, "查询不到合同信息");
 
         contractCancelEditAvailableQuantity(contract);
     }

+ 31 - 9
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -460,6 +460,37 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
             throw new ServiceException("采购合同已付款,禁止作废");
         }
 
+        //修改流程审批状态
+        flowExampleService.update(q -> q
+                .eq(FlowExample::getId, purchase.getFlowId())
+                .in(FlowExample::getStatus, 0, 1)
+                .set(FlowExample::getStatus, FlowStatusEnum.CANCELLATION.getKey())
+                .set(BasePo::getUpdateTime, new Date())
+                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+        );
+
+        //如果审批中作废
+        if (Objects.equals(FlowStatusEnum1.UNDER_REVIEW.getKey(), purchase.getStatus())) {
+            ehsdPurchaseService.update(q -> q
+                    .eq(EhsdPurchase::getId, id)
+                    .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
+                    .set(EhsdPurchase::getUpdateTime, new Date())
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+            );
+
+            //恢复原合同
+            Long oldPurchaseId = purchase.getOldPurchaseId();
+            if (ObjectUtil.isNotEmpty(oldPurchaseId)) {
+                ehsdPurchaseService.update(q -> q
+                        .eq(BasePo::getId, oldPurchaseId)
+                        .set(EhsdPurchase::getStatus, FlowStatusEnum1.PASS.getKey())
+                        .set(BasePo::getUpdateTime, new Date())
+                        .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                );
+            }
+            return;
+        }
+
         this.update(q -> q
                 .eq(EhsdPurchase::getId, id)
                 .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
@@ -494,15 +525,6 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         }
         //同时删除待入库数据
         stockWaitService.remove(q -> q.eq(StockWait::getPurchaseId, purchase.getId()));
-        //修改流程审批状态
-        flowExampleService.update(q -> q
-                .eq(FlowExample::getId, purchase.getFlowId())
-                .in(FlowExample::getStatus, 0, 1)
-                .set(FlowExample::getStatus, FlowStatusEnum.CANCELLATION.getKey())
-                .set(BasePo::getUpdateTime, new Date())
-                .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-        );
-
 
         //修改申购明细状态
         updateSubscribeStatus(id);