|
@@ -6,27 +6,34 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fjhx.area.utils.CustomizeAreaUtil;
|
|
|
+import com.fjhx.common.entity.InOutBo;
|
|
|
import com.fjhx.common.enums.CodingRuleEnum;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
+import com.fjhx.common.enums.InOutType;
|
|
|
import com.fjhx.common.service.coding.CodingRuleService;
|
|
|
import com.fjhx.common.utils.Assert;
|
|
|
-import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
+import com.fjhx.item.enums.ProductAvailableRecordType;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
import com.fjhx.purchase.entity.subscribe.enums.SubscribeDetailStatusEnum;
|
|
|
import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
|
|
|
import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
|
|
|
import com.fjhx.sale.entity.contract.po.Contract;
|
|
|
-import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
|
|
|
-import com.fjhx.sale.entity.purchase.po.*;
|
|
|
+import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
|
|
|
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseArrival;
|
|
|
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
|
|
|
+import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
|
|
|
import com.fjhx.sale.entity.sample.po.Sample;
|
|
|
import com.fjhx.sale.entity.sample.po.SampleProduct;
|
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
import com.fjhx.sale.service.contract.ContractService;
|
|
|
-import com.fjhx.sale.service.purchase.*;
|
|
|
+import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
|
|
|
+import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
|
|
|
+import com.fjhx.sale.service.purchase.EhsdPurchaseService;
|
|
|
import com.fjhx.sale.service.sample.SampleProductService;
|
|
|
import com.fjhx.sale.service.sample.SampleService;
|
|
|
import com.ruoyi.common.annotation.LogicIgnore;
|
|
@@ -41,6 +48,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -50,7 +58,6 @@ import java.util.stream.Collectors;
|
|
|
* @DATE:2023/4/3 17:38
|
|
|
*/
|
|
|
@Component
|
|
|
-//@DS(SourceConstant.SALE)
|
|
|
public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
@Autowired
|
|
@@ -62,11 +69,11 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
@Autowired
|
|
|
private EhsdPurchaseProjectService purchaseProjectService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private EhsdPurchaseArrivalService purchaseArrivalService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EhsdPurchaseProductMountingsService purchaseProductMountingsService;
|
|
|
+// @Autowired
|
|
|
+// private EhsdPurchaseArrivalService purchaseArrivalService;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private EhsdPurchaseProductMountingsService purchaseProductMountingsService;
|
|
|
|
|
|
@Autowired
|
|
|
private ContractProductService contractProductService;
|
|
@@ -82,6 +89,8 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
private ContractService contractService;
|
|
|
@Autowired
|
|
|
private SampleService sampleService;
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
|
|
|
@Override
|
|
|
public String getFlowKey() {
|
|
@@ -128,73 +137,6 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 公共代码块--变更
|
|
|
- */
|
|
|
- public EhsdPurchaseDto updateStart(EhsdPurchaseDto purchase) {
|
|
|
- //赋值城市省份信息
|
|
|
- CustomizeAreaUtil.setAreaId(purchase);
|
|
|
- purchase.setSellCityId(purchase.getCityId());
|
|
|
- purchase.setSellCountryId(purchase.getCountryId());
|
|
|
- purchase.setSellProvinceId(purchase.getProvinceId());
|
|
|
-
|
|
|
-
|
|
|
- purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
- String nickName = SecurityUtils.getLoginUser().getUser().getNickName();
|
|
|
- purchase.setUserName(nickName);
|
|
|
- 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) {//产品
|
|
|
- long id = IdWorker.getId();
|
|
|
- s.setId(id);
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
|
|
|
- purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
|
- addMountingsList.addAll(purchaseProductMountingsList);
|
|
|
- }
|
|
|
- ObsFileUtil.saveAllFile(s.getFileList(), s.getId(), 0);
|
|
|
-
|
|
|
- if ("0".equals(purchase.getDataResource())) {
|
|
|
- //计算采购数量是否大于申购数量
|
|
|
- List<EhsdPurchaseProduct> purchaseDetailList1 = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
|
|
|
- s.getSubscribeDetailId()));
|
|
|
- //求和
|
|
|
- BigDecimal purchaseCount = purchaseDetailList1.stream()
|
|
|
- .map(EhsdPurchaseProduct::getQuantity)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- //计算历史采购数量+本次采购数量之和
|
|
|
- BigDecimal count = purchaseCount.add(s.getQuantity());
|
|
|
- //判断采购数量是否大于申购数量
|
|
|
- SubscribeDetail subscribeDetail = subscribeDetailService.getById(s.getSubscribeDetailId());
|
|
|
- if (count.compareTo(subscribeDetail.getCount()) > 0) {
|
|
|
- throw new ServiceException("采购数量不能大于申购数量");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 公共代码块--发起
|
|
|
*/
|
|
|
public EhsdPurchaseDto connStart(EhsdPurchaseDto purchase) {
|
|
@@ -220,21 +162,15 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
//产品(采购明细)
|
|
|
for (EhsdPurchaseProduct s : purchaseProductList) {
|
|
|
- long id;
|
|
|
- if (ObjectUtils.isNotEmpty(s.getId())) {
|
|
|
- id = s.getId();
|
|
|
- } else {
|
|
|
- id = IdWorker.getId();
|
|
|
- }
|
|
|
- s.setId(id);
|
|
|
+ s.setId(ObjectUtils.isNotEmpty(s.getId()) ? s.getId() : IdWorker.getId());
|
|
|
s.setPurchaseId(purchase.getId());
|
|
|
- List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
- if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
|
|
|
- purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
|
- }
|
|
|
- //修改或删除数据
|
|
|
- purchaseProductMountingsService.editLinked(purchaseProductMountingsList,
|
|
|
- EhsdPurchaseProductMountings::getPurchaseProductId, id);
|
|
|
+// List<EhsdPurchaseProductMountings> purchaseProductMountingsList = s.getPurchaseProductMountingsList();
|
|
|
+// if (CollectionUtils.isNotEmpty(purchaseProductMountingsList)) {//产品配件
|
|
|
+// purchaseProductMountingsList.forEach(obj -> obj.setPurchaseProductId(id));
|
|
|
+// }
|
|
|
+// //修改或删除数据
|
|
|
+// purchaseProductMountingsService.editLinked(purchaseProductMountingsList,
|
|
|
+// EhsdPurchaseProductMountings::getPurchaseProductId, id);
|
|
|
|
|
|
if ("0".equals(purchase.getDataResource())) {
|
|
|
//计算采购数量是否大于申购数量
|
|
@@ -262,11 +198,11 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
}
|
|
|
purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
|
|
|
|
|
|
- //到货
|
|
|
- for (EhsdPurchaseArrival s : purchaseArrivalList) {
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- }
|
|
|
- purchaseArrivalService.editLinked(purchaseArrivalList, EhsdPurchaseArrival::getPurchaseId, purchase.getId());
|
|
|
+// //到货
|
|
|
+// for (EhsdPurchaseArrival s : purchaseArrivalList) {
|
|
|
+// s.setPurchaseId(purchase.getId());
|
|
|
+// }
|
|
|
+// purchaseArrivalService.editLinked(purchaseArrivalList, EhsdPurchaseArrival::getPurchaseId, purchase.getId());
|
|
|
|
|
|
return purchase;
|
|
|
}
|
|
@@ -287,33 +223,30 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
}
|
|
|
//查询采购产品
|
|
|
List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId, businessId));
|
|
|
- List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
+// 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 (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) < 0) {//小于0不让继续执行
|
|
|
// throw new ServiceException("采购数量不得大于合同剩余采购数量,请驳回审批修改");
|
|
|
// }
|
|
|
- contractProduct.setExpendQuantity(expendQuantity);
|
|
|
- upContractProduct.add(contractProduct);
|
|
|
- }
|
|
|
+// 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) < 0) {//小于0不让继续执行
|
|
|
-// throw new ServiceException("采购数量不得大于合同剩余采购数量,请驳回审批修改");
|
|
|
- }
|
|
|
sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
upSampleProduct.add(sampleProduct);
|
|
|
}
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
- contractProductService.updateBatchById(upContractProduct);
|
|
|
- }
|
|
|
+// if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
+// contractProductService.updateBatchById(upContractProduct);
|
|
|
+// }
|
|
|
if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
|
|
|
sampleProductService.updateBatchById(upSampleProduct);
|
|
|
}
|
|
@@ -344,6 +277,19 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
}
|
|
|
subscribeDetailService.updateBatchById(subscribeDetails);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ List<InOutBo> inOutBoList = new ArrayList<>();
|
|
|
+ for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
|
|
|
+ //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
|
|
|
+ if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
+ inOutBo.setProductId(purchaseProduct.getProductId());
|
|
|
+ inOutBo.setQuantity(purchaseProduct.getQuantity());
|
|
|
+ inOutBoList.add(inOutBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productInfoService.editAvailableQuantity(inOutBoList, InOutType.IN, businessId, ProductAvailableRecordType.PURCHASE_PASS);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -384,6 +330,9 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 作废
|
|
|
+ */
|
|
|
@Override
|
|
|
public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
super.cancellation(flowId, businessId, flowStatus);
|
|
@@ -393,5 +342,19 @@ public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
.set(BasePo::getUpdateTime, new Date())
|
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
);
|
|
|
+
|
|
|
+ //修改可用库存
|
|
|
+ List<InOutBo> inOutBoList = new ArrayList<>();
|
|
|
+ List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getPurchaseId, businessId));
|
|
|
+ for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
|
|
|
+ //如果数据来源是申购 操作可用库存(可用库存 = 当前可用库存 + 采购明细数量)
|
|
|
+ if (Objects.equals(purchaseProduct.getDataResource(), PurchaseDataResourceEnum.DATA_RESOURCE_0)) {
|
|
|
+ InOutBo inOutBo = new InOutBo();
|
|
|
+ inOutBo.setProductId(purchaseProduct.getProductId());
|
|
|
+ inOutBo.setQuantity(purchaseProduct.getQuantity());
|
|
|
+ inOutBoList.add(inOutBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ productInfoService.editAvailableQuantity(inOutBoList, InOutType.OUT, businessId, ProductAvailableRecordType.PURCHASE_CANCEL);
|
|
|
}
|
|
|
}
|