From 49d86da3ea1812c7fcd4ed5525e52189b89b6eee Mon Sep 17 00:00:00 2001 From: Odboy Date: Thu, 9 Oct 2025 12:24:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=BB=E5=8A=A1=E7=BA=BF=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../odboy/task/constant/TaskStatusEnum.java | 35 +++++ .../task/controller/TaskTestsController.java | 57 ++++++++ .../java/cn/odboy/task/core/TaskJobBean.java | 126 ++++++++++++++++++ .../java/cn/odboy/task/core/TaskManage.java | 117 ++++++++++++++++ .../cn/odboy/task/core/TaskStepCallback.java | 22 +++ .../cn/odboy/task/core/TaskStepExecutor.java | 32 +++++ .../task/core/impl/TaskStepNodeBuildJava.java | 37 +++++ .../core/impl/TaskStepNodeDeployJava.java | 37 +++++ .../task/core/impl/TaskStepNodeInit.java | 42 ++++++ .../core/impl/TaskStepNodeMergeBranch.java | 42 ++++++ .../dal/dataobject/TaskInstanceDetailTb.java | 19 +++ .../dal/dataobject/TaskInstanceInfoTb.java | 25 ++-- .../dataobject/TaskInstanceStepDetailTb.java | 79 +++++++++++ .../dal/dataobject/TaskTemplateInfoTb.java | 100 ++++++++++++++ .../task/dal/model/TaskTemplateInfoVo.java | 32 +++++ .../TaskTemplateNodeOperateButtonVo.java | 50 +++++++ .../task/dal/model/TaskTemplateNodeVo.java | 68 ++++++++++ .../mysql/TaskInstanceStepDetailMapper.java | 33 +++++ .../dal/mysql/TaskTemplateInfoMapper.java | 35 +++++ .../service/TaskInstanceDetailService.java | 5 + .../task/service/TaskInstanceInfoService.java | 8 ++ .../TaskInstanceStepDetailService.java | 45 +++++++ .../task/service/TaskTemplateInfoService.java | 32 +++++ .../impl/TaskInstanceDetailServiceImpl.java | 40 ++++++ .../impl/TaskInstanceInfoServiceImpl.java | 48 +++++++ .../TaskInstanceStepDetailServiceImpl.java | 55 ++++++++ .../impl/TaskTemplateInfoServiceImpl.java | 40 ++++++ .../mapper/TaskTemplateInfoMapper.xml | 18 +++ 28 files changed, 1269 insertions(+), 10 deletions(-) create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/constant/TaskStatusEnum.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/controller/TaskTestsController.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskJobBean.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskManage.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepCallback.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepExecutor.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeBuildJava.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeDeployJava.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeInit.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeMergeBranch.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceStepDetailTb.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskTemplateInfoTb.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeOperateButtonVo.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeVo.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskInstanceStepDetailMapper.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskTemplateInfoMapper.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceStepDetailService.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskTemplateInfoService.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceStepDetailServiceImpl.java create mode 100644 cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskTemplateInfoServiceImpl.java create mode 100644 cutejava/cutejava-module-task/src/main/resources/mapper/TaskTemplateInfoMapper.xml diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/constant/TaskStatusEnum.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/constant/TaskStatusEnum.java new file mode 100644 index 00000000..bf4d20f6 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/constant/TaskStatusEnum.java @@ -0,0 +1,35 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 任务状态(固定值) + * + * @author odboy + * @date 2025-09-26 + */ +@Getter +@AllArgsConstructor +public enum TaskStatusEnum { + Running("running", "运行中"), + Success("success", "执行成功"), + Fail("fail", "执行失败"); + private final String code; + private final String name; +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/controller/TaskTestsController.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/controller/TaskTestsController.java new file mode 100644 index 00000000..e76ddba8 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/controller/TaskTestsController.java @@ -0,0 +1,57 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.controller; + +import cn.hutool.core.thread.ThreadUtil; +import cn.odboy.annotation.AnonymousAccess; +import cn.odboy.task.constant.TaskChangeTypeEnum; +import cn.odboy.task.core.TaskManage; +import cn.odboy.task.dal.dataobject.TaskInstanceInfoTb; +import com.alibaba.fastjson2.JSON; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequestMapping("/api/task") +public class TaskTestsController { + @Autowired + private TaskManage taskManage; + + @AnonymousAccess + @GetMapping(value = "/testCreate") + public ResponseEntity testCreate() { + TaskInstanceInfoTb instanceInfo = taskManage.createJob("cutejava", TaskChangeTypeEnum.AppApply, "java", "daily", "cutejava", "功能测试", null); + log.info("任务创建成功,实例为:{}", JSON.toJSONString(instanceInfo)); + return ResponseEntity.ok(instanceInfo); + } + + @AnonymousAccess + @GetMapping(value = "/testCreateAfterStop") + public ResponseEntity testCreateAfterStop() { + TaskInstanceInfoTb instanceInfo = taskManage.createJob("cutejava", TaskChangeTypeEnum.AppApply, "java", "daily", "cutejava", "功能测试", null); + log.info("任务创建成功,实例为:{}", JSON.toJSONString(instanceInfo)); + ThreadUtil.execAsync(() -> { + ThreadUtil.safeSleep(5000); + taskManage.stopJob(instanceInfo.getId()); + }); + return ResponseEntity.ok(null); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskJobBean.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskJobBean.java new file mode 100644 index 00000000..de71717c --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskJobBean.java @@ -0,0 +1,126 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.odboy.task.core; + +import cn.hutool.core.util.StrUtil; +import cn.odboy.framework.context.CsSpringBeanHolder; +import cn.odboy.task.dal.dataobject.TaskInstanceDetailTb; +import cn.odboy.task.dal.model.TaskTemplateInfoVo; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import cn.odboy.task.service.TaskInstanceDetailService; +import cn.odboy.task.service.TaskInstanceInfoService; +import cn.odboy.task.service.TaskTemplateInfoService; +import com.alibaba.fastjson2.JSON; +import lombok.extern.slf4j.Slf4j; +import org.quartz.InterruptableJob; +import org.quartz.JobDataMap; +import org.quartz.JobExecutionContext; +import org.springframework.scheduling.quartz.QuartzJobBean; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Slf4j +public class TaskJobBean extends QuartzJobBean implements InterruptableJob { + private Thread subMainThread = null; + + private String getBeanAlias(String code) { + // node_init + String[] s = code.split("_"); + return Arrays.stream(s).map(StrUtil::upperFirst).collect(Collectors.joining()); + } + + @Override + public void executeInternal(JobExecutionContext context) { + this.subMainThread = Thread.currentThread(); + // ========================== 获取代理类 ========================== + TaskInstanceInfoService taskInstanceInfoService = CsSpringBeanHolder.getBean(TaskInstanceInfoService.class); + TaskInstanceDetailService taskInstanceDetailService = CsSpringBeanHolder.getBean(TaskInstanceDetailService.class); + TaskTemplateInfoService taskTemplateInfoService = CsSpringBeanHolder.getBean(TaskTemplateInfoService.class); + // ========================== 获取参数 ========================== + JobDataMap dataMap = context.getMergedJobDataMap(); + long id = dataMap.getLong("id"); + // 应用名、资源类型 + String contextName = dataMap.getString("contextName"); + // 开发语言、资源版本 + String language = dataMap.getString("language"); + String envAlias = dataMap.getString("envAlias"); + // ========================== 获取任务编排模板 ========================== + TaskTemplateInfoVo taskInstanceInfoVo = taskTemplateInfoService.getTemplateInfoByECL(envAlias, contextName, language); + if (taskInstanceInfoVo == null) { + taskInstanceInfoService.fastFailWithMessage(id, "没有查询到任务编排模板"); + return; + } + String templateInfo = taskInstanceInfoVo.getTemplateInfo(); + List taskTemplateNodeVos = JSON.parseArray(templateInfo, TaskTemplateNodeVo.class); + if (taskTemplateNodeVos == null || taskTemplateNodeVos.isEmpty()) { + taskInstanceInfoService.fastFailWithMessage(id, "没有查询到任务编排明细"); + return; + } + // ========================== 初始化执行明细 ========================== + List taskInstanceDetails = new ArrayList<>(); + for (TaskTemplateNodeVo taskTemplateNodeVo : taskTemplateNodeVos) { + TaskInstanceDetailTb taskInstanceDetail = new TaskInstanceDetailTb(); + taskInstanceDetail.setInstanceId(id); + taskInstanceDetail.setFinishTime(null); + taskInstanceDetail.setBizCode(taskTemplateNodeVo.getCode()); + taskInstanceDetail.setBizName(taskTemplateNodeVo.getName()); + taskInstanceDetail.setExecuteInfo("未开始"); + taskInstanceDetail.setExecuteStatus("pending"); + taskInstanceDetails.add(taskInstanceDetail); + } + taskInstanceDetailService.saveBatch(taskInstanceDetails); + Map codeIdMap = taskInstanceDetails.stream().collect(Collectors.toMap(TaskInstanceDetailTb::getBizCode, TaskInstanceDetailTb::getId)); + // ========================== 顺序执行 ========================== + try { + for (TaskTemplateNodeVo taskTemplateNodeVo : taskTemplateNodeVos) { + String code = taskTemplateNodeVo.getCode(); + try { + TaskStepExecutor executor = CsSpringBeanHolder.getBean("taskStep" + getBeanAlias(code)); + executor.execute(codeIdMap.getOrDefault(code, null), dataMap, taskTemplateNodeVo, new TaskStepCallback() { + @Override + public void onStart() { + taskInstanceDetailService.fastStart(id, code, dataMap); + } + + @Override + public void onFinish(String executeInfo) { + taskInstanceDetailService.fastSuccessWithInfo(id, code, executeInfo); + } + }); + } catch (Exception e) { + taskInstanceDetailService.fastFailWithInfo(id, code, e.getMessage()); + throw new RuntimeException(e); + } + } + taskInstanceInfoService.fastSuccessWithData(id, dataMap); + } catch (Exception e) { + log.error("任务执行失败", e); + taskInstanceInfoService.fastFailWithMessageData(id, e.getMessage(), dataMap); + } + } + + @Override + public void interrupt() { + if (subMainThread != null) { + subMainThread.stop(); + } + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskManage.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskManage.java new file mode 100644 index 00000000..00b04f94 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskManage.java @@ -0,0 +1,117 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core; + +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.constant.TaskChangeTypeEnum; +import cn.odboy.task.constant.TaskStatusEnum; +import cn.odboy.task.dal.dataobject.TaskInstanceInfoTb; +import cn.odboy.task.service.TaskInstanceInfoService; +import com.alibaba.fastjson2.JSON; +import lombok.extern.slf4j.Slf4j; +import org.quartz.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Date; + +@Slf4j +@Component +public class TaskManage { + @Resource + private Scheduler scheduler; + @Autowired + private TaskInstanceInfoService taskInstanceInfoService; + + /** + * 创建任务单 + * + * @param contextName 上下文名称,这里特指应用名 + * @param changeType 变更类型 + * @param envAlias 环境别名 + * @param source 来源 + * @param reason 变更原因 + * @param dataMap 任务参数 + */ + @Transactional(rollbackFor = Exception.class) + public TaskInstanceInfoTb createJob(String contextName, TaskChangeTypeEnum changeType, String language, String envAlias, String source, String reason, JobDataMap dataMap) { + if (dataMap == null) { + dataMap = new JobDataMap(); + } + // ========================== 传递参数 ========================== + // 应用名、资源类型 + dataMap.put("contextName", contextName); + // 开发语言、资源版本 + dataMap.put("language", language); + dataMap.put("envAlias", envAlias); + // ========================== 创建任务 ========================== + TaskInstanceInfoTb newInstance = new TaskInstanceInfoTb(); + newInstance.setContextName(contextName); + newInstance.setChangeType(changeType.getCode()); + newInstance.setEnvAlias(envAlias); + newInstance.setStatus(TaskStatusEnum.Running.getCode()); + newInstance.setFinishTime(null); + newInstance.setSource(source); + newInstance.setReason(reason); + newInstance.setJobData(JSON.toJSONString(dataMap)); + taskInstanceInfoService.save(newInstance); + dataMap.put("id", newInstance.getId()); + // ========================== 执行任务 ========================== + JobKey jobKey = JobKey.jobKey(changeType.getCode(), contextName); + TriggerKey triggerKey = TriggerKey.triggerKey(changeType.getCode(), contextName); + JobDetail jobDetail = JobBuilder.newJob(TaskJobBean.class).withIdentity(jobKey).usingJobData(dataMap).build(); + Trigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startNow().build(); + try { + scheduler.scheduleJob(jobDetail, cronTrigger); + } catch (ObjectAlreadyExistsException e) { + throw new BadRequestException("任务已存在,跳过加载"); + } catch (SchedulerException e) { + log.error("任务执行失败", e); + throw new BadRequestException(e); + } + return newInstance; + } + + @Transactional(rollbackFor = Exception.class) + public void stopJob(Long instanceId) { + TaskInstanceInfoTb taskInstanceInfoTb = taskInstanceInfoService.getRunningById(instanceId); + + String changeType = taskInstanceInfoTb.getChangeType(); + String contextName = taskInstanceInfoTb.getContextName(); + + taskInstanceInfoTb.setStatus(TaskStatusEnum.Fail.getCode()); + taskInstanceInfoTb.setErrorMessage("任务被中断"); + taskInstanceInfoTb.setFinishTime(new Date()); + taskInstanceInfoService.updateById(taskInstanceInfoTb); + + try { + JobKey jobKey = JobKey.jobKey(changeType, contextName); + TriggerKey triggerKey = TriggerKey.triggerKey(changeType, contextName); + // 停止触发器 + scheduler.resumeTrigger(triggerKey); + // 移除触发器 + scheduler.unscheduleJob(triggerKey); + // 删除并中断任务 + scheduler.deleteJob(jobKey); + scheduler.interrupt(jobKey); + } catch (SchedulerException e) { + log.error("任务停止失败", e); + throw new RuntimeException(e); + } + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepCallback.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepCallback.java new file mode 100644 index 00000000..a8af09d3 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepCallback.java @@ -0,0 +1,22 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core; + +public interface TaskStepCallback { + void onStart(); + + void onFinish(String executeInfo); +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepExecutor.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepExecutor.java new file mode 100644 index 00000000..da1fdf5d --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/TaskStepExecutor.java @@ -0,0 +1,32 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core; + +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import org.quartz.JobDataMap; + +import javax.validation.constraints.NotNull; + +public interface TaskStepExecutor { + /** + * @param instanceDetailId 任务实例明细id + * @param jobDataMap 执行参数 + * @param taskTemplateNode 任务节点信息 + * @param callback 执行成功回调 + */ + void execute(Long instanceDetailId, JobDataMap jobDataMap, TaskTemplateNodeVo taskTemplateNode, @NotNull TaskStepCallback callback) throws BadRequestException; +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeBuildJava.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeBuildJava.java new file mode 100644 index 00000000..53370224 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeBuildJava.java @@ -0,0 +1,37 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core.impl; + +import cn.hutool.core.thread.ThreadUtil; +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.core.TaskStepCallback; +import cn.odboy.task.core.TaskStepExecutor; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobDataMap; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class TaskStepNodeBuildJava implements TaskStepExecutor { + + @Override + public void execute(Long instanceDetailId, JobDataMap jobDataMap, TaskTemplateNodeVo taskTemplateNode, TaskStepCallback callback) throws BadRequestException { + callback.onStart(); + ThreadUtil.sleep(2000); + callback.onFinish("执行成功"); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeDeployJava.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeDeployJava.java new file mode 100644 index 00000000..847f4b86 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeDeployJava.java @@ -0,0 +1,37 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core.impl; + +import cn.hutool.core.thread.ThreadUtil; +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.core.TaskStepCallback; +import cn.odboy.task.core.TaskStepExecutor; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobDataMap; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class TaskStepNodeDeployJava implements TaskStepExecutor { + + @Override + public void execute(Long instanceDetailId, JobDataMap jobDataMap, TaskTemplateNodeVo taskTemplateNode, TaskStepCallback callback) throws BadRequestException { + callback.onStart(); + ThreadUtil.sleep(5000); + callback.onFinish("执行成功"); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeInit.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeInit.java new file mode 100644 index 00000000..09a181c2 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeInit.java @@ -0,0 +1,42 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core.impl; + +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.core.TaskStepCallback; +import cn.odboy.task.core.TaskStepExecutor; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import cn.odboy.task.service.TaskInstanceStepDetailService; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobDataMap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class TaskStepNodeInit implements TaskStepExecutor { + @Autowired + private TaskInstanceStepDetailService service; + + @Override + public void execute(Long instanceDetailId, JobDataMap jobDataMap, TaskTemplateNodeVo taskTemplateNode, TaskStepCallback callback) throws BadRequestException { + callback.onStart(); + service.success(instanceDetailId, "开始初始化"); + service.success(instanceDetailId, "初始化完毕后,放入了一些参数"); + jobDataMap.put("ExcuseMe", "Hello World!"); + callback.onFinish("执行成功"); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeMergeBranch.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeMergeBranch.java new file mode 100644 index 00000000..d3b85abf --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/core/impl/TaskStepNodeMergeBranch.java @@ -0,0 +1,42 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.core.impl; + +import cn.hutool.core.thread.ThreadUtil; +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.core.TaskStepCallback; +import cn.odboy.task.core.TaskStepExecutor; +import cn.odboy.task.dal.model.TaskTemplateNodeVo; +import cn.odboy.task.service.TaskInstanceStepDetailService; +import lombok.extern.slf4j.Slf4j; +import org.quartz.JobDataMap; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class TaskStepNodeMergeBranch implements TaskStepExecutor { + @Autowired + private TaskInstanceStepDetailService service; + + @Override + public void execute(Long instanceDetailId, JobDataMap jobDataMap, TaskTemplateNodeVo taskTemplateNode, TaskStepCallback callback) throws BadRequestException { + callback.onStart(); + ThreadUtil.sleep(3000); + service.fail(instanceDetailId, "执行失败测试"); + callback.onFinish("执行成功"); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceDetailTb.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceDetailTb.java index cda25364..62f83011 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceDetailTb.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceDetailTb.java @@ -16,7 +16,10 @@ package cn.odboy.task.dal.dataobject; import cn.odboy.base.CsObject; +import com.alibaba.fastjson2.annotation.JSONField; import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -48,6 +51,8 @@ public class TaskInstanceDetailTb extends CsObject { */ @ApiModelProperty("id") @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @JSONField(format = "string") private Long id; /** @@ -57,6 +62,13 @@ public class TaskInstanceDetailTb extends CsObject { @ApiModelProperty("任务实例id") private Long instanceId; + /** + * 开始时间 + */ + @ApiModelProperty("开始时间") + @TableField("start_time") + private Date startTime; + /** * 结束时间 */ @@ -78,6 +90,13 @@ public class TaskInstanceDetailTb extends CsObject { @ApiModelProperty("业务名称(步骤)") private String bizName; + /** + * 执行参数 + */ + @ApiModelProperty("执行参数") + @TableField("execute_params") + private String executeParams; + /** * 执行信息 */ diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceInfoTb.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceInfoTb.java index abdb4880..23f9982e 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceInfoTb.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceInfoTb.java @@ -16,7 +16,10 @@ package cn.odboy.task.dal.dataobject; import cn.odboy.base.CsObject; +import com.alibaba.fastjson2.annotation.JSONField; import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; @@ -54,10 +57,12 @@ public class TaskInstanceInfoTb extends CsObject { private Date updateTime; /** - * id + * id, @JsonSerialize和@JSONField,用于处理大数精度丢失问题 */ @ApiModelProperty("id") @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @JSONField(format = "string") private Long id; /** @@ -109,17 +114,17 @@ public class TaskInstanceInfoTb extends CsObject { @ApiModelProperty("变更原因") private String reason; - /** - * QuartzJob的key名称 - */ - @TableField("bind_job_key") - @ApiModelProperty("QuartzJob的key名称") - private String bindJobKey; - /** * QuartzJob参数 */ - @TableField("bind_job_data") + @TableField("job_data") @ApiModelProperty("QuartzJob参数") - private String bindJobData; + private String jobData; + + /** + * 异常信息 + */ + @TableField("error_message") + @ApiModelProperty("异常信息") + private String errorMessage; } diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceStepDetailTb.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceStepDetailTb.java new file mode 100644 index 00000000..92d8e7b6 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskInstanceStepDetailTb.java @@ -0,0 +1,79 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.dal.dataobject; + +import cn.odboy.base.CsObject; +import com.alibaba.fastjson2.annotation.JSONField; +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.Date; + + +/** + *

+ * 任务实例步骤明细 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Getter +@Setter +@ToString +@TableName("task_instance_step_detail") +@ApiModel(value = "TaskInstanceStepDetailTb对象", description = "") +public class TaskInstanceStepDetailTb extends CsObject { + @TableField(fill = FieldFill.INSERT) + @ApiModelProperty(value = "创建时间: yyyy-MM-dd HH:mm:ss", hidden = true) + private Date createTime; + + /** + * id + */ + @ApiModelProperty("id") + @TableId(value = "id", type = IdType.ASSIGN_ID) + @JsonSerialize(using = ToStringSerializer.class) + @JSONField(format = "string") + private Long id; + + /** + * task_instance_detail表id + */ + @TableField("instance_detail_id") + @ApiModelProperty("task_instance_detail表id") + private Long instanceDetailId; + + /** + * 步骤描述 + */ + @TableField("step_desc") + @ApiModelProperty("步骤描述") + private String stepDesc; + + /** + * 状态(success成功 fail失败) + */ + @TableField("step_status") + @ApiModelProperty("状态(success成功 fail失败)") + private String stepStatus; +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskTemplateInfoTb.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskTemplateInfoTb.java new file mode 100644 index 00000000..98d40927 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/dataobject/TaskTemplateInfoTb.java @@ -0,0 +1,100 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.dal.dataobject; + +import cn.odboy.base.CsBaseUserTimeTb; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + + +/** + *

+ * 任务模板 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Getter +@Setter +@ToString +@TableName("task_template_info") +@ApiModel(value = "TaskTemplateInfoTb对象", description = "任务模板") +public class TaskTemplateInfoTb extends CsBaseUserTimeTb { + + /** + * id + */ + @ApiModelProperty("id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 数据有效性 + */ + @TableField("available") + @ApiModelProperty("数据有效性") + private Boolean available; + + /** + * 变更类型 + */ + @ApiModelProperty("变更类型") + @TableField("change_type") + private String changeType; + + /** + * 流水线名称 + */ + @TableField("`name`") + @ApiModelProperty("流水线名称") + private String name; + + /** + * 流水线描述 + */ + @ApiModelProperty("流水线描述") + @TableField("`description`") + private String description; + + /** + * 流水线模板内容 + */ + @TableField("template") + @ApiModelProperty("流水线模板内容") + private String template; + + /** + * 环境别名 + */ + @TableField("env_alias") + @ApiModelProperty("环境别名") + private String envAlias; + + /** + * 应用为语言,资源为类型 + */ + @TableField("`language`") + @ApiModelProperty("应用为语言,资源为类型") + private String language; +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java new file mode 100644 index 00000000..fde41eb8 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateInfoVo.java @@ -0,0 +1,32 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.dal.model; + +import cn.odboy.base.CsObject; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TaskTemplateInfoVo extends CsObject { + private String changeType; + private String name; + private String description; + private String envAlias; + private String language; + private String contextName; + private String templateInfo; +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeOperateButtonVo.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeOperateButtonVo.java new file mode 100644 index 00000000..10c3558c --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeOperateButtonVo.java @@ -0,0 +1,50 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.odboy.task.dal.model; + +import cn.odboy.base.CsObject; +import lombok.Getter; +import lombok.Setter; + +import java.util.HashMap; +import java.util.Map; + +/** + * 流水线节点控制按钮 + * + * @author odboy + */ +@Getter +@Setter +public class TaskTemplateNodeOperateButtonVo extends CsObject { + /** + * 按钮类型(service:调用某个服务并传递参数 link:带参跳转) + */ + private String type; + /** + * 按钮标题 + */ + private String title; + /** + * 按钮传递的参数 + */ + private String code; + /** + * 默认附加参数 + */ + private Map parameters = new HashMap<>(); +} \ No newline at end of file diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeVo.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeVo.java new file mode 100644 index 00000000..167c94c0 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/model/TaskTemplateNodeVo.java @@ -0,0 +1,68 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package cn.odboy.task.dal.model; + +import cn.odboy.base.CsObject; +import lombok.Getter; +import lombok.Setter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 任务节点模板 + * + * @author odboy + */ +@Getter +@Setter +public class TaskTemplateNodeVo extends CsObject { + /** + * 业务编码 + */ + protected String code; + /** + * 业务类型(service:系统内置服务 rpc:远程调用) + */ + protected String type; + /** + * 业务名称 + */ + protected String name; + /** + * 是否可点击 + */ + protected Boolean click = false; + /** + * 是否可重试 + */ + protected Boolean retry = false; + /** + * 是否可点击:点击展示详情,详情内容类型 + */ + protected String detailType = ""; + /** + * 默认参数
execute: 执行调用 describe: 明细调用 + */ + protected Map parameters = new HashMap<>(); + /** + * 流水线节点控制按钮 + */ + protected List buttons = new ArrayList<>(); +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskInstanceStepDetailMapper.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskInstanceStepDetailMapper.java new file mode 100644 index 00000000..67451484 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskInstanceStepDetailMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.dal.mysql; + +import cn.odboy.task.dal.dataobject.TaskInstanceStepDetailTb; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 任务实例步骤明细 Mapper 接口 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Mapper +public interface TaskInstanceStepDetailMapper extends BaseMapper { + +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskTemplateInfoMapper.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskTemplateInfoMapper.java new file mode 100644 index 00000000..e22d17ef --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/dal/mysql/TaskTemplateInfoMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.dal.mysql; + +import cn.odboy.task.dal.dataobject.TaskTemplateInfoTb; +import cn.odboy.task.dal.model.TaskTemplateInfoVo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * 任务模板 Mapper 接口 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Mapper +public interface TaskTemplateInfoMapper extends BaseMapper { + TaskTemplateInfoVo selectTemplateInfoByECL(@Param("envAlias") String envAlias, @Param("contextName") String contextName, @Param("language") String language); +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceDetailService.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceDetailService.java index cc40a824..bb6657d6 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceDetailService.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceDetailService.java @@ -17,6 +17,7 @@ package cn.odboy.task.service; import cn.odboy.task.dal.dataobject.TaskInstanceDetailTb; import com.baomidou.mybatisplus.extension.service.IService; +import org.quartz.JobDataMap; /** *

@@ -27,5 +28,9 @@ import com.baomidou.mybatisplus.extension.service.IService; * @since 2025-09-26 */ public interface TaskInstanceDetailService extends IService { + void fastFailWithInfo(Long instanceId, String code, String message); + void fastSuccessWithInfo(Long id, String code, String executeInfo); + + void fastStart(Long id, String code, JobDataMap dataMap); } diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceInfoService.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceInfoService.java index 507896ce..8f3032ce 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceInfoService.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceInfoService.java @@ -17,6 +17,7 @@ package cn.odboy.task.service; import cn.odboy.task.dal.dataobject.TaskInstanceInfoTb; import com.baomidou.mybatisplus.extension.service.IService; +import org.quartz.JobDataMap; /** *

@@ -27,5 +28,12 @@ import com.baomidou.mybatisplus.extension.service.IService; * @since 2025-09-26 */ public interface TaskInstanceInfoService extends IService { + TaskInstanceInfoTb getRunningById(Long instanceId); + + void fastFailWithMessage(Long id, String errorMessage); + + void fastFailWithMessageData(Long id, String errorMessage, JobDataMap dataMap); + + void fastSuccessWithData(Long id, JobDataMap dataMap); } diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceStepDetailService.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceStepDetailService.java new file mode 100644 index 00000000..77017f0f --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskInstanceStepDetailService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.service; + +import cn.odboy.task.dal.dataobject.TaskInstanceStepDetailTb; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 任务实例步骤明细 服务类 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +public interface TaskInstanceStepDetailService extends IService { + /** + * 步骤执行成功 + * + * @param instanceDetailId 任务实例明细id + * @param stepDesc 步骤描述 + */ + void success(Long instanceDetailId, String stepDesc); + + /** + * 步骤执行失败 + * + * @param instanceDetailId 任务实例明细id + * @param stepDesc 步骤描述 + */ + void fail(Long instanceDetailId, String stepDesc); +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskTemplateInfoService.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskTemplateInfoService.java new file mode 100644 index 00000000..203bbf10 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/TaskTemplateInfoService.java @@ -0,0 +1,32 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.service; + +import cn.odboy.task.dal.dataobject.TaskTemplateInfoTb; +import cn.odboy.task.dal.model.TaskTemplateInfoVo; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 任务模板 服务类 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +public interface TaskTemplateInfoService extends IService { + TaskTemplateInfoVo getTemplateInfoByECL(String envAlias, String contextName, String language); +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceDetailServiceImpl.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceDetailServiceImpl.java index 148aca5e..0f28d509 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceDetailServiceImpl.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceDetailServiceImpl.java @@ -15,12 +15,17 @@ */ package cn.odboy.task.service.impl; +import cn.odboy.task.constant.TaskStatusEnum; import cn.odboy.task.dal.dataobject.TaskInstanceDetailTb; import cn.odboy.task.dal.mysql.TaskInstanceDetailMapper; import cn.odboy.task.service.TaskInstanceDetailService; +import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.quartz.JobDataMap; import org.springframework.stereotype.Service; +import java.util.Date; + /** *

* 任务实例明细 服务实现类 @@ -32,4 +37,39 @@ import org.springframework.stereotype.Service; @Service public class TaskInstanceDetailServiceImpl extends ServiceImpl implements TaskInstanceDetailService { + @Override + public void fastFailWithInfo(Long instanceId, String code, String executeInfo) { + TaskInstanceDetailTb updRecord = new TaskInstanceDetailTb(); + updRecord.setExecuteInfo(executeInfo); + updRecord.setExecuteStatus(TaskStatusEnum.Fail.getCode()); + lambdaUpdate() + .eq(TaskInstanceDetailTb::getInstanceId, instanceId) + .eq(TaskInstanceDetailTb::getBizCode, code) + .update(updRecord); + } + + @Override + public void fastSuccessWithInfo(Long instanceId, String code, String executeInfo) { + TaskInstanceDetailTb updRecord = new TaskInstanceDetailTb(); + updRecord.setFinishTime(new Date()); + updRecord.setExecuteInfo(executeInfo); + updRecord.setExecuteStatus(TaskStatusEnum.Success.getCode()); + lambdaUpdate() + .eq(TaskInstanceDetailTb::getInstanceId, instanceId) + .eq(TaskInstanceDetailTb::getBizCode, code) + .update(updRecord); + } + + @Override + public void fastStart(Long instanceId, String code, JobDataMap dataMap) { + TaskInstanceDetailTb updRecord = new TaskInstanceDetailTb(); + updRecord.setStartTime(new Date()); + updRecord.setExecuteInfo("运行中"); + updRecord.setExecuteParams(JSON.toJSONString(dataMap)); + updRecord.setExecuteStatus(TaskStatusEnum.Running.getCode()); + lambdaUpdate() + .eq(TaskInstanceDetailTb::getInstanceId, instanceId) + .eq(TaskInstanceDetailTb::getBizCode, code) + .update(updRecord); + } } diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceInfoServiceImpl.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceInfoServiceImpl.java index ae8aa767..eeb5ce7b 100644 --- a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceInfoServiceImpl.java +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceInfoServiceImpl.java @@ -15,11 +15,17 @@ */ package cn.odboy.task.service.impl; +import cn.odboy.task.constant.TaskStatusEnum; import cn.odboy.task.dal.dataobject.TaskInstanceInfoTb; import cn.odboy.task.dal.mysql.TaskInstanceInfoMapper; import cn.odboy.task.service.TaskInstanceInfoService; +import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.quartz.JobDataMap; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; /** *

@@ -32,4 +38,46 @@ import org.springframework.stereotype.Service; @Service public class TaskInstanceInfoServiceImpl extends ServiceImpl implements TaskInstanceInfoService { + @Override + public TaskInstanceInfoTb getRunningById(Long id) { + return lambdaQuery() + .eq(TaskInstanceInfoTb::getId, id) + .eq(TaskInstanceInfoTb::getStatus, TaskStatusEnum.Running.getCode()) + .orderByDesc(TaskInstanceInfoTb::getId) + .one(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void fastFailWithMessage(Long id, String errorMessage) { + TaskInstanceInfoTb updRecord = new TaskInstanceInfoTb(); + updRecord.setId(id); + updRecord.setFinishTime(new Date()); + updRecord.setStatus(TaskStatusEnum.Fail.getCode()); + updRecord.setErrorMessage(errorMessage); + updateById(updRecord); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void fastFailWithMessageData(Long id, String errorMessage, JobDataMap dataMap) { + TaskInstanceInfoTb updRecord = new TaskInstanceInfoTb(); + updRecord.setId(id); + updRecord.setFinishTime(new Date()); + updRecord.setStatus(TaskStatusEnum.Fail.getCode()); + updRecord.setErrorMessage(errorMessage); + updRecord.setJobData(JSON.toJSONString(dataMap)); + updateById(updRecord); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void fastSuccessWithData(Long id, JobDataMap dataMap) { + TaskInstanceInfoTb updRecord = new TaskInstanceInfoTb(); + updRecord.setId(id); + updRecord.setFinishTime(new Date()); + updRecord.setStatus(TaskStatusEnum.Success.getCode()); + updRecord.setJobData(JSON.toJSONString(dataMap)); + updateById(updRecord); + } } diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceStepDetailServiceImpl.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceStepDetailServiceImpl.java new file mode 100644 index 00000000..a01b1e11 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskInstanceStepDetailServiceImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.service.impl; + +import cn.odboy.framework.exception.web.BadRequestException; +import cn.odboy.task.constant.TaskStatusEnum; +import cn.odboy.task.dal.dataobject.TaskInstanceStepDetailTb; +import cn.odboy.task.dal.mysql.TaskInstanceStepDetailMapper; +import cn.odboy.task.service.TaskInstanceStepDetailService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 任务实例步骤明细 服务实现类 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Service +public class TaskInstanceStepDetailServiceImpl extends ServiceImpl implements TaskInstanceStepDetailService { + + @Override + public void success(Long instanceDetailId, String stepDesc) { + TaskInstanceStepDetailTb stepDetail = new TaskInstanceStepDetailTb(); + stepDetail.setInstanceDetailId(instanceDetailId); + stepDetail.setStepDesc(stepDesc); + stepDetail.setStepStatus(TaskStatusEnum.Success.getCode()); + save(stepDetail); + } + + @Override + public void fail(Long instanceDetailId, String stepDesc) { + TaskInstanceStepDetailTb stepDetail = new TaskInstanceStepDetailTb(); + stepDetail.setInstanceDetailId(instanceDetailId); + stepDetail.setStepDesc(stepDesc); + stepDetail.setStepStatus(TaskStatusEnum.Fail.getCode()); + save(stepDetail); + throw new BadRequestException(stepDesc); + } +} diff --git a/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskTemplateInfoServiceImpl.java b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskTemplateInfoServiceImpl.java new file mode 100644 index 00000000..75d56b63 --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/java/cn/odboy/task/service/impl/TaskTemplateInfoServiceImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright 2021-2025 Odboy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cn.odboy.task.service.impl; + +import cn.odboy.task.dal.dataobject.TaskTemplateInfoTb; +import cn.odboy.task.dal.model.TaskTemplateInfoVo; +import cn.odboy.task.dal.mysql.TaskTemplateInfoMapper; +import cn.odboy.task.service.TaskTemplateInfoService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.stereotype.Service; + +/** + *

+ * 任务模板 服务实现类 + *

+ * + * @author codegen + * @since 2025-09-28 + */ +@Service +public class TaskTemplateInfoServiceImpl extends ServiceImpl implements TaskTemplateInfoService { + + @Override + public TaskTemplateInfoVo getTemplateInfoByECL(String envAlias, String contextName, String language) { + return baseMapper.selectTemplateInfoByECL(envAlias, contextName, language); + } +} diff --git a/cutejava/cutejava-module-task/src/main/resources/mapper/TaskTemplateInfoMapper.xml b/cutejava/cutejava-module-task/src/main/resources/mapper/TaskTemplateInfoMapper.xml new file mode 100644 index 00000000..875f5edb --- /dev/null +++ b/cutejava/cutejava-module-task/src/main/resources/mapper/TaskTemplateInfoMapper.xml @@ -0,0 +1,18 @@ + + + + +