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

代码优化

上级 c546b748
......@@ -22,6 +22,11 @@
<artifactId>ruoyi-common-nacos</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-sentinel</artifactId>
</dependency>
<!--引入flowable依赖-->
<dependency>
<groupId>org.flowable</groupId>
......@@ -113,6 +118,10 @@
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-tenant</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-api-system</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
......@@ -134,6 +143,11 @@
<artifactId>ruoyi-api-workflow</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-core</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......
......@@ -2,11 +2,14 @@ package org.dromara.workflow.flowable.config;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import org.dromara.workflow.flowable.handler.TaskTimeoutJobHandler;
import org.flowable.common.engine.impl.cfg.SpringBeanFactoryProxyMap;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Collections;
......@@ -22,11 +25,14 @@ public class FlowableConfig implements EngineConfigurationConfigurer<SpringProce
private GlobalFlowableListener globalFlowableListener;
@Autowired
private IdentifierGenerator identifierGenerator;
@Resource
private ApplicationContext applicationContext;
@Override
public void configure(SpringProcessEngineConfiguration processEngineConfiguration) {
processEngineConfiguration.setIdGenerator(() -> identifierGenerator.nextId(null).toString());
processEngineConfiguration.setEventListeners(Collections.singletonList(globalFlowableListener));
processEngineConfiguration.addCustomJobHandler(new TaskTimeoutJobHandler());
processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(applicationContext));
}
}
package org.dromara.workflow.flowable.listener;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.system.api.RemoteDeptService;
import org.dromara.common.core.utils.SpringUtils;
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.TaskListener;
import org.springframework.stereotype.Component;
......@@ -12,18 +13,17 @@ import java.util.Objects;
@Component
public class DynamicAssigneeListener implements TaskListener {
@DubboReference
private RemoteDeptService remoteDeptService;
@Override
public void notify(DelegateTask delegateTask) {
// 获取申请人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;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.resource.api.RemoteFileService;
import org.dromara.system.api.RemoteDeptService;
import org.dromara.system.api.RemoteUserService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
......@@ -23,6 +24,8 @@ public class WorkflowApplicationRunner implements ApplicationRunner {
private RemoteUserService remoteUserService;
@DubboReference
private RemoteFileService remoteFileService;
@DubboReference
private RemoteDeptService remoteDeptService;
@Override
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论