|
@@ -15,7 +15,10 @@ import com.fjhx.purchase.entity.purchase.enums.PurchaseDetailStatusEnum;
|
|
|
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.entity.purchase.po.PurchaseOtherFee;
|
|
|
+import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
|
+import com.fjhx.purchase.service.purchase.PurchaseOtherFeeService;
|
|
|
import com.fjhx.purchase.service.purchase.PurchaseService;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
import com.fjhx.sale.entity.sample.po.SampleProduct;
|
|
@@ -53,6 +56,8 @@ public class PurchaseFlow extends FlowDelegate {
|
|
|
|
|
|
@Autowired
|
|
|
private CodingRuleService codingRuleService;
|
|
|
+ @Autowired
|
|
|
+ private PurchaseOtherFeeService purchaseOtherFeeService;
|
|
|
|
|
|
@Override
|
|
|
public String getFlowKey() {
|
|
@@ -61,33 +66,41 @@ public class PurchaseFlow 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);
|
|
|
+ PurchaseVo purchase = submitData.toJavaObject(PurchaseVo.class);
|
|
|
// purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
- purchase.setCode(codingRuleService.createCode(CodingRuleEnum.PURCHASE.getKey(),null));
|
|
|
+ purchase.setCode(codingRuleService.createCode(CodingRuleEnum.PURCHASE.getKey(), null));
|
|
|
purchase.setPurchaseStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());
|
|
|
purchase.setFlowId(flowId);
|
|
|
purchaseService.save(purchase);
|
|
|
List<PurchaseDetail> purchaseDetailList = purchase.getPurchaseDetailList();
|
|
|
- if(CollectionUtils.isNotEmpty(purchaseDetailList)){
|
|
|
- for(PurchaseDetail s : purchaseDetailList){
|
|
|
+ if (CollectionUtils.isNotEmpty(purchaseDetailList)) {
|
|
|
+ for (PurchaseDetail s : purchaseDetailList) {
|
|
|
s.setPurchaseId(purchase.getId());
|
|
|
}
|
|
|
purchaseDetailService.saveBatch(purchaseDetailList);
|
|
|
}
|
|
|
+ //保存其他费用信息
|
|
|
+ List<PurchaseOtherFee> otherFeeList = purchase.getOtherFeeList();
|
|
|
+ if (ObjectUtils.isNotEmpty(otherFeeList)) {
|
|
|
+ otherFeeList.forEach(item -> item.setPurchaseId(purchase.getId()));
|
|
|
+ purchaseOtherFeeService.saveBatch(otherFeeList);
|
|
|
+ }
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
return purchase.getId();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 结束流程
|
|
|
- * @param flowId 流程ID
|
|
|
+ *
|
|
|
+ * @param flowId 流程ID
|
|
|
* @param businessId 业务ID
|
|
|
* @param submitData 数据
|
|
|
*/
|
|
@@ -96,39 +109,39 @@ public class PurchaseFlow extends FlowDelegate {
|
|
|
public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
//通过业务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<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
|
|
|
List<ContractProduct> upContractProduct = new ArrayList<>();
|
|
|
List<SampleProduct> upSampleProduct = 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(ObjectUtils.isNotEmpty(p.getDataResourceId())&&
|
|
|
- p.getDataResource()== PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()){//如果采购的是样品单
|
|
|
+ if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
|
|
|
+ p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_2.getKey()) {//如果采购的是样品单
|
|
|
SampleProduct sampleProduct = sampleProductService.getById(p.getDataResourceId());
|
|
|
BigDecimal expendQuantity = sampleProduct.getExpendQuantity().subtract(p.getCount());
|
|
|
- if(expendQuantity.compareTo(BigDecimal.ZERO)< 1){//小于0不让继续执行
|
|
|
+ if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
|
|
|
throw new ServiceException("采购数量不得大于合同剩余采购数量");
|
|
|
}
|
|
|
sampleProduct.setExpendQuantity(expendQuantity);
|
|
|
upSampleProduct.add(sampleProduct);
|
|
|
}
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(upContractProduct)){//扣减销售合同数量
|
|
|
+ if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
|
|
|
contractProductService.updateBatchById(upContractProduct);
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(upSampleProduct)){//扣减样品单数量
|
|
|
+ if (CollectionUtils.isNotEmpty(upSampleProduct)) {//扣减样品单数量
|
|
|
sampleProductService.updateBatchById(upSampleProduct);
|
|
|
}
|
|
|
//修改采购状态为审批通过
|
|
@@ -138,8 +151,8 @@ public class PurchaseFlow 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()));
|
|
|
}
|
|
|
|
|
|
}
|