From e14f3615e23b5ea07b0a4c2e090c2e119bec6450 Mon Sep 17 00:00:00 2001 From: zhuxuetong <594754793@qq.com> Date: Wed, 11 Sep 2024 15:36:15 +0800 Subject: [PATCH] add getJobInstanceByTaskName api --- .../java/org/dinky/controller/APIController.java | 13 +++++++++++++ .../java/org/dinky/mapper/JobInstanceMapper.java | 2 ++ .../src/main/java/org/dinky/mapper/TaskMapper.java | 3 +++ .../java/org/dinky/service/JobInstanceService.java | 2 ++ .../main/java/org/dinky/service/TaskService.java | 6 ++++++ .../dinky/service/impl/JobInstanceServiceImpl.java | 5 +++++ .../org/dinky/service/impl/TaskServiceImpl.java | 8 ++++++++ .../src/main/resources/mapper/JobInstanceMapper.xml | 7 +++++++ .../src/main/resources/mapper/TaskMapper.xml | 6 ++++++ 9 files changed, 52 insertions(+) diff --git a/dinky-admin/src/main/java/org/dinky/controller/APIController.java b/dinky-admin/src/main/java/org/dinky/controller/APIController.java index 1d58b27cf5..57e3aa68ac 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/APIController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/APIController.java @@ -174,6 +174,19 @@ public Result getJobInstanceByTaskId(@RequestParam Integer id) { return Result.succeed(jobInstanceService.getJobInstanceByTaskId(id)); } + @GetMapping("/getJobInstanceByTaskName") + @ApiOperation("Get Job Instance By Task Id") + @ApiImplicitParam( + name = "id", + value = "Task Id", + required = true, + dataType = "Integer", + dataTypeClass = Integer.class) + public Result getJobInstanceByTaskId(@RequestParam String taskName) { + taskService.initTenantByTaskName(taskName); + return Result.succeed(jobInstanceService.getJobInstanceByTaskName(taskName)); + } + @GetMapping(value = "/exportSql") @ApiOperation("Export Sql") @Log(title = "Export Sql", businessType = BusinessType.EXPORT) diff --git a/dinky-admin/src/main/java/org/dinky/mapper/JobInstanceMapper.java b/dinky-admin/src/main/java/org/dinky/mapper/JobInstanceMapper.java index 55fd072a3e..3ab97ec1a0 100644 --- a/dinky-admin/src/main/java/org/dinky/mapper/JobInstanceMapper.java +++ b/dinky-admin/src/main/java/org/dinky/mapper/JobInstanceMapper.java @@ -51,6 +51,8 @@ public interface JobInstanceMapper extends SuperMapper { JobInstance getJobInstanceByTaskId(Integer id); + JobInstance getJobInstanceByTaskName(String taskName); + @InterceptorIgnore(tenantLine = "true") Integer getTenantByJobInstanceId(@Param("id") Integer id); } diff --git a/dinky-admin/src/main/java/org/dinky/mapper/TaskMapper.java b/dinky-admin/src/main/java/org/dinky/mapper/TaskMapper.java index 5c6b32b33e..9168debc61 100644 --- a/dinky-admin/src/main/java/org/dinky/mapper/TaskMapper.java +++ b/dinky-admin/src/main/java/org/dinky/mapper/TaskMapper.java @@ -53,6 +53,9 @@ List queryOnLineTaskByDoneStatus( @InterceptorIgnore(tenantLine = "true") Integer getTenantByTaskId(@Param("id") Integer id); + @InterceptorIgnore(tenantLine = "true") + Integer getTenantByTaskName(@Param("taskName") String taskName); + List getTaskOnlineRate(); JobModelOverview getJobStreamingOrBatchModelOverview(); diff --git a/dinky-admin/src/main/java/org/dinky/service/JobInstanceService.java b/dinky-admin/src/main/java/org/dinky/service/JobInstanceService.java index 1542364bfa..1df8ad2d10 100644 --- a/dinky-admin/src/main/java/org/dinky/service/JobInstanceService.java +++ b/dinky-admin/src/main/java/org/dinky/service/JobInstanceService.java @@ -119,6 +119,8 @@ public interface JobInstanceService extends ISuperService { */ JobInstance getJobInstanceByTaskId(Integer id); + JobInstance getJobInstanceByTaskName(String taskName); + /** * List all job instances in the system. * diff --git a/dinky-admin/src/main/java/org/dinky/service/TaskService.java b/dinky-admin/src/main/java/org/dinky/service/TaskService.java index c0453567dc..dc3b613f49 100644 --- a/dinky-admin/src/main/java/org/dinky/service/TaskService.java +++ b/dinky-admin/src/main/java/org/dinky/service/TaskService.java @@ -158,6 +158,12 @@ public interface TaskService extends ISuperService { */ void initTenantByTaskId(Integer id); + /** + * Initialize the tenant by task name. + * @param taskName task name + */ + void initTenantByTaskName(String taskName); + /** * Change the life cycle of the given task. * diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/JobInstanceServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/JobInstanceServiceImpl.java index 75454bb37e..1779cb05d1 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/JobInstanceServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/JobInstanceServiceImpl.java @@ -297,6 +297,11 @@ public JobInstance getJobInstanceByTaskId(Integer id) { return baseMapper.getJobInstanceByTaskId(id); } + @Override + public JobInstance getJobInstanceByTaskName(String taskName) { + return baseMapper.getJobInstanceByTaskName(taskName); + } + @Override public ProTableResult listJobInstances(JsonNode para) { int current = para.has("current") ? para.get("current").asInt() : 1; diff --git a/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java index 0d8a4c6fe0..69ae7b8d88 100644 --- a/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java @@ -574,6 +574,14 @@ public void initTenantByTaskId(Integer id) { log.info("Init task tenan finished.."); } + @Override + public void initTenantByTaskName(String taskName) { + Integer tenantId = baseMapper.getTenantByTaskName(taskName); + Asserts.checkNull(tenantId, Status.TASK_NOT_EXIST.getMessage()); + TenantContextHolder.set(tenantId); + log.info("Init task tenant finished.."); + } + @Override @Transactional(rollbackFor = Exception.class) public boolean changeTaskLifeRecyle(Integer taskId, JobLifeCycle lifeCycle) throws SqlExplainExcepition { diff --git a/dinky-admin/src/main/resources/mapper/JobInstanceMapper.xml b/dinky-admin/src/main/resources/mapper/JobInstanceMapper.xml index a5ee9ed2dd..cd014e09bb 100644 --- a/dinky-admin/src/main/resources/mapper/JobInstanceMapper.xml +++ b/dinky-admin/src/main/resources/mapper/JobInstanceMapper.xml @@ -98,6 +98,13 @@ order by id desc limit 1 + + + +