🚧 定时任务.

This commit is contained in:
lijiahangmax
2024-03-28 12:05:30 +08:00
parent 833ced5748
commit 247a688a7d
29 changed files with 1782 additions and 22 deletions

View File

@@ -44,28 +44,19 @@ public class CodeGenerators {
// .color("blue", "gray", "red", "green", "white")
// .valueUseFields()
// .build(),
Template.create("exec_log", "执行记录", "exec")
Template.create("exec_job", "计划执行任务", "exec")
.disableUnitTest()
.vue("exec", "exec-log")
.enableRowSelection()
.dict("execLogStatus", "status")
.keyName("execStatus")
.field("execStatus")
.fields("WAITING", "RUNNING", "COMPLETED", "FAILED")
.labels("等待中", "运行中", "执行完成", "执行失败")
.color("gray", "green", "arcoblue", "red")
.valueUseFields()
.vue("exec", "exec-job")
.enableDrawerForm()
.dict("execJobStatus", "status")
.field("execJobStatus")
.fields("DISABLED", "ENABLED")
.labels("禁用", "启用")
.values(0, 1)
.build(),
Template.create("exec_host_log", "主机执行记录", "exec")
Template.create("exec_job_host", "计划执行任务主机", "exec")
.disableUnitTest()
.vue("exec", "exec-host-log")
.dict("execHostLogStatus", "status")
.keyName("execHostStatus")
.field("execHostStatus")
.fields("WAITING", "RUNNING", "COMPLETED", "FAILED", "INTERRUPTED")
.labels("等待中", "运行中", "执行完成", "执行失败", "已中断")
.color("gray", "green", "arcoblue", "red", "purple")
.valueUseFields()
.vue("exec", "exec-job-host")
.build(),
};
// jdbc 配置 - 使用配置文件

View File

@@ -55,7 +55,7 @@ spring:
multi-statement-allow: true
redis:
database: 0
connect-timeout: 3000
connect-timeout: 5000
timeout: 3000
cache:
type: REDIS

View File

@@ -0,0 +1,89 @@
### 创建计划执行任务
POST {{baseUrl}}/asset/exec-job/create
Content-Type: application/json
Authorization: {{token}}
{
"name": "",
"expression": "",
"timeout": "",
"command": "",
"parameterSchema": "",
"status": "",
"recentLogId": ""
}
### 更新计划执行任务
PUT {{baseUrl}}/asset/exec-job/update
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"expression": "",
"timeout": "",
"command": "",
"parameterSchema": "",
"status": "",
"recentLogId": ""
}
### 查询计划执行任务
GET {{baseUrl}}/asset/exec-job/get?id=1
Authorization: {{token}}
### 批量查询计划执行任务
GET {{baseUrl}}/asset/exec-job/batch-get?idList=1,2,3
Authorization: {{token}}
### 查询全部计划执行任务
POST {{baseUrl}}/asset/exec-job/list
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"name": "",
"expression": "",
"timeout": "",
"command": "",
"parameterSchema": "",
"status": "",
"recentLogId": ""
}
### 分页查询计划执行任务
POST {{baseUrl}}/asset/exec-job/query
Content-Type: application/json
Authorization: {{token}}
{
"page": 1,
"limit": 10,
"id": "",
"name": "",
"expression": "",
"timeout": "",
"command": "",
"parameterSchema": "",
"status": "",
"recentLogId": ""
}
### 删除计划执行任务
DELETE {{baseUrl}}/asset/exec-job/delete?id=1
Authorization: {{token}}
### 批量删除计划执行任务
DELETE {{baseUrl}}/asset/exec-job/batch-delete?idList=1,2,3
Authorization: {{token}}
###

View File

@@ -0,0 +1,114 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecJobOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecJobCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
import com.orion.ops.module.asset.service.ExecJobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 计划执行任务 api
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Tag(name = "asset - 计划执行任务服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/asset/exec-job")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class ExecJobController {
@Resource
private ExecJobService execJobService;
@OperatorLog(ExecJobOperatorType.CREATE)
@PostMapping("/create")
@Operation(summary = "创建计划执行任务")
@PreAuthorize("@ss.hasPermission('asset:exec-job:create')")
public Long createExecJob(@Validated @RequestBody ExecJobCreateRequest request) {
return execJobService.createExecJob(request);
}
@OperatorLog(ExecJobOperatorType.UPDATE)
@PutMapping("/update")
@Operation(summary = "更新计划执行任务")
@PreAuthorize("@ss.hasPermission('asset:exec-job:update')")
public Integer updateExecJob(@Validated @RequestBody ExecJobUpdateRequest request) {
return execJobService.updateExecJobById(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "查询计划执行任务")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job:query')")
public ExecJobVO getExecJob(@RequestParam("id") Long id) {
return execJobService.getExecJobById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/batch-get")
@Operation(summary = "批量查询计划执行任务")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job:query')")
public List<ExecJobVO> getExecJobBatch(@RequestParam("idList") List<Long> idList) {
return execJobService.getExecJobByIdList(idList);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/list")
@Operation(summary = "查询全部计划执行任务")
@PreAuthorize("@ss.hasPermission('asset:exec-job:query')")
public List<ExecJobVO> getExecJobList(@Validated @RequestBody ExecJobQueryRequest request) {
return execJobService.getExecJobList(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询计划执行任务")
@PreAuthorize("@ss.hasPermission('asset:exec-job:query')")
public DataGrid<ExecJobVO> getExecJobPage(@Validated(Page.class) @RequestBody ExecJobQueryRequest request) {
return execJobService.getExecJobPage(request);
}
@OperatorLog(ExecJobOperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "删除计划执行任务")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job:delete')")
public Integer deleteExecJob(@RequestParam("id") Long id) {
return execJobService.deleteExecJobById(id);
}
@OperatorLog(ExecJobOperatorType.DELETE)
@DeleteMapping("/batch-delete")
@Operation(summary = "批量删除计划执行任务")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job:delete')")
public Integer batchDeleteExecJob(@RequestParam("idList") List<Long> idList) {
return execJobService.deleteExecJobByIdList(idList);
}
}

View File

@@ -0,0 +1,69 @@
### 创建计划执行任务主机
POST {{baseUrl}}/asset/exec-job-host/create
Content-Type: application/json
Authorization: {{token}}
{
"jobId": "",
"hostId": ""
}
### 更新计划执行任务主机
PUT {{baseUrl}}/asset/exec-job-host/update
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"jobId": "",
"hostId": ""
}
### 查询计划执行任务主机
GET {{baseUrl}}/asset/exec-job-host/get?id=1
Authorization: {{token}}
### 批量查询计划执行任务主机
GET {{baseUrl}}/asset/exec-job-host/batch-get?idList=1,2,3
Authorization: {{token}}
### 查询全部计划执行任务主机
POST {{baseUrl}}/asset/exec-job-host/list
Content-Type: application/json
Authorization: {{token}}
{
"id": "",
"jobId": "",
"hostId": ""
}
### 分页查询计划执行任务主机
POST {{baseUrl}}/asset/exec-job-host/query
Content-Type: application/json
Authorization: {{token}}
{
"page": 1,
"limit": 10,
"id": "",
"jobId": "",
"hostId": ""
}
### 删除计划执行任务主机
DELETE {{baseUrl}}/asset/exec-job-host/delete?id=1
Authorization: {{token}}
### 批量删除计划执行任务主机
DELETE {{baseUrl}}/asset/exec-job-host/batch-delete?idList=1,2,3
Authorization: {{token}}
###

View File

@@ -0,0 +1,114 @@
package com.orion.ops.module.asset.controller;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
import com.orion.ops.framework.common.validator.group.Page;
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
import com.orion.ops.framework.web.core.annotation.RestWrapper;
import com.orion.ops.module.asset.define.operator.ExecJobHostOperatorType;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobHostVO;
import com.orion.ops.module.asset.service.ExecJobHostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 计划执行任务主机 api
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Tag(name = "asset - 计划执行任务主机服务")
@Slf4j
@Validated
@RestWrapper
@RestController
@RequestMapping("/asset/exec-job-host")
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
public class ExecJobHostController {
@Resource
private ExecJobHostService execJobHostService;
@OperatorLog(ExecJobHostOperatorType.CREATE)
@PostMapping("/create")
@Operation(summary = "创建计划执行任务主机")
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:create')")
public Long createExecJobHost(@Validated @RequestBody ExecJobHostCreateRequest request) {
return execJobHostService.createExecJobHost(request);
}
@OperatorLog(ExecJobHostOperatorType.UPDATE)
@PutMapping("/update")
@Operation(summary = "更新计划执行任务主机")
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:update')")
public Integer updateExecJobHost(@Validated @RequestBody ExecJobHostUpdateRequest request) {
return execJobHostService.updateExecJobHostById(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/get")
@Operation(summary = "查询计划执行任务主机")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:query')")
public ExecJobHostVO getExecJobHost(@RequestParam("id") Long id) {
return execJobHostService.getExecJobHostById(id);
}
@IgnoreLog(IgnoreLogMode.RET)
@GetMapping("/batch-get")
@Operation(summary = "批量查询计划执行任务主机")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:query')")
public List<ExecJobHostVO> getExecJobHostBatch(@RequestParam("idList") List<Long> idList) {
return execJobHostService.getExecJobHostByIdList(idList);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/list")
@Operation(summary = "查询全部计划执行任务主机")
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:query')")
public List<ExecJobHostVO> getExecJobHostList(@Validated @RequestBody ExecJobHostQueryRequest request) {
return execJobHostService.getExecJobHostList(request);
}
@IgnoreLog(IgnoreLogMode.RET)
@PostMapping("/query")
@Operation(summary = "分页查询计划执行任务主机")
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:query')")
public DataGrid<ExecJobHostVO> getExecJobHostPage(@Validated(Page.class) @RequestBody ExecJobHostQueryRequest request) {
return execJobHostService.getExecJobHostPage(request);
}
@OperatorLog(ExecJobHostOperatorType.DELETE)
@DeleteMapping("/delete")
@Operation(summary = "删除计划执行任务主机")
@Parameter(name = "id", description = "id", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:delete')")
public Integer deleteExecJobHost(@RequestParam("id") Long id) {
return execJobHostService.deleteExecJobHostById(id);
}
@OperatorLog(ExecJobHostOperatorType.DELETE)
@DeleteMapping("/batch-delete")
@Operation(summary = "批量删除计划执行任务主机")
@Parameter(name = "idList", description = "idList", required = true)
@PreAuthorize("@ss.hasPermission('asset:exec-job-host:delete')")
public Integer batchDeleteExecJobHost(@RequestParam("idList") List<Long> idList) {
return execJobHostService.deleteExecJobHostByIdList(idList);
}
}

View File

@@ -0,0 +1,35 @@
package com.orion.ops.module.asset.convert;
import com.orion.ops.module.asset.entity.domain.ExecJobDO;
import com.orion.ops.module.asset.entity.request.exec.ExecJobCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 计划执行任务 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Mapper
public interface ExecJobConvert {
ExecJobConvert MAPPER = Mappers.getMapper(ExecJobConvert.class);
ExecJobDO to(ExecJobCreateRequest request);
ExecJobDO to(ExecJobUpdateRequest request);
ExecJobDO to(ExecJobQueryRequest request);
ExecJobVO to(ExecJobDO domain);
List<ExecJobVO> to(List<ExecJobDO> list);
}

View File

@@ -0,0 +1,35 @@
package com.orion.ops.module.asset.convert;
import com.orion.ops.module.asset.entity.domain.ExecJobHostDO;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobHostVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 计划执行任务主机 内部对象转换器
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Mapper
public interface ExecJobHostConvert {
ExecJobHostConvert MAPPER = Mappers.getMapper(ExecJobHostConvert.class);
ExecJobHostDO to(ExecJobHostCreateRequest request);
ExecJobHostDO to(ExecJobHostUpdateRequest request);
ExecJobHostDO to(ExecJobHostQueryRequest request);
ExecJobHostVO to(ExecJobHostDO domain);
List<ExecJobHostVO> to(List<ExecJobHostDO> list);
}

View File

@@ -0,0 +1,36 @@
package com.orion.ops.module.asset.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.asset.entity.domain.ExecJobDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 计划执行任务 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Mapper
public interface ExecJobDAO extends IMapper<ExecJobDO> {
/**
* 获取查询条件
*
* @param entity entity
* @return 查询条件
*/
default LambdaQueryWrapper<ExecJobDO> queryCondition(ExecJobDO entity) {
return this.wrapper()
.eq(ExecJobDO::getId, entity.getId())
.eq(ExecJobDO::getName, entity.getName())
.eq(ExecJobDO::getExpression, entity.getExpression())
.eq(ExecJobDO::getTimeout, entity.getTimeout())
.eq(ExecJobDO::getCommand, entity.getCommand())
.eq(ExecJobDO::getParameterSchema, entity.getParameterSchema())
.eq(ExecJobDO::getStatus, entity.getStatus())
.eq(ExecJobDO::getRecentLogId, entity.getRecentLogId());
}
}

View File

@@ -0,0 +1,31 @@
package com.orion.ops.module.asset.dao;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
import com.orion.ops.module.asset.entity.domain.ExecJobHostDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 计划执行任务主机 Mapper 接口
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Mapper
public interface ExecJobHostDAO extends IMapper<ExecJobHostDO> {
/**
* 获取查询条件
*
* @param entity entity
* @return 查询条件
*/
default LambdaQueryWrapper<ExecJobHostDO> queryCondition(ExecJobHostDO entity) {
return this.wrapper()
.eq(ExecJobHostDO::getId, entity.getId())
.eq(ExecJobHostDO::getJobId, entity.getJobId())
.eq(ExecJobHostDO::getHostId, entity.getHostId());
}
}

View File

@@ -0,0 +1,34 @@
package com.orion.ops.module.asset.define.operator;
import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
/**
* 计划执行任务主机 操作日志类型
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Module("asset:exec-job-host")
public class ExecJobHostOperatorType extends InitializingOperatorTypes {
public static final String CREATE = "exec-job-host:create";
public static final String UPDATE = "exec-job-host:update";
public static final String DELETE = "exec-job-host:delete";
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(L, CREATE, "创建计划执行任务主机"),
new OperatorType(M, UPDATE, "更新计划执行任务主机"),
new OperatorType(H, DELETE, "删除计划执行任务主机"),
};
}
}

View File

@@ -0,0 +1,34 @@
package com.orion.ops.module.asset.define.operator;
import com.orion.ops.framework.biz.operator.log.core.annotation.Module;
import com.orion.ops.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
import static com.orion.ops.framework.biz.operator.log.core.enums.OperatorRiskLevel.*;
/**
* 计划执行任务 操作日志类型
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Module("asset:exec-job")
public class ExecJobOperatorType extends InitializingOperatorTypes {
public static final String CREATE = "exec-job:create";
public static final String UPDATE = "exec-job:update";
public static final String DELETE = "exec-job:delete";
@Override
public OperatorType[] types() {
return new OperatorType[]{
new OperatorType(L, CREATE, "创建计划执行任务"),
new OperatorType(M, UPDATE, "更新计划执行任务"),
new OperatorType(H, DELETE, "删除计划执行任务"),
};
}
}

View File

@@ -0,0 +1,61 @@
package com.orion.ops.module.asset.entity.domain;
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 com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 计划执行任务 实体对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "exec_job", autoResultMap = true)
@Schema(name = "ExecJobDO", description = "计划执行任务 实体对象")
public class ExecJobDO extends BaseDO {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "任务名称")
@TableField("name")
private String name;
@Schema(description = "cron 表达式")
@TableField("expression")
private String expression;
@Schema(description = "超时时间")
@TableField("timeout")
private Integer timeout;
@Schema(description = "执行命令")
@TableField("command")
private String command;
@Schema(description = "命令参数")
@TableField("parameter_schema")
private String parameterSchema;
@Schema(description = "启用状态 0禁用 1启用")
@TableField("status")
private Integer status;
@Schema(description = "最近执行id")
@TableField("recent_log_id")
private Long recentLogId;
}

View File

@@ -0,0 +1,41 @@
package com.orion.ops.module.asset.entity.domain;
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 com.orion.ops.framework.mybatis.core.domain.BaseDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 计划执行任务主机 实体对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "exec_job_host", autoResultMap = true)
@Schema(name = "ExecJobHostDO", description = "计划执行任务主机 实体对象")
public class ExecJobHostDO extends BaseDO {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "任务id")
@TableField("job_id")
private Long jobId;
@Schema(description = "主机id")
@TableField("host_id")
private Long hostId;
}

View File

@@ -0,0 +1,60 @@
package com.orion.ops.module.asset.entity.request.exec;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 计划执行任务 创建请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobCreateRequest", description = "计划执行任务 创建请求对象")
public class ExecJobCreateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@NotBlank
@Size(max = 64)
@Schema(description = "任务名称")
private String name;
@NotBlank
@Size(max = 512)
@Schema(description = "cron 表达式")
private String expression;
@NotNull
@Schema(description = "超时时间")
private Integer timeout;
@NotBlank
@Schema(description = "执行命令")
private String command;
@NotBlank
@Schema(description = "命令参数")
private String parameterSchema;
@NotNull
@Schema(description = "启用状态 0禁用 1启用")
private Integer status;
@NotNull
@Schema(description = "最近执行id")
private Long recentLogId;
}

View File

@@ -0,0 +1,36 @@
package com.orion.ops.module.asset.entity.request.exec;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 计划执行任务主机 创建请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobHostCreateRequest", description = "计划执行任务主机 创建请求对象")
public class ExecJobHostCreateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Schema(description = "任务id")
private Long jobId;
@NotNull
@Schema(description = "主机id")
private Long hostId;
}

View File

@@ -0,0 +1,34 @@
package com.orion.ops.module.asset.entity.request.exec;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
/**
* 计划执行任务主机 查询请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "ExecJobHostQueryRequest", description = "计划执行任务主机 查询请求对象")
public class ExecJobHostQueryRequest extends PageRequest {
@Schema(description = "搜索")
private String searchValue;
@Schema(description = "id")
private Long id;
@Schema(description = "任务id")
private Long jobId;
@Schema(description = "主机id")
private Long hostId;
}

View File

@@ -0,0 +1,40 @@
package com.orion.ops.module.asset.entity.request.exec;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* 计划执行任务主机 更新请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobHostUpdateRequest", description = "计划执行任务主机 更新请求对象")
public class ExecJobHostUpdateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Schema(description = "id")
private Long id;
@NotNull
@Schema(description = "任务id")
private Long jobId;
@NotNull
@Schema(description = "主机id")
private Long hostId;
}

View File

@@ -0,0 +1,53 @@
package com.orion.ops.module.asset.entity.request.exec;
import com.orion.ops.framework.common.entity.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import javax.validation.constraints.Size;
/**
* 计划执行任务 查询请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "ExecJobQueryRequest", description = "计划执行任务 查询请求对象")
public class ExecJobQueryRequest extends PageRequest {
@Schema(description = "搜索")
private String searchValue;
@Schema(description = "id")
private Long id;
@Size(max = 64)
@Schema(description = "任务名称")
private String name;
@Size(max = 512)
@Schema(description = "cron 表达式")
private String expression;
@Schema(description = "超时时间")
private Integer timeout;
@Schema(description = "执行命令")
private String command;
@Schema(description = "命令参数")
private String parameterSchema;
@Schema(description = "启用状态 0禁用 1启用")
private Integer status;
@Schema(description = "最近执行id")
private Long recentLogId;
}

View File

@@ -0,0 +1,64 @@
package com.orion.ops.module.asset.entity.request.exec;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 计划执行任务 更新请求对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobUpdateRequest", description = "计划执行任务 更新请求对象")
public class ExecJobUpdateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
@Schema(description = "id")
private Long id;
@NotBlank
@Size(max = 64)
@Schema(description = "任务名称")
private String name;
@NotBlank
@Size(max = 512)
@Schema(description = "cron 表达式")
private String expression;
@NotNull
@Schema(description = "超时时间")
private Integer timeout;
@NotBlank
@Schema(description = "执行命令")
private String command;
@NotBlank
@Schema(description = "命令参数")
private String parameterSchema;
@NotNull
@Schema(description = "启用状态 0禁用 1启用")
private Integer status;
@NotNull
@Schema(description = "最近执行id")
private Long recentLogId;
}

View File

@@ -0,0 +1,49 @@
package com.orion.ops.module.asset.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 计划执行任务主机 视图响应对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobHostVO", description = "计划执行任务主机 视图响应对象")
public class ExecJobHostVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "任务id")
private Long jobId;
@Schema(description = "主机id")
private Long hostId;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
}

View File

@@ -0,0 +1,64 @@
package com.orion.ops.module.asset.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 计划执行任务 视图响应对象
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "ExecJobVO", description = "计划执行任务 视图响应对象")
public class ExecJobVO implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "id")
private Long id;
@Schema(description = "任务名称")
private String name;
@Schema(description = "cron 表达式")
private String expression;
@Schema(description = "超时时间")
private Integer timeout;
@Schema(description = "执行命令")
private String command;
@Schema(description = "命令参数")
private String parameterSchema;
@Schema(description = "启用状态 0禁用 1启用")
private Integer status;
@Schema(description = "最近执行id")
private Long recentLogId;
@Schema(description = "创建时间")
private Date createTime;
@Schema(description = "修改时间")
private Date updateTime;
@Schema(description = "创建人")
private String creator;
@Schema(description = "修改人")
private String updater;
}

View File

@@ -0,0 +1,109 @@
package com.orion.ops.module.asset.service;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobHostVO;
import java.util.List;
/**
* 计划执行任务主机 服务类
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
public interface ExecJobHostService {
/**
* 创建计划执行任务主机
*
* @param request request
* @return id
*/
Long createExecJobHost(ExecJobHostCreateRequest request);
/**
* 更新计划执行任务主机
*
* @param request request
* @return effect
*/
Integer updateExecJobHostById(ExecJobHostUpdateRequest request);
/**
* 根据条件更新计划执行任务主机
*
* @param query query
* @param update update
* @return effect
*/
Integer updateExecJobHost(ExecJobHostQueryRequest query, ExecJobHostUpdateRequest update);
/**
* 查询计划执行任务主机
*
* @param id id
* @return row
*/
ExecJobHostVO getExecJobHostById(Long id);
/**
* 批量查询计划执行任务主机
*
* @param idList idList
* @return rows
*/
List<ExecJobHostVO> getExecJobHostByIdList(List<Long> idList);
/**
* 查询全部计划执行任务主机
*
* @param request request
* @return rows
*/
List<ExecJobHostVO> getExecJobHostList(ExecJobHostQueryRequest request);
/**
* 查询计划执行任务主机数量
*
* @param request request
* @return count
*/
Long getExecJobHostCount(ExecJobHostQueryRequest request);
/**
* 分页查询计划执行任务主机
*
* @param request request
* @return rows
*/
DataGrid<ExecJobHostVO> getExecJobHostPage(ExecJobHostQueryRequest request);
/**
* 删除计划执行任务主机
*
* @param id id
* @return effect
*/
Integer deleteExecJobHostById(Long id);
/**
* 批量删除计划执行任务主机
*
* @param idList idList
* @return effect
*/
Integer deleteExecJobHostByIdList(List<Long> idList);
/**
* 根据条件删除计划执行任务主机
*
* @param request request
* @return effect
*/
Integer deleteExecJobHost(ExecJobHostQueryRequest request);
}

View File

@@ -0,0 +1,109 @@
package com.orion.ops.module.asset.service;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.ops.module.asset.entity.request.exec.ExecJobCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
import java.util.List;
/**
* 计划执行任务 服务类
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
public interface ExecJobService {
/**
* 创建计划执行任务
*
* @param request request
* @return id
*/
Long createExecJob(ExecJobCreateRequest request);
/**
* 更新计划执行任务
*
* @param request request
* @return effect
*/
Integer updateExecJobById(ExecJobUpdateRequest request);
/**
* 根据条件更新计划执行任务
*
* @param query query
* @param update update
* @return effect
*/
Integer updateExecJob(ExecJobQueryRequest query, ExecJobUpdateRequest update);
/**
* 查询计划执行任务
*
* @param id id
* @return row
*/
ExecJobVO getExecJobById(Long id);
/**
* 批量查询计划执行任务
*
* @param idList idList
* @return rows
*/
List<ExecJobVO> getExecJobByIdList(List<Long> idList);
/**
* 查询全部计划执行任务
*
* @param request request
* @return rows
*/
List<ExecJobVO> getExecJobList(ExecJobQueryRequest request);
/**
* 查询计划执行任务数量
*
* @param request request
* @return count
*/
Long getExecJobCount(ExecJobQueryRequest request);
/**
* 分页查询计划执行任务
*
* @param request request
* @return rows
*/
DataGrid<ExecJobVO> getExecJobPage(ExecJobQueryRequest request);
/**
* 删除计划执行任务
*
* @param id id
* @return effect
*/
Integer deleteExecJobById(Long id);
/**
* 批量删除计划执行任务
*
* @param idList idList
* @return effect
*/
Integer deleteExecJobByIdList(List<Long> idList);
/**
* 根据条件删除计划执行任务
*
* @param request request
* @return effect
*/
Integer deleteExecJob(ExecJobQueryRequest request);
}

View File

@@ -0,0 +1,197 @@
package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.module.asset.convert.ExecJobHostConvert;
import com.orion.ops.module.asset.dao.ExecJobHostDAO;
import com.orion.ops.module.asset.entity.domain.ExecJobHostDO;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobHostUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobHostVO;
import com.orion.ops.module.asset.service.ExecJobHostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 计划执行任务主机 服务实现类
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Slf4j
@Service
public class ExecJobHostServiceImpl implements ExecJobHostService {
@Resource
private ExecJobHostDAO execJobHostDAO;
@Override
public Long createExecJobHost(ExecJobHostCreateRequest request) {
log.info("ExecJobHostService-createExecJobHost request: {}", JSON.toJSONString(request));
// 转换
ExecJobHostDO record = ExecJobHostConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkExecJobHostPresent(record);
// 插入
int effect = execJobHostDAO.insert(record);
Long id = record.getId();
log.info("ExecJobHostService-createExecJobHost id: {}, effect: {}", id, effect);
return id;
}
@Override
public Integer updateExecJobHostById(ExecJobHostUpdateRequest request) {
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
log.info("ExecJobHostService-updateExecJobHostById id: {}, request: {}", id, JSON.toJSONString(request));
// 查询
ExecJobHostDO record = execJobHostDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
ExecJobHostDO updateRecord = ExecJobHostConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkExecJobHostPresent(updateRecord);
// 更新
int effect = execJobHostDAO.updateById(updateRecord);
log.info("ExecJobHostService-updateExecJobHostById effect: {}", effect);
return effect;
}
@Override
public Integer updateExecJobHost(ExecJobHostQueryRequest query, ExecJobHostUpdateRequest update) {
log.info("ExecJobHostService.updateExecJobHost query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update));
// 条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(query);
// 转换
ExecJobHostDO updateRecord = ExecJobHostConvert.MAPPER.to(update);
// 更新
int effect = execJobHostDAO.update(updateRecord, wrapper);
log.info("ExecJobHostService.updateExecJobHost effect: {}", effect);
return effect;
}
@Override
public ExecJobHostVO getExecJobHostById(Long id) {
// 查询
ExecJobHostDO record = execJobHostDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
return ExecJobHostConvert.MAPPER.to(record);
}
@Override
public List<ExecJobHostVO> getExecJobHostByIdList(List<Long> idList) {
// 查询
List<ExecJobHostDO> records = execJobHostDAO.selectBatchIds(idList);
if (records.isEmpty()) {
return Lists.empty();
}
// 转换
return ExecJobHostConvert.MAPPER.to(records);
}
@Override
public List<ExecJobHostVO> getExecJobHostList(ExecJobHostQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobHostDAO.of(wrapper).list(ExecJobHostConvert.MAPPER::to);
}
@Override
public Long getExecJobHostCount(ExecJobHostQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobHostDAO.selectCount(wrapper);
}
@Override
public DataGrid<ExecJobHostVO> getExecJobHostPage(ExecJobHostQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobHostDAO.of(wrapper)
.page(request)
.dataGrid(ExecJobHostConvert.MAPPER::to);
}
@Override
public Integer deleteExecJobHostById(Long id) {
log.info("ExecJobHostService-deleteExecJobHostById id: {}", id);
// 检查数据是否存在
ExecJobHostDO record = execJobHostDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 删除
int effect = execJobHostDAO.deleteById(id);
log.info("ExecJobHostService-deleteExecJobHostById id: {}, effect: {}", id, effect);
return effect;
}
@Override
public Integer deleteExecJobHostByIdList(List<Long> idList) {
log.info("ExecJobHostService-deleteExecJobHostByIdList idList: {}", idList);
int effect = execJobHostDAO.deleteBatchIds(idList);
log.info("ExecJobHostService-deleteExecJobHostByIdList effect: {}", effect);
return effect;
}
@Override
public Integer deleteExecJobHost(ExecJobHostQueryRequest request) {
log.info("ExecJobHostService.deleteExecJobHost request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(request);
// 删除
int effect = execJobHostDAO.delete(wrapper);
log.info("ExecJobHostService.deleteExecJobHost effect: {}", effect);
return effect;
}
/**
* 检查对象是否存在
*
* @param domain domain
*/
private void checkExecJobHostPresent(ExecJobHostDO domain) {
// 构造条件
LambdaQueryWrapper<ExecJobHostDO> wrapper = execJobHostDAO.wrapper()
// 更新时忽略当前记录
.ne(ExecJobHostDO::getId, domain.getId())
// 用其他字段做重复校验
.eq(ExecJobHostDO::getJobId, domain.getJobId())
.eq(ExecJobHostDO::getHostId, domain.getHostId());
// 检查是否存在
boolean present = execJobHostDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
}
/**
* 构建查询 wrapper
*
* @param request request
* @return wrapper
*/
private LambdaQueryWrapper<ExecJobHostDO> buildQueryWrapper(ExecJobHostQueryRequest request) {
String searchValue = request.getSearchValue();
return execJobHostDAO.wrapper()
.eq(ExecJobHostDO::getId, request.getId())
.eq(ExecJobHostDO::getJobId, request.getJobId())
.eq(ExecJobHostDO::getHostId, request.getHostId())
.and(Strings.isNotEmpty(searchValue), c -> c
.eq(ExecJobHostDO::getId, searchValue).or()
.eq(ExecJobHostDO::getJobId, searchValue).or()
.eq(ExecJobHostDO::getHostId, searchValue)
)
.orderByDesc(ExecJobHostDO::getId);
}
}

View File

@@ -0,0 +1,212 @@
package com.orion.ops.module.asset.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.orion.lang.define.wrapper.DataGrid;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.collect.Lists;
import com.orion.ops.framework.common.constant.ErrorMessage;
import com.orion.ops.framework.common.utils.Valid;
import com.orion.ops.module.asset.convert.ExecJobConvert;
import com.orion.ops.module.asset.dao.ExecJobDAO;
import com.orion.ops.module.asset.entity.domain.ExecJobDO;
import com.orion.ops.module.asset.entity.request.exec.ExecJobCreateRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobQueryRequest;
import com.orion.ops.module.asset.entity.request.exec.ExecJobUpdateRequest;
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
import com.orion.ops.module.asset.service.ExecJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 计划执行任务 服务实现类
*
* @author Jiahang Li
* @version 1.0.3
* @since 2024-3-28 12:03
*/
@Slf4j
@Service
public class ExecJobServiceImpl implements ExecJobService {
@Resource
private ExecJobDAO execJobDAO;
@Override
public Long createExecJob(ExecJobCreateRequest request) {
log.info("ExecJobService-createExecJob request: {}", JSON.toJSONString(request));
// 转换
ExecJobDO record = ExecJobConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkExecJobPresent(record);
// 插入
int effect = execJobDAO.insert(record);
Long id = record.getId();
log.info("ExecJobService-createExecJob id: {}, effect: {}", id, effect);
return id;
}
@Override
public Integer updateExecJobById(ExecJobUpdateRequest request) {
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
log.info("ExecJobService-updateExecJobById id: {}, request: {}", id, JSON.toJSONString(request));
// 查询
ExecJobDO record = execJobDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
ExecJobDO updateRecord = ExecJobConvert.MAPPER.to(request);
// 查询数据是否冲突
this.checkExecJobPresent(updateRecord);
// 更新
int effect = execJobDAO.updateById(updateRecord);
log.info("ExecJobService-updateExecJobById effect: {}", effect);
return effect;
}
@Override
public Integer updateExecJob(ExecJobQueryRequest query, ExecJobUpdateRequest update) {
log.info("ExecJobService.updateExecJob query: {}, update: {}", JSON.toJSONString(query), JSON.toJSONString(update));
// 条件
LambdaQueryWrapper<ExecJobDO> wrapper = this.buildQueryWrapper(query);
// 转换
ExecJobDO updateRecord = ExecJobConvert.MAPPER.to(update);
// 更新
int effect = execJobDAO.update(updateRecord, wrapper);
log.info("ExecJobService.updateExecJob effect: {}", effect);
return effect;
}
@Override
public ExecJobVO getExecJobById(Long id) {
// 查询
ExecJobDO record = execJobDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 转换
return ExecJobConvert.MAPPER.to(record);
}
@Override
public List<ExecJobVO> getExecJobByIdList(List<Long> idList) {
// 查询
List<ExecJobDO> records = execJobDAO.selectBatchIds(idList);
if (records.isEmpty()) {
return Lists.empty();
}
// 转换
return ExecJobConvert.MAPPER.to(records);
}
@Override
public List<ExecJobVO> getExecJobList(ExecJobQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobDAO.of(wrapper).list(ExecJobConvert.MAPPER::to);
}
@Override
public Long getExecJobCount(ExecJobQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobDAO.selectCount(wrapper);
}
@Override
public DataGrid<ExecJobVO> getExecJobPage(ExecJobQueryRequest request) {
// 条件
LambdaQueryWrapper<ExecJobDO> wrapper = this.buildQueryWrapper(request);
// 查询
return execJobDAO.of(wrapper)
.page(request)
.dataGrid(ExecJobConvert.MAPPER::to);
}
@Override
public Integer deleteExecJobById(Long id) {
log.info("ExecJobService-deleteExecJobById id: {}", id);
// 检查数据是否存在
ExecJobDO record = execJobDAO.selectById(id);
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
// 删除
int effect = execJobDAO.deleteById(id);
log.info("ExecJobService-deleteExecJobById id: {}, effect: {}", id, effect);
return effect;
}
@Override
public Integer deleteExecJobByIdList(List<Long> idList) {
log.info("ExecJobService-deleteExecJobByIdList idList: {}", idList);
int effect = execJobDAO.deleteBatchIds(idList);
log.info("ExecJobService-deleteExecJobByIdList effect: {}", effect);
return effect;
}
@Override
public Integer deleteExecJob(ExecJobQueryRequest request) {
log.info("ExecJobService.deleteExecJob request: {}", JSON.toJSONString(request));
// 条件
LambdaQueryWrapper<ExecJobDO> wrapper = this.buildQueryWrapper(request);
// 删除
int effect = execJobDAO.delete(wrapper);
log.info("ExecJobService.deleteExecJob effect: {}", effect);
return effect;
}
/**
* 检查对象是否存在
*
* @param domain domain
*/
private void checkExecJobPresent(ExecJobDO domain) {
// 构造条件
LambdaQueryWrapper<ExecJobDO> wrapper = execJobDAO.wrapper()
// 更新时忽略当前记录
.ne(ExecJobDO::getId, domain.getId())
// 用其他字段做重复校验
.eq(ExecJobDO::getName, domain.getName())
.eq(ExecJobDO::getExpression, domain.getExpression())
.eq(ExecJobDO::getTimeout, domain.getTimeout())
.eq(ExecJobDO::getCommand, domain.getCommand())
.eq(ExecJobDO::getParameterSchema, domain.getParameterSchema())
.eq(ExecJobDO::getStatus, domain.getStatus())
.eq(ExecJobDO::getRecentLogId, domain.getRecentLogId());
// 检查是否存在
boolean present = execJobDAO.of(wrapper).present();
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
}
/**
* 构建查询 wrapper
*
* @param request request
* @return wrapper
*/
private LambdaQueryWrapper<ExecJobDO> buildQueryWrapper(ExecJobQueryRequest request) {
String searchValue = request.getSearchValue();
return execJobDAO.wrapper()
.eq(ExecJobDO::getId, request.getId())
.eq(ExecJobDO::getName, request.getName())
.eq(ExecJobDO::getExpression, request.getExpression())
.eq(ExecJobDO::getTimeout, request.getTimeout())
.eq(ExecJobDO::getCommand, request.getCommand())
.eq(ExecJobDO::getParameterSchema, request.getParameterSchema())
.eq(ExecJobDO::getStatus, request.getStatus())
.eq(ExecJobDO::getRecentLogId, request.getRecentLogId())
.and(Strings.isNotEmpty(searchValue), c -> c
.eq(ExecJobDO::getId, searchValue).or()
.eq(ExecJobDO::getName, searchValue).or()
.eq(ExecJobDO::getExpression, searchValue).or()
.eq(ExecJobDO::getTimeout, searchValue).or()
.eq(ExecJobDO::getCommand, searchValue).or()
.eq(ExecJobDO::getParameterSchema, searchValue).or()
.eq(ExecJobDO::getStatus, searchValue).or()
.eq(ExecJobDO::getRecentLogId, searchValue)
)
.orderByDesc(ExecJobDO::getId);
}
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.orion.ops.module.asset.dao.ExecJobHostDAO">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.ExecJobHostDO">
<id column="id" property="id"/>
<result column="job_id" property="jobId"/>
<result column="host_id" property="hostId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="updater" property="updater"/>
<result column="deleted" property="deleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, job_id, host_id, create_time, update_time, creator, updater, deleted
</sql>
</mapper>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.orion.ops.module.asset.dao.ExecJobDAO">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.ExecJobDO">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="expression" property="expression"/>
<result column="timeout" property="timeout"/>
<result column="command" property="command"/>
<result column="parameter_schema" property="parameterSchema"/>
<result column="status" property="status"/>
<result column="recent_log_id" property="recentLogId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="creator" property="creator"/>
<result column="updater" property="updater"/>
<result column="deleted" property="deleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, expression, timeout, command, parameter_schema, status, recent_log_id, create_time, update_time, creator, updater, deleted
</sql>
</mapper>

View File

@@ -169,10 +169,10 @@
// 卸载
onBeforeUnmount(() => {
editor?.dispose();
editor = undefined;
completionItemProvider?.dispose();
completionItemProvider = undefined;
editor?.dispose();
editor = undefined;
});
</script>