|
@@ -64,281 +64,281 @@ import java.util.stream.Collectors;
|
|
|
@Component
|
|
|
public class EhsdPurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
- @Autowired
|
|
|
- private EhsdPurchaseService purchaseService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EhsdPurchaseProductService purchaseProductService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private EhsdPurchaseProjectService purchaseProjectService;
|
|
|
- @Autowired
|
|
|
- private SampleProductService sampleProductService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CodingRuleService codingRuleService;
|
|
|
- @Autowired
|
|
|
- private SubscribeDetailService subscribeDetailService;
|
|
|
- @Autowired
|
|
|
- private ContractService contractService;
|
|
|
- @Autowired
|
|
|
- private SampleService sampleService;
|
|
|
- @Autowired
|
|
|
- private ProductInfoService productInfoService;
|
|
|
- @Autowired
|
|
|
- private StockWaitService stockWaitService;
|
|
|
- @Autowired
|
|
|
- private StockWaitDetailsService stockWaitDetailsService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getFlowKey() {
|
|
|
- return "purchase_flow";
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发起流程
|
|
|
- *
|
|
|
- * @param flowId 流程ID
|
|
|
- * @param submitData 采购数据
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Long start(Long flowId, JSONObject submitData) {
|
|
|
- EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
- purchase.setId(null);//清空id防止前端误传
|
|
|
- purchase.setFlowId(flowId);//赋值流程id
|
|
|
- purchase.setProcessInstanceId(getFlowKey());//赋值流程key
|
|
|
-
|
|
|
- //赋值产品归属公司
|
|
|
- Long companyId = purchase.getCompanyId();
|
|
|
- if (ObjectUtil.isEmpty(companyId)) {
|
|
|
- purchase.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
- }
|
|
|
-
|
|
|
- Integer dataResource = purchase.getDataResource();
|
|
|
- if (ObjectUtils.isEmpty(dataResource)) {
|
|
|
- throw new ServiceException("数据来源类型不能为空!");
|
|
|
- }
|
|
|
-
|
|
|
- //采购单编号生成
|
|
|
- if (0 == dataResource) {
|
|
|
- //手动创建 编号规则
|
|
|
- purchase.setCode(codingRuleService.createCode(CodingRuleEnum.EHSD_PURCHASE.getKey(), null));
|
|
|
- } else if (1 == dataResource) {
|
|
|
- //合同 编号规则
|
|
|
- Contract contract = contractService.getById(purchase.getDataResourceId());
|
|
|
- Assert.notEmpty(contract, "查询不到合同信息,无法生成编号");
|
|
|
- long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, contract.getId()));
|
|
|
- purchase.setCode(contract.getCode() + "-" + (count + 1));
|
|
|
- } else if (2 == dataResource) {
|
|
|
- //样品单 编号规则
|
|
|
- Sample sample = sampleService.getById(purchase.getDataResourceId());
|
|
|
- Assert.notEmpty(sample, "查询不到样品单信息,无法生成编号");
|
|
|
- long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, sample.getId()));
|
|
|
- purchase.setCode(sample.getCode() + "-" + (count + 1));
|
|
|
- } else {
|
|
|
- throw new ServiceException("未知数据来源类型");
|
|
|
- }
|
|
|
-
|
|
|
- //公共代码
|
|
|
- purchase = connStart(purchase);
|
|
|
-
|
|
|
- return purchase.getId();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 公共代码块--发起
|
|
|
- */
|
|
|
- public EhsdPurchaseDto connStart(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.saveOrUpdate(purchase);
|
|
|
-
|
|
|
- List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
- List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
-
|
|
|
- //防止空指针
|
|
|
- purchaseProjectList = (purchaseProjectList == null ? new ArrayList<>() : purchaseProjectList);
|
|
|
- purchaseProductList = (purchaseProductList == null ? new ArrayList<>() : purchaseProductList);
|
|
|
-
|
|
|
- //产品(采购明细)
|
|
|
- for (EhsdPurchaseProduct s : purchaseProductList) {
|
|
|
- s.setId(ObjectUtils.isNotEmpty(s.getId()) ? s.getId() : IdWorker.getId());
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- }
|
|
|
- //修改或删除数据
|
|
|
- purchaseProductService.editLinked(purchaseProductList, EhsdPurchaseProduct::getPurchaseId, purchase.getId());
|
|
|
-
|
|
|
- //收费项目
|
|
|
- for (EhsdPurchaseProject s : purchaseProjectList) {
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
- }
|
|
|
- purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
|
|
|
-
|
|
|
- return purchase;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 结束流程
|
|
|
- *
|
|
|
- * @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("采购单不存在,或已被删除");
|
|
|
- }
|
|
|
- //查询采购产品
|
|
|
- List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId, businessId));
|
|
|
- List<SampleProduct> upSampleProduct = new ArrayList<>();
|
|
|
- for (EhsdPurchaseProduct p : purchaseProductList) {
|
|
|
- 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());
|
|
|
- sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
- upSampleProduct.add(sampleProduct);
|
|
|
- }
|
|
|
- }
|
|
|
- if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
|
|
|
- sampleProductService.updateBatchById(upSampleProduct);
|
|
|
- }
|
|
|
- //修改采购状态为审批通过
|
|
|
- purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
|
- purchase.setApprovedDate(new Date());
|
|
|
- purchaseService.updateById(purchase);
|
|
|
-
|
|
|
- if ("0".equals(purchase.getDataResource())) {
|
|
|
- //修改申购明细状态
|
|
|
- List<EhsdPurchaseProduct> purchaseDetailList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getProductId, businessId));
|
|
|
- List<Long> subscribeDetailIds = purchaseDetailList.stream().map(EhsdPurchaseProduct::getSubscribeDetailId).collect(Collectors.toList());
|
|
|
- List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
|
|
|
- for (SubscribeDetail subscribeDetail : subscribeDetails) {
|
|
|
- //获取申购明细下的所有采购记录 计算已采购数
|
|
|
- List<EhsdPurchaseProduct> purchaseDetails = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
|
|
|
- subscribeDetail.getId()).eq(EhsdPurchaseProduct::getProductId, subscribeDetail.getProductId()));
|
|
|
- BigDecimal count = purchaseDetails.stream()
|
|
|
- .map(EhsdPurchaseProduct::getQuantity)
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- if (count.compareTo(subscribeDetail.getCount()) >= 0) {
|
|
|
- //修改为已采购
|
|
|
- subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
|
|
|
- } else {
|
|
|
- //修改为部分采购
|
|
|
- subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
|
|
|
- }
|
|
|
- }
|
|
|
- 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, purchase.getCompanyId());
|
|
|
-
|
|
|
-
|
|
|
- //采购审批通过 生成待入库数据
|
|
|
- StockWait stockWait = new StockWait();
|
|
|
- stockWait.setType(1);
|
|
|
- stockWait.setBusinessType(StockWaitType.PURCHASE_ARRIVAL_IN.getDetailType());
|
|
|
- stockWait.setBusinessId(purchase.getId());
|
|
|
- stockWait.setBusinessCode(purchase.getCode());
|
|
|
- stockWait.setStatus(0);
|
|
|
- stockWait.setPurchaseId(purchase.getId());
|
|
|
- stockWaitService.save(stockWait);
|
|
|
- List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
|
- for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
|
|
|
- StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
- stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
- stockWaitDetails.setBusinessDetailsId(purchaseProduct.getId());
|
|
|
- stockWaitDetails.setPurchaseDetailId(purchaseProduct.getId());
|
|
|
-
|
|
|
- stockWaitDetails.setProductId(purchaseProduct.getProductId());
|
|
|
- stockWaitDetails.setQuantity(purchaseProduct.getQuantity());
|
|
|
- stockWaitDetails.setStatus(0);
|
|
|
-
|
|
|
- stockWaitDetailsList.add(stockWaitDetails);
|
|
|
- }
|
|
|
- stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重新发起
|
|
|
- */
|
|
|
- @Override
|
|
|
- @LogicIgnore
|
|
|
- @DSTransactional
|
|
|
- public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
- //删除采购合同
|
|
|
- EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
- if (ObjectUtils.isEmpty(purchase)) {
|
|
|
- throw new ServiceException("采购数据不能为空");
|
|
|
- }
|
|
|
- purchase.setFlowId(flowId);
|
|
|
- connStart(purchase);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 驳回
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
- purchaseService.update(q -> q
|
|
|
- .eq(EhsdPurchase::getId, businessId)
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
|
|
|
- .set(BasePo::getUpdateTime, new Date())
|
|
|
- .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 作废
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
- EhsdPurchase purchase = purchaseService.getById(businessId);
|
|
|
-
|
|
|
- super.cancellation(flowId, businessId, flowStatus);
|
|
|
- purchaseService.update(q -> q
|
|
|
- .eq(EhsdPurchase::getId, businessId)
|
|
|
- .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
|
|
|
- .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, purchase.getCompanyId());
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseService purchaseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProductService purchaseProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProjectService purchaseProjectService;
|
|
|
+ @Autowired
|
|
|
+ private SampleProductService sampleProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CodingRuleService codingRuleService;
|
|
|
+ @Autowired
|
|
|
+ private SubscribeDetailService subscribeDetailService;
|
|
|
+ @Autowired
|
|
|
+ private ContractService contractService;
|
|
|
+ @Autowired
|
|
|
+ private SampleService sampleService;
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitService stockWaitService;
|
|
|
+ @Autowired
|
|
|
+ private StockWaitDetailsService stockWaitDetailsService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "purchase_flow";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起流程
|
|
|
+ *
|
|
|
+ * @param flowId 流程ID
|
|
|
+ * @param submitData 采购数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
+ EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
+ purchase.setId(null);//清空id防止前端误传
|
|
|
+ purchase.setFlowId(flowId);//赋值流程id
|
|
|
+ purchase.setProcessInstanceId(getFlowKey());//赋值流程key
|
|
|
+
|
|
|
+ //赋值产品归属公司
|
|
|
+ Long companyId = purchase.getCompanyId();
|
|
|
+ if (ObjectUtil.isEmpty(companyId)) {
|
|
|
+ purchase.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer dataResource = purchase.getDataResource();
|
|
|
+ if (ObjectUtils.isEmpty(dataResource)) {
|
|
|
+ throw new ServiceException("数据来源类型不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //采购单编号生成
|
|
|
+ if (0 == dataResource) {
|
|
|
+ //手动创建 编号规则
|
|
|
+ purchase.setCode(codingRuleService.createCode(CodingRuleEnum.EHSD_PURCHASE.getKey(), null));
|
|
|
+ } else if (1 == dataResource) {
|
|
|
+ //合同 编号规则
|
|
|
+ Contract contract = contractService.getById(purchase.getDataResourceId());
|
|
|
+ Assert.notEmpty(contract, "查询不到合同信息,无法生成编号");
|
|
|
+ long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, contract.getId()));
|
|
|
+ purchase.setCode(contract.getCode() + "-" + (count + 1));
|
|
|
+ } else if (2 == dataResource) {
|
|
|
+ //样品单 编号规则
|
|
|
+ Sample sample = sampleService.getById(purchase.getDataResourceId());
|
|
|
+ Assert.notEmpty(sample, "查询不到样品单信息,无法生成编号");
|
|
|
+ long count = purchaseService.count(q -> q.eq(EhsdPurchase::getDataResourceId, sample.getId()));
|
|
|
+ purchase.setCode(sample.getCode() + "-" + (count + 1));
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("未知数据来源类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ //公共代码
|
|
|
+ purchase = connStart(purchase);
|
|
|
+
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 公共代码块--发起
|
|
|
+ */
|
|
|
+ public EhsdPurchaseDto connStart(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.saveOrUpdate(purchase);
|
|
|
+
|
|
|
+ List<EhsdPurchaseProduct> purchaseProductList = purchase.getPurchaseProductList();
|
|
|
+ List<EhsdPurchaseProject> purchaseProjectList = purchase.getPurchaseProjectList();
|
|
|
+
|
|
|
+ //防止空指针
|
|
|
+ purchaseProjectList = (purchaseProjectList == null ? new ArrayList<>() : purchaseProjectList);
|
|
|
+ purchaseProductList = (purchaseProductList == null ? new ArrayList<>() : purchaseProductList);
|
|
|
+
|
|
|
+ //产品(采购明细)
|
|
|
+ for (EhsdPurchaseProduct s : purchaseProductList) {
|
|
|
+ s.setId(ObjectUtils.isNotEmpty(s.getId()) ? s.getId() : IdWorker.getId());
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ }
|
|
|
+ //修改或删除数据
|
|
|
+ purchaseProductService.editLinked(purchaseProductList, EhsdPurchaseProduct::getPurchaseId, purchase.getId());
|
|
|
+
|
|
|
+ //收费项目
|
|
|
+ for (EhsdPurchaseProject s : purchaseProjectList) {
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ }
|
|
|
+ purchaseProjectService.editLinked(purchaseProjectList, EhsdPurchaseProject::getPurchaseId, purchase.getId());
|
|
|
+
|
|
|
+ return purchase;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结束流程
|
|
|
+ *
|
|
|
+ * @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("采购单不存在,或已被删除");
|
|
|
+ }
|
|
|
+ //查询采购产品
|
|
|
+ List<EhsdPurchaseProduct> purchaseProductList = purchaseProductService.list(Wrappers.<EhsdPurchaseProduct>query().lambda().eq(EhsdPurchaseProduct::getPurchaseId, businessId));
|
|
|
+ List<SampleProduct> upSampleProduct = new ArrayList<>();
|
|
|
+ for (EhsdPurchaseProduct p : purchaseProductList) {
|
|
|
+ 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());
|
|
|
+ sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
+ upSampleProduct.add(sampleProduct);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
|
|
|
+ sampleProductService.updateBatchById(upSampleProduct);
|
|
|
+ }
|
|
|
+ //修改采购状态为审批通过
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.PASS.getKey());
|
|
|
+ purchase.setApprovedDate(new Date());
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+
|
|
|
+ if (Objects.equals(purchase.getDataResource(), 0)) {
|
|
|
+ //修改申购明细状态
|
|
|
+ List<EhsdPurchaseProduct> purchaseDetailList = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getProductId, businessId));
|
|
|
+ List<Long> subscribeDetailIds = purchaseDetailList.stream().map(EhsdPurchaseProduct::getSubscribeDetailId).collect(Collectors.toList());
|
|
|
+ List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
|
|
|
+ for (SubscribeDetail subscribeDetail : subscribeDetails) {
|
|
|
+ //获取申购明细下的所有采购记录 计算已采购数
|
|
|
+ List<EhsdPurchaseProduct> purchaseDetails = purchaseProductService.list(q -> q.eq(EhsdPurchaseProduct::getSubscribeDetailId,
|
|
|
+ subscribeDetail.getId()).eq(EhsdPurchaseProduct::getProductId, subscribeDetail.getProductId()));
|
|
|
+ BigDecimal count = purchaseDetails.stream()
|
|
|
+ .map(EhsdPurchaseProduct::getQuantity)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (count.compareTo(subscribeDetail.getCount()) >= 0) {
|
|
|
+ //修改为已采购
|
|
|
+ subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
|
|
|
+ } else {
|
|
|
+ //修改为部分采购
|
|
|
+ subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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, purchase.getCompanyId());
|
|
|
+
|
|
|
+
|
|
|
+ //采购审批通过 生成待入库数据
|
|
|
+ StockWait stockWait = new StockWait();
|
|
|
+ stockWait.setType(1);
|
|
|
+ stockWait.setBusinessType(StockWaitType.PURCHASE_ARRIVAL_IN.getDetailType());
|
|
|
+ stockWait.setBusinessId(purchase.getId());
|
|
|
+ stockWait.setBusinessCode(purchase.getCode());
|
|
|
+ stockWait.setStatus(0);
|
|
|
+ stockWait.setPurchaseId(purchase.getId());
|
|
|
+ stockWaitService.save(stockWait);
|
|
|
+ List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
|
+ for (EhsdPurchaseProduct purchaseProduct : purchaseProductList) {
|
|
|
+ StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
|
+ stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
|
+ stockWaitDetails.setBusinessDetailsId(purchaseProduct.getId());
|
|
|
+ stockWaitDetails.setPurchaseDetailId(purchaseProduct.getId());
|
|
|
+
|
|
|
+ stockWaitDetails.setProductId(purchaseProduct.getProductId());
|
|
|
+ stockWaitDetails.setQuantity(purchaseProduct.getQuantity());
|
|
|
+ stockWaitDetails.setStatus(0);
|
|
|
+
|
|
|
+ stockWaitDetailsList.add(stockWaitDetails);
|
|
|
+ }
|
|
|
+ stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新发起
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @LogicIgnore
|
|
|
+ @DSTransactional
|
|
|
+ public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
|
|
|
+ //删除采购合同
|
|
|
+ EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
|
|
|
+ if (ObjectUtils.isEmpty(purchase)) {
|
|
|
+ throw new ServiceException("采购数据不能为空");
|
|
|
+ }
|
|
|
+ purchase.setFlowId(flowId);
|
|
|
+ connStart(purchase);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 驳回
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ purchaseService.update(q -> q
|
|
|
+ .eq(EhsdPurchase::getId, businessId)
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.REJECT.getKey())
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 作废
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cancellation(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
|
|
|
+ EhsdPurchase purchase = purchaseService.getById(businessId);
|
|
|
+
|
|
|
+ super.cancellation(flowId, businessId, flowStatus);
|
|
|
+ purchaseService.update(q -> q
|
|
|
+ .eq(EhsdPurchase::getId, businessId)
|
|
|
+ .set(EhsdPurchase::getStatus, FlowStatusEnum1.CANCELLATION.getKey())
|
|
|
+ .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, purchase.getCompanyId());
|
|
|
+ }
|
|
|
}
|