✨ 执行模板后端服务.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
### 创建执行模板
|
||||
POST {{baseUrl}}/asset/exec-template/create
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"parameter": ""
|
||||
}
|
||||
|
||||
|
||||
### 更新执行模板
|
||||
PUT {{baseUrl}}/asset/exec-template/update
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"id": "",
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"parameter": ""
|
||||
}
|
||||
|
||||
|
||||
### 查询执行模板
|
||||
GET {{baseUrl}}/asset/exec-template/get?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 查询全部执行模板
|
||||
GET {{baseUrl}}/asset/exec-template/list
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
### 分页查询执行模板
|
||||
POST {{baseUrl}}/asset/exec-template/query
|
||||
Content-Type: application/json
|
||||
Authorization: {{token}}
|
||||
|
||||
{
|
||||
"page": 1,
|
||||
"limit": 10,
|
||||
"id": "",
|
||||
"name": "",
|
||||
"command": "",
|
||||
"timeout": "",
|
||||
"parameter": ""
|
||||
}
|
||||
|
||||
|
||||
### 删除执行模板
|
||||
DELETE {{baseUrl}}/asset/exec-template/delete?id=1
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
###
|
||||
@@ -0,0 +1,97 @@
|
||||
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.ExecTemplateOperatorType;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||
import com.orion.ops.module.asset.service.ExecTemplateService;
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Tag(name = "asset - 执行模板服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/asset/exec-template")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class ExecTemplateController {
|
||||
|
||||
@Resource
|
||||
private ExecTemplateService execTemplateService;
|
||||
|
||||
@OperatorLog(ExecTemplateOperatorType.CREATE)
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建执行模板")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:create')")
|
||||
public Long createExecTemplate(@Validated @RequestBody ExecTemplateCreateRequest request) {
|
||||
return execTemplateService.createExecTemplate(request);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecTemplateOperatorType.UPDATE)
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新执行模板")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:update')")
|
||||
public Integer updateExecTemplate(@Validated @RequestBody ExecTemplateUpdateRequest request) {
|
||||
return execTemplateService.updateExecTemplateById(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "查询执行模板")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:query')")
|
||||
public ExecTemplateVO getExecTemplate(@RequestParam("id") Long id) {
|
||||
return execTemplateService.getExecTemplateById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "查询全部执行模板")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:query')")
|
||||
public List<ExecTemplateVO> getExecTemplateList() {
|
||||
return execTemplateService.getExecTemplateListByCache();
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询执行模板")
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:query')")
|
||||
public DataGrid<ExecTemplateVO> getExecTemplatePage(@Validated(Page.class) @RequestBody ExecTemplateQueryRequest request) {
|
||||
return execTemplateService.getExecTemplatePage(request);
|
||||
}
|
||||
|
||||
@OperatorLog(ExecTemplateOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除执行模板")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:exec-template:delete')")
|
||||
public Integer deleteExecTemplate(@RequestParam("id") Long id) {
|
||||
return execTemplateService.deleteExecTemplateById(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.orion.ops.module.asset.convert;
|
||||
|
||||
import com.orion.ops.module.asset.entity.domain.ExecTemplateDO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecTemplateCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 执行模板 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExecTemplateConvert {
|
||||
|
||||
ExecTemplateConvert MAPPER = Mappers.getMapper(ExecTemplateConvert.class);
|
||||
|
||||
ExecTemplateDO to(ExecTemplateCreateRequest request);
|
||||
|
||||
ExecTemplateDO to(ExecTemplateUpdateRequest request);
|
||||
|
||||
ExecTemplateVO to(ExecTemplateDO domain);
|
||||
|
||||
ExecTemplateVO to(ExecTemplateCacheDTO cache);
|
||||
|
||||
ExecTemplateCacheDTO toCache(ExecTemplateDO domain);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.orion.ops.module.asset.dao;
|
||||
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecTemplateDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 执行模板 Mapper 接口
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Mapper
|
||||
public interface ExecTemplateDAO extends IMapper<ExecTemplateDO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.orion.ops.module.asset.define.cache;
|
||||
|
||||
import com.orion.lang.define.cache.key.CacheKeyBuilder;
|
||||
import com.orion.lang.define.cache.key.CacheKeyDefine;
|
||||
import com.orion.lang.define.cache.key.struct.RedisCacheStruct;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecTemplateCacheDTO;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 执行模板缓存 key
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
public interface ExecTemplateCacheKeyDefine {
|
||||
|
||||
CacheKeyDefine EXEC_TEMPLATE = new CacheKeyBuilder()
|
||||
.key("exec:template:list")
|
||||
.desc("执行模板列表")
|
||||
.type(ExecTemplateCacheDTO.class)
|
||||
.struct(RedisCacheStruct.HASH)
|
||||
.timeout(1, TimeUnit.DAYS)
|
||||
.build();
|
||||
|
||||
}
|
||||
@@ -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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Module("asset:exec-template")
|
||||
public class ExecTemplateOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String CREATE = "exec-template:create";
|
||||
|
||||
public static final String UPDATE = "exec-template:update";
|
||||
|
||||
public static final String DELETE = "exec-template:delete";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建执行模板 ${name}"),
|
||||
new OperatorType(M, UPDATE, "更新执行模板 ${name}"),
|
||||
new OperatorType(H, DELETE, "删除执行模板 ${name}"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName(value = "exec_template", autoResultMap = true)
|
||||
@Schema(name = "ExecTemplateDO", description = "执行模板 实体对象")
|
||||
public class ExecTemplateDO 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 = "命令")
|
||||
@TableField("command")
|
||||
private String command;
|
||||
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
@TableField("timeout")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "参数")
|
||||
@TableField("parameter")
|
||||
private String parameter;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.orion.ops.module.asset.entity.dto;
|
||||
|
||||
import com.orion.lang.define.cache.key.model.LongCacheIdModel;
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecTemplateCacheDTO", description = "执行模板 缓存对象")
|
||||
public class ExecTemplateCacheDTO implements LongCacheIdModel, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "参数")
|
||||
private String parameter;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecTemplateCreateRequest", description = "执行模板 创建请求对象")
|
||||
public class ExecTemplateCreateRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 64)
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "参数")
|
||||
private String parameter;
|
||||
|
||||
}
|
||||
@@ -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.*;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* 执行模板 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "ExecTemplateQueryRequest", description = "执行模板 查询请求对象")
|
||||
public class ExecTemplateQueryRequest extends PageRequest {
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Size(max = 64)
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecTemplateUpdateRequest", description = "执行模板 更新请求对象")
|
||||
public class ExecTemplateUpdateRequest 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
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "参数")
|
||||
private String parameter;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "ExecTemplateVO", description = "执行模板 视图响应对象")
|
||||
public class ExecTemplateVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "命令")
|
||||
private String command;
|
||||
|
||||
@Schema(description = "超时时间秒 0不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@Schema(description = "参数")
|
||||
private String parameter;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@Schema(description = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.orion.ops.module.asset.service;
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 执行模板 服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
public interface ExecTemplateService {
|
||||
|
||||
/**
|
||||
* 创建执行模板
|
||||
*
|
||||
* @param request request
|
||||
* @return id
|
||||
*/
|
||||
Long createExecTemplate(ExecTemplateCreateRequest request);
|
||||
|
||||
/**
|
||||
* 更新执行模板
|
||||
*
|
||||
* @param request request
|
||||
* @return effect
|
||||
*/
|
||||
Integer updateExecTemplateById(ExecTemplateUpdateRequest request);
|
||||
|
||||
/**
|
||||
* 查询执行模板
|
||||
*
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
ExecTemplateVO getExecTemplateById(Long id);
|
||||
|
||||
/**
|
||||
* 通过缓存查询执行模板
|
||||
*
|
||||
* @return rows
|
||||
*/
|
||||
List<ExecTemplateVO> getExecTemplateListByCache();
|
||||
|
||||
/**
|
||||
* 分页查询执行模板
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<ExecTemplateVO> getExecTemplatePage(ExecTemplateQueryRequest request);
|
||||
|
||||
/**
|
||||
* 删除执行模板
|
||||
*
|
||||
* @param id id
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteExecTemplateById(Long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
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.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.framework.redis.core.utils.RedisMaps;
|
||||
import com.orion.ops.framework.redis.core.utils.barrier.CacheBarriers;
|
||||
import com.orion.ops.module.asset.convert.ExecTemplateConvert;
|
||||
import com.orion.ops.module.asset.dao.ExecTemplateDAO;
|
||||
import com.orion.ops.module.asset.define.cache.ExecTemplateCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.ExecTemplateDO;
|
||||
import com.orion.ops.module.asset.entity.dto.ExecTemplateCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.exec.ExecTemplateUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.ExecTemplateVO;
|
||||
import com.orion.ops.module.asset.service.ExecTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 执行模板 服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.1
|
||||
* @since 2024-3-7 18:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ExecTemplateServiceImpl implements ExecTemplateService {
|
||||
|
||||
@Resource
|
||||
private ExecTemplateDAO execTemplateDAO;
|
||||
|
||||
@Override
|
||||
public Long createExecTemplate(ExecTemplateCreateRequest request) {
|
||||
log.info("ExecTemplateService-createExecTemplate request: {}", JSON.toJSONString(request));
|
||||
// 转换
|
||||
ExecTemplateDO record = ExecTemplateConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkExecTemplatePresent(record);
|
||||
// 插入
|
||||
int effect = execTemplateDAO.insert(record);
|
||||
Long id = record.getId();
|
||||
log.info("ExecTemplateService-createExecTemplate id: {}, effect: {}", id, effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(ExecTemplateCacheKeyDefine.EXEC_TEMPLATE);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateExecTemplateById(ExecTemplateUpdateRequest request) {
|
||||
Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING);
|
||||
log.info("ExecTemplateService-updateExecTemplateById id: {}, request: {}", id, JSON.toJSONString(request));
|
||||
// 查询
|
||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
ExecTemplateDO updateRecord = ExecTemplateConvert.MAPPER.to(request);
|
||||
// 查询数据是否冲突
|
||||
this.checkExecTemplatePresent(updateRecord);
|
||||
// 更新
|
||||
int effect = execTemplateDAO.updateById(updateRecord);
|
||||
log.info("ExecTemplateService-updateExecTemplateById effect: {}", effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(ExecTemplateCacheKeyDefine.EXEC_TEMPLATE);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecTemplateVO getExecTemplateById(Long id) {
|
||||
// 查询
|
||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 转换
|
||||
return ExecTemplateConvert.MAPPER.to(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExecTemplateVO> getExecTemplateListByCache() {
|
||||
// 查询缓存
|
||||
List<ExecTemplateCacheDTO> list = RedisMaps.valuesJson(ExecTemplateCacheKeyDefine.EXEC_TEMPLATE);
|
||||
if (list.isEmpty()) {
|
||||
// 查询数据库
|
||||
list = execTemplateDAO.of().list(ExecTemplateConvert.MAPPER::toCache);
|
||||
// 设置屏障 防止穿透
|
||||
CacheBarriers.checkBarrier(list, ExecTemplateCacheDTO::new);
|
||||
// 设置缓存
|
||||
RedisMaps.putAllJson(ExecTemplateCacheKeyDefine.EXEC_TEMPLATE, s -> s.getId().toString(), list);
|
||||
}
|
||||
// 删除屏障
|
||||
CacheBarriers.removeBarrier(list);
|
||||
// 转换
|
||||
return list.stream()
|
||||
.map(ExecTemplateConvert.MAPPER::to)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataGrid<ExecTemplateVO> getExecTemplatePage(ExecTemplateQueryRequest request) {
|
||||
// 条件
|
||||
LambdaQueryWrapper<ExecTemplateDO> wrapper = this.buildQueryWrapper(request);
|
||||
// 查询
|
||||
return execTemplateDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(ExecTemplateConvert.MAPPER::to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteExecTemplateById(Long id) {
|
||||
log.info("ExecTemplateService-deleteExecTemplateById id: {}", id);
|
||||
// 检查数据是否存在
|
||||
ExecTemplateDO record = execTemplateDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.DATA_ABSENT);
|
||||
// 删除
|
||||
int effect = execTemplateDAO.deleteById(id);
|
||||
log.info("ExecTemplateService-deleteExecTemplateById id: {}, effect: {}", id, effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(ExecTemplateCacheKeyDefine.EXEC_TEMPLATE, id);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查对象是否存在
|
||||
*
|
||||
* @param domain domain
|
||||
*/
|
||||
private void checkExecTemplatePresent(ExecTemplateDO domain) {
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<ExecTemplateDO> wrapper = execTemplateDAO.wrapper()
|
||||
// 更新时忽略当前记录
|
||||
.ne(ExecTemplateDO::getId, domain.getId())
|
||||
// 用其他字段做重复校验
|
||||
.eq(ExecTemplateDO::getName, domain.getName());
|
||||
// 检查是否存在
|
||||
boolean present = execTemplateDAO.of(wrapper).present();
|
||||
Valid.isFalse(present, ErrorMessage.DATA_PRESENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询 wrapper
|
||||
*
|
||||
* @param request request
|
||||
* @return wrapper
|
||||
*/
|
||||
private LambdaQueryWrapper<ExecTemplateDO> buildQueryWrapper(ExecTemplateQueryRequest request) {
|
||||
return execTemplateDAO.wrapper()
|
||||
.eq(ExecTemplateDO::getId, request.getId())
|
||||
.eq(ExecTemplateDO::getName, request.getName())
|
||||
.eq(ExecTemplateDO::getCommand, request.getCommand());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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.ExecTemplateDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.asset.entity.domain.ExecTemplateDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="command" property="command"/>
|
||||
<result column="timeout" property="timeout"/>
|
||||
<result column="parameter" property="parameter"/>
|
||||
<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, command, timeout, parameter, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user