|
|
@@ -5,7 +5,6 @@ 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.common.util.ThreadPoolUtil; |
|
|
|
import com.hz.pm.api.external.MhApiClient; |
|
|
|
import com.hz.pm.api.external.model.dto.MhZwddWorkNoticeDTO; |
|
|
|
import com.hz.pm.api.external.todo.MHTodoClient; |
|
|
@@ -30,12 +29,9 @@ 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.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; |
|
|
|
|
|
|
@@ -43,6 +39,8 @@ import java.time.Instant; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import static com.hz.pm.api.common.util.ThreadPoolUtil.SCHEDULER; |
|
|
|
|
|
|
|
/** |
|
|
|
* <p> |
|
|
|
* TaskCreatedListener |
|
|
@@ -67,132 +65,133 @@ public class TaskCreatedListener { |
|
|
|
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) { |
|
|
|
Instant instant = Instant.now().plusSeconds(5); |
|
|
|
ThreadPoolUtil.SCHEDULER.schedule(() -> handleEvent(event), instant); |
|
|
|
SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); |
|
|
|
} |
|
|
|
|
|
|
|
@EventListener(classes = NodeCompleteEvent.class) |
|
|
|
public void onEvent(NodeCompleteEvent event) { |
|
|
|
Instant instant = Instant.now().plusSeconds(5); |
|
|
|
ThreadPoolUtil.SCHEDULER.schedule(() -> handleEvent(event), instant); |
|
|
|
SCHEDULER.schedule(() -> handleEvent(event), instantDelay10s()); |
|
|
|
} |
|
|
|
|
|
|
|
private void handleEvent(ApplicationEvent event) { |
|
|
|
if (event instanceof NodeCreateEvent) { |
|
|
|
NodeCreateEvent entityEvent = (NodeCreateEvent) event; |
|
|
|
String procDefId = entityEvent.getProcessDefinitionId(); |
|
|
|
String procInstId = entityEvent.getInstCode(); |
|
|
|
WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); |
|
|
|
ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); |
|
|
|
Task task = taskService.createTaskQuery() |
|
|
|
.taskId(entityEvent.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; |
|
|
|
} |
|
|
|
} else if (event instanceof NodeCompleteEvent) { |
|
|
|
FlowableEngineEntityEvent entityEvent = (FlowableEngineEntityEvent) event; |
|
|
|
String procDefId = entityEvent.getProcessDefinitionId(); |
|
|
|
WflowModelHistorys models = processModelHistorysService.getByProcessDefId(procDefId); |
|
|
|
ProjectProcessType procType = ProjectProcessType.getNoNull(models.getProcessType()); |
|
|
|
TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity(); |
|
|
|
WflowHelper wflowHelper = SpringUtil.getBean(WflowHelper.class); |
|
|
|
String taskDefKey = taskEntity.getTaskDefinitionKey(); |
|
|
|
boolean orUserTask = wflowHelper.isOrUserTask(procDefId, taskDefKey); |
|
|
|
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); |
|
|
|
if (orUserTask) { |
|
|
|
List<HistoricTaskInstance> tasks = wflowHelper.listFinishedTasks(taskDefKey); |
|
|
|
Set<String> taskIds = CollUtils.fieldSet(tasks, HistoricTaskInstance::getId); |
|
|
|
taskIds.add(taskEntity.getId()); |
|
|
|
mhTodoClient.completeTodo(todoType, taskIds); |
|
|
|
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 { |
|
|
|
mhTodoClient.completeTodo(todoType, taskEntity.getId()); |
|
|
|
ProjectInst projectInst = projectInstService.getByInstCode(procInstId); |
|
|
|
if (projectInst == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
paramObj.setProjectId(projectInst.getProjectId()); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
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); |
|
|
|
Task task = taskService.createTaskQuery() |
|
|
|
.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); |
|
|
|
if (orUserTask) { |
|
|
|
List<HistoricTaskInstance> tasks = wflowHelper.listFinishedTasks(task.getTaskDefinitionKey()); |
|
|
|
Set<String> taskIds = CollUtils.fieldSet(tasks, HistoricTaskInstance::getId); |
|
|
|
taskIds.add(task.getId()); |
|
|
|
mhTodoClient.completeTodo(todoType, taskIds); |
|
|
|
} else { |
|
|
|
mhTodoClient.completeTodo(todoType, task.getId()); |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|