|
@@ -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
|
|
|
-
|
|
|
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 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);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
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());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
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<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());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- 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) {
|
|
|
-
|
|
|
- }
|
|
|
sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
upSampleProduct.add(sampleProduct);
|
|
|
}
|
|
|
}
|
|
|
- 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);
|
|
|
}
|
|
|
}
|