|
|
|
|
@ -25,6 +25,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
|
|
import org.dromara.system.api.RemoteUserService;
|
|
|
|
|
import org.dromara.system.api.domain.vo.RemoteUserVo;
|
|
|
|
|
import org.dromara.warm.flow.core.FlowEngine;
|
|
|
|
|
import org.dromara.warm.flow.core.dto.FlowParams;
|
|
|
|
|
import org.dromara.warm.flow.core.entity.*;
|
|
|
|
|
import org.dromara.warm.flow.core.enums.NodeType;
|
|
|
|
|
@ -115,7 +116,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
if (ObjectUtil.isNotNull(flowInstance)) {
|
|
|
|
|
BusinessStatusEnum.checkStartStatus(flowInstance.getFlowStatus());
|
|
|
|
|
List<Task> taskList = taskService.list(new FlowTask().setInstanceId(flowInstance.getId()));
|
|
|
|
|
flwCommonService.mergeVariable(flowInstance, variables);
|
|
|
|
|
taskService.mergeVariable(flowInstance, variables);
|
|
|
|
|
insService.updateById(flowInstance);
|
|
|
|
|
RemoteStartProcessReturn dto = new RemoteStartProcessReturn();
|
|
|
|
|
dto.setProcessInstanceId(taskList.get(0).getInstanceId());
|
|
|
|
|
@ -158,6 +159,13 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
String notice = completeTaskBo.getNotice();
|
|
|
|
|
// 获取抄送人
|
|
|
|
|
List<FlowCopyBo> flowCopyList = completeTaskBo.getFlowCopyList();
|
|
|
|
|
// 设置抄送人
|
|
|
|
|
completeTaskBo.getVariables().put("flowCopyList", flowCopyList);
|
|
|
|
|
// 消息类型
|
|
|
|
|
completeTaskBo.getVariables().put("messageType", messageType);
|
|
|
|
|
// 消息通知
|
|
|
|
|
completeTaskBo.getVariables().put("notice", notice);
|
|
|
|
|
|
|
|
|
|
FlowTask flowTask = flowTaskMapper.selectById(taskId);
|
|
|
|
|
if (ObjectUtil.isNull(flowTask)) {
|
|
|
|
|
throw new ServiceException("流程任务不存在或任务已审批!");
|
|
|
|
|
@ -183,12 +191,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
.hisStatus(TaskStatusEnum.PASS.getStatus())
|
|
|
|
|
.hisTaskExt(completeTaskBo.getFileId());
|
|
|
|
|
// 执行任务跳转,并根据返回的处理人设置下一步处理人
|
|
|
|
|
Instance instance = taskService.skip(taskId, flowParams);
|
|
|
|
|
this.setHandler(instance, flowTask, flowCopyList);
|
|
|
|
|
// 消息通知
|
|
|
|
|
flwCommonService.sendMessage(definition.getFlowName(), ins.getId(), messageType, notice);
|
|
|
|
|
//设置下一环节处理人
|
|
|
|
|
setNextHandler(ins.getId(), completeTaskBo.getAssigneeMap());
|
|
|
|
|
taskService.skip(taskId, flowParams);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
@ -196,33 +199,6 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置下一环节处理人
|
|
|
|
|
*
|
|
|
|
|
* @param instanceId 实例ID
|
|
|
|
|
* @param assigneeMap 办理人
|
|
|
|
|
*/
|
|
|
|
|
private void setNextHandler(Long instanceId, Map<String, Object> assigneeMap) {
|
|
|
|
|
if (CollUtil.isEmpty(assigneeMap)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Instance inst = insService.getById(instanceId);
|
|
|
|
|
List<FlowTask> flowTaskList = selectByInstId(instanceId);
|
|
|
|
|
Map<String, Object> variableMap = inst.getVariableMap();
|
|
|
|
|
for (FlowTask task : flowTaskList) {
|
|
|
|
|
if (variableMap != null && variableMap.containsKey(task.getNodeCode())) {
|
|
|
|
|
String userIds = variableMap.get(task.getNodeCode()).toString();
|
|
|
|
|
// 批量删除现有任务的办理人记录
|
|
|
|
|
flwCommonService.getFlowUserService().deleteByTaskIds(List.of(task.getId()));
|
|
|
|
|
// 批量新增任务办理人记录
|
|
|
|
|
Set<User> users = flwCommonService.buildFlowUser(List.of(userIds.split(StringUtils.SEPARATOR)), task.getId());
|
|
|
|
|
flwCommonService.getFlowUserService().saveBatch(new ArrayList<>(users));
|
|
|
|
|
variableMap.remove(task.getNodeCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
flwCommonService.mergeVariable(inst, variableMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置弹窗处理人
|
|
|
|
|
*
|
|
|
|
|
@ -254,54 +230,14 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置办理人
|
|
|
|
|
*
|
|
|
|
|
* @param instance 实例
|
|
|
|
|
* @param task (当前任务)未办理的任务
|
|
|
|
|
* @param flowCopyList 抄送人
|
|
|
|
|
*/
|
|
|
|
|
private void setHandler(Instance instance, FlowTask task, List<FlowCopyBo> flowCopyList) {
|
|
|
|
|
if (ObjectUtil.isNull(instance)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 添加抄送人
|
|
|
|
|
this.setCopy(task, flowCopyList);
|
|
|
|
|
// 根据流程实例ID查询所有关联的任务
|
|
|
|
|
List<FlowTask> flowTasks = this.selectByInstId(instance.getId());
|
|
|
|
|
if (CollUtil.isEmpty(flowTasks)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<Long> taskIdList = StreamUtils.toList(flowTasks, FlowTask::getId);
|
|
|
|
|
// 获取与当前任务关联的用户列表
|
|
|
|
|
List<User> associatedUsers = flwCommonService.getFlowUserService().getByAssociateds(taskIdList);
|
|
|
|
|
if (CollUtil.isEmpty(associatedUsers)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<User> userList = new ArrayList<>();
|
|
|
|
|
// 遍历任务列表,处理每个任务的办理人
|
|
|
|
|
for (FlowTask flowTask : flowTasks) {
|
|
|
|
|
List<User> users = StreamUtils.filter(associatedUsers, user -> Objects.equals(user.getAssociated(), flowTask.getId()));
|
|
|
|
|
if (CollUtil.isNotEmpty(users)) {
|
|
|
|
|
userList.addAll(flwCommonService.buildUser(users, flowTask.getId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 批量删除现有任务的办理人记录
|
|
|
|
|
flwCommonService.getFlowUserService().deleteByTaskIds(taskIdList);
|
|
|
|
|
// 确保要保存的 userList 不为空
|
|
|
|
|
if (CollUtil.isEmpty(userList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
flwCommonService.getFlowUserService().saveBatch(userList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加抄送人
|
|
|
|
|
*
|
|
|
|
|
* @param task 任务信息
|
|
|
|
|
* @param flowCopyList 抄送人
|
|
|
|
|
*/
|
|
|
|
|
public void setCopy(FlowTask task, List<FlowCopyBo> flowCopyList) {
|
|
|
|
|
@Override
|
|
|
|
|
public void setCopy(Task task, List<FlowCopyBo> flowCopyList) {
|
|
|
|
|
if (CollUtil.isEmpty(flowCopyList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
@ -332,7 +268,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
return flowUser;
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
// 批量保存抄送人员
|
|
|
|
|
flwCommonService.getFlowUserService().saveBatch(userList);
|
|
|
|
|
FlowEngine.userService().saveBatch(userList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -459,21 +395,25 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
Instance inst = insService.getById(task.getInstanceId());
|
|
|
|
|
BusinessStatusEnum.checkBackStatus(inst.getFlowStatus());
|
|
|
|
|
Long definitionId = task.getDefinitionId();
|
|
|
|
|
Definition definition = defService.getById(definitionId);
|
|
|
|
|
String applyNodeCode = flwCommonService.applyNodeCode(definitionId);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> variable = new HashMap<>();
|
|
|
|
|
// 设置抄送人
|
|
|
|
|
variable.put("flowCopyList", bo.getMessageType());
|
|
|
|
|
// 消息类型
|
|
|
|
|
variable.put("messageType", messageType);
|
|
|
|
|
// 消息通知
|
|
|
|
|
variable.put("notice", notice);
|
|
|
|
|
|
|
|
|
|
FlowParams flowParams = FlowParams.build()
|
|
|
|
|
.nodeCode(bo.getNodeCode())
|
|
|
|
|
.variable(variable)
|
|
|
|
|
.message(message)
|
|
|
|
|
.skipType(SkipType.REJECT.getKey())
|
|
|
|
|
.flowStatus(applyNodeCode.equals(bo.getNodeCode()) ? TaskStatusEnum.BACK.getStatus() : TaskStatusEnum.WAITING.getStatus())
|
|
|
|
|
.hisStatus(TaskStatusEnum.BACK.getStatus())
|
|
|
|
|
.hisTaskExt(bo.getFileId());
|
|
|
|
|
taskService.skip(task.getId(), flowParams);
|
|
|
|
|
|
|
|
|
|
Instance instance = insService.getById(inst.getId());
|
|
|
|
|
this.setHandler(instance, task, null);
|
|
|
|
|
// 消息通知
|
|
|
|
|
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error(e.getMessage(), e);
|
|
|
|
|
@ -748,7 +688,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
List<FlowTask> flowTasks = this.selectByIdList(taskIdList);
|
|
|
|
|
// 批量删除现有任务的办理人记录
|
|
|
|
|
if (CollUtil.isNotEmpty(flowTasks)) {
|
|
|
|
|
flwCommonService.getFlowUserService().deleteByTaskIds(StreamUtils.toList(flowTasks, FlowTask::getId));
|
|
|
|
|
FlowEngine.userService().deleteByTaskIds(StreamUtils.toList(flowTasks, FlowTask::getId));
|
|
|
|
|
List<User> userList = flowTasks.stream()
|
|
|
|
|
.map(flowTask -> {
|
|
|
|
|
FlowUser flowUser = new FlowUser();
|
|
|
|
|
@ -759,7 +699,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
})
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (CollUtil.isNotEmpty(userList)) {
|
|
|
|
|
flwCommonService.getFlowUserService().saveBatch(userList);
|
|
|
|
|
FlowEngine.userService().saveBatch(userList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@ -778,13 +718,13 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
public Map<Long, List<RemoteUserVo>> currentTaskAllUser(List<Long> taskIdList) {
|
|
|
|
|
Map<Long, List<RemoteUserVo>> map = new HashMap<>();
|
|
|
|
|
// 获取与当前任务关联的用户列表
|
|
|
|
|
List<User> associatedUsers = flwCommonService.getFlowUserService().getByAssociateds(taskIdList);
|
|
|
|
|
List<User> associatedUsers = FlowEngine.userService().getByAssociateds(taskIdList);
|
|
|
|
|
Map<Long, List<User>> listMap = StreamUtils.groupByKey(associatedUsers, User::getAssociated);
|
|
|
|
|
for (Map.Entry<Long, List<User>> entry : listMap.entrySet()) {
|
|
|
|
|
List<User> value = entry.getValue();
|
|
|
|
|
if (CollUtil.isNotEmpty(value)) {
|
|
|
|
|
List<RemoteUserVo> userDTOS = remoteUserService.selectListByIds(StreamUtils.toList(value, e -> Long.valueOf(e.getProcessedBy())));
|
|
|
|
|
map.put(entry.getKey(), userDTOS);
|
|
|
|
|
List<RemoteUserVo> userDtoList = remoteUserService.selectListByIds(StreamUtils.toList(value, e -> Long.valueOf(e.getProcessedBy())));
|
|
|
|
|
map.put(entry.getKey(), userDtoList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
@ -798,7 +738,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|
|
|
|
@Override
|
|
|
|
|
public List<RemoteUserVo> currentTaskAllUser(Long taskId) {
|
|
|
|
|
// 获取与当前任务关联的用户列表
|
|
|
|
|
List<User> userList = flwCommonService.getFlowUserService().getByAssociateds(Collections.singletonList(taskId));
|
|
|
|
|
List<User> userList = FlowEngine.userService().getByAssociateds(Collections.singletonList(taskId));
|
|
|
|
|
if (CollUtil.isEmpty(userList)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|