因为这个项目license问题无法开源,更多技术支持与服务请加入我的知识星球。
在新的jeecg-boot3.6.3里加入下面的代码
/*** 部门经理处理类** @author nbacheng* @date 2023-08-06*/
@AllArgsConstructor
@Component("DepManagerHandler")
@DependsOn({"SpringContextUtils"})
public class DepManagerHandler {RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);IFlowThirdService flowThirdService = SpringContextUtils.getBean(IFlowThirdService.class);public List<String> getUsers(DelegateExecution execution) {List<String> assignUserName = new ArrayList<String>();FlowElement flowElement = execution.getCurrentFlowElement();if (ObjectUtil.isNotEmpty(flowElement) && flowElement instanceof UserTask) {UserTask userTask = (UserTask) flowElement;if ( ObjectUtil.isNotEmpty(userTask.getCandidateGroups())) {if(StringUtils.contains(userTask.getCandidateGroups().get(0),"DepManagerHandler")) {// 获取流程发起人ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();String startUserId = processInstance.getStartUserId();// 获取部门负责人列表List<String> depIds = flowThirdService.getDepartIdsByUsername(startUserId);List<String> DepHeadlist = new ArrayList<String>();for(String depId: depIds) {List<String> depList = flowThirdService.getDeptHeadByDepId(depId);if(depList != null) {DepHeadlist.addAll(depList);}}// 部门负责人列表去重if(!DepHeadlist.isEmpty() ) {for (String str : DepHeadlist) {if (!assignUserName.contains(str)) {assignUserName.add(str);}}}}}} return assignUserName;}
}
出现空指针的问题,如下
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2024-06-23 10:17:27.770 [main] [1;31mERROR[0;39m [36morg.springframework.boot.SpringApplication:818[0;39m - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DepManagerHandler' defined in file [F:\codestudy\jeecg-boot-v3.6.3\jeecg-module-flowable\target\classes\org\jeecg\modules\flowable\listener\DepManagerHandler.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jeecg.modules.flowable.listener.DepManagerHandler]: Constructor threw exception; nested exception is java.lang.NullPointerExceptionat org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:310)at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:291)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
通过跟踪就是就是下面出错,以前在3.00的时候好像没有问题
RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);
那就通过下面的方式修改
/*** 部门经理处理类** @author nbacheng* @date 2023-08-06*/
@AllArgsConstructor
@Component("DepManagerHandler")
public class DepManagerHandler {@ResourceSpringContextUtils springContextUtils;IFlowThirdService flowThirdService = SpringContextUtils.getBean(IFlowThirdService.class);RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class);public List<String> getUsers(DelegateExecution execution) {List<String> assignUserName = new ArrayList<String>();FlowElement flowElement = execution.getCurrentFlowElement();if (ObjectUtil.isNotEmpty(flowElement) && flowElement instanceof UserTask) {UserTask userTask = (UserTask) flowElement;if ( ObjectUtil.isNotEmpty(userTask.getCandidateGroups())) {if(StringUtils.contains(userTask.getCandidateGroups().get(0),"DepManagerHandler")) {// 获取流程发起人ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult();String startUserId = processInstance.getStartUserId();// 获取部门负责人列表List<String> depIds = flowThirdService.getDepartIdsByUsername(startUserId);List<String> DepHeadlist = new ArrayList<String>();for(String depId: depIds) {List<String> depList = flowThirdService.getDeptHeadByDepId(depId);if(depList != null) {DepHeadlist.addAll(depList);}}// 部门负责人列表去重if(!DepHeadlist.isEmpty() ) {for (String str : DepHeadlist) {if (!assignUserName.contains(str)) {assignUserName.add(str);}}}}}} return assignUserName;}
}
这样启动就不会出现问题了。