diff --git a/renren-admin/src/main/java/io/renren/common/annotation/ActivitiNoticeOperation.java b/renren-admin/src/main/java/io/renren/common/annotation/ActivitiNoticeOperation.java index b4a0a2c1..1a60a025 100644 --- a/renren-admin/src/main/java/io/renren/common/annotation/ActivitiNoticeOperation.java +++ b/renren-admin/src/main/java/io/renren/common/annotation/ActivitiNoticeOperation.java @@ -25,4 +25,9 @@ public @interface ActivitiNoticeOperation { * @return */ String process() default ""; + + /** + * @return activiti 监听器类型 1:TaskListener 任务监听器; 2:ExecutionListener 执行监听器; + */ + int type() default 1; } diff --git a/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java b/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java index 5cab0772..7a282a39 100644 --- a/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java +++ b/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java @@ -7,7 +7,9 @@ import io.renren.modules.notice.enums.NoticeStatusEnum; import io.renren.modules.notice.service.SysNoticeService; import io.renren.modules.sys.dto.SysUserDTO; import io.renren.modules.sys.service.SysUserService; +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 org.apache.commons.lang3.StringUtils; import org.aspectj.lang.JoinPoint; @@ -57,25 +59,119 @@ public class ActivitiNoticeAspect { MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = joinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), signature.getParameterTypes()); final ActivitiNoticeOperation activitiNoticeOperation = method.getAnnotation(ActivitiNoticeOperation.class); - Arrays.asList(joinPoint.getArgs()).stream().findFirst().ifPresent(arg -> { - final DelegateTask delegateTask = (DelegateTask) arg; - final String eventName = delegateTask.getEventName(); - switch (eventName) { - case TaskListener.EVENTNAME_ASSIGNMENT: // 节点被委派给某人 - logger.error("事件:" + eventName); - notice(delegateTask, activitiNoticeOperation); - break; - default: - } - }); + switch (activitiNoticeOperation.type()) { + case 1: { + Arrays.asList(joinPoint.getArgs()).stream().findFirst().ifPresent(arg -> { + final DelegateTask delegateTask = (DelegateTask) arg; + final String eventName = delegateTask.getEventName(); + switch (eventName) { + case TaskListener.EVENTNAME_ASSIGNMENT: // 节点被委派给某人 + logger.error("任务监听器事件:" + eventName); + assignment_notice(delegateTask, activitiNoticeOperation); + break; + default: + } + }); + } // 任务监听器类型 + break; + case 2: { + Arrays.asList(joinPoint.getArgs()).stream().findFirst().ifPresent(arg -> { + final DelegateExecution execution = (DelegateExecution) arg; + final String eventName = execution.getEventName(); + switch (eventName) { + case ExecutionListener.EVENTNAME_END: // 节点被委派给某人 + logger.error("执行监听器事件:" + eventName); + end_notice(execution, activitiNoticeOperation); + break; + default: + } + }); + } // 执行监听器 + break; + } //执行时长(毫秒) long time = System.currentTimeMillis() - beginTime; logger.error("执行时长{} ms", time); } - private void notice(DelegateTask delegateTask, final ActivitiNoticeOperation activitiNoticeOperation) { + /** + * 流程结束时通知 + * + * @param execution + * @param activitiNoticeOperation + */ + private void end_notice(final DelegateExecution execution, final ActivitiNoticeOperation activitiNoticeOperation) { + Map kv = execution.getVariables(); + logger.error("表单:" + kv.toString()); + if (work_.contains(kv.get("id").toString())) { + logger.error("------------出现重放------------"); + return; + } + work_.add(kv.get("id").toString()); + String creator = null; + if (kv.containsKey("creator")) { // 表单存在创建者 + creator = kv.get("creator").toString(); + } else if (kv.containsKey("userId")) { + creator = kv.get("userId").toString(); + } + if (StringUtils.isEmpty(creator)) { + return; + } + try { + String result = ""; + Boolean termination = + Boolean.valueOf(execution.getVariables().get("termination").toString()); // 直接终结 + Boolean reject = + Boolean.valueOf(execution.getVariables().get("reject").toString()); // 被拒绝 + if (termination) { + result = "终止被拒"; + } else if (reject) { + result = "被拒"; + } else { + result = "通过"; + } + String finalCreator = creator; + String finalResult = result; + CompletableFuture.runAsync(() -> { // 发起人 + String content = "您发起的流程<" + activitiNoticeOperation.process() + "> 已结束。审核结果为:" + finalResult; + SysNoticeDTO dto = new SysNoticeDTO(); + dto.setType(2); + dto.setTitle("流程结束系统通知"); + dto.setContent(content); // 通知内容 + dto.setReceiverType(1); + dto.setReceiverTypeIds(finalCreator); + dto.setStatus(NoticeStatusEnum.SEND.value()); + dto.setSenderName("流程系统"); + dto.setSenderDate(new Date()); + dto.setCreator(sysUserService.getByUsername("admin").getId()); + dto.setCreateDate(new Date()); + sysNoticeService.save(dto); + }).thenRunAsync(() -> { + // 防止重放 + new Thread(() -> { + try { + Thread.sleep(200); + work_.remove(kv.get("id").toString()); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }).start(); + }); + } catch (Exception exception) { + logger.error("发送通知消息异常", exception); + } + + } + + /** + * 分配审批人时 + * + * @param delegateTask + * @param activitiNoticeOperation + */ + private void assignment_notice(final DelegateTask delegateTask, final ActivitiNoticeOperation activitiNoticeOperation) { Map kv = delegateTask.getVariables(); - logger.error("录入表单:" + kv.toString()); + logger.error("表单:" + kv.toString()); if (work_.contains(kv.get("id").toString())) { logger.error("------------出现重放------------"); return; @@ -96,7 +192,7 @@ public class ActivitiNoticeAspect { SysUserDTO assignee = sysUserService.get(Long.valueOf(delegateTask.getAssignee())); String content = "您发起的流程<" + activitiNoticeOperation.process() + ">当前审核节点为:" + activitiNoticeOperation.value() + - "
当前审核人为\"" + + ";当前审核人为:\"" + assignee.getDeptName() + "\"审核负责人\"" + assignee.getRealName(); SysNoticeDTO dto = new SysNoticeDTO(); dto.setType(2); @@ -112,7 +208,7 @@ public class ActivitiNoticeAspect { sysNoticeService.save(dto); }).thenRunAsync(() -> { // 审批者 SysUserDTO owner = sysUserService.get(Long.valueOf(finalCreator)); - String content = owner.getRealName() + "发起的流程<" + activitiNoticeOperation.process() + ">当前审核节点为:" + activitiNoticeOperation.value() + "
当前审核人指派为您"; + String content = owner.getRealName() + "发起的流程<" + activitiNoticeOperation.process() + ">当前审核节点为:" + activitiNoticeOperation.value() + ";当前审核人指派为您"; SysNoticeDTO dto = new SysNoticeDTO(); dto.setType(2); dto.setTitle("流程流转系统通知"); diff --git a/renren-admin/src/main/java/io/renren/modules/demanData/listener/DemandDataListener.java b/renren-admin/src/main/java/io/renren/modules/demanData/listener/DemandDataListener.java index f68f5f90..2a410089 100644 --- a/renren-admin/src/main/java/io/renren/modules/demanData/listener/DemandDataListener.java +++ b/renren-admin/src/main/java/io/renren/modules/demanData/listener/DemandDataListener.java @@ -60,6 +60,7 @@ public class DemandDataListener implements TaskListener, ExecutionListener, Acti private TDemandDataService tDemandDataService; @Override + @ActivitiNoticeOperation(value = "流程结束", process = "能力需求申请", type = 2) public void notify(DelegateExecution execution) throws Exception { logger.error("----------------------进入能力需求受理者结束节点---------------------------"); execution.getProcessBusinessKey(); 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 aebfc761..ec017133 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 @@ -84,6 +84,7 @@ public class CorrectionListener implements TaskListener, ExecutionListener, Acti } @Override + @ActivitiNoticeOperation(value = "流程结束", process = "能力申请流程", type = 2) public void notify(DelegateExecution delegateExecution) throws Exception { logger.error("----------------------进入部门审批结束节点---------------------------"); delegateExecution.getProcessBusinessKey(); diff --git a/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java b/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java index 514a3cec..f09d37c5 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/listener/ResourceUndercarriageListener.java @@ -74,6 +74,7 @@ public class ResourceUndercarriageListener implements TaskListener, ExecutionLis } @Override + @ActivitiNoticeOperation(value = "流程结束", process = "能力资源下架", type = 2) public void notify(DelegateExecution execution) throws Exception { logger.error("----------------------进入审批通过节点---------------------------"); logger.error("事件类型:" + execution.getEventName()); diff --git a/renren-admin/src/main/java/io/renren/modules/resourceMountApply/listener/ResourceOwnerListener.java b/renren-admin/src/main/java/io/renren/modules/resourceMountApply/listener/ResourceOwnerListener.java index b8c6d7f3..9ba09605 100644 --- a/renren-admin/src/main/java/io/renren/modules/resourceMountApply/listener/ResourceOwnerListener.java +++ b/renren-admin/src/main/java/io/renren/modules/resourceMountApply/listener/ResourceOwnerListener.java @@ -56,6 +56,7 @@ public class ResourceOwnerListener implements TaskListener, ExecutionListener, A private ResourceService resourceService; @Override + @ActivitiNoticeOperation(value = "流程结束", process = "能力资源上架", type = 2) public void notify(DelegateExecution execution) throws Exception { logger.error("----------------------进入审批通过节点---------------------------"); logger.error("事件类型:" + execution.getEventName());