Browse Source

问题处理

yzc 1 year ago
parent
commit
57a3007046

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java

@@ -52,4 +52,13 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
      * 分类ID集合
      */
     private String productCategoryIds;
+
+    /**
+     * 产品编号
+     */
+    private String productCode;
+    /**
+     * 产品规格
+     */
+    private String productSpec;
 }

+ 125 - 130
hx-sale/src/main/java/com/fjhx/sale/flow/PurchaseFlow.java

@@ -2,45 +2,18 @@ package com.fjhx.sale.flow;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
-import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.fjhx.common.constant.SourceConstant;
-import com.fjhx.common.enums.CodingRuleEnum;
 import com.fjhx.common.service.coding.CodingRuleService;
 import com.fjhx.flow.core.FlowDelegate;
-import com.fjhx.flow.core.FlowThreadLocalUtil;
 import com.fjhx.flow.enums.FlowStatusEnum;
-import com.fjhx.flow.enums.HandleTypeEnum;
-import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
-import com.fjhx.purchase.entity.purchase.enums.PurchaseDetailStatusEnum;
-import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
-import com.fjhx.purchase.entity.purchase.po.Purchase;
-import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
-import com.fjhx.purchase.entity.purchase.po.PurchaseOtherFee;
-import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
-import com.fjhx.purchase.entity.subscribe.enums.SubscribeDetailStatusEnum;
-import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.service.purchase.PurchaseDetailService;
 import com.fjhx.purchase.service.purchase.PurchaseOtherFeeService;
 import com.fjhx.purchase.service.purchase.PurchaseService;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
-import com.fjhx.sale.entity.contract.po.ContractProduct;
-import com.fjhx.sale.entity.sample.po.SampleProduct;
 import com.fjhx.sale.service.contract.ContractProductService;
 import com.fjhx.sale.service.sample.SampleProductService;
-import com.ruoyi.common.core.domain.BasePo;
-import com.ruoyi.common.exception.ServiceException;
-import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
 /**
  * EHSD采购流程
  *
@@ -69,6 +42,8 @@ public class PurchaseFlow extends FlowDelegate {
     private PurchaseOtherFeeService purchaseOtherFeeService;
     @Autowired
     private SubscribeDetailService subscribeDetailService;
+    @Autowired
+    private EhsdPurchaseFlow ehsdPurchaseFlow;
 
     @Override
     public String getFlowKey() {
@@ -84,49 +59,50 @@ public class PurchaseFlow extends FlowDelegate {
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-        DynamicDataSourceContextHolder.push(SourceConstant.PURCHASE);
-        PurchaseVo purchase = submitData.toJavaObject(PurchaseVo.class);
-//        purchase.setCode(CodeEnum.PURCHASE.getCode());
-        purchase.setCode(codingRuleService.createCode(CodingRuleEnum.PURCHASE.getKey(), null));
-        purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
-        purchase.setFlowId(flowId);
-        purchaseService.save(purchase);
-        List<PurchaseDetail> purchaseDetailList = purchase.getPurchaseDetailList();
-        if (CollectionUtils.isNotEmpty(purchaseDetailList)) {
-            for (PurchaseDetail s : purchaseDetailList) {
-                s.setPurchaseId(purchase.getId());
-            }
-            purchaseDetailService.saveBatch(purchaseDetailList);
-            //修改申购明细的采购状态
-            for (PurchaseDetail purchaseDetail : purchaseDetailList) {
-                //如果来源是申购
-                if (ObjectUtils.isEmpty(purchaseDetail.getDataResource())) {
-                    //计算已经采购的数量
-                    List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q
-                            .eq(PurchaseDetail::getSubscribeDetailId, purchaseDetail.getSubscribeDetailId())
-                    );
-                    BigDecimal pdCount = purchaseDetails.stream().map(PurchaseDetail::getCount).reduce(BigDecimal.ZERO, BigDecimal::add);
-                    SubscribeDetail subscribeDetail = subscribeDetailService.getById(purchaseDetail.getSubscribeDetailId());
-                    if (pdCount.compareTo(subscribeDetail.getCount()) >= 0) {
-                        //修改为已采购
-                        subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
-                    } else {
-                        //修改为部分采购
-                        subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
-                    }
-                    subscribeDetailService.updateById(subscribeDetail);
-                }
-            }
-
-        }
-        //保存其他费用信息
-        List<PurchaseOtherFee> otherFeeList = purchase.getOtherFeeList();
-        if (ObjectUtils.isNotEmpty(otherFeeList)) {
-            otherFeeList.forEach(item -> item.setPurchaseId(purchase.getId()));
-            purchaseOtherFeeService.saveBatch(otherFeeList);
-        }
-        DynamicDataSourceContextHolder.poll();
-        return purchase.getId();
+//        DynamicDataSourceContextHolder.push(SourceConstant.PURCHASE);
+//        PurchaseVo purchase = submitData.toJavaObject(PurchaseVo.class);
+////        purchase.setCode(CodeEnum.PURCHASE.getCode());
+//        purchase.setCode(codingRuleService.createCode(CodingRuleEnum.PURCHASE.getKey(), null));
+//        purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
+//        purchase.setFlowId(flowId);
+//        purchaseService.save(purchase);
+//        List<PurchaseDetail> purchaseDetailList = purchase.getPurchaseDetailList();
+//        if (CollectionUtils.isNotEmpty(purchaseDetailList)) {
+//            for (PurchaseDetail s : purchaseDetailList) {
+//                s.setPurchaseId(purchase.getId());
+//            }
+//            purchaseDetailService.saveBatch(purchaseDetailList);
+//            //修改申购明细的采购状态
+//            for (PurchaseDetail purchaseDetail : purchaseDetailList) {
+//                //如果来源是申购
+//                if (ObjectUtils.isEmpty(purchaseDetail.getDataResource())) {
+//                    //计算已经采购的数量
+//                    List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q
+//                            .eq(PurchaseDetail::getSubscribeDetailId, purchaseDetail.getSubscribeDetailId())
+//                    );
+//                    BigDecimal pdCount = purchaseDetails.stream().map(PurchaseDetail::getCount).reduce(BigDecimal.ZERO, BigDecimal::add);
+//                    SubscribeDetail subscribeDetail = subscribeDetailService.getById(purchaseDetail.getSubscribeDetailId());
+//                    if (pdCount.compareTo(subscribeDetail.getCount()) >= 0) {
+//                        //修改为已采购
+//                        subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
+//                    } else {
+//                        //修改为部分采购
+//                        subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
+//                    }
+//                    subscribeDetailService.updateById(subscribeDetail);
+//                }
+//            }
+//
+//        }
+//        //保存其他费用信息
+//        List<PurchaseOtherFee> otherFeeList = purchase.getOtherFeeList();
+//        if (ObjectUtils.isNotEmpty(otherFeeList)) {
+//            otherFeeList.forEach(item -> item.setPurchaseId(purchase.getId()));
+//            purchaseOtherFeeService.saveBatch(otherFeeList);
+//        }
+//        DynamicDataSourceContextHolder.poll();
+//        return purchase.getId();
+        return ehsdPurchaseFlow.start(flowId, submitData);
     }
 
     /**
@@ -139,68 +115,87 @@ public class PurchaseFlow extends FlowDelegate {
     @Override
     @DSTransactional
     public void end(Long flowId, Long businessId, JSONObject submitData) {
-        //通过业务ID查询采购数据
-        Purchase purchase = purchaseService.getById(businessId);
-        if (ObjectUtils.isEmpty(purchase)) {
-            throw new ServiceException("采购单不存在");
-        }
-        //查询采购产品
-        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
-        List<ContractProduct> upContractProduct = new ArrayList<>();
-        List<SampleProduct> upSampleProduct = new ArrayList<>();
-        for (PurchaseDetail p : purchaseDetailList) {
-            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
-                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
-                ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
-                BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
-                if (expendQuantity.compareTo(BigDecimal.ZERO) < 0) {
-                    //外销合同-交接单采购 如果采购数量大于大于合同数量 将待处理数量改为0
-                    expendQuantity = BigDecimal.ZERO;
-                }
-                contractProduct.setExpendQuantity(expendQuantity);
-                upContractProduct.add(contractProduct);
-            }
-            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
-                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
-                SampleProduct sampleProduct = sampleProductService.getById(p.getDataResourceId());
-                BigDecimal expendQuantity = sampleProduct.getExpendQuantity().subtract(p.getCount());
-                if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
-//                    throw new ServiceException("采购数量不得大于合同剩余采购数量");
-                    expendQuantity = BigDecimal.ZERO;
-                }
-                sampleProduct.setExpendQuantity(expendQuantity);
-                upSampleProduct.add(sampleProduct);
-            }
-        }
-        if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
-            contractProductService.updateBatchById(upContractProduct);
-        }
-        if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
-            sampleProductService.updateBatchById(upSampleProduct);
-        }
-        //修改采购状态为审批通过
-        purchase.setPurchaseStatus(PurchaseStatusEnum.PASS.getKey());
-        purchase.setApprovedDate(new Date());
-        purchaseService.updateById(purchase);
-        //修改采购明细为待采购
-        PurchaseDetail detail = new PurchaseDetail();
-        detail.setStatus(PurchaseDetailStatusEnum.PASS.getKey());
-        purchaseDetailService.update(detail, Wrappers.<PurchaseDetail>query()
-                .lambda().eq(PurchaseDetail::getPurchaseId, purchase.getId()));
+//        //通过业务ID查询采购数据
+//        Purchase purchase = purchaseService.getById(businessId);
+//        if (ObjectUtils.isEmpty(purchase)) {
+//            throw new ServiceException("采购单不存在");
+//        }
+//        //查询采购产品
+//        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
+//        List<ContractProduct> upContractProduct = new ArrayList<>();
+//        List<SampleProduct> upSampleProduct = new ArrayList<>();
+//        for (PurchaseDetail p : purchaseDetailList) {
+//            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
+//                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
+//                ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
+//                BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
+//                if (expendQuantity.compareTo(BigDecimal.ZERO) < 0) {
+//                    //外销合同-交接单采购 如果采购数量大于大于合同数量 将待处理数量改为0
+//                    expendQuantity = BigDecimal.ZERO;
+//                }
+//                contractProduct.setExpendQuantity(expendQuantity);
+//                upContractProduct.add(contractProduct);
+//            }
+//            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
+//                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
+//                SampleProduct sampleProduct = sampleProductService.getById(p.getDataResourceId());
+//                BigDecimal expendQuantity = sampleProduct.getExpendQuantity().subtract(p.getCount());
+//                if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
+////                    throw new ServiceException("采购数量不得大于合同剩余采购数量");
+//                    expendQuantity = BigDecimal.ZERO;
+//                }
+//                sampleProduct.setExpendQuantity(expendQuantity);
+//                upSampleProduct.add(sampleProduct);
+//            }
+//        }
+//        if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
+//            contractProductService.updateBatchById(upContractProduct);
+//        }
+//        if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
+//            sampleProductService.updateBatchById(upSampleProduct);
+//        }
+//        //修改采购状态为审批通过
+//        purchase.setPurchaseStatus(PurchaseStatusEnum.PASS.getKey());
+//        purchase.setApprovedDate(new Date());
+//        purchaseService.updateById(purchase);
+//        //修改采购明细为待采购
+//        PurchaseDetail detail = new PurchaseDetail();
+//        detail.setStatus(PurchaseDetailStatusEnum.PASS.getKey());
+//        purchaseDetailService.update(detail, Wrappers.<PurchaseDetail>query()
+//                .lambda().eq(PurchaseDetail::getPurchaseId, purchase.getId()));
+        ehsdPurchaseFlow.end(flowId, businessId, submitData);
     }
 
-    /**
-     * 驳回方法
-     */
-    public void reject() {
-        if (HandleTypeEnum.REJECT.equals(FlowThreadLocalUtil.getHandleTypeEnum())) {
-            purchaseService.update(q -> q
-                    .eq(Purchase::getId, FlowThreadLocalUtil.getBusinessId())
-                    .set(Purchase::getPurchaseStatus, 20)
-                    .set(Purchase::getUpdateTime, new Date())
-                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-            );
-        }
+//    /**
+//     * 驳回方法
+//     */
+//    public void reject() {
+//        if (HandleTypeEnum.REJECT.equals(FlowThreadLocalUtil.getHandleTypeEnum())) {
+//            purchaseService.update(q -> q
+//                    .eq(Purchase::getId, FlowThreadLocalUtil.getBusinessId())
+//                    .set(Purchase::getPurchaseStatus, 20)
+//                    .set(Purchase::getUpdateTime, new Date())
+//                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+//            );
+//        }
+//    }
+
+
+    @Override
+    public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
+        super.relaunch(flowId, businessId, flowStatus, submitData);
+        ehsdPurchaseFlow.relaunch(flowId, businessId, flowStatus, submitData);
+    }
+
+    @Override
+    public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+        super.reject(flowId, businessId, flowStatus);
+        ehsdPurchaseFlow.reject(flowId, businessId, flowStatus);
     }
 
+    @Override
+    public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
+        super.cancellation(flowId, businessId, flowStatus);
+        ehsdPurchaseFlow.cancellation(flowId, businessId, flowStatus);
+    }
 }

+ 4 - 2
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -229,10 +229,10 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
             //申购来源
             List<EhsdPurchaseProductVo> subscribeSource = ehsdPurchaseProductVos.stream().filter(item -> Objects.equals(item.getDataResource(), 0)).collect(Collectors.toList());
             if (ObjectUtils.isNotEmpty(subscribeSource)) {
-                List<Long> subscribeDetailSourceIds = subscribeSource.stream().map(EhsdPurchaseProductVo::getDataResourceId).distinct().collect(Collectors.toList());
+                List<Long> subscribeDetailSourceIds = subscribeSource.stream().map(EhsdPurchaseProductVo::getSubscribeDetailId).distinct().collect(Collectors.toList());
                 Map<Long, SubscribeDetail> contractProductMap = subscribeDetailService.mapKEntity(SubscribeDetail::getId, q -> q.in(SubscribeDetail::getId, subscribeDetailSourceIds));
                 for (EhsdPurchaseProductVo ehsdPurchaseProductVo : subscribeSource) {
-                    SubscribeDetail subscribeDetail = contractProductMap.get(ehsdPurchaseProductVo.getDataResourceId());
+                    SubscribeDetail subscribeDetail = contractProductMap.get(ehsdPurchaseProductVo.getSubscribeDetailId());
                     BigDecimal count = subscribeDetail.getCount();
                     //获取已采购数量
                     List<EhsdPurchaseProduct> ehsdPurchaseProductList1 = ehsdPurchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getDataResource, 0).eq(EhsdPurchaseProduct::getSubscribeDetailId, subscribeDetail.getId()));
@@ -265,6 +265,8 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //赋值产品信息
         productInfoService.attributeAssign(ehsdPurchaseProductVos, EhsdPurchaseProductVo::getProductId, (item, product) -> {
             item.setDefinition(product.getDefinition());
+            item.setProductCode(product.getCode());
+            item.setProductSpec(product.getSpec());
         });
         result.setEhsdPurchaseProductList(ehsdPurchaseProductVos);
         //赋值出货明细