提交 41ace484 编写于 作者: sq3536's avatar sq3536

工作流审批意见

上级 dd174a92
package cn.ibizlab.core.extensions.domain;
import cn.ibizlab.util.security.AuthenticationUser;
import org.flowable.common.engine.api.identity.AuthenticationContext;
import org.flowable.common.engine.impl.identity.Authentication;
import java.security.Principal;
public class FlowUser implements Principal {
public String getName() {
return this.user.getUserid();
}
private AuthenticationUser user;
private String token;
public AuthenticationUser getUser() {
return user;
}
public void setUser(AuthenticationUser user) {
this.user = user;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public static FlowUser getCurUser()
{
AuthenticationContext context = Authentication.getAuthenticationContext();
if(context!=null&&context.getPrincipal()!=null&&context.getPrincipal() instanceof FlowUser)
return (FlowUser)context.getPrincipal();
else
{
FlowUser user = new FlowUser();
user.setUser(AuthenticationUser.getAuthenticationUser());
return user;
}
}
}
package cn.ibizlab.core.extensions.listener;
import cn.ibizlab.core.extensions.domain.FlowUser;
import cn.ibizlab.core.extensions.service.WFCoreService;
import cn.ibizlab.core.extensions.service.WFModelService;
import cn.ibizlab.util.security.AuthTokenUtil;
......@@ -11,7 +12,9 @@ import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.delegate.event.*;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
......@@ -27,11 +30,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 流程实例监听器,监听流程实例启动、流转、结束状态
* 1.流程状态发生变化时,将实例信息同步到统一工作流平台
* 2.到达流程节点时,调用统一接口,查询当前节点办理人并设置到引擎中
*/
@Slf4j
@Component
public class ProcessInstanceListener implements FlowableEventListener {
......@@ -45,11 +43,37 @@ public class ProcessInstanceListener implements FlowableEventListener {
@Lazy
private RemoteService remoteService;
@Autowired
@Lazy
private TaskService taskService;
@Override
public void onEvent(FlowableEvent evt) {
if(evt instanceof FlowableProcessStartedEventImpl)
if(evt instanceof FlowableEntityWithVariablesEventImpl)
{
FlowableEntityWithVariablesEventImpl event = (FlowableEntityWithVariablesEventImpl) evt;
if(event.getType() == FlowableEngineEventType.TASK_COMPLETED)
{
TaskEntity taskEntity = (TaskEntity)event.getEntity();
if(taskEntity.getTaskDefinitionKey().startsWith("tid-"))
{
Object data=taskEntity.getVariable("activedata");
Object link=taskEntity.getVariable("sequenceFlowName");
if(data!=null&&(data instanceof Map)&&link!=null)
{
Map activedata=(Map)data;
String wfprocdesc="";
if(activedata.get("wfprocdesc")!=null)
wfprocdesc=activedata.get("wfprocdesc").toString();
taskService.addComment(taskEntity.getId(),taskEntity.getProcessInstanceId(),link.toString(),wfprocdesc);
}
}
}
}
else if(evt instanceof FlowableProcessStartedEventImpl)
{
FlowableProcessStartedEventImpl event=(FlowableProcessStartedEventImpl)evt;
if(event.getEntity() instanceof ExecutionEntityImpl){
......@@ -57,9 +81,9 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(executionEntity.getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)executionEntity.getVariable("businessKey");
HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
//HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
Map setting=wfModelService.getProcessGlobalSetting(executionEntity.getProcessDefinitionId());
String wfstepfield="";
......@@ -103,9 +127,9 @@ public class ProcessInstanceListener implements FlowableEventListener {
callbackArg.put(wfverfield,Integer.parseInt(executionEntity.getVariable("wfversion").toString()));
if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null)
if(StringUtils.isEmpty(curUser.getToken()))
return;
String token=curUser.get("bearer-token").toString();
String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
}
......@@ -113,18 +137,14 @@ public class ProcessInstanceListener implements FlowableEventListener {
else if(evt instanceof FlowableEntityEventImpl)
{
FlowableEntityEventImpl event=((FlowableEntityEventImpl) evt);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType();
//待办创建
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED){
ExecutionEntityImpl executionEntity= (ExecutionEntityImpl) event.getEntity();
if(executionEntity.getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)executionEntity.getVariable("businessKey");
HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
//HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
String wfstepfield = executionEntity.getVariable("wfstepfield").toString();
......@@ -138,23 +158,14 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(!StringUtils.isEmpty(wfstepfield))
callbackArg.put(wfstepfield,"");
if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null)
if(StringUtils.isEmpty(curUser.getToken()))
return;
String token=curUser.get("bearer-token").toString();
String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
System.out.println("流程结束");
}
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT){
event.getEntity();
System.out.println("流程异常结束");
}
if(eventType == FlowableEngineEventType.TASK_COMPLETED){
TaskEntity taskEntity = (TaskEntity) event.getEntity();
event.getEntity();
System.out.println("流程异常结束");
}
......@@ -162,15 +173,13 @@ public class ProcessInstanceListener implements FlowableEventListener {
else if(evt instanceof FlowableActivityEventImpl)
{
FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType();
if(eventType == FlowableEngineEventType.ACTIVITY_STARTED && "userTask".equals(event.getActivityType())){
if(event.getExecution().getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)event.getExecution().getVariable("businessKey");
HashMap curUser=(HashMap) event.getExecution().getVariable("curuser");
//HashMap curUser=(HashMap) event.getExecution().getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=event.getExecution().getVariable("entitys").toString();
String cloudServiceid=event.getExecution().getVariable("cloud-serviceid").toString();
String wfstepfield = event.getExecution().getVariable("wfstepfield").toString();
......@@ -178,12 +187,11 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(!StringUtils.isEmpty(wfstepfield)&&event.getActivityId().startsWith("tid-"))
callbackArg.put(wfstepfield,event.getActivityId().split("-")[1]);
if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null)
if(StringUtils.isEmpty(curUser.getToken()))
return;
String token=curUser.get("bearer-token").toString();
String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
}
}
......
......@@ -65,6 +65,16 @@ public class WFCoreResource
return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getTaskLink(system,appname,entity,businessKey,taskId));
}
@ApiOperation(value = "getWFHistory", tags = {"getWFHistory" }, notes = "根据业务主键获取审批意见记录")
@RequestMapping(method = RequestMethod.GET, value = "/{system}-app-{appname}/{entity}/{businessKey}/process-instances/{processInstanceId}/history")
public ResponseEntity<WFProcessInstance> getWFHistory(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@PathVariable("processInstanceId") String processInstanceId) {
if(StringUtils.isEmpty(processInstanceId)||"null".equals(processInstanceId)||"alls".equals(processInstanceId))
processInstanceId="";
return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getWFHistory(system,appname,entity,businessKey,processInstanceId));
}
//@PreAuthorize("hasPermission(#entity,'WFSTART',this.getEntity())")
@ApiOperation(value = "wfsubmit", tags = {"WFProcessInstance" }, notes = "工作流执行步骤")
@RequestMapping(method = RequestMethod.POST, value = "/{system}-app-{appname}/{entity}/{businessKey}/tasks/{taskId}")
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册