|
@@ -0,0 +1,108 @@
|
|
|
|
+package com.fjhx.sale.flow;
|
|
|
|
+
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
|
+import com.fjhx.file.utils.ObsFileUtil;
|
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
|
+import com.fjhx.sale.entity.sample.po.Sample;
|
|
|
|
+import com.fjhx.sale.entity.sample.po.SampleProduct;
|
|
|
|
+import com.fjhx.sale.entity.sample.po.SampleProject;
|
|
|
|
+import com.fjhx.sale.entity.sample.po.SampleShipment;
|
|
|
|
+import com.fjhx.sale.enums.FlowStatusEnum;
|
|
|
|
+import com.fjhx.sale.service.sample.SampleProductService;
|
|
|
|
+import com.fjhx.sale.service.sample.SampleProjectService;
|
|
|
|
+import com.fjhx.sale.service.sample.SampleService;
|
|
|
|
+import com.fjhx.sale.service.sample.SampleShipmentService;
|
|
|
|
+import com.fjhx.sale.util.code.CodeEnum;
|
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 样品单流程
|
|
|
|
+ * @Author:caozj
|
|
|
|
+ * @DATE:2023/4/3 17:38
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+public class SampleFlow extends FlowDelegate {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getFlowKey() {
|
|
|
|
+ return "sample_flow";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 发起流程
|
|
|
|
+ * @param flowId 流程ID
|
|
|
|
+ * @param submitData 采购付款数据
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @DSTransactional
|
|
|
|
+ public Long start(Long flowId, JSONObject submitData) {
|
|
|
|
+ SampleService sampleService = SpringUtil.getBean(SampleService.class);
|
|
|
|
+ SampleProductService sampleProductService = SpringUtil.getBean(SampleProductService.class);
|
|
|
|
+ SampleProjectService sampleProjectService = SpringUtil.getBean(SampleProjectService.class);
|
|
|
|
+ SampleShipmentService sampleShipmentService = SpringUtil.getBean(SampleShipmentService.class);
|
|
|
|
+ Sample sample = submitData.toJavaObject(Sample.class);
|
|
|
|
+ sample.setCode(CodeEnum.SAMPLE.getCode());
|
|
|
|
+ sample.setStatus(FlowStatusEnum.UNDER_REVIEW.getKey());
|
|
|
|
+ sampleService.save(sample);
|
|
|
|
+ List<SampleProduct> sampleProductList = sample.getSampleProductList();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(sampleProductList)){//保存样品单产品
|
|
|
|
+ for(SampleProduct c : sampleProductList){
|
|
|
|
+ c.setId(IdWorker.getId());
|
|
|
|
+ c.setSampleId(sample.getId());
|
|
|
|
+ c.setExpendQuantity(c.getQuantity());
|
|
|
|
+ ObsFileUtil.saveFile(c.getFileList(),c.getId());
|
|
|
|
+ }
|
|
|
|
+ sampleProductService.saveBatch(sampleProductList);
|
|
|
|
+ }
|
|
|
|
+ List<SampleProject> sampleProjectList = sample.getSampleProjectList();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(sampleProjectList)){//保存收费项目
|
|
|
|
+ for(SampleProject c : sampleProjectList){
|
|
|
|
+ c.setSampleId(sample.getId());
|
|
|
|
+ }
|
|
|
|
+ sampleProjectService.saveBatch(sampleProjectList);
|
|
|
|
+ }
|
|
|
|
+ List<SampleShipment> sampleShipmentList = sample.getSampleShipmentList();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(sampleShipmentList)){//保存自定义出货
|
|
|
|
+ for(SampleShipment c : sampleShipmentList){
|
|
|
|
+ c.setSampleId(sample.getId());
|
|
|
|
+ }
|
|
|
|
+ sampleShipmentService.saveBatch(sampleShipmentList);
|
|
|
|
+ }
|
|
|
|
+ return sample.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 结束流程
|
|
|
|
+ * @param flowId 流程ID
|
|
|
|
+ * @param businessId 业务ID
|
|
|
|
+ * @param submitData 数据
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
|
+ SampleService sampleService = SpringUtil.getBean(SampleService.class);
|
|
|
|
+ //通过业务ID查询合同数据
|
|
|
|
+ Sample sample = sampleService.getById(businessId);
|
|
|
|
+ if(ObjectUtils.isEmpty(sample)){
|
|
|
|
+ throw new ServiceException("样品单不存在");
|
|
|
|
+ }
|
|
|
|
+ //修改采购状态为审批通过
|
|
|
|
+ sample.setStatus(FlowStatusEnum.PASS.getKey());
|
|
|
|
+ sample.setApprovedDate(new Date());
|
|
|
|
+ sampleService.updateById(sample);
|
|
|
|
+ }
|
|
|
|
+}
|