|
@@ -16,20 +16,39 @@
|
|
*/
|
|
*/
|
|
package org.springblade.business.service.impl;
|
|
package org.springblade.business.service.impl;
|
|
|
|
|
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
import org.apache.commons.lang.time.DateUtils;
|
|
|
|
+import org.springblade.business.entity.FixedFlowLink;
|
|
import org.springblade.business.entity.Task;
|
|
import org.springblade.business.entity.Task;
|
|
|
|
+import org.springblade.business.entity.TaskParallel;
|
|
import org.springblade.business.mapper.TaskMapper;
|
|
import org.springblade.business.mapper.TaskMapper;
|
|
|
|
+import org.springblade.business.service.IFixedFlowLinkService;
|
|
|
|
+import org.springblade.business.service.ITaskParallelService;
|
|
import org.springblade.business.service.ITaskService;
|
|
import org.springblade.business.service.ITaskService;
|
|
import org.springblade.business.vo.TaskVO;
|
|
import org.springblade.business.vo.TaskVO;
|
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
|
+import org.springblade.core.mp.support.Query;
|
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
|
+import org.springblade.core.tool.support.Kv;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.DateUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.flow.core.constant.ProcessConstant;
|
|
import org.springblade.flow.core.constant.ProcessConstant;
|
|
|
|
+import org.springblade.flow.core.entity.BladeFlow;
|
|
|
|
+import org.springblade.flow.core.feign.IFlowClient;
|
|
import org.springblade.flow.core.utils.FlowUtil;
|
|
import org.springblade.flow.core.utils.FlowUtil;
|
|
|
|
+import org.springblade.flow.core.utils.TaskUtil;
|
|
|
|
+import org.springblade.flow.core.vo.FlowProcessVO;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 任务审核主表 服务实现类
|
|
* 任务审核主表 服务实现类
|
|
@@ -37,23 +56,102 @@ import java.util.Date;
|
|
* @author BladeX
|
|
* @author BladeX
|
|
* @since 2022-07-01
|
|
* @since 2022-07-01
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
|
|
+@AllArgsConstructor
|
|
public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implements ITaskService {
|
|
public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implements ITaskService {
|
|
|
|
|
|
|
|
+ private final IFlowClient flowClient;
|
|
|
|
+
|
|
|
|
+ private final IFixedFlowLinkService fixedFlowLinkService;
|
|
|
|
+
|
|
|
|
+ private final ITaskParallelService taskParallelService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Boolean startApproval(TaskVO vo) {
|
|
public Boolean startApproval(TaskVO vo) {
|
|
//获取业务表
|
|
//获取业务表
|
|
String businessTable = FlowUtil.getBusinessTable(ProcessConstant.EXAMINATION_AND_APPROVAL);
|
|
String businessTable = FlowUtil.getBusinessTable(ProcessConstant.EXAMINATION_AND_APPROVAL);
|
|
if(Func.isEmpty(vo.getId())){
|
|
if(Func.isEmpty(vo.getId())){
|
|
|
|
+ vo.setId(SnowFlakeUtil.getId());
|
|
|
|
+ //设置开始/结束时间
|
|
|
|
+ Date nowTime = new Date();
|
|
|
|
+ vo.setStartTime(DateUtil.format(nowTime, "yyyy-MM-dd"));
|
|
|
|
+ vo.setEndTime(DateUtil.format(DateUtils.addDays(nowTime, vo.getRestrictDay()), "yyyy-MM-dd"));
|
|
|
|
+
|
|
|
|
+ Query query = new Query();
|
|
|
|
+ query.setCurrent(1);
|
|
|
|
+ query.setSize(999);
|
|
|
|
+ //获取流程
|
|
|
|
+ List<FlowProcessVO> modeProcessVOS = this.flowClient.startFlowList("", query, 1);
|
|
|
|
+ if(modeProcessVOS == null || modeProcessVOS.size() == 0){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //获取当中的审批流程
|
|
|
|
+ String taskFlowId = null;
|
|
|
|
+ for(FlowProcessVO processVO : modeProcessVOS){
|
|
|
|
+ if("approval".equals(processVO.getKey())){
|
|
|
|
+ taskFlowId = processVO.getId();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //如果没有对应流程,直接返回
|
|
|
|
+ if(StringUtils.isEmpty(taskFlowId)){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //获取选择的固定流程
|
|
|
|
+ List<FixedFlowLink> links = this.fixedFlowLinkService.selectFixedFlowLink(vo.getFixedFlowId().toString());
|
|
|
|
+ if(links == null || links.size() == 0){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //根据所选择的固定流程所含有的环节发起审批任务
|
|
|
|
+ StringBuilder instanceIds = new StringBuilder();
|
|
|
|
+ for(FixedFlowLink link : links){
|
|
|
|
+ // 启动流程
|
|
|
|
+ Kv variables = Kv.create()
|
|
|
|
+ //下一步流程审批人
|
|
|
|
+ .set("taskUser", TaskUtil.getTaskUser(link.getFixedFlowLinkUser().toString()));
|
|
|
|
+ R<BladeFlow> result = flowClient.startProcessInstanceById(taskFlowId, FlowUtil.getBusinessKey(businessTable, String.valueOf(vo.getId())), variables);
|
|
|
|
+ if (result.isSuccess()) {
|
|
|
|
+ log.debug("并行流程已启动,流程ID:" + result.getData().getProcessInstanceId());
|
|
|
|
+ //拼接并行的实例ID
|
|
|
|
+ instanceIds.append(",").append(result.getData().getProcessInstanceId());
|
|
|
|
+ } else {
|
|
|
|
+ throw new ServiceException("开启并行流程失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //启动主流程
|
|
|
|
+ R<BladeFlow> result = this.flowClient.startProcessInstanceById(taskFlowId, FlowUtil.getBusinessKey(businessTable, String.valueOf(vo.getId())),
|
|
|
|
+ Kv.create().set(ProcessConstant.TASK_VARIABLE_CREATE_USER, AuthUtil.getUserName()).set("taskUser", TaskUtil.getTaskUser("")));
|
|
|
|
+ if (result.isSuccess()) {
|
|
|
|
+ log.debug("主流程已启动,流程ID:" + result.getData().getProcessInstanceId());
|
|
|
|
+ //拼接并行的实例ID
|
|
|
|
+ vo.setProcessInstanceId(result.getData().getProcessInstanceId());
|
|
|
|
+ } else {
|
|
|
|
+ throw new ServiceException("开启主流程失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vo.setProcessDefinitionId(taskFlowId);
|
|
//bean Copy
|
|
//bean Copy
|
|
|
|
+ vo.setReportUser(AuthUtil.getUserId().toString());
|
|
|
|
+ vo.setReportUserName(AuthUtil.getUserName());
|
|
|
|
+ vo.setCreateUser(AuthUtil.getUserId());
|
|
|
|
+ vo.setCreateTime(nowTime);
|
|
Task task = new Task();
|
|
Task task = new Task();
|
|
BeanUtils.copyProperties(vo, task);
|
|
BeanUtils.copyProperties(vo, task);
|
|
- //设置开始/结束时间
|
|
|
|
- Date nowTime = new Date();
|
|
|
|
- task.setStartTime(DateUtil.format(nowTime, "yyyy-MM-dd"));
|
|
|
|
- task.setEndTime(DateUtil.format(DateUtils.addDays(nowTime, vo.getRestrictDay()), "yyyy-MM-dd"));
|
|
|
|
|
|
+ //保存并行数据
|
|
|
|
+ String[] instanceIdArray = instanceIds.toString().split(",");
|
|
|
|
+ List<TaskParallel> taskParallelArray = new ArrayList<>();
|
|
|
|
+ for(String instanceId : instanceIdArray){
|
|
|
|
+ if(StringUtils.isNotEmpty(instanceId)){
|
|
|
|
+ taskParallelArray.add(new TaskParallel(vo.getProcessInstanceId(), instanceId));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.taskParallelService.saveBatch(taskParallelArray);
|
|
|
|
|
|
|
|
+ //保存主表数据
|
|
|
|
+ this.save(task);
|
|
}
|
|
}
|
|
- return null;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|