From 396a7b5c6b1400814c4d5ef898e8bb2cbb26bce1 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Mon, 16 May 2022 16:33:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=85=AC=E5=85=B1=E5=BD=95?= =?UTF-8?q?=E5=85=A5=E8=A1=A8=E5=8D=95=EF=BC=88=E4=BD=9C=E4=B8=BA=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=B5=81=E7=A8=8B=E7=AC=AC=E4=B8=80=E4=B8=AA=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BB=BB=E5=8A=A1=EF=BC=89=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/InitiatorDataEntryListener.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 renren-admin/src/main/java/io/renren/common/listener/InitiatorDataEntryListener.java diff --git a/renren-admin/src/main/java/io/renren/common/listener/InitiatorDataEntryListener.java b/renren-admin/src/main/java/io/renren/common/listener/InitiatorDataEntryListener.java new file mode 100644 index 00000000..c83e5f59 --- /dev/null +++ b/renren-admin/src/main/java/io/renren/common/listener/InitiatorDataEntryListener.java @@ -0,0 +1,67 @@ +package io.renren.common.listener; + + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import io.renren.common.dto.AuditingBaseDTO; +import org.activiti.engine.TaskService; +import org.activiti.engine.delegate.DelegateTask; +import org.activiti.engine.delegate.TaskListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.util.Map; + +/** + * 流程发起人录入表单 + */ +@Component +public class InitiatorDataEntryListener implements TaskListener { + private static Logger logger = LoggerFactory.getLogger(InitiatorDataEntryListener.class); + + @Autowired + private TaskService taskService; + + @Override + public void notify(DelegateTask delegateTask) { + logger.error("----------------------流程发起人录入表单节点---------------------------"); + logger.error("事件类型:" + delegateTask.getEventName()); + final String eventName = delegateTask.getEventName(); + switch (eventName) { + case EVENTNAME_CREATE: + create(delegateTask); + break; + } + } + + private void create(DelegateTask delegateTask) { + Map kv = delegateTask.getVariables(); + logger.error("录入表单:" + kv.toString()); + if (kv.containsKey("creator")) { // 表单存在创建者 + taskService.setAssignee(delegateTask.getId(), kv.get("creator").toString()); + } + GsonBuilder builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, (JsonDeserializer) (json, typeOfT, context) -> new Date(json.getAsJsonPrimitive().getAsLong())); + + Gson gson = builder.create(); + JsonElement jsonElement = gson.toJsonTree(kv); + AuditingBaseDTO auditingBaseDTO = gson.fromJson(jsonElement, AuditingBaseDTO.class); + if (auditingBaseDTO.getBackToFirst() != null && auditingBaseDTO.getBackToFirst()) { + taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "被驳回需修改后重新提交"); + logger.error("被驳回,需修改后重新提交"); + } else { + if (auditingBaseDTO.getCompleteEntry()) { + taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "完成申请提交"); + taskService.complete(delegateTask.getId(), delegateTask.getVariables()); + logger.error("首次录入,自动审核通过!"); + } + } + logger.error("----------完成录入表单-----------"); + return; + } +}