提交 7f260ac6 authored 作者: hzh's avatar hzh

代码优化

上级 c546b748
...@@ -22,6 +22,11 @@ ...@@ -22,6 +22,11 @@
<artifactId>ruoyi-common-nacos</artifactId> <artifactId>ruoyi-common-nacos</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-sentinel</artifactId>
</dependency>
<!--引入flowable依赖--> <!--引入flowable依赖-->
<dependency> <dependency>
<groupId>org.flowable</groupId> <groupId>org.flowable</groupId>
...@@ -113,6 +118,10 @@ ...@@ -113,6 +118,10 @@
<groupId>org.dromara</groupId> <groupId>org.dromara</groupId>
<artifactId>ruoyi-common-tenant</artifactId> <artifactId>ruoyi-common-tenant</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-api-system</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.dromara</groupId> <groupId>org.dromara</groupId>
...@@ -134,6 +143,11 @@ ...@@ -134,6 +143,11 @@
<artifactId>ruoyi-api-workflow</artifactId> <artifactId>ruoyi-api-workflow</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
......
...@@ -2,11 +2,14 @@ package org.dromara.workflow.flowable.config; ...@@ -2,11 +2,14 @@ package org.dromara.workflow.flowable.config;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.dromara.workflow.flowable.handler.TaskTimeoutJobHandler; import org.dromara.workflow.flowable.handler.TaskTimeoutJobHandler;
import org.flowable.common.engine.impl.cfg.SpringBeanFactoryProxyMap;
import org.flowable.spring.SpringProcessEngineConfiguration; import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer; import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Collections; import java.util.Collections;
...@@ -22,11 +25,14 @@ public class FlowableConfig implements EngineConfigurationConfigurer<SpringProce ...@@ -22,11 +25,14 @@ public class FlowableConfig implements EngineConfigurationConfigurer<SpringProce
private GlobalFlowableListener globalFlowableListener; private GlobalFlowableListener globalFlowableListener;
@Autowired @Autowired
private IdentifierGenerator identifierGenerator; private IdentifierGenerator identifierGenerator;
@Resource
private ApplicationContext applicationContext;
@Override @Override
public void configure(SpringProcessEngineConfiguration processEngineConfiguration) { public void configure(SpringProcessEngineConfiguration processEngineConfiguration) {
processEngineConfiguration.setIdGenerator(() -> identifierGenerator.nextId(null).toString()); processEngineConfiguration.setIdGenerator(() -> identifierGenerator.nextId(null).toString());
processEngineConfiguration.setEventListeners(Collections.singletonList(globalFlowableListener)); processEngineConfiguration.setEventListeners(Collections.singletonList(globalFlowableListener));
processEngineConfiguration.addCustomJobHandler(new TaskTimeoutJobHandler()); processEngineConfiguration.addCustomJobHandler(new TaskTimeoutJobHandler());
processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(applicationContext));
} }
} }
package org.dromara.workflow.flowable.listener; package org.dromara.workflow.flowable.listener;
import org.apache.dubbo.config.annotation.DubboReference; import org.dromara.common.core.utils.SpringUtils;
import org.dromara.system.api.RemoteDeptService; import org.dromara.workflow.common.constant.FlowConstant;
import org.dromara.workflow.service.IDeptService;
import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.DelegateTask;
import org.flowable.task.service.delegate.TaskListener; import org.flowable.task.service.delegate.TaskListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -12,18 +13,17 @@ import java.util.Objects; ...@@ -12,18 +13,17 @@ import java.util.Objects;
@Component @Component
public class DynamicAssigneeListener implements TaskListener { public class DynamicAssigneeListener implements TaskListener {
@DubboReference
private RemoteDeptService remoteDeptService;
@Override @Override
public void notify(DelegateTask delegateTask) { public void notify(DelegateTask delegateTask) {
// 获取申请人ID(从流程变量中获取) // 获取申请人ID(从流程变量中获取)
Long applicantId = (Long) delegateTask.getVariable("applicantId"); Long applicantId = Long.parseLong(delegateTask.getVariable(FlowConstant.INITIATOR).toString());
IDeptService deptService = SpringUtils.getBean(IDeptService.class);
// 调用服务获取审批人列表 // 调用服务获取审批人列表
Long approveId = remoteDeptService.selectLeaderIdByUserId(applicantId); Long approveId = deptService.selectLeaderIdByUserId(applicantId);
// 设置候选用户 // 设置候选用户
delegateTask.addCandidateUser(Objects.isNull(approveId) ? null : approveId.toString()); delegateTask.setAssignee(Objects.isNull(approveId) ? null : approveId.toString());
} }
} }
...@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; ...@@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.resource.api.RemoteFileService; import org.dromara.resource.api.RemoteFileService;
import org.dromara.system.api.RemoteDeptService;
import org.dromara.system.api.RemoteUserService; import org.dromara.system.api.RemoteUserService;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
...@@ -23,6 +24,8 @@ public class WorkflowApplicationRunner implements ApplicationRunner { ...@@ -23,6 +24,8 @@ public class WorkflowApplicationRunner implements ApplicationRunner {
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@DubboReference @DubboReference
private RemoteFileService remoteFileService; private RemoteFileService remoteFileService;
@DubboReference
private RemoteDeptService remoteDeptService;
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
......
package org.dromara.workflow.service;
public interface IDeptService {
/**
* 获取部门负责人id
*
* @param userId 用户id
* @return 负责人id
*/
Long selectLeaderIdByUserId(Long userId);
}
package org.dromara.workflow.service.impl;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.system.api.RemoteDeptService;
import org.dromara.workflow.service.IDeptService;
import org.springframework.stereotype.Service;
/**
* @author hzh
* @date 2025-05-20
* @desc TODO
**/
@Service
@RequiredArgsConstructor
public class DeptServiceImpl implements IDeptService {
@DubboReference
private RemoteDeptService remoteDeptService;
@Override
public Long selectLeaderIdByUserId(Long userId) {
return remoteDeptService.selectLeaderIdByUserId(userId);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论