diff --git a/src/main/java/neatlogic/module/autoexec/process/audithandler/handler/AutoexecSuccessMessageAuditHandler.java b/src/main/java/neatlogic/module/autoexec/process/audithandler/handler/AutoexecSuccessMessageAuditHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..10fd5e86ef25ab61d8295a87d9131a7fa7fa809b --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/audithandler/handler/AutoexecSuccessMessageAuditHandler.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.autoexec.process.audithandler.handler; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.autoexec.constvalue.JobStatus; +import neatlogic.framework.autoexec.dao.mapper.AutoexecJobMapper; +import neatlogic.framework.autoexec.dto.job.AutoexecJobPhaseVo; +import neatlogic.framework.autoexec.dto.job.AutoexecJobVo; +import neatlogic.framework.process.audithandler.core.IProcessTaskStepAuditDetailHandler; +import neatlogic.framework.process.dto.ProcessTaskStepAuditDetailVo; +import neatlogic.module.autoexec.process.constvalue.AutoexecProcessTaskAuditDetailType; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class AutoexecSuccessMessageAuditHandler implements IProcessTaskStepAuditDetailHandler { + + @Resource + private AutoexecJobMapper autoexecJobMapper; + + @Override + public String getType() { + return AutoexecProcessTaskAuditDetailType.AUTOEXECMESSAGE.getValue(); + } + + @Override + public int handle(ProcessTaskStepAuditDetailVo processTaskStepAuditDetailVo) { + JSONObject resultObj = new JSONObject(); + String newContent = processTaskStepAuditDetailVo.getNewContent(); + if (StringUtils.isNotBlank(newContent)) { + JSONObject jsonObj = JSONObject.parseObject(newContent); + if (MapUtils.isNotEmpty(jsonObj)) { + JSONArray jobIdArray = jsonObj.getJSONArray("jobIdList"); + if (CollectionUtils.isNotEmpty(jobIdArray)) { + List jobIdList = jobIdArray.toJavaList(Long.class); + int completed = 0, failed = 0, running = 0; + Map> jobIdToAutoexecJobPhaseListMap = new HashMap<>(); + List jobPhaseList = autoexecJobMapper.getJobPhaseListWithGroupByJobIdList(jobIdList); + for (AutoexecJobPhaseVo autoexecJobPhaseVo : jobPhaseList) { + jobIdToAutoexecJobPhaseListMap.computeIfAbsent(autoexecJobPhaseVo.getJobId(), key -> new ArrayList<>()).add(autoexecJobPhaseVo); + } + List autoexecJobList = autoexecJobMapper.getJobListByIdList(jobIdList); + for (AutoexecJobVo autoexecJobVo : autoexecJobList) { + List jobPhaseVoList = jobIdToAutoexecJobPhaseListMap.get(autoexecJobVo.getId()); + autoexecJobVo.setPhaseList(jobPhaseVoList); + if (JobStatus.isRunningStatus(autoexecJobVo.getStatus())) { + running++; + } else if (JobStatus.isCompletedStatus(autoexecJobVo.getStatus())) { + completed++; + } else if (JobStatus.isFailedStatus(autoexecJobVo.getStatus())) { + failed++; + } + } + + if (running > 0) { + resultObj.put("status", JobStatus.RUNNING.getValue()); + } else if (failed > 0) { + resultObj.put("status", JobStatus.FAILED.getValue()); + } else if (completed > 0) { + resultObj.put("status", JobStatus.COMPLETED.getValue()); + } + resultObj.put("jobList", autoexecJobList); + processTaskStepAuditDetailVo.setNewContent(resultObj.toJSONString()); + } + return 1; + } + } + return 0; + } +} diff --git a/src/main/java/neatlogic/module/autoexec/process/constvalue/AutoexecProcessTaskAuditDetailType.java b/src/main/java/neatlogic/module/autoexec/process/constvalue/AutoexecProcessTaskAuditDetailType.java new file mode 100644 index 0000000000000000000000000000000000000000..747f1c71d02d70a003e75852159559f244d99fcd --- /dev/null +++ b/src/main/java/neatlogic/module/autoexec/process/constvalue/AutoexecProcessTaskAuditDetailType.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.autoexec.process.constvalue; + +import neatlogic.framework.process.audithandler.core.IProcessTaskAuditDetailType; + +public enum AutoexecProcessTaskAuditDetailType implements IProcessTaskAuditDetailType { + AUTOEXECMESSAGE("autoexecmessage", "", "autoexecMessage", "oldAutoexecMessage", 22, false), + ; + + private String value; + private String text; + private String paramName; + private String oldDataParamName; + private int sort; + private boolean needCompression; + + AutoexecProcessTaskAuditDetailType(String value, String text, String paramName, String oldDataParamName, int sort, boolean needCompression) { + this.value = value; + this.text = text; + this.paramName = paramName; + this.oldDataParamName = oldDataParamName; + this.sort = sort; + this.needCompression = needCompression; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String getText() { + return text; + } + + @Override + public String getParamName() { + return paramName; + } + + @Override + public String getOldDataParamName() { + return oldDataParamName; + } + + @Override + public int getSort() { + return sort; + } + + @Override + public boolean getNeedCompression() { + return needCompression; + } +} diff --git a/src/main/java/neatlogic/module/autoexec/process/stephandler/component/CreateJobProcessComponent.java b/src/main/java/neatlogic/module/autoexec/process/stephandler/component/CreateJobProcessComponent.java index 0e08433445f093787432dd3fa18f51ff8ca25f93..13eeb3ade665ca4fb898adc0045b5071514ecff1 100644 --- a/src/main/java/neatlogic/module/autoexec/process/stephandler/component/CreateJobProcessComponent.java +++ b/src/main/java/neatlogic/module/autoexec/process/stephandler/component/CreateJobProcessComponent.java @@ -50,6 +50,7 @@ import neatlogic.framework.process.stephandler.core.*; import neatlogic.module.autoexec.constvalue.FailPolicy; import neatlogic.module.autoexec.dao.mapper.AutoexecCombopVersionMapper; import neatlogic.module.autoexec.dao.mapper.AutoexecServiceMapper; +import neatlogic.module.autoexec.process.constvalue.AutoexecProcessTaskAuditDetailType; import neatlogic.module.autoexec.process.constvalue.CreateJobProcessStepHandlerType; import neatlogic.module.autoexec.process.dto.AutoexecJobBuilder; import neatlogic.module.autoexec.process.dto.CreateJobConfigConfigVo; @@ -335,6 +336,7 @@ public class CreateJobProcessComponent extends ProcessStepHandlerBase { processTaskStepDataVo.setData(dataObj.toJSONString()); processTaskStepDataVo.setFcu(UserContext.get().getUserUuid()); processTaskStepDataCrossoverMapper.replaceProcessTaskStepData(processTaskStepDataVo); + currentProcessTaskStepVo.getParamObj().put(AutoexecProcessTaskAuditDetailType.AUTOEXECMESSAGE.getParamName(), dataObj.toJSONString()); String failPolicy = createJobConfigVo.getFailPolicy(); if (FailPolicy.KEEP_ON.getValue().equals(failPolicy)) { if (CollectionUtils.isNotEmpty(jobIdList)) { @@ -364,11 +366,17 @@ public class CreateJobProcessComponent extends ProcessStepHandlerBase { IProcessStepHandlerCrossoverUtil processStepHandlerCrossoverUtil = CrossoverServiceFactory.getApi(IProcessStepHandlerCrossoverUtil.class); /* 触发通知 **/ processStepHandlerCrossoverUtil.notify(processTaskStepVo, AutoexecNotifyTriggerType.CREATE_JOB_FAILED); + } else { + JSONObject dataObj = new JSONObject(); + dataObj.put("jobIdList", jobIdList); + currentProcessTaskStepVo.getParamObj().put(AutoexecProcessTaskAuditDetailType.AUTOEXECMESSAGE.getParamName(), dataObj.toJSONString()); } } catch (Exception e) { logger.error(e.getMessage(), e); + } finally { + IProcessStepHandlerCrossoverUtil processStepHandlerCrossoverUtil = CrossoverServiceFactory.getApi(IProcessStepHandlerCrossoverUtil.class); + processStepHandlerCrossoverUtil.audit(currentProcessTaskStepVo, ProcessTaskAuditType.ACTIVE); } - } }; processTaskStepThreadList.add(thread);