Commit 771dac8c by Java-曹文达

监听测试 添加工具类解决无法注入bean的问题

parent a8c1e2d7
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
<select id="getUserId" parameterType="com.bbd.bpm.domain.BpmEmployee" resultType="com.bbd.bpm.domain.BpmEmployee"> <select id="getUserId" parameterType="com.bbd.bpm.domain.BpmEmployee" resultType="com.bbd.bpm.domain.BpmEmployee">
SELECT SELECT
user_id userId user_code userCode
FROM FROM
bpm_employee bpm_employee
where position=#{position} where position=#{position}
......
...@@ -28,6 +28,9 @@ public class BpmEmployee extends BaseEntity { ...@@ -28,6 +28,9 @@ public class BpmEmployee extends BaseEntity {
//用户标识 //用户标识
@Column(name = "user_id") @Column(name = "user_id")
private Integer userId; private Integer userId;
//用户code
@Column(name = "user_code")
private String userCode;
} }
package com.bbd.bpm.dto.response; package com.bbd.bpm.dto.response;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date; import java.util.Date;
/** /**
...@@ -11,8 +13,10 @@ public class ApprovedDetailBean { ...@@ -11,8 +13,10 @@ public class ApprovedDetailBean {
private String assigneeUserId; private String assigneeUserId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime; private Date startTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime; private Date endTime;
private String comments; private String comments;
......
...@@ -5,6 +5,7 @@ import com.bbd.bpm.repository.UserRepository; ...@@ -5,6 +5,7 @@ import com.bbd.bpm.repository.UserRepository;
import com.bbd.bpm.result.Result; import com.bbd.bpm.result.Result;
import com.bbd.bpm.service.UserInfoService; import com.bbd.bpm.service.UserInfoService;
import com.bbd.bpm.serviceImpl.UserInfoServiceImpl; import com.bbd.bpm.serviceImpl.UserInfoServiceImpl;
import com.bbd.bpm.util.ApplicationContextHolder;
import com.bbd.bpm.util.ContextUtils; import com.bbd.bpm.util.ContextUtils;
import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines; import org.activiti.engine.ProcessEngines;
...@@ -16,10 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,10 +17,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.Serializable; import java.io.Serializable;
import java.util.Optional;
/** /**
* Created by houkang on 2019/1/28. * Created by houkang on 2019/1/28.
*/ */
@Component
public class PutAssigneeListener implements Serializable, TaskListener { public class PutAssigneeListener implements Serializable, TaskListener {
private FixedValue job; private FixedValue job;
...@@ -29,8 +32,6 @@ public class PutAssigneeListener implements Serializable, TaskListener { ...@@ -29,8 +32,6 @@ public class PutAssigneeListener implements Serializable, TaskListener {
private FixedValue company; private FixedValue company;
@Autowired
private UserInfoService userInfoService;
@Override @Override
...@@ -49,6 +50,8 @@ public class PutAssigneeListener implements Serializable, TaskListener { ...@@ -49,6 +50,8 @@ public class PutAssigneeListener implements Serializable, TaskListener {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
TaskService taskService = processEngine.getTaskService(); TaskService taskService = processEngine.getTaskService();
UserInfoService userInfoService = ApplicationContextHolder.getBean(UserInfoService.class).orElse(null);
BpmEmployee bpmEmployee=new BpmEmployee(); BpmEmployee bpmEmployee=new BpmEmployee();
BpmEmployee bpmEmployee1=new BpmEmployee(); BpmEmployee bpmEmployee1=new BpmEmployee();
...@@ -74,7 +77,7 @@ public class PutAssigneeListener implements Serializable, TaskListener { ...@@ -74,7 +77,7 @@ public class PutAssigneeListener implements Serializable, TaskListener {
} }
} }
//取出查到的userId 标识 //取出查到的userId 标识
delegateTask.setAssignee(bpmEmployee.getUserId().toString()); delegateTask.setAssignee(bpmEmployee.getUserCode());
} }
}else{ }else{
taskService.setAssignee(delegateTask.getId(),"hr"); taskService.setAssignee(delegateTask.getId(),"hr");
......
package com.bbd.bpm.util;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* Created by houkang on 2019/3/19.
*/
@Component
public class ApplicationContextHolder implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context=applicationContext;
}
public static <T> Optional<T> getBean(Class<T> type){
if (context==null){
return Optional.empty();
}
return Optional.of(context.getBean(type));
}
public static <T> Optional<T> getBean(String name,Class<T> type){
if (context==null){
return Optional.empty();
}
return Optional.of(context.getBean(name,type));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment