Explorar el Código

modify:

1. 待办推送;
tags/24091301
WendyYang hace 1 mes
padre
commit
e13676cef5
Se han modificado 2 ficheros con 45 adiciones y 82 borrados
  1. +0
    -37
      hz-pm-api/src/main/java/com/hz/pm/api/common/config/CustomFlowableConfig.java
  2. +45
    -45
      hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java

+ 0
- 37
hz-pm-api/src/main/java/com/hz/pm/api/common/config/CustomFlowableConfig.java Ver fichero

@@ -1,37 +0,0 @@
package com.hz.pm.api.common.config;

import com.google.common.collect.Lists;
import com.hz.pm.api.scheduler.listener.TaskCreatedListener;
import lombok.RequiredArgsConstructor;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
* <p>
* FlowableConfig
* </p>
*
* @author WendyYang
* @since 12:16 2024/3/12
*/
@RequiredArgsConstructor
@Configuration("customFlowableConfig")
public class CustomFlowableConfig implements EngineConfigurationConfigurer<SpringProcessEngineConfiguration> {

private final TaskCreatedListener taskCreatedListener;

@Override
public void configure(SpringProcessEngineConfiguration engineConfiguration) {
List<FlowableEventListener> listeners = engineConfiguration.getEventListeners();
if (listeners == null) {
engineConfiguration.setEventListeners(Lists.newArrayList(taskCreatedListener));
} else {
engineConfiguration.getEventListeners().add(taskCreatedListener);
}
}

}

+ 45
- 45
hz-pm-api/src/main/java/com/hz/pm/api/scheduler/listener/TaskCreatedListener.java Ver fichero

@@ -25,15 +25,18 @@ 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.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEventListener;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.time.Instant;
@@ -51,7 +54,7 @@ import java.util.Set;
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskCreatedListener implements FlowableEventListener {
public class TaskCreatedListener {

private final IProjectService projectService;
private final IProjectInstService projectInstService;
@@ -62,22 +65,31 @@ public class TaskCreatedListener implements FlowableEventListener {
private final IPurchaseInstService purchaseInstService;
private final IXinchuangInstService xinchuangInstService;
private final IXinchuangService xinchuangService;
private final TaskService taskService;

@Override
public void onEvent(FlowableEvent event) {
@EventListener(classes = NodeCreateEvent.class)
public void onEvent(NodeCreateEvent event) {
Instant instant = Instant.now().plusSeconds(5);
ThreadPoolUtil.SCHEDULER.schedule(() -> handleEvent(event), instant);
}

private void handleEvent(FlowableEvent event) {
if (event.getType().equals(FlowableEngineEventType.TASK_CREATED)) {
FlowableEngineEntityEvent entityEvent = (FlowableEngineEntityEvent) event;
@EventListener(classes = NodeCompleteEvent.class)
public void onEvent(NodeCompleteEvent event) {
Instant instant = Instant.now().plusSeconds(5);
ThreadPoolUtil.SCHEDULER.schedule(() -> handleEvent(event), instant);
}

private void handleEvent(ApplicationEvent event) {
if (event instanceof NodeCreateEvent) {
NodeCreateEvent entityEvent = (NodeCreateEvent) event;
String procDefId = entityEvent.getProcessDefinitionId();
String procInstId = entityEvent.getProcessInstanceId();
String procInstId = entityEvent.getInstCode();
WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId);
ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType());
TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
UserFullInfoDTO assignee = userInfoHelper.getUserFullInfo(taskEntity.getAssignee());
Task task = taskService.createTaskQuery()
.taskId(entityEvent.getTaskId())
.singleResult();
UserFullInfoDTO assignee = userInfoHelper.getUserFullInfo(task.getAssignee());
if (assignee == null || StrUtil.isBlank(assignee.getMhUserId())) {
return;
}
@@ -95,9 +107,9 @@ public class TaskCreatedListener implements FlowableEventListener {
// 发送信产平台待办
MHTodoTypeEnum todoType = getMhTodoTypeEnum(procType);
MhTodoExtraParamDTO paramObj = MhTodoExtraParamDTO.builder()
.taskId(taskEntity.getId())
.instanceId(taskEntity.getProcessInstanceId())
.nodeId(taskEntity.getTaskDefinitionId())
.taskId(task.getId())
.instanceId(task.getProcessInstanceId())
.nodeId(task.getTaskDefinitionId())
.userId(assignee.getUserId())
.userName(assignee.getRealName())
.path("/toDoCenter/handleDuringExamine")
@@ -109,30 +121,32 @@ public class TaskCreatedListener implements FlowableEventListener {
|| procType.equals(ProjectProcessType.SELF_TEST)) {
PurchaseInst purchaseInst = purchaseInstService.getByProjectIdAndInstCode(paramObj.getProjectId(), procInstId);
paramObj.setBidId(purchaseInst.getBidId());
paramObj.setProjectId(purchaseInst.getProjectId());
}
String projectName;
String projectName = "";
// 上边查不到ID的时候说明是手动新增的信创项目
if (paramObj.getBidId() == null) {
XinchuangInst xinchuangInst = xinchuangInstService.getByInstCode(procInstId);
if (xinchuangInst == null) {
return;
}
Xinchuang xinchuang = xinchuangService.getById(xinchuangInst.getXinchuangId());
paramObj.setXinchuangId(xinchuangInst.getId());
projectName = xinchuang.getProjectName();
} else {
ProjectInst projectInst = projectInstService.getByInstCode(procInstId);
if (projectInst == null) {
return;
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());
}
Project project = projectService.getById(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, taskEntity.getId(), content);
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()
@@ -146,7 +160,7 @@ public class TaskCreatedListener implements FlowableEventListener {
default:
break;
}
} else if (event.getType().equals(FlowableEngineEventType.TASK_COMPLETED)) {
} else if (event instanceof NodeCompleteEvent) {
FlowableEngineEntityEvent entityEvent = (FlowableEngineEntityEvent) event;
String procDefId = entityEvent.getProcessDefinitionId();
WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId);
@@ -221,18 +235,4 @@ public class TaskCreatedListener implements FlowableEventListener {
return todoType;
}

@Override
public boolean isFailOnException() {
return false;
}

@Override
public boolean isFireOnTransactionLifecycleEvent() {
return false;
}

@Override
public String getOnTransaction() {
return null;
}
}

Cargando…
Cancelar
Guardar