update 优化 工作流代码

dev
疯狂的狮子Li 4 months ago
parent 328f5dcdac
commit de6fffc6fe

@ -12,13 +12,13 @@ import org.dromara.common.core.enums.BusinessStatusEnum;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.system.api.RemoteUserService;
import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.dto.FlowParams;
import org.dromara.warm.flow.core.entity.Definition;
import org.dromara.warm.flow.core.entity.Instance;
import org.dromara.warm.flow.core.entity.Task;
import org.dromara.warm.flow.core.listener.GlobalListener;
import org.dromara.warm.flow.core.listener.ListenerVariable;
import org.dromara.warm.flow.core.service.InsService;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.dromara.workflow.common.constant.FlowConstant;
import org.dromara.workflow.common.enums.TaskStatusEnum;
@ -48,11 +48,10 @@ import java.util.Set;
public class WorkflowGlobalListener implements GlobalListener {
private final IFlwTaskService flwTaskService;
private final IFlwInstanceService instanceService;
private final IFlwInstanceService flwInstanceService;
private final FlowProcessEventHandler flowProcessEventHandler;
private final IFlwCommonService flwCommonService;
private final IFlwNodeExtService nodeExtService;
private final InsService insService;
@DubboReference
private RemoteUserService remoteUserService;
@ -162,7 +161,7 @@ public class WorkflowGlobalListener implements GlobalListener {
flowProcessEventHandler.processHandler(definition.getFlowCode(), instance, BusinessStatusEnum.BACK.getStatus(), params, false);
// 修改流程实例状态
instance.setFlowStatus(BusinessStatusEnum.BACK.getStatus());
insService.updateById(instance);
FlowEngine.insService().updateById(instance);
}
}
}
@ -191,12 +190,9 @@ public class WorkflowGlobalListener implements GlobalListener {
if (variable.containsKey(FlowConstant.MESSAGE_TYPE)) {
List<String> messageType = MapUtil.get(variable, FlowConstant.MESSAGE_TYPE, new TypeReference<>() {});
String notice = MapUtil.getStr(variable, FlowConstant.MESSAGE_NOTICE);
// 消息通知
if (CollUtil.isNotEmpty(messageType)) {
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
}
flwCommonService.sendMessage(definition.getFlowName(), instance.getId(), messageType, notice);
}
insService.removeVariables(instance.getId(),
FlowEngine.insService().removeVariables(instance.getId(),
FlowConstant.FLOW_COPY_LIST,
FlowConstant.MESSAGE_TYPE,
FlowConstant.MESSAGE_NOTICE,
@ -220,7 +216,7 @@ public class WorkflowGlobalListener implements GlobalListener {
if (flwTaskService.isTaskEnd(instanceId)) {
String status = BusinessStatusEnum.FINISH.getStatus();
// 更新流程状态为已完成
instanceService.updateStatus(instanceId, status);
flwInstanceService.updateStatus(instanceId, status);
log.info("流程已结束,状态更新为: {}", status);
return status;
}

@ -11,9 +11,8 @@ import org.dromara.common.core.utils.StringUtils;
import org.dromara.resource.api.RemoteMailService;
import org.dromara.resource.api.RemoteMessageService;
import org.dromara.system.api.domain.vo.RemoteUserVo;
import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.entity.Node;
import org.dromara.warm.flow.core.enums.SkipType;
import org.dromara.warm.flow.core.service.NodeService;
import org.dromara.warm.flow.orm.entity.FlowTask;
import org.dromara.workflow.common.ConditionalOnEnable;
import org.dromara.workflow.common.enums.MessageTypeEnum;
@ -21,8 +20,9 @@ import org.dromara.workflow.service.IFlwCommonService;
import org.dromara.workflow.service.IFlwTaskService;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
/**
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
@Service
public class FlwCommonServiceImpl implements IFlwCommonService {
private final NodeService nodeService;
private static final String DEFAULT_SUBJECT = "单据审批提醒";
@DubboReference
private RemoteMessageService remoteMessageService;
@ -44,16 +44,23 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
private RemoteMailService remoteMailService;
/**
*
*
*
* @param flowName
* @param messageType
* @param message
* @param instId ID
* @param messageType
* @param message 使
*/
@Override
public void sendMessage(String flowName, Long instId, List<String> messageType, String message) {
if (CollUtil.isNotEmpty(messageType)) {
return;
}
IFlwTaskService flwTaskService = SpringUtils.getBean(IFlwTaskService.class);
List<FlowTask> list = flwTaskService.selectByInstId(instId);
if (CollUtil.isEmpty(list)) {
return;
}
if (StringUtils.isBlank(message)) {
message = "有新的【" + flowName + "】单据已经提交至您,请您及时处理。";
}
@ -61,19 +68,25 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
if (CollUtil.isEmpty(userList)) {
return;
}
sendMessage(messageType, message, "单据审批提醒", userList);
sendMessage(messageType, message, DEFAULT_SUBJECT, userList);
}
/**
*
*
*
* @param messageType
* @param messageType
* @param message
* @param subject
* @param userList
* @param userList
*/
@Override
public void sendMessage(List<String> messageType, String message, String subject, List<RemoteUserVo> userList) {
if (CollUtil.isEmpty(messageType) || CollUtil.isEmpty(userList)) {
return;
}
List<Long> userIds = new ArrayList<>(StreamUtils.toSet(userList, RemoteUserVo::getUserId));
String emails = StreamUtils.join(userList, RemoteUserVo::getEmail);
for (String code : messageType) {
MessageTypeEnum messageTypeEnum = MessageTypeEnum.getByCode(code);
if (ObjectUtil.isEmpty(messageTypeEnum)) {
@ -81,11 +94,10 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
}
switch (messageTypeEnum) {
case SYSTEM_MESSAGE -> {
List<Long> userIds = StreamUtils.toList(userList, RemoteUserVo::getUserId).stream().distinct().collect(Collectors.toList());
remoteMessageService.publishMessage(userIds, message);
}
case EMAIL_MESSAGE -> {
remoteMailService.send(StreamUtils.join(userList, RemoteUserVo::getEmail), "单据审批提醒", message);
remoteMailService.send(emails, subject, message);
}
case SMS_MESSAGE -> {
//todo 短信发送
@ -103,9 +115,8 @@ public class FlwCommonServiceImpl implements IFlwCommonService {
*/
@Override
public String applyNodeCode(Long definitionId) {
Node startNode = nodeService.getStartNode(definitionId);
Node nextNode = nodeService.getNextNode(definitionId, startNode.getNodeCode(), null, SkipType.PASS.getKey());
return nextNode.getNodeCode();
List<Node> firstBetweenNode = FlowEngine.nodeService().getFirstBetweenNode(definitionId, new HashMap<>());
return firstBetweenNode.get(0).getNodeCode();
}
}

Loading…
Cancel
Save