feature: tag功能.
This commit is contained in:
@@ -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})
|
||||
|
||||
@@ -29,11 +29,13 @@ public class WrapperResultHandler implements ResponseBodyAdvice<Object> {
|
||||
|
||||
@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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<Long> tagIdList);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return tag
|
||||
*/
|
||||
Future<List<TagDTO>> getRelTags(String type, Long relId);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
*
|
||||
* @param type type
|
||||
* @param relIdList relIdList
|
||||
* @return tag
|
||||
*/
|
||||
Future<List<List<TagDTO>>> getRelTags(String type, List<Long> 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<Long> relIdList);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<Long> tagIdList) {
|
||||
tagRelService.addTagRel(type, relId, tagIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<List<TagDTO>> getRelTags(String type, Long relId) {
|
||||
List<TagCacheDTO> values = tagRelService.getRelTags(type, relId);
|
||||
return CompletableFuture.completedFuture(TagProviderConvert.MAPPER.toList(values));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<List<List<TagDTO>>> getRelTags(String type, List<Long> relIdList) {
|
||||
List<List<TagDTO>> 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<Long> relIdList) {
|
||||
return tagRelService.deleteRelIdList(type, relIdList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<TagDTO> toList(List<TagCacheDTO> cache);
|
||||
|
||||
}
|
||||
@@ -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<TagCacheDTO> toCacheList(List<TagRelDO> list);
|
||||
|
||||
}
|
||||
@@ -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<TagRelDO> {
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 查询条件
|
||||
*/
|
||||
default LambdaQueryWrapper<TagRelDO> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<Long> relIdList;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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<Long> tagIdList);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return tag
|
||||
*/
|
||||
List<TagCacheDTO> getRelTags(String type, Long relId);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
*
|
||||
* @param type type
|
||||
* @param relIdList relIdList
|
||||
* @return tag
|
||||
*/
|
||||
List<List<TagCacheDTO>> getRelTags(String type, List<Long> 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<Long> relIdList);
|
||||
|
||||
}
|
||||
@@ -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, "*");
|
||||
// 获取登陆信息
|
||||
|
||||
@@ -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<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public void addTagRel(String type, Long relId, List<Long> tagIdList) {
|
||||
// 删除引用
|
||||
TagRelQueryRequest deleteRequest = new TagRelQueryRequest();
|
||||
deleteRequest.setTagType(type);
|
||||
deleteRequest.setRelId(relId);
|
||||
LambdaQueryWrapper<TagRelDO> deleteWrapper = this.buildQueryWrapper(deleteRequest);
|
||||
tagRelDAO.delete(deleteWrapper);
|
||||
// 查询 tag
|
||||
List<TagDO> tagList = tagDAO.selectBatchIds(tagIdList);
|
||||
// 插入引用
|
||||
List<TagRelDO> 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<TagCacheDTO> 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<TagRelDO> wrapper = this.buildQueryWrapper(queryRequest);
|
||||
List<TagRelDO> relList = tagRelDAO.selectList(wrapper);
|
||||
// 设置缓存
|
||||
List<TagCacheDTO> 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<List<TagCacheDTO>> getRelTags(String type, List<Long> relIdList) {
|
||||
// 查询缓存
|
||||
List<String> cacheKeyList = relIdList.stream()
|
||||
.map(relId -> TagCacheKeyDefine.TAG_REL.format(type, relId))
|
||||
.collect(Collectors.toList());
|
||||
List<List<TagCacheDTO>> cacheValueList = redisTemplate.opsForValue()
|
||||
.multiGet(cacheKeyList)
|
||||
.stream()
|
||||
.map(s -> JSON.parseArray(s, TagCacheDTO.class))
|
||||
.collect(Collectors.toList());
|
||||
// 查询为空的缓存
|
||||
Map<Long, List<TagCacheDTO>> 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<TagRelDO> wrapper = this.buildQueryWrapper(queryRequest);
|
||||
List<TagRelDO> relList = tagRelDAO.selectList(wrapper);
|
||||
// 分组
|
||||
Map<Long, List<TagRelDO>> relGrouping = relList.stream()
|
||||
.collect(Collectors.groupingBy(TagRelDO::getRelId));
|
||||
// 设置缓存
|
||||
emptyCacheMap.keySet().forEach(relId -> {
|
||||
String cacheKey = TagCacheKeyDefine.TAG_REL.format(type, relId);
|
||||
List<TagCacheDTO> 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<TagRelDO> 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<Long> relIdList) {
|
||||
// 删除数据库
|
||||
TagRelQueryRequest queryRequest = new TagRelQueryRequest();
|
||||
queryRequest.setTagType(type);
|
||||
queryRequest.setRelIdList(relIdList);
|
||||
LambdaQueryWrapper<TagRelDO> wrapper = this.buildQueryWrapper(queryRequest);
|
||||
int effect = tagRelDAO.delete(wrapper);
|
||||
// 删除缓存
|
||||
List<String> 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<TagRelDO> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.infra.dao.TagRelDAO">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.TagRelDO">
|
||||
<id column="id" property="id"/>
|
||||
<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"/>
|
||||
<result column="tag_id" property="tagId"/>
|
||||
<result column="tag_name" property="tagName"/>
|
||||
<result column="tag_type" property="tagType"/>
|
||||
<result column="rel_id" property="relId"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, tag_id, tag_name, tag_type, rel_id, create_time, update_time, creator, updater, deleted
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user