|
@@ -62,77 +62,82 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
|
|
|
/**
|
|
|
* 发起流程
|
|
|
- * @param flowId 流程ID
|
|
|
+ *
|
|
|
+ * @param flowId 流程ID
|
|
|
* @param submitData 采购数据
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public Long start(Long flowId, JSONObject submitData) {
|
|
|
DynamicDataSourceContextHolder.push(SourceConstant.PURCHASE);
|
|
|
- Purchase purchase = submitData.toJavaObject(Purchase.class);
|
|
|
- purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
- purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
- purchaseService.save(purchase);
|
|
|
- List<PurchaseDetail> purchaseDetailList = purchase.getPurchaseDetailList();
|
|
|
- if(CollectionUtils.isNotEmpty(purchaseDetailList)){
|
|
|
- for(PurchaseDetail s : purchaseDetailList){
|
|
|
- s.setPurchaseId(purchase.getId());
|
|
|
+ try {
|
|
|
+ Purchase purchase = submitData.toJavaObject(Purchase.class);
|
|
|
+ purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
+ purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ purchaseService.save(purchase);
|
|
|
+ List<PurchaseDetail> purchaseDetailList = purchase.getPurchaseDetailList();
|
|
|
+ if (CollectionUtils.isNotEmpty(purchaseDetailList)) {
|
|
|
+ for (PurchaseDetail s : purchaseDetailList) {
|
|
|
+ s.setPurchaseId(purchase.getId());
|
|
|
+ }
|
|
|
+ purchaseDetailService.saveBatch(purchaseDetailList);
|
|
|
}
|
|
|
- purchaseDetailService.saveBatch(purchaseDetailList);
|
|
|
- }
|
|
|
- //根据申购明细id去申购单获取仓库id 名称
|
|
|
- if(ObjectUtils.isEmpty(purchaseDetailList)){
|
|
|
- return purchase.getId();
|
|
|
- }
|
|
|
- PurchaseDetail purchaseDetail = purchaseDetailList.get(0);
|
|
|
- SubscribeDetail subscribeDetail = subscribeDetailService.getById(purchaseDetail.getSubscribeDetailId());
|
|
|
- if(ObjectUtils.isEmpty(subscribeDetail)){
|
|
|
- return purchase.getId();
|
|
|
- }
|
|
|
- Subscribe subscribe = subscribeService.getById(subscribeDetail.getSubscribeId());
|
|
|
- if(ObjectUtils.isEmpty(subscribe)){
|
|
|
- return purchase.getId();
|
|
|
- }
|
|
|
- String victoriatouristJson = subscribe.getVictoriatouristJson();
|
|
|
- if(ObjectUtils.isNotEmpty(victoriatouristJson)) {
|
|
|
- JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
- Long receiptWarehouseId = json.getLong("receiptWarehouseId");
|
|
|
+ //根据申购明细id去申购单获取仓库id 名称
|
|
|
+ if (ObjectUtils.isEmpty(purchaseDetailList)) {
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+ PurchaseDetail purchaseDetail = purchaseDetailList.get(0);
|
|
|
+ SubscribeDetail subscribeDetail = subscribeDetailService.getById(purchaseDetail.getSubscribeDetailId());
|
|
|
+ if (ObjectUtils.isEmpty(subscribeDetail)) {
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+ Subscribe subscribe = subscribeService.getById(subscribeDetail.getSubscribeId());
|
|
|
+ if (ObjectUtils.isEmpty(subscribe)) {
|
|
|
+ return purchase.getId();
|
|
|
+ }
|
|
|
+ String victoriatouristJson = subscribe.getVictoriatouristJson();
|
|
|
+ if (ObjectUtils.isNotEmpty(victoriatouristJson)) {
|
|
|
+ JSONObject json = JSONObject.parseObject(victoriatouristJson);
|
|
|
+ Long receiptWarehouseId = json.getLong("receiptWarehouseId");
|
|
|
|
|
|
- String victoriatouristJson1 = purchase.getVictoriatouristJson();
|
|
|
- JSONObject json1 = JSONObject.parseObject(victoriatouristJson1);
|
|
|
- json1.put("receiptWarehouseId",receiptWarehouseId);
|
|
|
- purchase.setVictoriatouristJson(json1.toJSONString());
|
|
|
- purchaseService.updateById(purchase);
|
|
|
+ String victoriatouristJson1 = purchase.getVictoriatouristJson();
|
|
|
+ JSONObject json1 = JSONObject.parseObject(victoriatouristJson1);
|
|
|
+ json1.put("receiptWarehouseId", receiptWarehouseId);
|
|
|
+ purchase.setVictoriatouristJson(json1.toJSONString());
|
|
|
+ purchaseService.updateById(purchase);
|
|
|
+ }
|
|
|
+ return purchase.getId();
|
|
|
+ } finally {
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
}
|
|
|
- DynamicDataSourceContextHolder.poll();
|
|
|
- return purchase.getId();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 结束流程
|
|
|
- * @param flowId 流程ID
|
|
|
+ *
|
|
|
+ * @param flowId 流程ID
|
|
|
* @param businessId 业务ID
|
|
|
* @param submitData 数据
|
|
|
*/
|
|
|
@Override
|
|
|
public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
//修改申购明细状态
|
|
|
- List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId,businessId));
|
|
|
+ List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
|
|
|
Map<Long, PurchaseDetail> purchaseDetailMap = purchaseDetailList.stream().collect(Collectors.toMap(PurchaseDetail::getSubscribeDetailId, Function.identity()));
|
|
|
List<Long> subscribeDetailIds = purchaseDetailList.stream().map(PurchaseDetail::getSubscribeDetailId).collect(Collectors.toList());
|
|
|
List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
|
|
|
for (SubscribeDetail subscribeDetail : subscribeDetails) {
|
|
|
//获取申购明细下的所有采购记录 计算已采购数
|
|
|
List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId,
|
|
|
- subscribeDetail.getId()).eq(PurchaseDetail::getBussinessId,subscribeDetail.getBussinessId()));
|
|
|
+ subscribeDetail.getId()).eq(PurchaseDetail::getBussinessId, subscribeDetail.getBussinessId()));
|
|
|
BigDecimal count = purchaseDetails.stream()
|
|
|
.map(PurchaseDetail::getCount)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
// PurchaseDetail purchaseDetail = purchaseDetailMap.get(subscribeDetail.getId());
|
|
|
- if(count.compareTo(subscribeDetail.getCount())==0){
|
|
|
+ if (count.compareTo(subscribeDetail.getCount()) == 0) {
|
|
|
//修改为已采购
|
|
|
subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//修改为部分采购
|
|
|
subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
|
|
|
}
|
|
@@ -142,25 +147,25 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
|
|
|
//通过业务ID查询采购数据
|
|
|
Purchase purchase = purchaseService.getById(businessId);
|
|
|
- if(ObjectUtils.isEmpty(purchase)){
|
|
|
+ if (ObjectUtils.isEmpty(purchase)) {
|
|
|
throw new ServiceException("采购单不存在");
|
|
|
}
|
|
|
//查询采购产品
|
|
|
// List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId,businessId));
|
|
|
List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
- for(PurchaseDetail p:purchaseDetailList){
|
|
|
- if(ObjectUtils.isNotEmpty(p.getDataResourceId())&&
|
|
|
- p.getDataResource()== PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()){//如果采购的是外销合同
|
|
|
+ for (PurchaseDetail p : purchaseDetailList) {
|
|
|
+ if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
|
|
|
+ p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
|
|
|
ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
|
|
|
BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
|
|
|
- if(expendQuantity.compareTo(BigDecimal.ZERO)< 1){//小于0不让继续执行
|
|
|
+ if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
|
|
|
throw new ServiceException("采购数量不得大于外销合同数量");
|
|
|
}
|
|
|
contractProduct.setExpendQuantity(expendQuantity);
|
|
|
upContractProduct.add(contractProduct);
|
|
|
}
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(upContractProduct)){//扣减销售合同数量
|
|
|
+ if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
contractProductService.updateBatchById(upContractProduct);
|
|
|
}
|
|
|
//修改采购状态为审批通过
|
|
@@ -170,8 +175,8 @@ public class PurchaseFlowByWdly extends FlowDelegate {
|
|
|
//修改采购明细为待采购
|
|
|
PurchaseDetail detail = new PurchaseDetail();
|
|
|
detail.setStatus(PurchaseDetailStatusEnum.PASS.getKey());
|
|
|
- purchaseDetailService.update(detail,Wrappers.<PurchaseDetail>query()
|
|
|
- .lambda().eq(PurchaseDetail::getPurchaseId,purchase.getId()));
|
|
|
+ purchaseDetailService.update(detail, Wrappers.<PurchaseDetail>query()
|
|
|
+ .lambda().eq(PurchaseDetail::getPurchaseId, purchase.getId()));
|
|
|
}
|
|
|
|
|
|
}
|