update 优化 工作流代码写法
This commit is contained in:
parent
589ec1fdbc
commit
176793e15b
@ -206,7 +206,7 @@ public class FlwTaskController extends BaseController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/currentTaskAllUser/{taskId}")
|
@GetMapping("/currentTaskAllUser/{taskId}")
|
||||||
public R<List<UserDTO>> currentTaskAllUser(@PathVariable Long taskId) {
|
public R<List<UserDTO>> currentTaskAllUser(@PathVariable Long taskId) {
|
||||||
return R.ok(flwTaskService.currentTaskAllUser(taskId));
|
return R.ok(flwTaskService.currentTaskAllUser(List.of(taskId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.dromara.workflow.listener;
|
package org.dromara.workflow.listener;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.lang.TypeReference;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -136,17 +137,22 @@ public class WorkflowGlobalListener implements GlobalListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 只有办理或者退回的时候才执行消息通知和抄送
|
// 只有办理或者退回的时候才执行消息通知和抄送
|
||||||
if (TaskStatusEnum.PASS.getStatus().equals(flowParams.getHisStatus())
|
if (!StringUtils.equalsAny(flowParams.getHisStatus(),
|
||||||
|| TaskStatusEnum.BACK.getStatus().equals(flowParams.getHisStatus())) {
|
TaskStatusEnum.PASS.getStatus(), TaskStatusEnum.BACK.getStatus())) {
|
||||||
if (variable != null) {
|
return;
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNull(variable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (variable.containsKey(FlowConstant.FLOW_COPY_LIST)) {
|
if (variable.containsKey(FlowConstant.FLOW_COPY_LIST)) {
|
||||||
List<FlowCopyBo> flowCopyList = (List<FlowCopyBo>) variable.get(FlowConstant.FLOW_COPY_LIST);
|
List<FlowCopyBo> flowCopyList = MapUtil.get(variable, FlowConstant.FLOW_COPY_LIST, new TypeReference<>() {});
|
||||||
// 添加抄送人
|
// 添加抄送人
|
||||||
flwTaskService.setCopy(task, flowCopyList);
|
flwTaskService.setCopy(task, flowCopyList);
|
||||||
}
|
}
|
||||||
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
|
||||||
List<String> messageType = (List<String>) variable.get(FlowConstant.MESSAGE_TYPE);
|
List<String> messageType = MapUtil.get(variable, FlowConstant.FLOW_COPY_LIST, new TypeReference<>() {});
|
||||||
String notice = (String) variable.get(FlowConstant.MESSAGE_NOTICE);
|
String notice = MapUtil.getStr(variable, FlowConstant.MESSAGE_NOTICE);
|
||||||
// 消息通知
|
// 消息通知
|
||||||
if (CollUtil.isNotEmpty(messageType)) {
|
if (CollUtil.isNotEmpty(messageType)) {
|
||||||
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
|
||||||
@ -162,8 +168,6 @@ public class WorkflowGlobalListener implements GlobalListener {
|
|||||||
ins.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
ins.setVariable(FlowEngine.jsonConvert.objToStr(variableMap));
|
||||||
insService.updateById(ins);
|
insService.updateById(ins);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据流程实例确定最终状态
|
* 根据流程实例确定最终状态
|
||||||
|
@ -177,10 +177,10 @@ public interface IFlwTaskService {
|
|||||||
/**
|
/**
|
||||||
* 获取当前任务的所有办理人
|
* 获取当前任务的所有办理人
|
||||||
*
|
*
|
||||||
* @param taskId 任务id
|
* @param taskIds 任务id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
List<UserDTO> currentTaskAllUser(Long taskId);
|
List<UserDTO> currentTaskAllUser(List<Long> taskIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按照节点编码查询节点
|
* 按照节点编码查询节点
|
||||||
|
@ -49,40 +49,36 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
|
|||||||
@Override
|
@Override
|
||||||
public void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
public void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
|
||||||
IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class);
|
IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class);
|
||||||
List<UserDTO> userList = new ArrayList<>();
|
|
||||||
List<FlowTask> list = flwTaskService.selectByInstId(instId);
|
List<FlowTask> list = flwTaskService.selectByInstId(instId);
|
||||||
if (StringUtils.isBlank(message)) {
|
if (StringUtils.isBlank(message)) {
|
||||||
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
|
||||||
}
|
}
|
||||||
for (Task task : list) {
|
List<UserDTO> userList = flwTaskService.currentTaskAllUser(StreamUtils.toList(list, FlowTask::getId));
|
||||||
List<UserDTO> users = flwTaskService.currentTaskAllUser(task.getId());
|
if (CollUtil.isEmpty(userList)) {
|
||||||
if (CollUtil.isNotEmpty(users)) {
|
return;
|
||||||
userList.addAll(users);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (CollUtil.isNotEmpty(userList)) {
|
|
||||||
for (String code : messageType) {
|
for (String code : messageType) {
|
||||||
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
|
||||||
if (ObjectUtil.isNotEmpty(messageTypeEnum)) {
|
if (ObjectUtil.isEmpty(messageTypeEnum)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
switch (messageTypeEnum) {
|
switch (messageTypeEnum) {
|
||||||
case SYSTEM_MESSAGE:
|
case SYSTEM_MESSAGE -> {
|
||||||
SseMessageDto dto = new SseMessageDto();
|
SseMessageDto dto = new SseMessageDto();
|
||||||
dto.setUserIds(StreamUtils.toList(userList, UserDTO::getUserId).stream().distinct().collect(Collectors.toList()));
|
dto.setUserIds(StreamUtils.toList(userList, UserDTO::getUserId).stream().distinct().collect(Collectors.toList()));
|
||||||
dto.setMessage(message);
|
dto.setMessage(message);
|
||||||
SseMessageUtils.publishMessage(dto);
|
SseMessageUtils.publishMessage(dto);
|
||||||
break;
|
}
|
||||||
case EMAIL_MESSAGE:
|
case EMAIL_MESSAGE -> {
|
||||||
MailUtils.sendText(StreamUtils.join(userList, UserDTO::getEmail), "单据审批提醒", message);
|
MailUtils.sendText(StreamUtils.join(userList, UserDTO::getEmail), "单据审批提醒", message);
|
||||||
break;
|
}
|
||||||
case SMS_MESSAGE:
|
case SMS_MESSAGE -> {
|
||||||
//todo 短信发送
|
//todo 短信发送
|
||||||
break;
|
}
|
||||||
default:
|
default -> throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
||||||
throw new IllegalStateException("Unexpected value: " + messageTypeEnum);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,8 +121,8 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
|||||||
List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id));
|
List<FlowNode> flowNodes = flowNodeMapper.selectList(new LambdaQueryWrapper<FlowNode>().eq(FlowNode::getDefinitionId, id));
|
||||||
List<String> errorMsg = new ArrayList<>();
|
List<String> errorMsg = new ArrayList<>();
|
||||||
if (CollUtil.isNotEmpty(flowNodes)) {
|
if (CollUtil.isNotEmpty(flowNodes)) {
|
||||||
for (FlowNode flowNode : flowNodes) {
|
|
||||||
String applyNodeCode = flwCommonService.applyNodeCode(id);
|
String applyNodeCode = flwCommonService.applyNodeCode(id);
|
||||||
|
for (FlowNode flowNode : flowNodes) {
|
||||||
if (StringUtils.isBlank(flowNode.getPermissionFlag()) && !applyNodeCode.equals(flowNode.getNodeCode()) && NodeType.BETWEEN.getKey().equals(flowNode.getNodeType())) {
|
if (StringUtils.isBlank(flowNode.getPermissionFlag()) && !applyNodeCode.equals(flowNode.getNodeCode()) && NodeType.BETWEEN.getKey().equals(flowNode.getNodeType())) {
|
||||||
errorMsg.add(flowNode.getNodeName());
|
errorMsg.add(flowNode.getNodeName());
|
||||||
}
|
}
|
||||||
@ -213,7 +213,8 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FlowCategory flowCategory = flwCategoryMapper.selectOne(new LambdaQueryWrapper<FlowCategory>()
|
FlowCategory flowCategory = flwCategoryMapper.selectOne(new LambdaQueryWrapper<FlowCategory>()
|
||||||
.eq(FlowCategory::getTenantId, DEFAULT_TENANT_ID).eq(FlowCategory::getCategoryId, FlowConstant.FLOW_CATEGORY_ID));
|
.eq(FlowCategory::getTenantId, DEFAULT_TENANT_ID)
|
||||||
|
.eq(FlowCategory::getCategoryId, FlowConstant.FLOW_CATEGORY_ID));
|
||||||
flowCategory.setCategoryId(null);
|
flowCategory.setCategoryId(null);
|
||||||
flowCategory.setTenantId(tenantId);
|
flowCategory.setTenantId(tenantId);
|
||||||
flowCategory.setCreateDept(null);
|
flowCategory.setCreateDept(null);
|
||||||
|
@ -531,12 +531,12 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
//构建以下节点数据
|
//构建以下节点数据
|
||||||
List<Task> buildNextTaskList = StreamUtils.toList(nextNodeList, node -> taskService.addTask(node, instance, definition, FlowParams.build()));
|
List<Task> buildNextTaskList = StreamUtils.toList(nextNodeList, node -> taskService.addTask(node, instance, definition, FlowParams.build()));
|
||||||
//办理人变量替换
|
//办理人变量替换
|
||||||
ExpressionUtil.evalVariable(buildNextTaskList,
|
ExpressionUtil.evalVariable(buildNextTaskList, FlowParams.build().variable(mergeVariable));
|
||||||
FlowParams.build()
|
|
||||||
.variable(mergeVariable)
|
|
||||||
);
|
|
||||||
for (FlowNode flowNode : nextFlowNodes) {
|
for (FlowNode flowNode : nextFlowNodes) {
|
||||||
buildNextTaskList.stream().filter(t -> t.getNodeCode().equals(flowNode.getNodeCode())).findFirst().ifPresent(t -> {
|
Optional<Task> first = buildNextTaskList.stream()
|
||||||
|
.filter(t -> t.getNodeCode().equals(flowNode.getNodeCode()))
|
||||||
|
.findFirst();
|
||||||
|
first.ifPresent(t -> {
|
||||||
if (CollUtil.isNotEmpty(t.getPermissionList())) {
|
if (CollUtil.isNotEmpty(t.getPermissionList())) {
|
||||||
List<UserDTO> users = flwTaskAssigneeService.fetchUsersByStorageIds(String.join(StringUtils.SEPARATOR, t.getPermissionList()));
|
List<UserDTO> users = flwTaskAssigneeService.fetchUsersByStorageIds(String.join(StringUtils.SEPARATOR, t.getPermissionList()));
|
||||||
if (CollUtil.isNotEmpty(users)) {
|
if (CollUtil.isNotEmpty(users)) {
|
||||||
@ -681,12 +681,12 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
|
|||||||
/**
|
/**
|
||||||
* 获取当前任务的所有办理人
|
* 获取当前任务的所有办理人
|
||||||
*
|
*
|
||||||
* @param taskId 任务id
|
* @param taskIds 任务id
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<UserDTO> currentTaskAllUser(Long taskId) {
|
public List<UserDTO> currentTaskAllUser(List<Long> taskIds) {
|
||||||
// 获取与当前任务关联的用户列表
|
// 获取与当前任务关联的用户列表
|
||||||
List<User> userList = FlowEngine.userService().getByAssociateds(Collections.singletonList(taskId));
|
List<User> userList = FlowEngine.userService().getByAssociateds(taskIds);
|
||||||
if (CollUtil.isEmpty(userList)) {
|
if (CollUtil.isEmpty(userList)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user