From d2439cd0962356f56c0c4611d485aa66be089fd7 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Wed, 20 Apr 2022 10:50:43 +0800 Subject: [PATCH] ... --- .../listener/CorrectionListener.java | 73 +++++++++++++++++-- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java b/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java index cc21c4dd..983a862b 100644 --- a/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java +++ b/renren-admin/src/main/java/io/renren/modules/processForm/listener/CorrectionListener.java @@ -1,19 +1,76 @@ package io.renren.modules.processForm.listener; -import org.activiti.engine.delegate.DelegateExecution; -import org.activiti.engine.delegate.DelegateTask; -import org.activiti.engine.delegate.ExecutionListener; -import org.activiti.engine.delegate.TaskListener; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import io.renren.modules.processForm.dto.TAbilityApplicationDTO; +import io.renren.modules.sys.service.SysRoleService; +import io.renren.modules.sys.service.SysRoleUserService; +import io.renren.modules.sys.service.SysUserService; +import org.activiti.engine.TaskService; +import org.activiti.engine.delegate.*; +import org.activiti.engine.delegate.event.ActivitiEvent; +import org.activiti.engine.delegate.event.ActivitiEventListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Component +public class CorrectionListener implements TaskListener, ExecutionListener, ActivitiEventListener, JavaDelegate { + private static Logger logger = LoggerFactory.getLogger(CorrectionListener.class); + + @Autowired + private SysRoleService sysRoleService; + @Autowired + private TaskService taskService; + @Autowired + private SysUserService sysUserService; + @Autowired + private SysRoleUserService sysRoleUserService; -public class CorrectionListener implements TaskListener, ExecutionListener { @Override public void notify(DelegateTask delegateTask) { + logger.info("进入DelegateTask"); + logger.info("EventName:" + delegateTask.getEventName()); + logger.info("Owner:" + delegateTask.getOwner()); + Map kv = delegateTask.getVariables(); + Gson gson = new Gson(); + JsonElement jsonElement = gson.toJsonTree(kv); + TAbilityApplicationDTO abilityApplicationDTO = gson.fromJson(jsonElement, TAbilityApplicationDTO.class); + logger.info(abilityApplicationDTO.toString()); + abilityApplicationDTO.getUnit(); + delegateTask.setAssignee("1513432847327199233"); - System.out.println("进入DelegateTask"); + String taskKey = delegateTask.getTaskDefinitionKey(); + taskService.setAssignee(delegateTask.getId(), "1516307964617076737"); + String processDefinitionId = delegateTask.getProcessDefinitionId(); } @Override - public void notify(DelegateExecution execution) throws Exception { - System.out.println("进入DelegateExecution"); + public void notify(DelegateExecution delegateExecution) throws Exception { + logger.info("事件:" + delegateExecution.getEventName()); + delegateExecution.getVariableNames().stream().forEach(index -> logger.info("variable:" + index)); + delegateExecution.getVariables().values().stream().filter(index -> index != null).forEach(value -> logger.info(value.toString())); + // taskService.setAssignee(delegateExecution.getProcessInstanceId(), "1516307964617076737");// 可以设置 + + logger.info("修改审批人成功!" + delegateExecution.getCurrentActivityId() + " " + delegateExecution.getProcessInstanceId() + " " + delegateExecution.getProcessBusinessKey()); + } + + @Override + public void onEvent(ActivitiEvent activitiEvent) { // 事件回调 + logger.info("事件类型:" + activitiEvent.getType().toString()); + logger.info("" + activitiEvent.getProcessDefinitionId()); + } + + @Override + public boolean isFailOnException() { + return true; + } + + @Override + public void execute(DelegateExecution delegateExecution) throws Exception { + logger.info("异常", delegateExecution); } }