🔨 定时执行.
This commit is contained in:
@@ -10,6 +10,7 @@ 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.request.exec.ExecJobUpdateStatusRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
|
||||
import com.orion.ops.module.asset.service.ExecJobService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -21,7 +22,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划执行任务 api
|
||||
@@ -39,6 +39,13 @@ import java.util.List;
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class ExecJobController {
|
||||
|
||||
|
||||
// TODO EXEC_seq
|
||||
// todo 测试一下添加失败 操作日志是怎么
|
||||
// TODO 操作日志 菜单
|
||||
// TODO 手动执行
|
||||
// TODO NEXT time
|
||||
|
||||
@Resource
|
||||
private ExecJobService execJobService;
|
||||
|
||||
@@ -58,6 +65,14 @@ public class ExecJobController {
|
||||
return execJobService.updateExecJobById(request);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecJobOperatorType.UPDATE_STATUS)
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "更新计划执行任务状态")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-job:update-status')")
|
||||
public Integer updateExecJobStatus(@Validated @RequestBody ExecJobUpdateStatusRequest request) {
|
||||
return execJobService.updateExecJobStatus(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询计划执行任务")
|
||||
@@ -67,23 +82,6 @@ public class ExecJobController {
|
||||
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 = "分页查询计划执行任务")
|
||||
@@ -101,14 +99,5 @@ public class ExecJobController {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
### 创建计划执行任务主机
|
||||
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}}
|
||||
|
||||
###
|
||||
@@ -1,114 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecJobHostDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划执行任务主机 Mapper 接口
|
||||
*
|
||||
@@ -16,16 +18,42 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
public interface ExecJobHostDAO extends IMapper<ExecJobHostDO> {
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
* 通过 hostId 获取 jobId
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 查询条件
|
||||
* @param jobId jobId
|
||||
* @return hostId
|
||||
*/
|
||||
default LambdaQueryWrapper<ExecJobHostDO> queryCondition(ExecJobHostDO entity) {
|
||||
return this.wrapper()
|
||||
.eq(ExecJobHostDO::getId, entity.getId())
|
||||
.eq(ExecJobHostDO::getJobId, entity.getJobId())
|
||||
.eq(ExecJobHostDO::getHostId, entity.getHostId());
|
||||
default List<Long> selectHostIdByJobId(Long jobId) {
|
||||
return this.of()
|
||||
.createWrapper()
|
||||
.select(ExecJobHostDO::getHostId)
|
||||
.eq(ExecJobHostDO::getJobId, jobId)
|
||||
.then()
|
||||
.list(ExecJobHostDO::getHostId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 jobId 删除
|
||||
*
|
||||
* @param jobId jobId
|
||||
* @return effect
|
||||
*/
|
||||
default Integer deleteByJobId(Long jobId) {
|
||||
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.wrapper()
|
||||
.eq(ExecJobHostDO::getJobId, jobId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
* @param hostId hostId
|
||||
* @return effect
|
||||
*/
|
||||
default Integer deleteByHostId(Long hostId) {
|
||||
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.wrapper()
|
||||
.eq(ExecJobHostDO::getHostId, hostId);
|
||||
return this.delete(wrapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
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, "删除计划执行任务主机"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.module.asset.define.operator;
|
||||
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;
|
||||
@@ -20,14 +20,20 @@ public class ExecJobOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String UPDATE = "exec-job:update";
|
||||
|
||||
public static final String UPDATE_STATUS = "exec-job:update-status";
|
||||
|
||||
public static final String EXEC = "exec-job:exec";
|
||||
|
||||
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, "删除计划执行任务"),
|
||||
new OperatorType(L, CREATE, "创建计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, EXEC, "手动执行计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新计划任务 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE_STATUS, "更新计划任务状态 <sb>${name}</sb> <sb>${statusName}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除计划任务 <sb>${name}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划执行任务 创建请求对象
|
||||
@@ -49,12 +51,8 @@ public class ExecJobCreateRequest implements Serializable {
|
||||
@Schema(description = "命令参数")
|
||||
private String parameterSchema;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
private Integer status;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "最近执行id")
|
||||
private Long recentLogId;
|
||||
@NotEmpty
|
||||
@Schema(description = "执行主机")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -21,9 +21,6 @@ import javax.validation.constraints.Size;
|
||||
@Schema(name = "ExecJobQueryRequest", description = "计划执行任务 查询请求对象")
|
||||
public class ExecJobQueryRequest extends PageRequest {
|
||||
|
||||
@Schema(description = "搜索")
|
||||
private String searchValue;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@@ -31,23 +28,10 @@ public class ExecJobQueryRequest extends PageRequest {
|
||||
@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;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,11 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划执行任务 更新请求对象
|
||||
@@ -53,12 +55,8 @@ public class ExecJobUpdateRequest implements Serializable {
|
||||
@Schema(description = "命令参数")
|
||||
private String parameterSchema;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
private Integer status;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "最近执行id")
|
||||
private Long recentLogId;
|
||||
@NotEmpty
|
||||
@Schema(description = "执行主机")
|
||||
private List<Long> hostIdList;
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 计划执行任务主机 更新请求对象
|
||||
* 计划执行任务 更新状态请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.3
|
||||
@@ -20,8 +20,8 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecJobHostUpdateRequest", description = "计划执行任务主机 更新请求对象")
|
||||
public class ExecJobHostUpdateRequest implements Serializable {
|
||||
@Schema(name = "ExecJobUpdateStatusRequest", description = "计划执行任务 更新状态请求对象")
|
||||
public class ExecJobUpdateStatusRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -30,11 +30,7 @@ public class ExecJobHostUpdateRequest implements Serializable {
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "任务id")
|
||||
private Long jobId;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "主机id")
|
||||
private Long hostId;
|
||||
@Schema(description = "启用状态 0禁用 1启用")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.orion.ops.module.asset.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 执行任务状态
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/3/28 16:25
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ExecJobStatusEnum {
|
||||
|
||||
/**
|
||||
* 停用
|
||||
*/
|
||||
DISABLED(0),
|
||||
|
||||
/**
|
||||
* 启用
|
||||
*/
|
||||
ENABLED(1),
|
||||
|
||||
;
|
||||
|
||||
private final Integer status;
|
||||
|
||||
public static ExecJobStatusEnum of(Integer status) {
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
for (ExecJobStatusEnum value : values()) {
|
||||
if (value.status.equals(status)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,5 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -18,92 +12,35 @@ import java.util.List;
|
||||
public interface ExecJobHostService {
|
||||
|
||||
/**
|
||||
* 创建计划执行任务主机
|
||||
* 设置任务主机
|
||||
*
|
||||
* @param request request
|
||||
* @return id
|
||||
* @param jobId jobId
|
||||
* @param hostIdList hostIdList
|
||||
*/
|
||||
Long createExecJobHost(ExecJobHostCreateRequest request);
|
||||
void setHostIdByJobId(Long jobId, List<Long> hostIdList);
|
||||
|
||||
/**
|
||||
* 更新计划执行任务主机
|
||||
* 通过 hostId 获取 jobId
|
||||
*
|
||||
* @param request request
|
||||
* @param jobId jobId
|
||||
* @return hostId
|
||||
*/
|
||||
List<Long> getHostIdByJobId(Long jobId);
|
||||
|
||||
/**
|
||||
* 通过 jobId 删除
|
||||
*
|
||||
* @param jobId jobId
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateExecJobHostById(ExecJobHostUpdateRequest request);
|
||||
Integer deleteByJobId(Long jobId);
|
||||
|
||||
/**
|
||||
* 根据条件更新计划执行任务主机
|
||||
* 通过 hostId 删除
|
||||
*
|
||||
* @param query query
|
||||
* @param update update
|
||||
* @param hostId hostId
|
||||
* @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);
|
||||
Integer deleteByHostId(Long hostId);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ 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.request.exec.ExecJobUpdateStatusRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecJobVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 计划执行任务 服务类
|
||||
*
|
||||
@@ -34,13 +33,12 @@ public interface ExecJobService {
|
||||
Integer updateExecJobById(ExecJobUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 根据条件更新计划执行任务
|
||||
* 更新计划执行任务状态
|
||||
*
|
||||
* @param query query
|
||||
* @param update update
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateExecJob(ExecJobQueryRequest query, ExecJobUpdateRequest update);
|
||||
Integer updateExecJobStatus(ExecJobUpdateStatusRequest request);
|
||||
|
||||
/**
|
||||
* 查询计划执行任务
|
||||
@@ -50,30 +48,6 @@ public interface ExecJobService {
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 分页查询计划执行任务
|
||||
*
|
||||
@@ -90,20 +64,4 @@ public interface ExecJobService {
|
||||
*/
|
||||
Integer deleteExecJobById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除计划执行任务
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteExecJobByIdList(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 根据条件删除计划执行任务
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteExecJob(ExecJobQueryRequest request);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 计划执行任务主机 服务实现类
|
||||
@@ -36,162 +26,35 @@ public class ExecJobHostServiceImpl implements ExecJobHostService {
|
||||
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();
|
||||
public void setHostIdByJobId(Long jobId, List<Long> hostIdList) {
|
||||
log.info("ExecJobHostService.setHostIdByJobId jobId: {}, hostIdList: {}", jobId, hostIdList);
|
||||
// 删除
|
||||
execJobHostDAO.deleteByJobId(jobId);
|
||||
// 如果不为空则重新插入
|
||||
if (!Lists.isEmpty(hostIdList)) {
|
||||
List<ExecJobHostDO> rows = hostIdList.stream()
|
||||
.map(s -> ExecJobHostDO.builder()
|
||||
.hostId(s)
|
||||
.jobId(jobId)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
execJobHostDAO.insertBatch(rows);
|
||||
}
|
||||
// 转换
|
||||
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);
|
||||
public List<Long> getHostIdByJobId(Long jobId) {
|
||||
return execJobHostDAO.selectHostIdByJobId(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getExecJobHostCount(ExecJobHostQueryRequest request) {
|
||||
// 条件
|
||||
LambdaQueryWrapper<ExecJobHostDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
return execJobHostDAO.selectCount(wrapper);
|
||||
public Integer deleteByJobId(Long jobId) {
|
||||
return execJobHostDAO.deleteByJobId(jobId);
|
||||
}
|
||||
|
||||
@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);
|
||||
public Integer deleteByHostId(Long hostId) {
|
||||
return execJobHostDAO.deleteByHostId(hostId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ 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;
|
||||
@@ -13,13 +11,13 @@ 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.request.exec.ExecJobUpdateStatusRequest;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 计划执行任务 服务实现类
|
||||
@@ -42,9 +40,12 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
ExecJobDO record = ExecJobConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkExecJobPresent(record);
|
||||
// TODO 查询主机是否存在
|
||||
// 查询是否有主机权限
|
||||
// 插入
|
||||
int effect = execJobDAO.insert(record);
|
||||
Long id = record.getId();
|
||||
// TODO 插入主机
|
||||
log.info("ExecJobService-createExecJob id: {}, effect: {}", id, effect);
|
||||
return id;
|
||||
}
|
||||
@@ -67,16 +68,8 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
}
|
||||
|
||||
@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;
|
||||
public Integer updateExecJobStatus(ExecJobUpdateStatusRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,33 +81,6 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
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) {
|
||||
// 条件
|
||||
@@ -137,25 +103,6 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查对象是否存在
|
||||
*
|
||||
@@ -167,13 +114,7 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
// 更新时忽略当前记录
|
||||
.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());
|
||||
.eq(ExecJobDO::getName, domain.getName());
|
||||
// 检查是否存在
|
||||
boolean present = execJobDAO.of(wrapper).present();
|
||||
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
|
||||
@@ -186,26 +127,11 @@ public class ExecJobServiceImpl implements ExecJobService {
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user