|
@@ -0,0 +1,134 @@
|
|
|
+package com.fjhx.ehsd.flow;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.ehsd.entity.purchase.po.*;
|
|
|
+import com.fjhx.ehsd.service.purchase.*;
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
+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.service.purchase.PurchaseDetailService;
|
|
|
+import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
+import com.fjhx.purchase.util.code.CodeEnum;
|
|
|
+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.obs.services.internal.ServiceException;
|
|
|
+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;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * EHSD采购流程
|
|
|
+ *
|
|
|
+ * @Author:caozj
|
|
|
+ * @DATE:2023/4/3 17:38
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseService purchaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SampleProductService sampleProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProductService purchaseProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProjectService purchaseProjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseArrivalService purchaseArrivalService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContractProductService contractProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProductMountingsService purchaseProductMountingsService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "ehsd_purchase_flow";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起流程
|
|
|
+ * @param flowId 流程ID
|
|
|
+ * @param submitData 采购数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+ EhsdPurchase purchase = submitData.toJavaObject(EhsdPurchase.class);
|
|
|
+ purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ purchaseService.save(purchase);
|
|
|
+ List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
+ List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
+ List<EhsdPurchaseArrival> purchaseArrivalList = purchase.getPurchaseArrivalList();
|
|
|
+ List<EhsdPurchaseProductMountings> addMountingsList = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(purchaseProductList)){
|
|
|
+ for(EhsdPurchaseProduct s : purchaseProductList){//产品
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
+ if(CollectionUtils.isNotEmpty(purchaseProductMountingsList)){//产品配件
|
|
|
+ purchaseProductMountingsList.forEach(obj -> obj.setId(s.getId()));
|
|
|
+ addMountingsList.addAll(purchaseProductMountingsList);
|
|
|
+ }
|
|
|
+ ObsFileUtil.saveFile(s.getFileList(),s.getId());
|
|
|
+ }
|
|
|
+ purchaseProductService.saveBatch(purchaseProductList);
|
|
|
+ purchaseProductMountingsService.saveBatch(addMountingsList);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(purchaseProjectList)){//到货
|
|
|
+ for(EhsdPurchaseProject s : purchaseProjectList){
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ }
|
|
|
+ purchaseProjectService.saveBatch(purchaseProjectList);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(purchaseArrivalList)){//收费项目
|
|
|
+ for(EhsdPurchaseArrival s : purchaseArrivalList){
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ }
|
|
|
+ purchaseArrivalService.saveBatch(purchaseArrivalList);
|
|
|
+ }
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束流程
|
|
|
+ * @param flowId 流程ID
|
|
|
+ * @param businessId 业务ID
|
|
|
+ * @param submitData 数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+ //通过业务ID查询采购数据
|
|
|
+ EhsdPurchase purchase = purchaseService.getById(businessId);
|
|
|
+ if(ObjectUtils.isEmpty(purchase)){
|
|
|
+ throw new ServiceException("采购单不存在,或已被删除");
|
|
|
+ }
|
|
|
+ //修改采购状态为审批通过
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
|
+ purchase.setApprovedDate(new Date());
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|