|
@@ -0,0 +1,135 @@
|
|
|
+package com.sd.business.flow;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.sd.business.entity.apply.po.ApplyBuy;
|
|
|
+import com.sd.business.entity.apply.po.ApplyBuyBom;
|
|
|
+import com.sd.business.entity.purchase.enums.PurchaseEnums;
|
|
|
+import com.sd.business.entity.purchase.po.Purchase;
|
|
|
+import com.sd.business.entity.purchase.po.PurchaseBom;
|
|
|
+import com.sd.business.entity.purchase.vo.PurchaseBomVo;
|
|
|
+import com.sd.business.entity.purchase.vo.PurchaseVo;
|
|
|
+import com.sd.business.service.apply.ApplyBuyBomService;
|
|
|
+import com.sd.business.service.apply.ApplyBuyService;
|
|
|
+import com.sd.business.service.purchase.PurchaseBomService;
|
|
|
+import com.sd.business.service.purchase.PurchaseService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发起流程
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PurchaseFlow extends FlowDelegate {
|
|
|
+ @Autowired
|
|
|
+ private PurchaseService purchaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseBomService purchaseBomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplyBuyService applyBuyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplyBuyBomService applyBuyBomService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "purchase";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流程发起
|
|
|
+ */
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+ PurchaseVo purchase = submitData.toJavaObject(PurchaseVo.class);
|
|
|
+
|
|
|
+ //判断是否存在采购ID,如果存在说明已经暂存
|
|
|
+ if (ObjectUtil.isNotEmpty(purchase.getId())){
|
|
|
+ purchase.setFlowStatus(PurchaseEnums.IN_PROGRESS.getKey());
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ //修改采购暂存表的数据
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+
|
|
|
+ //删除采购bom表的数据
|
|
|
+ purchaseBomService.remove(Wrappers.<PurchaseBom>lambdaQuery().eq(PurchaseBom::getPurchaseId,purchase.getId()));
|
|
|
+
|
|
|
+ //获取到采购bom表的数据
|
|
|
+ List<PurchaseBom> purchaseBomList = purchase.getPurchaseBomList();
|
|
|
+ //添加采购bom表的数据
|
|
|
+ purchaseBomList.forEach(purchaseBom -> purchaseBom.setPurchaseId(purchase.getId()));
|
|
|
+ purchaseBomService.saveBatch(purchaseBomList);
|
|
|
+ }else {
|
|
|
+ //修改状态为进行中
|
|
|
+ purchase.setFlowStatus(PurchaseEnums.IN_PROGRESS.getKey());
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ purchaseService.save(purchase);
|
|
|
+ //获取到采购bom表的数据
|
|
|
+ List<PurchaseBom> purchaseBomList = purchase.getPurchaseBomList();
|
|
|
+ //添加采购bom表的数据
|
|
|
+ purchaseBomList.forEach(purchaseBom -> purchaseBom.setPurchaseId(purchase.getId()));
|
|
|
+ purchaseBomService.saveBatch(purchaseBomList);
|
|
|
+ }
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流程结束
|
|
|
+ * @param flowId
|
|
|
+ * @param businessId
|
|
|
+ * @param submitData
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
+ Purchase purchase = purchaseService.getById(businessId);
|
|
|
+ purchase.setFlowStatus(PurchaseEnums.PASSED.getKey());
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ //修改采购暂存表的数据
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+
|
|
|
+ //修改申购表的状态为已申购
|
|
|
+ ApplyBuy applyBuy = new ApplyBuy();
|
|
|
+ applyBuy.setId(purchase.getApplyBuyId());
|
|
|
+ applyBuy.setFlowStatus(4);
|
|
|
+ applyBuyService.updateById(applyBuy);
|
|
|
+
|
|
|
+
|
|
|
+ //查询采购合同bom表的信息
|
|
|
+ List<PurchaseBom> purchaseBoms = purchaseBomService.list(Wrappers.<PurchaseBom>lambdaQuery().eq(PurchaseBom::getPurchaseId, businessId));
|
|
|
+
|
|
|
+ List<ApplyBuyBom> applyBuyBomList = new ArrayList<>();
|
|
|
+ //修改申购bom表的采购数量
|
|
|
+ for (PurchaseBom purchaseBom : purchaseBoms) {
|
|
|
+ ApplyBuyBom applyBuyBom = new ApplyBuyBom();
|
|
|
+ applyBuyBom.setPurchaseQuantity(purchaseBom.getPurchaseQuantity());
|
|
|
+ applyBuyBom.setId(purchaseBom.getApplyBuyBomId());
|
|
|
+ applyBuyBomList.add(applyBuyBom);
|
|
|
+ }
|
|
|
+ applyBuyBomService.updateBatchById(applyBuyBomList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流程驳回
|
|
|
+ * @param flowId
|
|
|
+ * @param businessId
|
|
|
+ * @param flowStatus
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ Purchase purchase = purchaseService.getById(businessId);
|
|
|
+ purchase.setFlowStatus(PurchaseEnums.REJECTED.getKey());
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ //修改采购暂存表的数据
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+ }
|
|
|
+}
|