From 7d614f0bdc602712ddb77ba0434365e477cbb9d3 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Wed, 24 Jan 2024 17:39:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=91=BD=E4=BB=A4=E5=88=86=E7=BB=84.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/validator/group/Batch.java | 13 ++ .../core/generator/CodeGenerators.java | 4 +- .../controller/CommandSnippetController.java | 7 +- .../CommandSnippetGroupController.http | 32 ++++ .../CommandSnippetGroupController.java | 66 ++++++++ .../convert/CommandSnippetGroupConvert.java | 37 +++++ .../module/asset/dao/CommandSnippetDAO.java | 28 ++++ .../asset/dao/CommandSnippetGroupDAO.java | 17 ++ .../cache/CommandSnippetCacheKeyDefine.java | 11 +- .../asset/entity/domain/CommandSnippetDO.java | 12 +- .../entity/domain/CommandSnippetGroupDO.java | 41 +++++ .../entity/dto/CommandSnippetCacheDTO.java | 4 +- .../dto/CommandSnippetGroupCacheDTO.java | 34 ++++ .../command/CommandSnippetCreateRequest.java | 2 +- .../CommandSnippetGroupCreateRequest.java | 34 ++++ .../CommandSnippetGroupDeleteRequest.java | 37 +++++ .../CommandSnippetGroupUpdateRequest.java | 39 +++++ .../command/CommandSnippetUpdateRequest.java | 6 +- .../entity/vo/CommandSnippetGroupVO.java | 33 ++++ .../asset/entity/vo/CommandSnippetVO.java | 3 + .../entity/vo/CommandSnippetWrapperVO.java | 34 ++++ .../service/CommandSnippetGroupService.java | 50 ++++++ .../asset/service/CommandSnippetService.java | 26 +++ .../impl/CommandSnippetGroupServiceImpl.java | 156 ++++++++++++++++++ .../impl/CommandSnippetServiceImpl.java | 75 ++++++--- .../mapper/CommandSnippetGroupMapper.xml | 22 +++ .../resources/mapper/CommandSnippetMapper.xml | 3 +- .../infra/entity/domain/DataExtraDO.java | 8 +- .../infra/entity/domain/DataPermissionDO.java | 8 +- .../module/infra/entity/domain/TagRelDO.java | 8 +- 30 files changed, 795 insertions(+), 55 deletions(-) create mode 100644 orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Batch.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.http create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/CommandSnippetGroupConvert.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetGroupDAO.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetGroupDO.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetGroupCacheDTO.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupCreateRequest.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupDeleteRequest.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupUpdateRequest.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetGroupService.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetGroupServiceImpl.java create mode 100644 orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetGroupMapper.xml diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Batch.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Batch.java new file mode 100644 index 00000000..67ccfbf7 --- /dev/null +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Batch.java @@ -0,0 +1,13 @@ +package com.orion.ops.framework.common.validator.group; + +import javax.validation.groups.Default; + +/** + * 批量验证分组 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023/9/1 19:13 + */ +public interface Batch extends Default { +} diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java index 028c317b..30f55cc0 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java @@ -45,9 +45,9 @@ public class CodeGenerators { // .color("blue", "gray", "red", "green", "white") // .valueUseFields() // .build(), - Template.create("command_snippet", "命令片段", "command") + Template.create("command_snippet_group", "命令片段分组", "command") .disableUnitTest() - .cache("command:snippet:list:{}", "命令片段列表 ${userId}") + .cache("command:snippet:group:{}", "命令片段分组 ${userId}") .expire(1, TimeUnit.DAYS) .vue("host", "command-snippet") .build(), diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetController.java index a4113859..5c9f124d 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetController.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetController.java @@ -5,7 +5,7 @@ import com.orion.ops.framework.log.core.enums.IgnoreLogMode; import com.orion.ops.framework.web.core.annotation.RestWrapper; import com.orion.ops.module.asset.entity.request.command.CommandSnippetCreateRequest; import com.orion.ops.module.asset.entity.request.command.CommandSnippetUpdateRequest; -import com.orion.ops.module.asset.entity.vo.CommandSnippetVO; +import com.orion.ops.module.asset.entity.vo.CommandSnippetWrapperVO; import com.orion.ops.module.asset.service.CommandSnippetService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -15,7 +15,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import java.util.List; /** * 命令片段 api @@ -51,8 +50,8 @@ public class CommandSnippetController { @IgnoreLog(IgnoreLogMode.RET) @GetMapping("/list") @Operation(summary = "查询全部命令片段") - public List getCommandSnippetList() { - return commandSnippetService.getCommandSnippetList(); + public CommandSnippetWrapperVO getCommandSnippetList() { + return commandSnippetService.getCommandSnippet(); } @DeleteMapping("/delete") diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.http b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.http new file mode 100644 index 00000000..907913ff --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.http @@ -0,0 +1,32 @@ +### 创建命令片段分组 +POST {{baseUrl}}/asset/command-snippet-group/create +Content-Type: application/json +Authorization: {{token}} + +{ + "name": "" +} + + +### 更新命令片段分组 +PUT {{baseUrl}}/asset/command-snippet-group/update +Content-Type: application/json +Authorization: {{token}} + +{ + "id": "", + "name": "" +} + + +### 查询全部命令片段分组 +GET {{baseUrl}}/asset/command-snippet-group/list +Authorization: {{token}} + + +### 删除命令片段分组 +DELETE {{baseUrl}}/asset/command-snippet-group/delete?id=1 +Authorization: {{token}} + + +### diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.java new file mode 100644 index 00000000..d87f74de --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/controller/CommandSnippetGroupController.java @@ -0,0 +1,66 @@ +package com.orion.ops.module.asset.controller; + +import com.orion.ops.framework.common.validator.group.Id; +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.entity.request.command.CommandSnippetGroupCreateRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupDeleteRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupUpdateRequest; +import com.orion.ops.module.asset.entity.vo.CommandSnippetGroupVO; +import com.orion.ops.module.asset.service.CommandSnippetGroupService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +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.0 + * @since 2024-1-24 12:28 + */ +@Tag(name = "asset - 命令片段分组服务") +@Slf4j +@Validated +@RestWrapper +@RestController +@RequestMapping("/asset/command-snippet-group") +@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"}) +public class CommandSnippetGroupController { + + @Resource + private CommandSnippetGroupService commandSnippetGroupService; + + @PostMapping("/create") + @Operation(summary = "创建命令片段分组") + public Long createCommandSnippetGroup(@Validated @RequestBody CommandSnippetGroupCreateRequest request) { + return commandSnippetGroupService.createCommandSnippetGroup(request); + } + + @PutMapping("/update") + @Operation(summary = "更新命令片段分组") + public Integer updateCommandSnippetGroup(@Validated @RequestBody CommandSnippetGroupUpdateRequest request) { + return commandSnippetGroupService.updateCommandSnippetGroupById(request); + } + + @IgnoreLog(IgnoreLogMode.RET) + @PostMapping("/list") + @Operation(summary = "查询全部命令片段分组") + public List getCommandSnippetGroupList() { + return commandSnippetGroupService.getCommandSnippetGroupList(); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除命令片段分组") + public Integer deleteCommandSnippetGroup(@Validated(Id.class) @RequestBody CommandSnippetGroupDeleteRequest request) { + return commandSnippetGroupService.deleteCommandSnippetGroup(request); + } + +} + diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/CommandSnippetGroupConvert.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/CommandSnippetGroupConvert.java new file mode 100644 index 00000000..660e4350 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/convert/CommandSnippetGroupConvert.java @@ -0,0 +1,37 @@ +package com.orion.ops.module.asset.convert; + +import com.orion.ops.module.asset.entity.domain.CommandSnippetGroupDO; +import com.orion.ops.module.asset.entity.dto.CommandSnippetGroupCacheDTO; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupCreateRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupUpdateRequest; +import com.orion.ops.module.asset.entity.vo.CommandSnippetGroupVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 命令片段分组 内部对象转换器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Mapper +public interface CommandSnippetGroupConvert { + + CommandSnippetGroupConvert MAPPER = Mappers.getMapper(CommandSnippetGroupConvert.class); + + CommandSnippetGroupDO to(CommandSnippetGroupCreateRequest request); + + CommandSnippetGroupDO to(CommandSnippetGroupUpdateRequest request); + + CommandSnippetGroupVO to(CommandSnippetGroupDO domain); + + List to(List list); + + CommandSnippetGroupVO to(CommandSnippetGroupCacheDTO cache); + + CommandSnippetGroupCacheDTO toCache(CommandSnippetGroupDO domain); + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetDAO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetDAO.java index 8ffae191..3551bd0a 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetDAO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetDAO.java @@ -1,5 +1,8 @@ package com.orion.ops.module.asset.dao; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.orion.ops.framework.mybatis.core.mapper.IMapper; import com.orion.ops.module.asset.entity.domain.CommandSnippetDO; import org.apache.ibatis.annotations.Mapper; @@ -14,4 +17,29 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface CommandSnippetDAO extends IMapper { + /** + * 设置 groupId 为 null + * + * @param groupId groupId + * @return effect + */ + default int setGroupIdWithNull(Long groupId) { + LambdaUpdateWrapper wrapper = Wrappers.lambdaUpdate() + .set(CommandSnippetDO::getGroupId, null) + .eq(CommandSnippetDO::getGroupId, groupId); + return this.update(null, wrapper); + } + + /** + * 通过 groupId 删除 + * + * @param groupId groupId + * @return effect + */ + default int deleteByGroupId(Long groupId) { + LambdaQueryWrapper wrapper = this.lambda() + .eq(CommandSnippetDO::getGroupId, groupId); + return this.delete(wrapper); + } + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetGroupDAO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetGroupDAO.java new file mode 100644 index 00000000..d8aa7c9f --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/dao/CommandSnippetGroupDAO.java @@ -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.CommandSnippetGroupDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 命令片段分组 Mapper 接口 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Mapper +public interface CommandSnippetGroupDAO extends IMapper { + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/CommandSnippetCacheKeyDefine.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/CommandSnippetCacheKeyDefine.java index d9769c61..efd3e7db 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/CommandSnippetCacheKeyDefine.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/define/cache/CommandSnippetCacheKeyDefine.java @@ -4,6 +4,7 @@ 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.CommandSnippetCacheDTO; +import com.orion.ops.module.asset.entity.dto.CommandSnippetGroupCacheDTO; import java.util.concurrent.TimeUnit; @@ -16,7 +17,7 @@ import java.util.concurrent.TimeUnit; */ public interface CommandSnippetCacheKeyDefine { - CacheKeyDefine COMMAND_SNIPPET = new CacheKeyBuilder() + CacheKeyDefine SNIPPET = new CacheKeyBuilder() .key("command:snippet:list:{}") .desc("命令片段列表 ${userId}") .type(CommandSnippetCacheDTO.class) @@ -24,4 +25,12 @@ public interface CommandSnippetCacheKeyDefine { .timeout(1, TimeUnit.DAYS) .build(); + CacheKeyDefine SNIPPET_GROUP = new CacheKeyBuilder() + .key("command:snippet:group:{}") + .desc("命令片段分组 ${userId}") + .type(CommandSnippetGroupCacheDTO.class) + .struct(RedisCacheStruct.HASH) + .timeout(1, TimeUnit.DAYS) + .build(); + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetDO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetDO.java index 4390d3a8..44ae1709 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetDO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetDO.java @@ -1,13 +1,13 @@ package com.orion.ops.module.asset.entity.domain; -import com.baomidou.mybatisplus.annotation.*; +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.*; -import java.util.*; -import java.math.*; - /** * 命令片段 实体对象 * @@ -34,6 +34,10 @@ public class CommandSnippetDO extends BaseDO { @TableField("user_id") private Long userId; + @Schema(description = "分组id") + @TableField("group_id") + private Long groupId; + @Schema(description = "名称") @TableField("name") private String name; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetGroupDO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetGroupDO.java new file mode 100644 index 00000000..8089a7ca --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/domain/CommandSnippetGroupDO.java @@ -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.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@TableName(value = "command_snippet_group", autoResultMap = true) +@Schema(name = "CommandSnippetGroupDO", description = "命令片段分组 实体对象") +public class CommandSnippetGroupDO extends BaseDO { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @Schema(description = "用户id") + @TableField("user_id") + private Long userId; + + @Schema(description = "分组名称") + @TableField("name") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetCacheDTO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetCacheDTO.java index 08f94914..9e4b416e 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetCacheDTO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetCacheDTO.java @@ -8,7 +8,6 @@ import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; -import java.util.Date; /** * 命令片段 缓存对象 @@ -29,6 +28,9 @@ public class CommandSnippetCacheDTO implements LongCacheIdModel, Serializable { @Schema(description = "id") private Long id; + @Schema(description = "分组id") + private Long groupId; + @Schema(description = "名称") private String name; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetGroupCacheDTO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetGroupCacheDTO.java new file mode 100644 index 00000000..0475aa43 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/dto/CommandSnippetGroupCacheDTO.java @@ -0,0 +1,34 @@ +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; + +/** + * 命令片段分组 缓存对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetGroupCacheDTO", description = "命令片段分组 缓存对象") +public class CommandSnippetGroupCacheDTO implements LongCacheIdModel, Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "分组名称") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetCreateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetCreateRequest.java index 23b57b87..7529c2ec 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetCreateRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetCreateRequest.java @@ -31,7 +31,7 @@ public class CommandSnippetCreateRequest implements Serializable { @Schema(description = "名称") private String name; - @Schema(description = "groupId") + @Schema(description = "分组id") private Long groupId; @NotBlank diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupCreateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupCreateRequest.java new file mode 100644 index 00000000..af760a1e --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupCreateRequest.java @@ -0,0 +1,34 @@ +package com.orion.ops.module.asset.entity.request.command; + +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.Size; +import java.io.Serializable; + +/** + * 命令片段分组 创建请求对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetGroupCreateRequest", description = "命令片段分组 创建请求对象") +public class CommandSnippetGroupCreateRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotBlank + @Size(max = 64) + @Schema(description = "分组名称") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupDeleteRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupDeleteRequest.java new file mode 100644 index 00000000..39b85852 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupDeleteRequest.java @@ -0,0 +1,37 @@ +package com.orion.ops.module.asset.entity.request.command; + +import com.orion.ops.framework.common.validator.group.Id; +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.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetGroupDeleteRequest", description = "命令片段分组 删除请求对象") +public class CommandSnippetGroupDeleteRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotNull(groups = Id.class) + @Schema(description = "id") + private Long id; + + @NotNull + @Schema(description = "是否删除组内数据") + private Boolean deleteItem; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupUpdateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupUpdateRequest.java new file mode 100644 index 00000000..c5e7df16 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetGroupUpdateRequest.java @@ -0,0 +1,39 @@ +package com.orion.ops.module.asset.entity.request.command; + +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.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetGroupUpdateRequest", description = "命令片段分组 更新请求对象") +public class CommandSnippetGroupUpdateRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotNull + @Schema(description = "id") + private Long id; + + @NotBlank + @Size(max = 64) + @Schema(description = "分组名称") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetUpdateRequest.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetUpdateRequest.java index bb28d072..966de0be 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetUpdateRequest.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/request/command/CommandSnippetUpdateRequest.java @@ -31,14 +31,14 @@ public class CommandSnippetUpdateRequest implements Serializable { @Schema(description = "id") private Long id; + @Schema(description = "分组id") + private Long groupId; + @NotBlank @Size(max = 64) @Schema(description = "名称") private String name; - @Schema(description = "groupId") - private Long groupId; - @NotBlank @Schema(description = "代码片段") private String command; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java new file mode 100644 index 00000000..28222917 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetGroupVO.java @@ -0,0 +1,33 @@ +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; + +/** + * 命令片段分组 视图响应对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetGroupVO", description = "命令片段分组 视图响应对象") +public class CommandSnippetGroupVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "分组名称") + private String name; + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetVO.java index 1e22c9ea..4cd24ef4 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetVO.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetVO.java @@ -27,6 +27,9 @@ public class CommandSnippetVO implements Serializable { @Schema(description = "id") private Long id; + @Schema(description = "分组id") + private Long groupId; + @Schema(description = "名称") private String name; diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java new file mode 100644 index 00000000..fed88046 --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/entity/vo/CommandSnippetWrapperVO.java @@ -0,0 +1,34 @@ +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.List; + +/** + * 命令片段组合 视图响应对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024/1/24 17:30 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "CommandSnippetWrapperVO", description = "命令片段组合 视图响应对象") +public class CommandSnippetWrapperVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "分组") + private List groups; + + @Schema(description = "命令片段") + private List items; + +} \ No newline at end of file diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetGroupService.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetGroupService.java new file mode 100644 index 00000000..ba3d5d9c --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetGroupService.java @@ -0,0 +1,50 @@ +package com.orion.ops.module.asset.service; + +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupCreateRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupDeleteRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupUpdateRequest; +import com.orion.ops.module.asset.entity.vo.CommandSnippetGroupVO; + +import java.util.List; + +/** + * 命令片段分组 服务类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +public interface CommandSnippetGroupService { + + /** + * 创建命令片段分组 + * + * @param request request + * @return id + */ + Long createCommandSnippetGroup(CommandSnippetGroupCreateRequest request); + + /** + * 更新命令片段分组 + * + * @param request request + * @return effect + */ + Integer updateCommandSnippetGroupById(CommandSnippetGroupUpdateRequest request); + + /** + * 查询全部命令片段分组 + * + * @return rows + */ + List getCommandSnippetGroupList(); + + /** + * 删除命令片段分组 + * + * @param request request + * @return effect + */ + Integer deleteCommandSnippetGroup(CommandSnippetGroupDeleteRequest request); + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetService.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetService.java index db654bf8..696d7047 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetService.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/CommandSnippetService.java @@ -3,6 +3,7 @@ package com.orion.ops.module.asset.service; import com.orion.ops.module.asset.entity.request.command.CommandSnippetCreateRequest; import com.orion.ops.module.asset.entity.request.command.CommandSnippetUpdateRequest; import com.orion.ops.module.asset.entity.vo.CommandSnippetVO; +import com.orion.ops.module.asset.entity.vo.CommandSnippetWrapperVO; import java.util.List; @@ -31,6 +32,13 @@ public interface CommandSnippetService { */ Integer updateCommandSnippetById(CommandSnippetUpdateRequest request); + /** + * 查询命令片段 + * + * @return rows + */ + CommandSnippetWrapperVO getCommandSnippet(); + /** * 查询全部命令片段 * @@ -46,4 +54,22 @@ public interface CommandSnippetService { */ Integer deleteCommandSnippetById(Long id); + /** + * 设置分组为 null + * + * @param userId userId + * @param groupId groupId + * @return effect + */ + Integer setGroupNull(Long userId, Long groupId); + + /** + * 通过 groupId 删除 + * + * @param userId userId + * @param groupId groupId + * @return effect + */ + Integer deleteByGroupId(Long userId, Long groupId); + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetGroupServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetGroupServiceImpl.java new file mode 100644 index 00000000..34812f1e --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetGroupServiceImpl.java @@ -0,0 +1,156 @@ +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.utils.Booleans; +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.framework.security.core.utils.SecurityUtils; +import com.orion.ops.module.asset.convert.CommandSnippetGroupConvert; +import com.orion.ops.module.asset.dao.CommandSnippetGroupDAO; +import com.orion.ops.module.asset.define.cache.CommandSnippetCacheKeyDefine; +import com.orion.ops.module.asset.entity.domain.CommandSnippetGroupDO; +import com.orion.ops.module.asset.entity.dto.CommandSnippetGroupCacheDTO; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupCreateRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupDeleteRequest; +import com.orion.ops.module.asset.entity.request.command.CommandSnippetGroupUpdateRequest; +import com.orion.ops.module.asset.entity.vo.CommandSnippetGroupVO; +import com.orion.ops.module.asset.service.CommandSnippetGroupService; +import com.orion.ops.module.asset.service.CommandSnippetService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 命令片段分组 服务实现类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2024-1-24 12:28 + */ +@Slf4j +@Service +public class CommandSnippetGroupServiceImpl implements CommandSnippetGroupService { + + @Resource + private CommandSnippetGroupDAO commandSnippetGroupDAO; + + @Resource + private CommandSnippetService commandSnippetService; + + @Override + public Long createCommandSnippetGroup(CommandSnippetGroupCreateRequest request) { + Long userId = SecurityUtils.getLoginUserId(); + log.info("CommandSnippetGroupService-createCommandSnippetGroup request: {}", JSON.toJSONString(request)); + // 转换 + CommandSnippetGroupDO record = CommandSnippetGroupConvert.MAPPER.to(request); + record.setUserId(userId); + // 查询数据是否冲突 + this.checkCommandSnippetGroupPresent(record); + // 插入 + int effect = commandSnippetGroupDAO.insert(record); + Long id = record.getId(); + log.info("CommandSnippetGroupService-createCommandSnippetGroup id: {}, effect: {}", id, effect); + // 删除缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET_GROUP.format(userId); + RedisMaps.delete(cacheKey); + return id; + } + + @Override + public Integer updateCommandSnippetGroupById(CommandSnippetGroupUpdateRequest request) { + Long id = Valid.notNull(request.getId(), ErrorMessage.ID_MISSING); + log.info("CommandSnippetGroupService-updateCommandSnippetGroupById id: {}, request: {}", id, JSON.toJSONString(request)); + // 查询 + CommandSnippetGroupDO record = commandSnippetGroupDAO.selectById(id); + Valid.notNull(record, ErrorMessage.DATA_ABSENT); + // 转换 + CommandSnippetGroupDO updateRecord = CommandSnippetGroupConvert.MAPPER.to(request); + updateRecord.setUserId(record.getUserId()); + // 查询数据是否冲突 + this.checkCommandSnippetGroupPresent(updateRecord); + // 更新 + int effect = commandSnippetGroupDAO.updateById(updateRecord); + log.info("CommandSnippetGroupService-updateCommandSnippetGroupById effect: {}", effect); + // 删除缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET_GROUP.format(record.getUserId()); + RedisMaps.delete(cacheKey); + return effect; + } + + @Override + public List getCommandSnippetGroupList() { + Long userId = SecurityUtils.getLoginUserId(); + // 查询缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET_GROUP.format(userId); + List list = RedisMaps.valuesJson(cacheKey, CommandSnippetCacheKeyDefine.SNIPPET_GROUP); + if (list.isEmpty()) { + // 查询数据库 + list = commandSnippetGroupDAO.of() + .createWrapper() + .eq(CommandSnippetGroupDO::getUserId, userId) + .then() + .list(CommandSnippetGroupConvert.MAPPER::toCache); + // 设置屏障 防止穿透 + CacheBarriers.checkBarrier(list, CommandSnippetGroupCacheDTO::new); + // 设置缓存 + RedisMaps.putAllJson(cacheKey, s -> s.getId().toString(), list); + } + // 删除屏障 + CacheBarriers.removeBarrier(list); + // 转换 + return list.stream() + .map(CommandSnippetGroupConvert.MAPPER::to) + .collect(Collectors.toList()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Integer deleteCommandSnippetGroup(CommandSnippetGroupDeleteRequest request) { + Long id = request.getId(); + log.info("CommandSnippetGroupService-deleteCommandSnippetGroupById id: {}", id); + // 检查数据是否存在 + CommandSnippetGroupDO record = commandSnippetGroupDAO.selectById(id); + Valid.notNull(record, ErrorMessage.DATA_ABSENT); + Long userId = record.getUserId(); + // 删除 + int effect = commandSnippetGroupDAO.deleteById(id); + log.info("CommandSnippetGroupService-deleteCommandSnippetGroupById id: {}, effect: {}", id, effect); + if (Booleans.isTrue(request.getDeleteItem())) { + // 删除组内数据 + commandSnippetService.deleteByGroupId(userId, id); + } else { + // 移动到根节点 + commandSnippetService.setGroupNull(userId, id); + } + // 删除缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET_GROUP.format(userId); + RedisMaps.delete(cacheKey, id); + return effect; + } + + /** + * 检查对象是否存在 + * + * @param domain domain + */ + private void checkCommandSnippetGroupPresent(CommandSnippetGroupDO domain) { + // 构造条件 + LambdaQueryWrapper wrapper = commandSnippetGroupDAO.wrapper() + // 更新时忽略当前记录 + .ne(CommandSnippetGroupDO::getId, domain.getId()) + // 用其他字段做重复校验 + .eq(CommandSnippetGroupDO::getUserId, domain.getUserId()) + .eq(CommandSnippetGroupDO::getName, domain.getName()); + // 检查是否存在 + boolean present = commandSnippetGroupDAO.of(wrapper).present(); + Valid.isFalse(present, ErrorMessage.DATA_PRESENT); + } + +} diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java index 9dff62eb..0d412702 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/java/com/orion/ops/module/asset/service/impl/CommandSnippetServiceImpl.java @@ -1,6 +1,8 @@ package com.orion.ops.module.asset.service.impl; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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; @@ -13,10 +15,11 @@ import com.orion.ops.module.asset.entity.domain.CommandSnippetDO; import com.orion.ops.module.asset.entity.dto.CommandSnippetCacheDTO; import com.orion.ops.module.asset.entity.request.command.CommandSnippetCreateRequest; import com.orion.ops.module.asset.entity.request.command.CommandSnippetUpdateRequest; +import com.orion.ops.module.asset.entity.vo.CommandSnippetGroupVO; import com.orion.ops.module.asset.entity.vo.CommandSnippetVO; +import com.orion.ops.module.asset.entity.vo.CommandSnippetWrapperVO; +import com.orion.ops.module.asset.service.CommandSnippetGroupService; import com.orion.ops.module.asset.service.CommandSnippetService; -import com.orion.ops.module.infra.api.DataGroupRelApi; -import com.orion.ops.module.infra.enums.DataGroupTypeEnum; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +43,7 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { private CommandSnippetDAO commandSnippetDAO; @Resource - private DataGroupRelApi dataGroupRelApi; + private CommandSnippetGroupService commandSnippetGroupService; @Override public Long createCommandSnippet(CommandSnippetCreateRequest request) { @@ -53,12 +56,8 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { int effect = commandSnippetDAO.insert(record); Long id = record.getId(); log.info("CommandSnippetService-createCommandSnippet id: {}, effect: {}", id, effect); - // 设置分组引用 - if (request.getGroupId() != null) { - dataGroupRelApi.addGroupRel(request.getGroupId(), id); - } // 删除缓存 - String cacheKey = CommandSnippetCacheKeyDefine.COMMAND_SNIPPET.format(userId); + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); RedisMaps.delete(cacheKey); return id; } @@ -72,31 +71,39 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { // 查询 CommandSnippetDO record = commandSnippetDAO.selectById(id); Valid.notNull(record, ErrorMessage.DATA_ABSENT); - // 转换 - CommandSnippetDO updateRecord = CommandSnippetConvert.MAPPER.to(request); // 更新 - int effect = commandSnippetDAO.updateById(updateRecord); + LambdaUpdateWrapper update = Wrappers.lambdaUpdate() + .set(CommandSnippetDO::getGroupId, request.getGroupId()) + .set(CommandSnippetDO::getName, request.getName()) + .set(CommandSnippetDO::getCommand, request.getCommand()) + .eq(CommandSnippetDO::getId, id) + .eq(CommandSnippetDO::getUserId, userId); + int effect = commandSnippetDAO.update(null, update); log.info("CommandSnippetService-updateCommandSnippetById effect: {}", effect); - // fixme 删除分组引用 - dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.COMMAND_SNIPPET, id); - // 设置分组引用 - if (request.getGroupId() != null) { - dataGroupRelApi.addGroupRel(request.getGroupId(), id); - } // 删除缓存 - String cacheKey = CommandSnippetCacheKeyDefine.COMMAND_SNIPPET.format(userId); + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); RedisMaps.delete(cacheKey); return effect; } + @Override + public CommandSnippetWrapperVO getCommandSnippet() { + // 查询分组 + List groups = commandSnippetGroupService.getCommandSnippetGroupList(); + // 查询命令片段 + List items = this.getCommandSnippetList(); + return CommandSnippetWrapperVO.builder() + .groups(groups) + .items(items) + .build(); + } + @Override public List getCommandSnippetList() { Long userId = SecurityUtils.getLoginUserId(); - String cacheKey = CommandSnippetCacheKeyDefine.COMMAND_SNIPPET.format(userId); - // fixme 查询分组 - + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); // 查询缓存 - List list = RedisMaps.valuesJson(cacheKey, CommandSnippetCacheKeyDefine.COMMAND_SNIPPET); + List list = RedisMaps.valuesJson(cacheKey, CommandSnippetCacheKeyDefine.SNIPPET); if (list.isEmpty()) { // 查询数据库 list = commandSnippetDAO.of() @@ -107,7 +114,7 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { // 设置屏障 防止穿透 CacheBarriers.checkBarrier(list, CommandSnippetCacheDTO::new); // 设置缓存 - RedisMaps.putAllJson(CommandSnippetCacheKeyDefine.COMMAND_SNIPPET, s -> s.getId().toString(), list); + RedisMaps.putAllJson(CommandSnippetCacheKeyDefine.SNIPPET, s -> s.getId().toString(), list); } // 删除屏障 CacheBarriers.removeBarrier(list); @@ -128,12 +135,28 @@ public class CommandSnippetServiceImpl implements CommandSnippetService { // 删除 int effect = commandSnippetDAO.deleteById(id); log.info("CommandSnippetService-deleteCommandSnippetById id: {}, effect: {}", id, effect); - // 删除分组引用 - dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.COMMAND_SNIPPET, id); // 删除缓存 - String cacheKey = CommandSnippetCacheKeyDefine.COMMAND_SNIPPET.format(userId); + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); RedisMaps.delete(cacheKey, id); return effect; } + @Override + public Integer setGroupNull(Long userId, Long groupId) { + int effect = commandSnippetDAO.setGroupIdWithNull(groupId); + // 删除缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); + RedisMaps.delete(cacheKey); + return effect; + } + + @Override + public Integer deleteByGroupId(Long userId, Long groupId) { + int effect = commandSnippetDAO.deleteByGroupId(groupId); + // 删除缓存 + String cacheKey = CommandSnippetCacheKeyDefine.SNIPPET.format(userId); + RedisMaps.delete(cacheKey); + return effect; + } + } diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetGroupMapper.xml b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetGroupMapper.xml new file mode 100644 index 00000000..79de6c7d --- /dev/null +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetGroupMapper.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + id, user_id, name, create_time, update_time, creator, updater, deleted + + + diff --git a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetMapper.xml b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetMapper.xml index dccc868b..d9462e62 100644 --- a/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetMapper.xml +++ b/orion-ops-module-asset/orion-ops-module-asset-service/src/main/resources/mapper/CommandSnippetMapper.xml @@ -6,6 +6,7 @@ + @@ -18,7 +19,7 @@ - id, user_id, name, prefix, command, create_time, update_time, creator, updater, deleted + id, user_id, group_id, name, prefix, command, create_time, update_time, creator, updater, deleted diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataExtraDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataExtraDO.java index 0ae4bfdf..0298ffad 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataExtraDO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataExtraDO.java @@ -1,13 +1,13 @@ package com.orion.ops.module.infra.entity.domain; -import com.baomidou.mybatisplus.annotation.*; +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.*; -import java.util.*; -import java.math.*; - /** * 数据拓展信息 实体对象 * diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataPermissionDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataPermissionDO.java index b8b4e6b4..38934082 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataPermissionDO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/DataPermissionDO.java @@ -1,13 +1,13 @@ package com.orion.ops.module.infra.entity.domain; -import com.baomidou.mybatisplus.annotation.*; +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.*; -import java.util.*; -import java.math.*; - /** * 数据权限 实体对象 * diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java index ab7a9f50..7513ddb5 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java @@ -1,13 +1,13 @@ package com.orion.ops.module.infra.entity.domain; -import com.baomidou.mybatisplus.annotation.*; +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.*; -import java.util.*; -import java.math.*; - /** * 标签引用 实体对象 *