|
@@ -1,36 +1,34 @@
|
|
package com.fjhx.ehsd.flow;
|
|
package com.fjhx.ehsd.flow;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
-import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
import com.fjhx.ehsd.entity.purchase.po.*;
|
|
import com.fjhx.ehsd.entity.purchase.po.*;
|
|
import com.fjhx.ehsd.service.purchase.*;
|
|
import com.fjhx.ehsd.service.purchase.*;
|
|
|
|
+import com.fjhx.ehsd.util.CodeEnum;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
|
|
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.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.contract.po.ContractProduct;
|
|
import com.fjhx.sale.entity.sample.po.SampleProduct;
|
|
import com.fjhx.sale.entity.sample.po.SampleProduct;
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
import com.fjhx.sale.service.sample.SampleProductService;
|
|
import com.fjhx.sale.service.sample.SampleProductService;
|
|
import com.obs.services.internal.ServiceException;
|
|
import com.obs.services.internal.ServiceException;
|
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* EHSD采购流程
|
|
* EHSD采购流程
|
|
@@ -39,15 +37,13 @@ import java.util.stream.Collectors;
|
|
* @DATE:2023/4/3 17:38
|
|
* @DATE:2023/4/3 17:38
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
|
|
+@DS(SourceConstant.EHSD)
|
|
public class EhsdPurchaseFlow extends FlowDelegate {
|
|
public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private EhsdPurchaseService purchaseService;
|
|
private EhsdPurchaseService purchaseService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private SampleProductService sampleProductService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
private EhsdPurchaseProductService purchaseProductService;
|
|
private EhsdPurchaseProductService purchaseProductService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -57,10 +53,13 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
private EhsdPurchaseArrivalService purchaseArrivalService;
|
|
private EhsdPurchaseArrivalService purchaseArrivalService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private EhsdPurchaseProductMountingsService purchaseProductMountingsService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private ContractProductService contractProductService;
|
|
private ContractProductService contractProductService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private EhsdPurchaseProductMountingsService purchaseProductMountingsService;
|
|
|
|
|
|
+ private SampleProductService sampleProductService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -75,10 +74,12 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
|
|
+ @DSTransactional
|
|
public Long start(Long flowId, JSONObject submitData) {
|
|
public Long start(Long flowId, JSONObject submitData) {
|
|
EhsdPurchase purchase = submitData.toJavaObject(EhsdPurchase.class);
|
|
EhsdPurchase purchase = submitData.toJavaObject(EhsdPurchase.class);
|
|
purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
|
+ purchase.setUserName(SecurityUtils.getUsername());
|
|
purchaseService.save(purchase);
|
|
purchaseService.save(purchase);
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
@@ -86,10 +87,12 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
List<EhsdPurchaseProductMountings> addMountingsList = new ArrayList<>();
|
|
List<EhsdPurchaseProductMountings> addMountingsList = new ArrayList<>();
|
|
if(CollectionUtils.isNotEmpty(purchaseProductList)){
|
|
if(CollectionUtils.isNotEmpty(purchaseProductList)){
|
|
for(EhsdPurchaseProduct s : purchaseProductList){//产品
|
|
for(EhsdPurchaseProduct s : purchaseProductList){//产品
|
|
|
|
+ long id = IdWorker.getId();
|
|
|
|
+ s.setId(id);
|
|
s.setPurchaseId(purchase.getId());
|
|
s.setPurchaseId(purchase.getId());
|
|
List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
if(CollectionUtils.isNotEmpty(purchaseProductMountingsList)){//产品配件
|
|
if(CollectionUtils.isNotEmpty(purchaseProductMountingsList)){//产品配件
|
|
- purchaseProductMountingsList.forEach(obj -> obj.setId(s.getId()));
|
|
|
|
|
|
+ purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
addMountingsList.addAll(purchaseProductMountingsList);
|
|
addMountingsList.addAll(purchaseProductMountingsList);
|
|
}
|
|
}
|
|
ObsFileUtil.saveFile(s.getFileList(),s.getId());
|
|
ObsFileUtil.saveFile(s.getFileList(),s.getId());
|
|
@@ -119,12 +122,45 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
* @param submitData 数据
|
|
* @param submitData 数据
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
|
|
+ @DSTransactional
|
|
public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
//通过业务ID查询采购数据
|
|
//通过业务ID查询采购数据
|
|
EhsdPurchase purchase = purchaseService.getById(businessId);
|
|
EhsdPurchase purchase = purchaseService.getById(businessId);
|
|
if(ObjectUtils.isEmpty(purchase)){
|
|
if(ObjectUtils.isEmpty(purchase)){
|
|
throw new ServiceException("采购单不存在,或已被删除");
|
|
throw new ServiceException("采购单不存在,或已被删除");
|
|
}
|
|
}
|
|
|
|
+ //查询采购产品
|
|
|
|
+ List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId,businessId));
|
|
|
|
+ List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
|
+ List<SampleProduct> upSampleProduct = new ArrayList<>();
|
|
|
|
+ for(EhsdPurchaseProduct p:purchaseProductList){
|
|
|
|
+ if(ObjectUtils.isNotEmpty(p.getDataResourceId())&&
|
|
|
|
+ p.getDataResource()== PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()){//如果采购的是外销合同
|
|
|
|
+ ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
|
|
|
|
+ BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getQuantity());
|
|
|
|
+ if(expendQuantity.compareTo(BigDecimal.ZERO)< 1){//小于0不让继续执行
|
|
|
|
+ throw new ServiceException("采购数量不得大于合同剩余采购数量");
|
|
|
|
+ }
|
|
|
|
+ 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.getQuantity());
|
|
|
|
+ if(expendQuantity.compareTo(BigDecimal.ZERO)< 1){//小于0不让继续执行
|
|
|
|
+ throw new ServiceException("采购数量不得大于合同剩余采购数量");
|
|
|
|
+ }
|
|
|
|
+ sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
|
+ upSampleProduct.add(sampleProduct);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(CollectionUtils.isNotEmpty(upContractProduct)){//扣减销售合同数量
|
|
|
|
+ contractProductService.updateBatchById(upContractProduct);
|
|
|
|
+ }
|
|
|
|
+ if(CollectionUtils.isNotEmpty(upSampleProduct)){//扣减样品单数量
|
|
|
|
+ sampleProductService.updateBatchById(upSampleProduct);
|
|
|
|
+ }
|
|
//修改采购状态为审批通过
|
|
//修改采购状态为审批通过
|
|
purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
purchase.setApprovedDate(new Date());
|
|
purchase.setApprovedDate(new Date());
|