From 2e121a8e90e6d2f2ada7c215761273df1b930343 Mon Sep 17 00:00:00 2001 From: lijiahang Date: Thu, 7 Sep 2023 09:47:53 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20tag=E5=8A=9F=E8=83=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/annotation/RestWrapper.java | 2 + .../core/handler/WrapperResultHandler.java | 6 +- .../ops/launch/generator/CodeGenerator.java | 2 +- .../orion/ops/module/infra/api/TagRelApi.java | 62 ++++++ .../module/infra/entity/dto/tag/TagDTO.java | 33 ++++ .../module/infra/api/impl/TagRelApiImpl.java | 63 ++++++ .../infra/convert/TagProviderConvert.java | 24 +++ .../module/infra/convert/TagRelConvert.java | 31 +++ .../orion/ops/module/infra/dao/TagRelDAO.java | 33 ++++ .../infra/define/TagCacheKeyDefine.java | 2 +- .../module/infra/entity/domain/TagRelDO.java | 49 +++++ .../module/infra/entity/dto/TagCacheDTO.java | 5 - .../infra/entity/export/SystemRoleExport.java | 58 ------ .../request/tag/TagRelQueryRequest.java | 45 +++++ .../ops/module/infra/entity/vo/TagRelVO.java | 41 ---- .../module/infra/service/TagRelService.java | 61 ++++++ .../impl/AuthenticationServiceImpl.java | 2 + .../infra/service/impl/TagRelServiceImpl.java | 187 ++++++++++++++++++ .../main/resources/mapper/TagRelMapper.xml | 24 +++ 19 files changed, 622 insertions(+), 108 deletions(-) create mode 100644 orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/TagRelApi.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/tag/TagDTO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/TagRelApiImpl.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagProviderConvert.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagRelConvert.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/TagRelDAO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java delete mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/export/SystemRoleExport.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/tag/TagRelQueryRequest.java delete mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/TagRelVO.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TagRelService.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java create mode 100644 orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/TagRelMapper.xml diff --git a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/annotation/RestWrapper.java b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/annotation/RestWrapper.java index 36de889b..5c064e1d 100644 --- a/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/annotation/RestWrapper.java +++ b/orion-ops-framework/orion-ops-common/src/main/java/com/orion/ops/framework/common/annotation/RestWrapper.java @@ -7,6 +7,8 @@ import java.lang.annotation.*; * * @author Jiahang Li * @version 1.0.0 + * @see Void#TYPE + * @see IgnoreWrapper * @since 2021/4/2 12:34 */ @Target({ElementType.TYPE}) diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/handler/WrapperResultHandler.java b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/handler/WrapperResultHandler.java index 238d4d44..f9a6be32 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/handler/WrapperResultHandler.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-web/src/main/java/com/orion/ops/framework/web/core/handler/WrapperResultHandler.java @@ -29,11 +29,13 @@ public class WrapperResultHandler implements ResponseBodyAdvice { @Override public boolean supports(MethodParameter methodParameter, @NotNull Class converterType) { - // 统一返回值 + // 检查是否包含统一返回值注解 if (!methodParameter.getContainingClass().isAnnotationPresent(RestWrapper.class)) { return false; } - return !methodParameter.hasMethodAnnotation(IgnoreWrapper.class); + // 检查是否包含忽略返回值注解 && 方法返回值不为 void + return !methodParameter.hasMethodAnnotation(IgnoreWrapper.class) && + methodParameter.getExecutable().getAnnotatedReturnType().getType() != Void.TYPE; } @Override diff --git a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java index 703a8290..9ba1e8af 100644 --- a/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java +++ b/orion-ops-launch/src/main/java/com/orion/ops/launch/generator/CodeGenerator.java @@ -44,7 +44,7 @@ public class CodeGenerator { // new GenTable("system_user", "用户", "user") // .vue("user", "user") // .enums(UserStatusEnum.class), - new GenTable("tag", "标签枚举", "tag"), + new GenTable("tag_rel", "标签引用", "tag").ignoreTest(), }; // jdbc 配置 - 使用配置文件 File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml"); diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/TagRelApi.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/TagRelApi.java new file mode 100644 index 00000000..3137cb94 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/TagRelApi.java @@ -0,0 +1,62 @@ +package com.orion.ops.module.infra.api; + +import com.orion.ops.module.infra.entity.dto.tag.TagDTO; + +import java.util.List; +import java.util.concurrent.Future; + +/** + * 标签引用 对外服务类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +public interface TagRelApi { + + /** + * 创建标签引用 + * + * @param type type + * @param relId relId + * @param tagIdList tagIdList + */ + void addTagRel(String type, Long relId, List tagIdList); + + /** + * 获取引用 tag + * + * @param type type + * @param relId relId + * @return tag + */ + Future> getRelTags(String type, Long relId); + + /** + * 获取引用 tag + * + * @param type type + * @param relIdList relIdList + * @return tag + */ + Future>> getRelTags(String type, List relIdList); + + /** + * 通过 relId 删除 + * + * @param type type + * @param relId relId + * @return effect + */ + Integer deleteRelId(String type, Long relId); + + /** + * 通过 relIdList 删除 + * + * @param type type + * @param relIdList relIdList + * @return effect + */ + Integer deleteRelIdList(String type, List relIdList); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/tag/TagDTO.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/tag/TagDTO.java new file mode 100644 index 00000000..2205c255 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/tag/TagDTO.java @@ -0,0 +1,33 @@ +package com.orion.ops.module.infra.entity.dto.tag; + +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 2023-9-6 16:54 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "TagDTO", description = "标签 业务对象") +public class TagDTO 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-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/TagRelApiImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/TagRelApiImpl.java new file mode 100644 index 00000000..9257f169 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/TagRelApiImpl.java @@ -0,0 +1,63 @@ +package com.orion.ops.module.infra.api.impl; + +import com.orion.ops.module.infra.api.TagRelApi; +import com.orion.ops.module.infra.convert.TagProviderConvert; +import com.orion.ops.module.infra.entity.dto.TagCacheDTO; +import com.orion.ops.module.infra.entity.dto.tag.TagDTO; +import com.orion.ops.module.infra.service.TagRelService; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.stream.Collectors; + +/** + * 标签引用 对外服务实现类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Service +public class TagRelApiImpl implements TagRelApi { + + @Resource + private TagRelService tagRelService; + + @Override + @Async("asyncExecutor") + public void addTagRel(String type, Long relId, List tagIdList) { + tagRelService.addTagRel(type, relId, tagIdList); + } + + @Override + @Async("asyncExecutor") + public Future> getRelTags(String type, Long relId) { + List values = tagRelService.getRelTags(type, relId); + return CompletableFuture.completedFuture(TagProviderConvert.MAPPER.toList(values)); + } + + @Override + @Async("asyncExecutor") + public Future>> getRelTags(String type, List relIdList) { + List> values = tagRelService.getRelTags(type, relIdList) + .stream() + .map(TagProviderConvert.MAPPER::toList) + .collect(Collectors.toList()); + return CompletableFuture.completedFuture(values); + } + + @Override + public Integer deleteRelId(String type, Long relId) { + return tagRelService.deleteRelId(type, relId); + } + + @Override + public Integer deleteRelIdList(String type, List relIdList) { + return tagRelService.deleteRelIdList(type, relIdList); + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagProviderConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagProviderConvert.java new file mode 100644 index 00000000..17489a96 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagProviderConvert.java @@ -0,0 +1,24 @@ +package com.orion.ops.module.infra.convert; + +import com.orion.ops.module.infra.entity.dto.TagCacheDTO; +import com.orion.ops.module.infra.entity.dto.tag.TagDTO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 标签枚举 对外对象转换器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-5 11:58 + */ +@Mapper +public interface TagProviderConvert { + + TagProviderConvert MAPPER = Mappers.getMapper(TagProviderConvert.class); + + List toList(List cache); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagRelConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagRelConvert.java new file mode 100644 index 00000000..5f8c8c2b --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/TagRelConvert.java @@ -0,0 +1,31 @@ +package com.orion.ops.module.infra.convert; + +import com.orion.ops.module.infra.entity.domain.TagRelDO; +import com.orion.ops.module.infra.entity.dto.TagCacheDTO; +import com.orion.ops.module.infra.entity.request.tag.TagRelQueryRequest; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 标签引用 内部对象转换器 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Mapper +public interface TagRelConvert { + + TagRelConvert MAPPER = Mappers.getMapper(TagRelConvert.class); + + TagRelDO to(TagRelQueryRequest request); + + @Mapping(target = "name", source = "tagName") + TagCacheDTO toCache(TagRelDO domain); + + List toCacheList(List list); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/TagRelDAO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/TagRelDAO.java new file mode 100644 index 00000000..9e5bcd0b --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/TagRelDAO.java @@ -0,0 +1,33 @@ +package com.orion.ops.module.infra.dao; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.orion.ops.framework.mybatis.core.mapper.IMapper; +import com.orion.ops.module.infra.entity.domain.TagRelDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 标签引用 Mapper 接口 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Mapper +public interface TagRelDAO extends IMapper { + + /** + * 获取查询条件 + * + * @param entity entity + * @return 查询条件 + */ + default LambdaQueryWrapper queryCondition(TagRelDO entity) { + return this.wrapper() + .eq(TagRelDO::getId, entity.getId()) + .eq(TagRelDO::getTagId, entity.getTagId()) + .eq(TagRelDO::getTagName, entity.getTagName()) + .eq(TagRelDO::getTagType, entity.getTagType()) + .eq(TagRelDO::getRelId, entity.getRelId()); + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TagCacheKeyDefine.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TagCacheKeyDefine.java index dab2d52c..53fe8088 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TagCacheKeyDefine.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/TagCacheKeyDefine.java @@ -25,7 +25,7 @@ public interface TagCacheKeyDefine { CacheKeyDefine TAG_REL = new CacheKeyBuilder() .key("tag:rel:{}:{}") .desc("tag 引用 ${type} ${relId}") - .type(Long.class) + .type(TagCacheDTO.class) .timeout(3, TimeUnit.DAYS) .build(); 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 new file mode 100644 index 00000000..ab7a9f50 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/TagRelDO.java @@ -0,0 +1,49 @@ +package com.orion.ops.module.infra.entity.domain; + +import com.baomidou.mybatisplus.annotation.*; +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.*; + +/** + * 标签引用 实体对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@TableName(value = "tag_rel", autoResultMap = true) +@Schema(name = "TagRelDO", description = "标签引用 实体对象") +public class TagRelDO extends BaseDO { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @Schema(description = "标签id") + @TableField("tag_id") + private Long tagId; + + @Schema(description = "标签名称") + @TableField("tag_name") + private String tagName; + + @Schema(description = "标签类型") + @TableField("tag_type") + private String tagType; + + @Schema(description = "关联id") + @TableField("rel_id") + private Long relId; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/TagCacheDTO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/TagCacheDTO.java index 98047dc7..4f45a87c 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/TagCacheDTO.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/TagCacheDTO.java @@ -1,8 +1,5 @@ package com.orion.ops.module.infra.entity.dto; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; @@ -21,11 +18,9 @@ public class TagCacheDTO { @EqualsAndHashCode.Include @Schema(description = "id") - @TableId(value = "id", type = IdType.AUTO) private Long id; @Schema(description = "标签名称") - @TableField("name") private String name; } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/export/SystemRoleExport.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/export/SystemRoleExport.java deleted file mode 100644 index 0db9fe41..00000000 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/export/SystemRoleExport.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.orion.ops.module.infra.entity.export; - -import com.orion.lang.utils.time.Dates; -import com.orion.office.excel.annotation.ExportField; -import com.orion.office.excel.annotation.ExportSheet; -import com.orion.office.excel.annotation.ExportTitle; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.Date; - -/** - * 系统角色导出 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023/8/31 17:40 - */ -@Data -@ExportTitle(title = SystemRoleExport.TITLE) -@ExportSheet(name = "系统角色", filterHeader = true, freezeHeader = true, indexToSort = true) -public class SystemRoleExport { - - public static final String TITLE = "系统角色导出"; - - @ExportField(index = 0, header = "id", width = 16) - @Schema(description = "id") - private Long id; - - @ExportField(index = 1, header = "角色名称", width = 16) - @Schema(description = "角色名称") - private String name; - - @ExportField(index = 2, header = "角色编码", width = 16) - @Schema(description = "角色编码") - private String code; - - @ExportField(index = 3, header = "状态", width = 16) - @Schema(description = "状态 0停用 1启用") - private Integer status; - - @ExportField(index = 4, header = "创建时间", width = 16, format = Dates.YMD_HMS) - @Schema(description = "创建时间") - private Date createTime; - - @ExportField(index = 5, header = "修改时间", width = 16, format = Dates.YMD_HMS) - @Schema(description = "修改时间") - private Date updateTime; - - @ExportField(index = 6, header = "创建人", width = 16) - @Schema(description = "创建人") - private String creator; - - @ExportField(index = 7, header = "修改人", width = 16) - @Schema(description = "修改人") - private String updater; - -} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/tag/TagRelQueryRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/tag/TagRelQueryRequest.java new file mode 100644 index 00000000..1b1ef567 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/tag/TagRelQueryRequest.java @@ -0,0 +1,45 @@ +package com.orion.ops.module.infra.entity.request.tag; + +import com.orion.ops.framework.common.entity.PageRequest; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import javax.validation.constraints.Size; +import java.util.Collection; + +/** + * 标签引用 查询请求对象 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Schema(name = "TagRelQueryRequest", description = "标签引用 查询请求对象") +public class TagRelQueryRequest extends PageRequest { + + @Schema(description = "id") + private Long id; + + @Schema(description = "标签id") + private Long tagId; + + @Size(max = 32) + @Schema(description = "标签名称") + private String tagName; + + @Size(max = 12) + @Schema(description = "标签类型") + private String tagType; + + @Schema(description = "关联id") + private Long relId; + + @Schema(description = "关联id") + private Collection relIdList; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/TagRelVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/TagRelVO.java deleted file mode 100644 index ae499786..00000000 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/TagRelVO.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.orion.ops.module.infra.entity.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; - -import java.io.Serializable; -import java.util.*; -import java.math.*; - -/** - * 标签引用 视图响应对象 - * - * @author Jiahang Li - * @version 1.0.0 - * @since 2023-9-5 17:39 - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Schema(name = "TagRelVO", description = "标签引用 视图响应对象") -public class TagRelVO implements Serializable { - - private static final long serialVersionUID = 1L; - - @Schema(description = "id") - private Long id; - - @Schema(description = "标签名称") - private String name; - - @Schema(description = "标签类型") - private String type; - - @Schema(description = "标签id") - private Long tagId; - - @Schema(description = "关联id") - private Long relId; - -} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TagRelService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TagRelService.java new file mode 100644 index 00000000..579c6973 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/TagRelService.java @@ -0,0 +1,61 @@ +package com.orion.ops.module.infra.service; + +import com.orion.ops.module.infra.entity.dto.TagCacheDTO; + +import java.util.List; + +/** + * 标签引用 服务类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +public interface TagRelService { + + /** + * 创建标签引用 + * + * @param type type + * @param relId relId + * @param tagIdList tagIdList + */ + void addTagRel(String type, Long relId, List tagIdList); + + /** + * 获取引用 tag + * + * @param type type + * @param relId relId + * @return tag + */ + List getRelTags(String type, Long relId); + + /** + * 获取引用 tag + * + * @param type type + * @param relIdList relIdList + * @return tag + */ + List> getRelTags(String type, List relIdList); + + /** + * 通过 relId 删除 + * + * @param type type + * @param relId relId + * @return effect + */ + Integer deleteRelId(String type, Long relId); + + /** + * 通过 relIdList 删除 + * + * @param type type + * @param relIdList relIdList + * @return effect + */ + Integer deleteRelIdList(String type, List relIdList); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java index a0d4aa9c..21470cee 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/AuthenticationServiceImpl.java @@ -203,6 +203,7 @@ public class AuthenticationServiceImpl implements AuthenticationService { * @param user user * @return 是否正确 */ + @SuppressWarnings("ALL") private boolean checkPassword(UserLoginRequest request, SystemUserDO user) { // 密码正确 if (user != null && user.getPassword().equals(Signatures.md5(request.getPassword()))) { @@ -288,6 +289,7 @@ public class AuthenticationServiceImpl implements AuthenticationService { * @param remoteAddr remoteAddr * @param location location */ + @SuppressWarnings("ALL") private void invalidOtherDeviceToken(Long id, long loginTime, String remoteAddr, String location) { String loginKey = UserCacheKeyDefine.LOGIN_TOKEN.format(id, "*"); // 获取登陆信息 diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java new file mode 100644 index 00000000..d10795ad --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/TagRelServiceImpl.java @@ -0,0 +1,187 @@ +package com.orion.ops.module.infra.service.impl; + +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.orion.lang.utils.collect.Lists; +import com.orion.lang.utils.collect.Maps; +import com.orion.ops.framework.redis.core.utils.RedisUtils; +import com.orion.ops.module.infra.convert.TagRelConvert; +import com.orion.ops.module.infra.dao.TagDAO; +import com.orion.ops.module.infra.dao.TagRelDAO; +import com.orion.ops.module.infra.define.TagCacheKeyDefine; +import com.orion.ops.module.infra.entity.domain.TagDO; +import com.orion.ops.module.infra.entity.domain.TagRelDO; +import com.orion.ops.module.infra.entity.dto.TagCacheDTO; +import com.orion.ops.module.infra.entity.request.tag.TagRelQueryRequest; +import com.orion.ops.module.infra.service.TagRelService; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 标签引用 服务实现类 + * + * @author Jiahang Li + * @version 1.0.0 + * @since 2023-9-6 16:54 + */ +@Service +public class TagRelServiceImpl implements TagRelService { + + @Resource + private TagDAO tagDAO; + + @Resource + private TagRelDAO tagRelDAO; + + @Resource + private RedisTemplate redisTemplate; + + @Override + public void addTagRel(String type, Long relId, List tagIdList) { + // 删除引用 + TagRelQueryRequest deleteRequest = new TagRelQueryRequest(); + deleteRequest.setTagType(type); + deleteRequest.setRelId(relId); + LambdaQueryWrapper deleteWrapper = this.buildQueryWrapper(deleteRequest); + tagRelDAO.delete(deleteWrapper); + // 查询 tag + List tagList = tagDAO.selectBatchIds(tagIdList); + // 插入引用 + List tagRelList = tagList.stream() + .map(s -> TagRelDO.builder() + .tagId(s.getId()) + .tagName(s.getName()) + .tagType(type) + .relId(relId) + .build()) + .collect(Collectors.toList()); + tagRelDAO.insertBatch(tagRelList); + // 设置缓存 + String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId); + RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, TagRelConvert.MAPPER.toCacheList(tagRelList)); + } + + @Override + public List getRelTags(String type, Long relId) { + // 查询缓存 + String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId); + String cacheValue = redisTemplate.opsForValue().get(cacheKey); + if (cacheValue == null) { + // 查询数据库 + TagRelQueryRequest queryRequest = new TagRelQueryRequest(); + queryRequest.setTagType(type); + queryRequest.setRelId(relId); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(queryRequest); + List relList = tagRelDAO.selectList(wrapper); + // 设置缓存 + List relCacheList = TagRelConvert.MAPPER.toCacheList(relList); + RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, relCacheList); + return relCacheList; + } else { + // 返回缓存数据 + return JSON.parseArray(cacheValue, TagCacheDTO.class); + } + } + + @Override + @SuppressWarnings("ALL") + public List> getRelTags(String type, List relIdList) { + // 查询缓存 + List cacheKeyList = relIdList.stream() + .map(relId -> TagCacheKeyDefine.TAG_REL.format(type, relId)) + .collect(Collectors.toList()); + List> cacheValueList = redisTemplate.opsForValue() + .multiGet(cacheKeyList) + .stream() + .map(s -> JSON.parseArray(s, TagCacheDTO.class)) + .collect(Collectors.toList()); + // 查询为空的缓存 + Map> emptyCacheMap = Maps.newMap(); + for (int i = 0; i < relIdList.size(); i++) { + if (cacheValueList.get(i) == null) { + emptyCacheMap.put(relIdList.get(i), null); + } + } + // 填充为空的数据 + if (!emptyCacheMap.isEmpty()) { + // 查询数据库 + TagRelQueryRequest queryRequest = new TagRelQueryRequest(); + queryRequest.setTagType(type); + queryRequest.setRelIdList(emptyCacheMap.keySet()); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(queryRequest); + List relList = tagRelDAO.selectList(wrapper); + // 分组 + Map> relGrouping = relList.stream() + .collect(Collectors.groupingBy(TagRelDO::getRelId)); + // 设置缓存 + emptyCacheMap.keySet().forEach(relId -> { + String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId); + List cacheValue = TagRelConvert.MAPPER.toCacheList(relGrouping.get(relId)); + if (cacheValue == null) { + cacheValue = Lists.empty(); + } + RedisUtils.setJson(cacheKey, TagCacheKeyDefine.TAG_REL, cacheValue); + emptyCacheMap.put(relId, cacheValue); + }); + // 设置返回 + for (int i = 0; i < relIdList.size(); i++) { + if (cacheValueList.get(i) == null) { + cacheValueList.set(i, emptyCacheMap.get(relIdList.get(i))); + } + } + } + return cacheValueList; + } + + @Override + public Integer deleteRelId(String type, Long relId) { + // 删除数据库 + TagRelQueryRequest queryRequest = new TagRelQueryRequest(); + queryRequest.setTagType(type); + queryRequest.setRelId(relId); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(queryRequest); + int effect = tagRelDAO.delete(wrapper); + // 删除缓存 + String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId); + redisTemplate.delete(cacheKey); + return effect; + } + + @Override + public Integer deleteRelIdList(String type, List relIdList) { + // 删除数据库 + TagRelQueryRequest queryRequest = new TagRelQueryRequest(); + queryRequest.setTagType(type); + queryRequest.setRelIdList(relIdList); + LambdaQueryWrapper wrapper = this.buildQueryWrapper(queryRequest); + int effect = tagRelDAO.delete(wrapper); + // 删除缓存 + List cacheKeyList = relIdList.stream() + .map(relId -> TagCacheKeyDefine.TAG_REL.format(type, relId)) + .collect(Collectors.toList()); + redisTemplate.delete(cacheKeyList); + return effect; + } + + /** + * 构建查询 wrapper + * + * @param request request + * @return wrapper + */ + private LambdaQueryWrapper buildQueryWrapper(TagRelQueryRequest request) { + return tagRelDAO.wrapper() + .eq(TagRelDO::getId, request.getId()) + .eq(TagRelDO::getTagId, request.getTagId()) + .eq(TagRelDO::getTagName, request.getTagName()) + .eq(TagRelDO::getTagType, request.getTagType()) + .eq(TagRelDO::getRelId, request.getRelId()) + .in(TagRelDO::getRelId, request.getRelIdList()); + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/TagRelMapper.xml b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/TagRelMapper.xml new file mode 100644 index 00000000..d2c38e3d --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/TagRelMapper.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + id, tag_id, tag_name, tag_type, rel_id, create_time, update_time, creator, updater, deleted + + +