From bdc81e53743077aa3c9aae1168ed125d1c04efbd Mon Sep 17 00:00:00 2001 From: WendyYang Date: Tue, 24 Sep 2024 14:28:57 +0800 Subject: [PATCH] =?UTF-8?q?modify:=201.=20=E7=94=A8=E6=88=B7=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=AE=8C=E6=88=90=E7=9B=91=E5=90=AC=E5=99=A8;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/listener/TaskCreatedListener.java | 240 --------------------- .../listener/UserTaskCreateOrFinishListener.java | 240 +++++++++++++++++++++ 2 files changed, 240 insertions(+), 240 deletions(-) delete mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java create mode 100644 hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java deleted file mode 100644 index 1b9e153..0000000 --- a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.hz.pm.api.scheduler.listener; - -import cn.hutool.core.util.StrUtil; -import cn.hutool.extra.spring.SpringUtil; -import com.hz.pm.api.common.enumeration.ProjectProcessType; -import com.hz.pm.api.common.helper.UserInfoHelper; -import com.hz.pm.api.common.helper.WflowHelper; -import com.hz.pm.api.external.MhApiClient; -import com.hz.pm.api.external.model.dto.MhZwddWorkNoticeDTO; -import com.hz.pm.api.external.todo.MHTodoClient; -import com.hz.pm.api.external.todo.dto.MhTodoExtraParamDTO; -import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; -import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; -import com.hz.pm.api.projectdeclared.model.entity.Xinchuang; -import com.hz.pm.api.projectdeclared.model.entity.XinchuangInst; -import com.hz.pm.api.projectdeclared.service.IPurchaseInstService; -import com.hz.pm.api.projectdeclared.service.IXinchuangInstService; -import com.hz.pm.api.projectdeclared.service.IXinchuangService; -import com.hz.pm.api.projectlib.model.entity.Project; -import com.hz.pm.api.projectlib.model.entity.ProjectInst; -import com.hz.pm.api.projectlib.service.IProjectInstService; -import com.hz.pm.api.projectlib.service.IProjectService; -import com.hz.pm.api.user.security.model.UserFullInfoDTO; -import com.ningdatech.basic.exception.BizException; -import com.ningdatech.basic.util.CollUtils; -import com.wflow.bean.entity.WflowModelHistorys; -import com.wflow.workflow.notify.event.NodeCompleteEvent; -import com.wflow.workflow.notify.event.NodeCreateEvent; -import com.wflow.workflow.service.ProcessModelHistorysService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.flowable.engine.HistoryService; -import org.flowable.engine.TaskService; -import org.flowable.task.api.Task; -import org.flowable.task.api.history.HistoricTaskInstance; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -import java.time.Instant; -import java.util.List; -import java.util.Set; - -import static com.hz.pm.api.common.util.ThreadPoolUtil.SCHEDULER; - -/** - *

- * TaskCreatedListener - *

- * - * @author WendyYang - * @since 10:38 2024/3/12 - */ -@Slf4j -@Component -@RequiredArgsConstructor -public class TaskCreatedListener { - - private final HistoryService historyService; - private final IProjectService projectService; - private final IProjectInstService projectInstService; - private final ProcessModelHistorysService processModelHistorysService; - private final MHTodoClient mhTodoClient; - private final MhApiClient mhApiClient; - private final UserInfoHelper userInfoHelper; - private final IPurchaseInstService purchaseInstService; - private final IXinchuangInstService xinchuangInstService; - private final IXinchuangService xinchuangService; - private final TaskService taskService; - - private Instant instantDelay10s() { - return Instant.now().plusSeconds(10); - } - - @EventListener(classes = NodeCreateEvent.class) - public void onEvent(NodeCreateEvent event) { - SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); - } - - @EventListener(classes = NodeCompleteEvent.class) - public void onEvent(NodeCompleteEvent event) { - SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); - } - - public void handleEvent(NodeCreateEvent event) { - String procDefId = event.getProcessDefinitionId(); - String procInstId = event.getInstCode(); - WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); - ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); - Task task = taskService.createTaskQuery() - .taskId(event.getTaskId()) - .singleResult(); - UserFullInfoDTO assignee = userInfoHelper.getUserFullInfo(task.getAssignee()); - if (assignee == null || StrUtil.isBlank(assignee.getMhUserId())) { - return; - } - switch (procType) { - case XC_APPROVAL_PROCESS: - case PROJECT_RECORD_APPROVAL_PROCESS: - case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: - case ADAPTION: - case SELF_TEST: - case TEST_VALID: - case PROJECT_CHANGE: - case PROJECT_STOPPED: - case COMPLIANCE_REVIEW: - case PROJECT_REVIEW: - // 发送信产平台待办 - MHTodoTypeEnum todoType = getMhTodoTypeEnum(procType); - MhTodoExtraParamDTO paramObj = MhTodoExtraParamDTO.builder() - .taskId(task.getId()) - .instanceId(task.getProcessInstanceId()) - .nodeId(task.getTaskDefinitionId()) - .userId(assignee.getUserId()) - .userName(assignee.getRealName()) - .path("/toDoCenter/handleDuringExamine") - .build(); - if (procType.equals(ProjectProcessType.ACCEPTANCE_DECLARATION_APPROVAL_PROCESS) - || procType.equals(ProjectProcessType.ADAPTION) - || procType.equals(ProjectProcessType.XC_APPROVAL_PROCESS) - || procType.equals(ProjectProcessType.TEST_VALID) - || procType.equals(ProjectProcessType.SELF_TEST)) { - PurchaseInst purchaseInst = purchaseInstService.getByProjectIdAndInstCode(paramObj.getProjectId(), procInstId); - paramObj.setBidId(purchaseInst.getBidId()); - paramObj.setProjectId(purchaseInst.getProjectId()); - } - String projectName = ""; - // 上边查不到ID的时候说明是手动新增的信创项目 - if (paramObj.getBidId() == null) { - XinchuangInst xinchuangInst = xinchuangInstService.getByInstCode(procInstId); - if (xinchuangInst != null) { - Xinchuang xinchuang = xinchuangService.getById(xinchuangInst.getXinchuangId()); - paramObj.setXinchuangId(xinchuang.getId()); - projectName = xinchuang.getProjectName(); - } else { - ProjectInst projectInst = projectInstService.getByInstCode(procInstId); - if (projectInst == null) { - return; - } - paramObj.setProjectId(projectInst.getProjectId()); - } - } - if (paramObj.getProjectId() != null) { - Project project = projectService.getNewProject(paramObj.getProjectId()); - projectName = project.getProjectName(); - paramObj.setProjectId(project.getId()); - paramObj.setProjectCode(project.getProjectCode()); - } - String content = String.format("【%s】的【%s】需要您审核,请及时处理。", projectName, procType.getDesc()); - mhTodoClient.addTodo(paramObj, assignee, todoType, task.getId(), content); - // 发送浙政钉工作通知 - if (assignee.getAccountId() != null) { - MhZwddWorkNoticeDTO notice = MhZwddWorkNoticeDTO.builder() - .content(content) - .title(todoType.getVal()) - .targetUser(assignee.getMhUserId()) - .build(); - mhApiClient.sendZwddWorkNotice(notice); - } - break; - default: - break; - } - } - - public void handleEvent(NodeCompleteEvent event) { - String procDefId = event.getProcessDefinitionId(); - WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); - ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); - WflowHelper wflowHelper = SpringUtil.getBean(WflowHelper.class); - HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery() - .taskId(event.getTaskId()) - .singleResult(); - boolean orUserTask = wflowHelper.isOrUserTask(procDefId, task.getTaskDefinitionKey()); - switch (procType) { - case XC_APPROVAL_PROCESS: - case PROJECT_RECORD_APPROVAL_PROCESS: - case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: - case ADAPTION: - case SELF_TEST: - case TEST_VALID: - case PROJECT_CHANGE: - case PROJECT_STOPPED: - case COMPLIANCE_REVIEW: - case PROJECT_REVIEW: - MHTodoTypeEnum todoType = getMhTodoTypeEnum(procType); - log.info("完成任务: {} 信产待办:{}", event.getTaskId(), todoType); - if (orUserTask) { - List tasks = wflowHelper.listFinishedTasks(task.getTaskDefinitionKey()); - Set taskIds = CollUtils.fieldSet(tasks, HistoricTaskInstance::getId); - taskIds.add(task.getId()); - mhTodoClient.completeTodo(todoType, taskIds); - } else { - mhTodoClient.completeTodo(todoType, task.getId()); - } - break; - default: - break; - } - } - - private MHTodoTypeEnum getMhTodoTypeEnum(ProjectProcessType procType) { - MHTodoTypeEnum todoType; - switch (procType) { - case XC_APPROVAL_PROCESS: - todoType = MHTodoTypeEnum.XCFHX_INSPECT_AUDIT; - break; - case PROJECT_RECORD_APPROVAL_PROCESS: - todoType = MHTodoTypeEnum.DECLARED_RECORD_AUDIT; - break; - case PROJECT_REVIEW: - todoType = MHTodoTypeEnum.PROJECT_REVIEW_AUDIT; - break; - case COMPLIANCE_REVIEW: - todoType = MHTodoTypeEnum.COMPLIANCE_REVIEW_AUDIT; - break; - case PROJECT_STOPPED: - todoType = MHTodoTypeEnum.PROJECT_STOPPED_AUDIT; - break; - case TEST_VALID: - todoType = MHTodoTypeEnum.TEST_VALID_AUDIT; - break; - case PROJECT_CHANGE: - todoType = MHTodoTypeEnum.PROJECT_CHANGE_AUDIT; - break; - case ADAPTION: - todoType = MHTodoTypeEnum.ADAPTION_AUDIT; - break; - case SELF_TEST: - todoType = MHTodoTypeEnum.SELF_TEST_AUDIT; - break; - case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: - todoType = MHTodoTypeEnum.FINAL_INSPECT_AUDIT; - break; - default: - throw BizException.wrap("未知待办类型:" + procType); - } - return todoType; - } - -} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java new file mode 100644 index 0000000..d1b9b3a --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/UserTaskCreateOrFinishListener.java @@ -0,0 +1,240 @@ +package com.hz.pm.api.scheduler.listener; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; +import com.hz.pm.api.common.enumeration.ProjectProcessType; +import com.hz.pm.api.common.helper.UserInfoHelper; +import com.hz.pm.api.common.helper.WflowHelper; +import com.hz.pm.api.external.MhApiClient; +import com.hz.pm.api.external.model.dto.MhZwddWorkNoticeDTO; +import com.hz.pm.api.external.todo.MHTodoClient; +import com.hz.pm.api.external.todo.dto.MhTodoExtraParamDTO; +import com.hz.pm.api.external.todo.enumerization.MHTodoTypeEnum; +import com.hz.pm.api.projectdeclared.model.entity.PurchaseInst; +import com.hz.pm.api.projectdeclared.model.entity.Xinchuang; +import com.hz.pm.api.projectdeclared.model.entity.XinchuangInst; +import com.hz.pm.api.projectdeclared.service.IPurchaseInstService; +import com.hz.pm.api.projectdeclared.service.IXinchuangInstService; +import com.hz.pm.api.projectdeclared.service.IXinchuangService; +import com.hz.pm.api.projectlib.model.entity.Project; +import com.hz.pm.api.projectlib.model.entity.ProjectInst; +import com.hz.pm.api.projectlib.service.IProjectInstService; +import com.hz.pm.api.projectlib.service.IProjectService; +import com.hz.pm.api.user.security.model.UserFullInfoDTO; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.basic.util.CollUtils; +import com.wflow.bean.entity.WflowModelHistorys; +import com.wflow.workflow.notify.event.NodeCompleteEvent; +import com.wflow.workflow.notify.event.NodeCreateEvent; +import com.wflow.workflow.service.ProcessModelHistorysService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.flowable.engine.HistoryService; +import org.flowable.engine.TaskService; +import org.flowable.task.api.Task; +import org.flowable.task.api.history.HistoricTaskInstance; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.util.List; +import java.util.Set; + +import static com.hz.pm.api.common.util.ThreadPoolUtil.SCHEDULER; + +/** + *

+ * TaskCreatedListener + *

+ * + * @author WendyYang + * @since 10:38 2024/3/12 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class UserTaskCreateOrFinishListener { + + private final HistoryService historyService; + private final IProjectService projectService; + private final IProjectInstService projectInstService; + private final ProcessModelHistorysService processModelHistorysService; + private final MHTodoClient mhTodoClient; + private final MhApiClient mhApiClient; + private final UserInfoHelper userInfoHelper; + private final IPurchaseInstService purchaseInstService; + private final IXinchuangInstService xinchuangInstService; + private final IXinchuangService xinchuangService; + private final TaskService taskService; + + private Instant instantDelay10s() { + return Instant.now().plusSeconds(10); + } + + @EventListener(classes = NodeCreateEvent.class) + public void onEvent(NodeCreateEvent event) { + SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); + } + + @EventListener(classes = NodeCompleteEvent.class) + public void onEvent(NodeCompleteEvent event) { + SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); + } + + public void handleEvent(NodeCreateEvent event) { + String procDefId = event.getProcessDefinitionId(); + String procInstId = event.getInstCode(); + WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); + ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); + Task task = taskService.createTaskQuery() + .taskId(event.getTaskId()) + .singleResult(); + UserFullInfoDTO assignee = userInfoHelper.getUserFullInfo(task.getAssignee()); + if (assignee == null || StrUtil.isBlank(assignee.getMhUserId())) { + return; + } + switch (procType) { + case XC_APPROVAL_PROCESS: + case PROJECT_RECORD_APPROVAL_PROCESS: + case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: + case ADAPTION: + case SELF_TEST: + case TEST_VALID: + case PROJECT_CHANGE: + case PROJECT_STOPPED: + case COMPLIANCE_REVIEW: + case PROJECT_REVIEW: + // 发送信产平台待办 + MHTodoTypeEnum todoType = getMhTodoTypeEnum(procType); + MhTodoExtraParamDTO paramObj = MhTodoExtraParamDTO.builder() + .taskId(task.getId()) + .instanceId(task.getProcessInstanceId()) + .nodeId(task.getTaskDefinitionId()) + .userId(assignee.getUserId()) + .userName(assignee.getRealName()) + .path("/toDoCenter/handleDuringExamine") + .build(); + if (procType.equals(ProjectProcessType.ACCEPTANCE_DECLARATION_APPROVAL_PROCESS) + || procType.equals(ProjectProcessType.ADAPTION) + || procType.equals(ProjectProcessType.XC_APPROVAL_PROCESS) + || procType.equals(ProjectProcessType.TEST_VALID) + || procType.equals(ProjectProcessType.SELF_TEST)) { + PurchaseInst purchaseInst = purchaseInstService.getByProjectIdAndInstCode(paramObj.getProjectId(), procInstId); + paramObj.setBidId(purchaseInst.getBidId()); + paramObj.setProjectId(purchaseInst.getProjectId()); + } + String projectName = ""; + // 上边查不到ID的时候说明是手动新增的信创项目 + if (paramObj.getBidId() == null) { + XinchuangInst xinchuangInst = xinchuangInstService.getByInstCode(procInstId); + if (xinchuangInst != null) { + Xinchuang xinchuang = xinchuangService.getById(xinchuangInst.getXinchuangId()); + paramObj.setXinchuangId(xinchuang.getId()); + projectName = xinchuang.getProjectName(); + } else { + ProjectInst projectInst = projectInstService.getByInstCode(procInstId); + if (projectInst == null) { + return; + } + paramObj.setProjectId(projectInst.getProjectId()); + } + } + if (paramObj.getProjectId() != null) { + Project project = projectService.getNewProject(paramObj.getProjectId()); + projectName = project.getProjectName(); + paramObj.setProjectId(project.getId()); + paramObj.setProjectCode(project.getProjectCode()); + } + String content = String.format("【%s】的【%s】需要您审核,请及时处理。", projectName, procType.getDesc()); + mhTodoClient.addTodo(paramObj, assignee, todoType, task.getId(), content); + // 发送浙政钉工作通知 + if (assignee.getAccountId() != null) { + MhZwddWorkNoticeDTO notice = MhZwddWorkNoticeDTO.builder() + .content(content) + .title(todoType.getVal()) + .targetUser(assignee.getMhUserId()) + .build(); + mhApiClient.sendZwddWorkNotice(notice); + } + break; + default: + break; + } + } + + public void handleEvent(NodeCompleteEvent event) { + String procDefId = event.getProcessDefinitionId(); + WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); + ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); + WflowHelper wflowHelper = SpringUtil.getBean(WflowHelper.class); + HistoricTaskInstance task = historyService.createHistoricTaskInstanceQuery() + .taskId(event.getTaskId()) + .singleResult(); + boolean orUserTask = wflowHelper.isOrUserTask(procDefId, task.getTaskDefinitionKey()); + switch (procType) { + case XC_APPROVAL_PROCESS: + case PROJECT_RECORD_APPROVAL_PROCESS: + case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: + case ADAPTION: + case SELF_TEST: + case TEST_VALID: + case PROJECT_CHANGE: + case PROJECT_STOPPED: + case COMPLIANCE_REVIEW: + case PROJECT_REVIEW: + MHTodoTypeEnum todoType = getMhTodoTypeEnum(procType); + log.info("完成任务: {} 信产待办:{}", event.getTaskId(), todoType); + if (orUserTask) { + List tasks = wflowHelper.listFinishedTasks(task.getTaskDefinitionKey()); + Set taskIds = CollUtils.fieldSet(tasks, HistoricTaskInstance::getId); + taskIds.add(task.getId()); + mhTodoClient.completeTodo(todoType, taskIds); + } else { + mhTodoClient.completeTodo(todoType, task.getId()); + } + break; + default: + break; + } + } + + private MHTodoTypeEnum getMhTodoTypeEnum(ProjectProcessType procType) { + MHTodoTypeEnum todoType; + switch (procType) { + case XC_APPROVAL_PROCESS: + todoType = MHTodoTypeEnum.XCFHX_INSPECT_AUDIT; + break; + case PROJECT_RECORD_APPROVAL_PROCESS: + todoType = MHTodoTypeEnum.DECLARED_RECORD_AUDIT; + break; + case PROJECT_REVIEW: + todoType = MHTodoTypeEnum.PROJECT_REVIEW_AUDIT; + break; + case COMPLIANCE_REVIEW: + todoType = MHTodoTypeEnum.COMPLIANCE_REVIEW_AUDIT; + break; + case PROJECT_STOPPED: + todoType = MHTodoTypeEnum.PROJECT_STOPPED_AUDIT; + break; + case TEST_VALID: + todoType = MHTodoTypeEnum.TEST_VALID_AUDIT; + break; + case PROJECT_CHANGE: + todoType = MHTodoTypeEnum.PROJECT_CHANGE_AUDIT; + break; + case ADAPTION: + todoType = MHTodoTypeEnum.ADAPTION_AUDIT; + break; + case SELF_TEST: + todoType = MHTodoTypeEnum.SELF_TEST_AUDIT; + break; + case ACCEPTANCE_DECLARATION_APPROVAL_PROCESS: + todoType = MHTodoTypeEnum.FINAL_INSPECT_AUDIT; + break; + default: + throw BizException.wrap("未知待办类型:" + procType); + } + return todoType; + } + +}