refactor: 规范化代码.
This commit is contained in:
@@ -11,6 +11,8 @@ import com.orion.ops.framework.common.constant.FieldConst;
|
||||
*/
|
||||
public interface OperatorLogKeys extends FieldConst {
|
||||
|
||||
String GROUP_NAME = "groupName";
|
||||
|
||||
String ID_LIST = "idList";
|
||||
|
||||
String USERNAME = "username";
|
||||
|
||||
@@ -67,17 +67,9 @@ public class HostController {
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "通过 id 查询主机")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@Parameter(name = "extra", description = "是否查询额外信息")
|
||||
@Parameter(name = "config", description = "是否查询配置信息")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:query')")
|
||||
public HostVO getHost(@RequestParam("id") Long id,
|
||||
@RequestParam(name = "extra", required = false) boolean extra,
|
||||
@RequestParam(name = "config", required = false) boolean config) {
|
||||
HostQueryRequest request = new HostQueryRequest();
|
||||
request.setId(id);
|
||||
request.setExtra(extra);
|
||||
request.setConfig(config);
|
||||
return hostService.getHostById(request);
|
||||
public HostVO getHost(@RequestParam("id") Long id) {
|
||||
return hostService.getHostById(id);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
|
||||
@@ -7,10 +7,14 @@ import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.asset.convert.HostGroupConvert;
|
||||
import com.orion.ops.module.asset.define.operator.HostGroupOperatorType;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostGroupRelUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostGroupTreeVO;
|
||||
import com.orion.ops.module.infra.api.DataGroupApi;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.*;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupMoveDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRenameDTO;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -91,17 +95,17 @@ public class HostGroupController {
|
||||
@GetMapping("/rel-list")
|
||||
@Operation(summary = "查询分组主机")
|
||||
@Parameter(name = "groupId", description = "groupId", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query-rel')")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:query')")
|
||||
public Set<Long> queryHostGroupRel(@RequestParam("groupId") Long groupId) {
|
||||
return dataGroupRelApi.getGroupRelList(DataGroupTypeEnum.HOST, groupId);
|
||||
return dataGroupRelApi.getGroupRelIdByGroupId(DataGroupTypeEnum.HOST, groupId);
|
||||
}
|
||||
|
||||
@OperatorLog(HostGroupOperatorType.UPDATE_REL)
|
||||
@PostMapping("/update-rel")
|
||||
@Operation(summary = "修改分组主机")
|
||||
@PreAuthorize("@ss.hasPermission('asset:host-group:update-rel')")
|
||||
public HttpWrapper<?> updateGroupHost(@Validated @RequestBody DataGroupRelUpdateDTO request) {
|
||||
dataGroupRelApi.updateGroupRel(request);
|
||||
@PreAuthorize("@ss.hasPermission('asset:host:update')")
|
||||
public HttpWrapper<?> updateGroupHost(@Validated @RequestBody HostGroupRelUpdateRequest request) {
|
||||
dataGroupRelApi.updateGroupRel(request.getGroupId(), request.getHostIdList());
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ public class HostGroupOperatorType extends InitializingOperatorTypes {
|
||||
new OperatorType(L, CREATE, "创建主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(L, RENAME, "重命名主机分组 <sb>${before}</sb> -> <sb>${name}</sb>"),
|
||||
new OperatorType(L, MOVE, "移动主机分组 <sb>${source}</sb> 到 <sb>${target}(${position})</sb>"),
|
||||
new OperatorType(H, DELETE, "删除主机分组 <sb>${name}</sb>"),
|
||||
new OperatorType(M, UPDATE_REL, "修改分组内主机 <sb>${name}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除主机分组 <sb>${groupName}</sb>"),
|
||||
new OperatorType(M, UPDATE_REL, "修改分组内主机 <sb>${groupName}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ public class HostCreateRequest implements Serializable {
|
||||
@Schema(description = "主机地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "主机分组")
|
||||
private List<Long> groupIdList;
|
||||
|
||||
@Size(max = 5)
|
||||
@Schema(description = "tags")
|
||||
private List<Long> tags;
|
||||
|
||||
@@ -40,16 +40,13 @@ public class HostQueryRequest extends PageRequest {
|
||||
@Schema(description = "主机地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "是否为收藏")
|
||||
private Boolean favorite;
|
||||
|
||||
@Schema(description = "tag")
|
||||
private List<Long> tags;
|
||||
|
||||
@Schema(description = "是否查询额外信息")
|
||||
private Boolean extra;
|
||||
@Schema(description = "是否查询 tag 信息")
|
||||
private Boolean queryTag;
|
||||
|
||||
@Schema(description = "是否查询配置信息")
|
||||
private Boolean config;
|
||||
private Boolean queryConfig;
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public class HostUpdateRequest implements Serializable {
|
||||
@Schema(description = "主机地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "主机分组")
|
||||
private List<Long> groupIdList;
|
||||
|
||||
@Size(max = 5)
|
||||
@Schema(description = "tags")
|
||||
private List<Long> tags;
|
||||
|
||||
@@ -10,7 +10,7 @@ import lombok.NoArgsConstructor;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 主机 视图响应对象
|
||||
@@ -52,13 +52,10 @@ public class HostVO implements Serializable {
|
||||
@Schema(description = "修改人")
|
||||
private String updater;
|
||||
|
||||
@Schema(description = "是否收藏")
|
||||
private Boolean favorite;
|
||||
|
||||
@Schema(description = "tags")
|
||||
private List<TagDTO> tags;
|
||||
|
||||
@Schema(description = "configs")
|
||||
private Map<String, HostConfigVO> configs;
|
||||
@Schema(description = "分组 id")
|
||||
private Set<Long> groupIdList;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public interface HostService {
|
||||
/**
|
||||
* 通过 id 查询主机
|
||||
*
|
||||
* @param request request
|
||||
* @param id id
|
||||
* @return row
|
||||
*/
|
||||
HostVO getHostById(HostQueryRequest request);
|
||||
HostVO getHostById(Long id);
|
||||
|
||||
/**
|
||||
* 查询主机
|
||||
|
||||
@@ -11,25 +11,24 @@ import com.orion.ops.framework.common.constant.Const;
|
||||
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.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.module.asset.convert.HostConfigConvert;
|
||||
import com.orion.ops.module.asset.convert.HostConvert;
|
||||
import com.orion.ops.module.asset.dao.HostConfigDAO;
|
||||
import com.orion.ops.module.asset.dao.HostDAO;
|
||||
import com.orion.ops.module.asset.define.cache.HostCacheKeyDefine;
|
||||
import com.orion.ops.module.asset.entity.domain.HostConfigDO;
|
||||
import com.orion.ops.module.asset.entity.domain.HostDO;
|
||||
import com.orion.ops.module.asset.entity.dto.HostCacheDTO;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostCreateRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostQueryRequest;
|
||||
import com.orion.ops.module.asset.entity.request.host.HostUpdateRequest;
|
||||
import com.orion.ops.module.asset.entity.vo.HostConfigVO;
|
||||
import com.orion.ops.module.asset.entity.vo.HostVO;
|
||||
import com.orion.ops.module.asset.service.HostConfigService;
|
||||
import com.orion.ops.module.asset.service.HostService;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.api.FavoriteApi;
|
||||
import com.orion.ops.module.infra.api.TagRelApi;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.tag.TagDTO;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import com.orion.ops.module.infra.enums.FavoriteTypeEnum;
|
||||
import com.orion.ops.module.infra.enums.TagTypeEnum;
|
||||
import lombok.SneakyThrows;
|
||||
@@ -37,10 +36,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -55,10 +52,6 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class HostServiceImpl implements HostService {
|
||||
|
||||
// FIXME 这里的收藏删除
|
||||
|
||||
private static final ThreadLocal<List<Long>> FAVORITE_HOLDER = new ThreadLocal<>();
|
||||
|
||||
@Resource
|
||||
private HostDAO hostDAO;
|
||||
|
||||
@@ -74,6 +67,9 @@ public class HostServiceImpl implements HostService {
|
||||
@Resource
|
||||
private FavoriteApi favoriteApi;
|
||||
|
||||
@Resource
|
||||
private DataGroupRelApi dataGroupRelApi;
|
||||
|
||||
@Override
|
||||
public Long createHost(HostCreateRequest request) {
|
||||
log.info("HostService-createHost request: {}", JSON.toJSONString(request));
|
||||
@@ -87,9 +83,17 @@ public class HostServiceImpl implements HostService {
|
||||
log.info("HostService-createHost effect: {}", effect);
|
||||
Long id = record.getId();
|
||||
// 插入 tag
|
||||
List<Long> tags = request.getTags();
|
||||
if (!Lists.isEmpty(tags)) {
|
||||
tagRelApi.addTagRel(TagTypeEnum.HOST, id, tags);
|
||||
tagRelApi.addTagRelAsync(TagTypeEnum.HOST, id, request.getTags());
|
||||
// 引用分组
|
||||
List<Long> groupIdList = request.getGroupIdList();
|
||||
if (!Lists.isEmpty(groupIdList)) {
|
||||
List<DataGroupRelCreateDTO> groupRelList = groupIdList.stream()
|
||||
.map(s -> DataGroupRelCreateDTO.builder()
|
||||
.groupId(s)
|
||||
.relId(id)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
dataGroupRelApi.addGroupRel(groupRelList);
|
||||
}
|
||||
// 创建配置
|
||||
hostConfigService.initHostConfig(id);
|
||||
@@ -113,22 +117,33 @@ public class HostServiceImpl implements HostService {
|
||||
// 更新
|
||||
int effect = hostDAO.updateById(updateRecord);
|
||||
log.info("HostService-updateHostById effect: {}", effect);
|
||||
// 引用分组
|
||||
dataGroupRelApi.updateGroupRel(DataGroupTypeEnum.HOST, request.getGroupIdList(), id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO);
|
||||
// 更新 tag
|
||||
tagRelApi.setTagRel(TagTypeEnum.HOST, id, request.getTags());
|
||||
tagRelApi.setTagRelAsync(TagTypeEnum.HOST, id, request.getTags());
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO getHostById(HostQueryRequest request) {
|
||||
// 查询
|
||||
HostDO record = hostDAO.selectById(request.getId());
|
||||
@SneakyThrows
|
||||
public HostVO getHostById(Long id) {
|
||||
// 查询 tag 信息
|
||||
Future<List<TagDTO>> tagFuture = tagRelApi.getRelTagsAsync(TagTypeEnum.HOST, id);
|
||||
// 查询分组信息
|
||||
Future<Set<Long>> groupIdFuture = dataGroupRelApi.getGroupIdByRelIdAsync(DataGroupTypeEnum.HOST, id);
|
||||
// 查询主机
|
||||
HostDO record = hostDAO.selectById(id);
|
||||
Valid.notNull(record, ErrorMessage.HOST_ABSENT);
|
||||
// 转换
|
||||
HostVO vo = HostConvert.MAPPER.to(record);
|
||||
// 查询拓展信息
|
||||
this.setExtraInfo(request, Lists.singleton(vo));
|
||||
// 设置 tag 信息
|
||||
List<TagDTO> tags = tagFuture.get();
|
||||
// 设置分组信息
|
||||
vo.setTags(tags);
|
||||
Set<Long> groupIdList = groupIdFuture.get();
|
||||
vo.setGroupIdList(groupIdList);
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -158,22 +173,18 @@ public class HostServiceImpl implements HostService {
|
||||
|
||||
@Override
|
||||
public DataGrid<HostVO> getHostPage(HostQueryRequest request) {
|
||||
try {
|
||||
// 条件
|
||||
LambdaQueryWrapper<HostDO> wrapper = this.buildQueryWrapper(request);
|
||||
if (wrapper == null) {
|
||||
return DataGrid.of(Lists.empty());
|
||||
}
|
||||
// 查询
|
||||
DataGrid<HostVO> hosts = hostDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(HostConvert.MAPPER::to);
|
||||
// 查询拓展信息
|
||||
this.setExtraInfo(request, hosts.getRows());
|
||||
return hosts;
|
||||
} finally {
|
||||
FAVORITE_HOLDER.remove();
|
||||
// 条件
|
||||
LambdaQueryWrapper<HostDO> wrapper = this.buildQueryWrapper(request);
|
||||
if (wrapper == null) {
|
||||
return DataGrid.of(Lists.empty());
|
||||
}
|
||||
// 查询
|
||||
DataGrid<HostVO> hosts = hostDAO.of(wrapper)
|
||||
.page(request)
|
||||
.dataGrid(HostConvert.MAPPER::to);
|
||||
// 查询拓展信息
|
||||
this.setExtraInfo(request, hosts.getRows());
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,14 +198,16 @@ public class HostServiceImpl implements HostService {
|
||||
// 删除
|
||||
int effect = hostDAO.deleteById(id);
|
||||
log.info("HostService-deleteHostById effect: {}", effect);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id);
|
||||
// 删除配置
|
||||
hostConfigDAO.deleteByHostId(id);
|
||||
// 删除分组
|
||||
dataGroupRelApi.deleteByRelId(DataGroupTypeEnum.HOST, id);
|
||||
// 删除缓存
|
||||
RedisMaps.delete(HostCacheKeyDefine.HOST_INFO, id);
|
||||
// 删除 tag 引用
|
||||
tagRelApi.deleteRelId(TagTypeEnum.HOST, id);
|
||||
tagRelApi.deleteRelIdAsync(TagTypeEnum.HOST, id);
|
||||
// 删除收藏引用
|
||||
favoriteApi.deleteByRelId(FavoriteTypeEnum.HOST, id);
|
||||
favoriteApi.deleteByRelIdAsync(FavoriteTypeEnum.HOST, id);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -236,48 +249,19 @@ public class HostServiceImpl implements HostService {
|
||||
* @param request request
|
||||
* @return wrapper
|
||||
*/
|
||||
@SneakyThrows
|
||||
private LambdaQueryWrapper<HostDO> buildQueryWrapper(HostQueryRequest request) {
|
||||
boolean setIdList = Booleans.isTrue(request.getFavorite()) || Lists.isNotEmpty(request.getTags());
|
||||
List<List<Long>> idListGrouping = new ArrayList<>();
|
||||
// 查询收藏
|
||||
Future<List<Long>> favoriteFuture = null;
|
||||
if (Booleans.isTrue(request.getFavorite())) {
|
||||
favoriteFuture = favoriteApi.getFavoriteRelIdList(FavoriteTypeEnum.HOST, SecurityUtils.getLoginUserId());
|
||||
}
|
||||
String searchValue = request.getSearchValue();
|
||||
LambdaQueryWrapper<HostDO> wrapper = hostDAO.wrapper();
|
||||
// tag 条件
|
||||
if (Lists.isNotEmpty(request.getTags())) {
|
||||
List<Long> tagRelIdList = tagRelApi.getRelIdByTagId(request.getTags());
|
||||
if (tagRelIdList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
idListGrouping.add(tagRelIdList);
|
||||
}
|
||||
// 获取收藏结果
|
||||
if (favoriteFuture != null) {
|
||||
List<Long> favorites = favoriteFuture.get();
|
||||
// 无收藏
|
||||
if (Lists.isEmpty(favorites)) {
|
||||
return null;
|
||||
}
|
||||
idListGrouping.add(favorites);
|
||||
}
|
||||
// flat
|
||||
List<Long> idList = null;
|
||||
if (setIdList && !idListGrouping.isEmpty()) {
|
||||
idList = idListGrouping.get(0);
|
||||
// 交集
|
||||
for (int i = 1; i < idListGrouping.size(); i++) {
|
||||
idList.retainAll(idListGrouping.get(i));
|
||||
}
|
||||
if (idList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
wrapper.in(HostDO::getId, tagRelIdList);
|
||||
}
|
||||
// 基础条件
|
||||
String searchValue = request.getSearchValue();
|
||||
LambdaQueryWrapper<HostDO> wrapper = hostDAO.wrapper()
|
||||
.eq(HostDO::getId, request.getId())
|
||||
wrapper.eq(HostDO::getId, request.getId())
|
||||
.like(HostDO::getName, request.getName())
|
||||
.like(HostDO::getCode, request.getCode())
|
||||
.like(HostDO::getAddress, request.getAddress())
|
||||
@@ -287,9 +271,6 @@ public class HostServiceImpl implements HostService {
|
||||
.like(HostDO::getCode, searchValue).or()
|
||||
.like(HostDO::getAddress, searchValue)
|
||||
);
|
||||
if (setIdList) {
|
||||
wrapper.in(HostDO::getId, idList);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -299,61 +280,19 @@ public class HostServiceImpl implements HostService {
|
||||
* @param request request
|
||||
* @param hosts hosts
|
||||
*/
|
||||
@SneakyThrows
|
||||
private void setExtraInfo(HostQueryRequest request, List<HostVO> hosts) {
|
||||
if (hosts.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<Long> idList = hosts.stream().map(HostVO::getId).collect(Collectors.toList());
|
||||
// 查询额外信息
|
||||
Future<List<List<TagDTO>>> tagsFuture = null;
|
||||
Future<List<Long>> favoriteFuture = null;
|
||||
if (Booleans.isTrue(request.getExtra())) {
|
||||
// tag
|
||||
tagsFuture = tagRelApi.getRelTags(TagTypeEnum.HOST, idList);
|
||||
// 从缓存中读取 收藏
|
||||
List<Long> favorites = FAVORITE_HOLDER.get();
|
||||
if (favorites != null) {
|
||||
favoriteFuture = CompletableFuture.completedFuture(favorites);
|
||||
} else {
|
||||
favoriteFuture = favoriteApi.getFavoriteRelIdList(FavoriteTypeEnum.HOST, SecurityUtils.getLoginUserId());
|
||||
}
|
||||
}
|
||||
// 查询配置
|
||||
if (Booleans.isTrue(request.getConfig())) {
|
||||
// 配置分组
|
||||
Map<Long, List<HostConfigDO>> hostConfigGrouping = hostConfigDAO.getHostConfigByHostIdList(idList)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(HostConfigDO::getHostId));
|
||||
// 设置配置
|
||||
hosts.forEach(s -> {
|
||||
List<HostConfigDO> configs = hostConfigGrouping.get(s.getId());
|
||||
if (Lists.isEmpty(configs)) {
|
||||
return;
|
||||
}
|
||||
Map<String, HostConfigVO> configMap = configs.stream()
|
||||
.collect(Collectors.toMap(
|
||||
HostConfigDO::getType,
|
||||
HostConfigConvert.MAPPER::to,
|
||||
(v1, v2) -> v2
|
||||
));
|
||||
s.setConfigs(configMap);
|
||||
});
|
||||
}
|
||||
// 设置 tag 信息
|
||||
List<List<TagDTO>> tagList = null;
|
||||
if (tagsFuture != null && (tagList = tagsFuture.get()) != null) {
|
||||
// 查询 tag 信息
|
||||
if (Booleans.isTrue(request.getQueryTag())) {
|
||||
// 设置 tag 信息
|
||||
List<List<TagDTO>> tagList = tagRelApi.getRelTags(TagTypeEnum.HOST, idList);
|
||||
for (int i = 0; i < hosts.size(); i++) {
|
||||
hosts.get(i).setTags(tagList.get(i));
|
||||
}
|
||||
}
|
||||
// 设置收藏信息
|
||||
List<Long> favoriteIdList = null;
|
||||
if (favoriteFuture != null && (favoriteIdList = favoriteFuture.get()) != null) {
|
||||
for (HostVO host : hosts) {
|
||||
host.setFavorite(favoriteIdList.contains(host.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 数据分组关联 对外服务类
|
||||
@@ -20,26 +20,37 @@ public interface DataGroupRelApi {
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param dto dto
|
||||
* @param groupId groupId
|
||||
* @param relIdList relIdList
|
||||
*/
|
||||
void updateGroupRel(DataGroupRelUpdateDTO dto);
|
||||
void updateGroupRel(Long groupId, List<Long> relIdList);
|
||||
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param type type
|
||||
* @param groupIdList groupIdList
|
||||
* @param relId relId
|
||||
*/
|
||||
void updateGroupRel(DataGroupTypeEnum type, List<Long> groupIdList, Long relId);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
*
|
||||
* @param dto dto
|
||||
* @param groupId groupId
|
||||
* @param relId relId
|
||||
*/
|
||||
void addGroupRel(DataGroupRelCreateDTO dto);
|
||||
void addGroupRel(Long groupId, Long relId);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
* 批量添加关联
|
||||
*
|
||||
* @param list list
|
||||
*/
|
||||
void addGroupRel(List<DataGroupRelCreateDTO> list);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组关联
|
||||
* 通过 type 查询 relId 缓存
|
||||
* <p>
|
||||
* groupId - relId
|
||||
*
|
||||
@@ -49,13 +60,22 @@ public interface DataGroupRelApi {
|
||||
Map<Long, Set<Long>> getGroupRelList(DataGroupTypeEnum type);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组关联
|
||||
* 通过 groupId 查询 relId 缓存
|
||||
*
|
||||
* @param type type
|
||||
* @param groupId groupId
|
||||
* @return rows
|
||||
* @return relId
|
||||
*/
|
||||
Set<Long> getGroupRelList(DataGroupTypeEnum type, Long groupId);
|
||||
Set<Long> getGroupRelIdByGroupId(DataGroupTypeEnum type, Long groupId);
|
||||
|
||||
/**
|
||||
* 通过 relId 查询 groupId
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return groupId
|
||||
*/
|
||||
Future<Set<Long>> getGroupIdByRelIdAsync(DataGroupTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 删除数据分组关联
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.orion.ops.module.infra.api;
|
||||
import com.orion.ops.module.infra.enums.FavoriteTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 收藏 对外服务类
|
||||
@@ -21,7 +20,7 @@ public interface FavoriteApi {
|
||||
* @param userId userId
|
||||
* @return relIdList
|
||||
*/
|
||||
Future<List<Long>> getFavoriteRelIdList(FavoriteTypeEnum type, Long userId);
|
||||
List<Long> getFavoriteRelIdList(FavoriteTypeEnum type, Long userId);
|
||||
|
||||
/**
|
||||
* 通过 relId 删除收藏
|
||||
@@ -29,7 +28,7 @@ public interface FavoriteApi {
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
*/
|
||||
void deleteByRelId(FavoriteTypeEnum type, Long relId);
|
||||
void deleteByRelIdAsync(FavoriteTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 通过 relId 删除收藏
|
||||
@@ -37,6 +36,6 @@ public interface FavoriteApi {
|
||||
* @param type type
|
||||
* @param relIdList relIdList
|
||||
*/
|
||||
void deleteByRelIdList(FavoriteTypeEnum type, List<Long> relIdList);
|
||||
void deleteByRelIdListAsync(FavoriteTypeEnum type, List<Long> relIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface TagRelApi {
|
||||
* @param relId relId
|
||||
* @param tagIdList tagIdList
|
||||
*/
|
||||
void addTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList);
|
||||
void addTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList);
|
||||
|
||||
/**
|
||||
* 设置标签引用 先删除后新增
|
||||
@@ -31,7 +31,7 @@ public interface TagRelApi {
|
||||
* @param relId relId
|
||||
* @param tagIdList tagIdList
|
||||
*/
|
||||
void setTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList);
|
||||
void setTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
@@ -40,7 +40,7 @@ public interface TagRelApi {
|
||||
* @param relId relId
|
||||
* @return tag
|
||||
*/
|
||||
Future<List<TagDTO>> getRelTags(TagTypeEnum type, Long relId);
|
||||
Future<List<TagDTO>> getRelTagsAsync(TagTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 获取引用 tag
|
||||
@@ -49,7 +49,7 @@ public interface TagRelApi {
|
||||
* @param relIdList relIdList
|
||||
* @return tag
|
||||
*/
|
||||
Future<List<List<TagDTO>>> getRelTags(TagTypeEnum type, List<Long> relIdList);
|
||||
List<List<TagDTO>> getRelTags(TagTypeEnum type, List<Long> relIdList);
|
||||
|
||||
/**
|
||||
* 查询 tag 关联的所有 id
|
||||
@@ -73,7 +73,7 @@ public interface TagRelApi {
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
*/
|
||||
void deleteRelId(TagTypeEnum type, Long relId);
|
||||
void deleteRelIdAsync(TagTypeEnum type, Long relId);
|
||||
|
||||
/**
|
||||
* 通过 relIdList 删除
|
||||
@@ -81,6 +81,6 @@ public interface TagRelApi {
|
||||
* @param type type
|
||||
* @param relIdList relIdList
|
||||
*/
|
||||
void deleteRelIdList(TagTypeEnum type, List<Long> relIdList);
|
||||
void deleteRelIdListAsync(TagTypeEnum type, List<Long> relIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.orion.ops.module.infra.entity.dto.data;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据分组关联 更新请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-11-7 18:44
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "DataGroupRelUpdateDTO", description = "数据分组关联 更新请求对象")
|
||||
public class DataGroupRelUpdateDTO implements Serializable {
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "组id")
|
||||
private Long groupId;
|
||||
|
||||
@Schema(description = "引用id")
|
||||
private List<Long> relIdList;
|
||||
|
||||
}
|
||||
@@ -3,20 +3,22 @@ package com.orion.ops.module.infra.api.impl;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.module.infra.api.DataGroupRelApi;
|
||||
import com.orion.ops.module.infra.convert.DataGroupRelProviderConvert;
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupRelDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import com.orion.ops.module.infra.enums.DataGroupTypeEnum;
|
||||
import com.orion.ops.module.infra.service.DataGroupRelService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -34,17 +36,22 @@ public class DataGroupRelApiImpl implements DataGroupRelApi {
|
||||
private DataGroupRelService dataGroupRelService;
|
||||
|
||||
@Override
|
||||
public void updateGroupRel(DataGroupRelUpdateDTO dto) {
|
||||
Valid.valid(dto);
|
||||
DataGroupRelUpdateRequest request = DataGroupRelProviderConvert.MAPPER.toRequest(dto);
|
||||
dataGroupRelService.updateGroupRel(request);
|
||||
public void updateGroupRel(Long groupId, List<Long> relIdList) {
|
||||
Valid.notNull(groupId);
|
||||
dataGroupRelService.updateGroupRel(groupId, relIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroupRel(DataGroupRelCreateDTO dto) {
|
||||
Valid.valid(dto);
|
||||
DataGroupRelCreateRequest request = DataGroupRelProviderConvert.MAPPER.toRequest(dto);
|
||||
dataGroupRelService.addGroupRel(request);
|
||||
public void updateGroupRel(DataGroupTypeEnum type, List<Long> groupIdList, Long relId) {
|
||||
Valid.notNull(relId);
|
||||
dataGroupRelService.updateGroupRel(type.name(), groupIdList, relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGroupRel(Long groupId, Long relId) {
|
||||
Valid.notNull(groupId);
|
||||
Valid.notNull(relId);
|
||||
dataGroupRelService.addGroupRel(groupId, relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,13 +72,23 @@ public class DataGroupRelApiImpl implements DataGroupRelApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getGroupRelList(DataGroupTypeEnum type, Long groupId) {
|
||||
public Set<Long> getGroupRelIdByGroupId(DataGroupTypeEnum type, Long groupId) {
|
||||
List<DataGroupRelCacheDTO> rows = dataGroupRelService.getGroupRelListByCache(type.name(), groupId);
|
||||
return rows.stream()
|
||||
.map(DataGroupRelCacheDTO::getRelId)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<Set<Long>> getGroupIdByRelIdAsync(DataGroupTypeEnum type, Long relId) {
|
||||
Set<Long> groupIdList = dataGroupRelService.getGroupRelByRelId(type.name(), relId)
|
||||
.stream()
|
||||
.map(DataGroupRelDO::getGroupId)
|
||||
.collect(Collectors.toSet());
|
||||
return CompletableFuture.completedFuture(groupIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteByRelId(DataGroupTypeEnum type, Long relId) {
|
||||
return dataGroupRelService.deleteByRelId(type.name(), relId);
|
||||
|
||||
@@ -11,8 +11,6 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* 收藏 对外服务实现类
|
||||
@@ -31,27 +29,25 @@ public class FavoriteApiImpl implements FavoriteApi {
|
||||
private FavoriteDAO favoriteDAO;
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<List<Long>> getFavoriteRelIdList(FavoriteTypeEnum type, Long userId) {
|
||||
public List<Long> getFavoriteRelIdList(FavoriteTypeEnum type, Long userId) {
|
||||
Valid.allNotNull(type, userId);
|
||||
// 查询
|
||||
FavoriteQueryRequest request = new FavoriteQueryRequest();
|
||||
request.setType(type.name());
|
||||
request.setUserId(userId);
|
||||
List<Long> relIdList = favoriteService.getFavoriteRelIdList(request);
|
||||
return CompletableFuture.completedFuture(relIdList);
|
||||
return favoriteService.getFavoriteRelIdList(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteByRelId(FavoriteTypeEnum type, Long relId) {
|
||||
public void deleteByRelIdAsync(FavoriteTypeEnum type, Long relId) {
|
||||
Valid.allNotNull(type, relId);
|
||||
favoriteDAO.deleteFavoriteByRelId(type.name(), relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteByRelIdList(FavoriteTypeEnum type, List<Long> relIdList) {
|
||||
public void deleteByRelIdListAsync(FavoriteTypeEnum type, List<Long> relIdList) {
|
||||
Valid.notNull(type);
|
||||
Valid.notEmpty(relIdList);
|
||||
favoriteDAO.deleteFavoriteByRelIdList(type.name(), relIdList);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.infra.api.impl;
|
||||
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
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;
|
||||
@@ -30,31 +32,34 @@ public class TagRelApiImpl implements TagRelApi {
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void addTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList) {
|
||||
public void addTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList) {
|
||||
Valid.notNull(relId);
|
||||
if (Lists.isEmpty(tagIdList)) {
|
||||
return;
|
||||
}
|
||||
tagRelService.addTagRel(type.name(), relId, tagIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void setTagRel(TagTypeEnum type, Long relId, List<Long> tagIdList) {
|
||||
public void setTagRelAsync(TagTypeEnum type, Long relId, List<Long> tagIdList) {
|
||||
Valid.notNull(relId);
|
||||
tagRelService.setTagRel(type.name(), relId, tagIdList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<List<TagDTO>> getRelTags(TagTypeEnum type, Long relId) {
|
||||
public Future<List<TagDTO>> getRelTagsAsync(TagTypeEnum type, Long relId) {
|
||||
List<TagCacheDTO> values = tagRelService.getRelTags(type.name(), relId);
|
||||
return CompletableFuture.completedFuture(TagProviderConvert.MAPPER.toList(values));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<List<List<TagDTO>>> getRelTags(TagTypeEnum type, List<Long> relIdList) {
|
||||
List<List<TagDTO>> values = tagRelService.getRelTags(type.name(), relIdList)
|
||||
public List<List<TagDTO>> getRelTags(TagTypeEnum type, List<Long> relIdList) {
|
||||
return tagRelService.getRelTags(type.name(), relIdList)
|
||||
.stream()
|
||||
.map(TagProviderConvert.MAPPER::toList)
|
||||
.collect(Collectors.toList());
|
||||
return CompletableFuture.completedFuture(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,13 +74,13 @@ public class TagRelApiImpl implements TagRelApi {
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteRelId(TagTypeEnum type, Long relId) {
|
||||
public void deleteRelIdAsync(TagTypeEnum type, Long relId) {
|
||||
tagRelService.deleteRelId(type.name(), relId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteRelIdList(TagTypeEnum type, List<Long> relIdList) {
|
||||
public void deleteRelIdListAsync(TagTypeEnum type, List<Long> relIdList) {
|
||||
tagRelService.deleteRelIdList(type.name(), relIdList);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.orion.ops.module.infra.convert;
|
||||
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.data.DataGroupRelUpdateDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -23,8 +21,6 @@ public interface DataGroupRelProviderConvert {
|
||||
|
||||
DataGroupRelCreateRequest toRequest(DataGroupRelCreateDTO request);
|
||||
|
||||
DataGroupRelUpdateRequest toRequest(DataGroupRelUpdateDTO request);
|
||||
|
||||
List<DataGroupRelCreateRequest> toList(List<DataGroupRelCreateDTO> list);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.orion.ops.module.infra.service;
|
||||
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupRelDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,16 +18,27 @@ public interface DataGroupRelService {
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param request request
|
||||
* @param groupId groupId
|
||||
* @param relIdList relIdList
|
||||
*/
|
||||
void updateGroupRel(DataGroupRelUpdateRequest request);
|
||||
void updateGroupRel(Long groupId, List<Long> relIdList);
|
||||
|
||||
/**
|
||||
* 设置关联
|
||||
*
|
||||
* @param type type
|
||||
* @param groupIdList groupIdList
|
||||
* @param relId relId
|
||||
*/
|
||||
void updateGroupRel(String type, List<Long> groupIdList, Long relId);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
*
|
||||
* @param request request
|
||||
* @param groupId groupId
|
||||
* @param relId relId
|
||||
*/
|
||||
void addGroupRel(DataGroupRelCreateRequest request);
|
||||
void addGroupRel(Long groupId, Long relId);
|
||||
|
||||
/**
|
||||
* 添加关联
|
||||
@@ -37,7 +48,7 @@ public interface DataGroupRelService {
|
||||
void addGroupRel(List<DataGroupRelCreateRequest> list);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组关联
|
||||
* 通过 type 查询 relId 缓存
|
||||
*
|
||||
* @param type type
|
||||
* @return rows
|
||||
@@ -45,7 +56,7 @@ public interface DataGroupRelService {
|
||||
List<DataGroupRelCacheDTO> getGroupRelListByCache(String type);
|
||||
|
||||
/**
|
||||
* 通过缓存查询数据分组关联
|
||||
* 通过 groupId 查询 relId 缓存
|
||||
*
|
||||
* @param type type
|
||||
* @param groupId groupId
|
||||
@@ -53,6 +64,15 @@ public interface DataGroupRelService {
|
||||
*/
|
||||
List<DataGroupRelCacheDTO> getGroupRelListByCache(String type, Long groupId);
|
||||
|
||||
/**
|
||||
* 通过 relId 查询 groupRel
|
||||
*
|
||||
* @param type type
|
||||
* @param relId relId
|
||||
* @return rows
|
||||
*/
|
||||
List<DataGroupRelDO> getGroupRelByRelId(String type, Long relId);
|
||||
|
||||
/**
|
||||
* 删除数据分组关联
|
||||
*
|
||||
|
||||
@@ -40,7 +40,7 @@ public interface PreferenceService {
|
||||
* @param type type
|
||||
* @return 偏好
|
||||
*/
|
||||
Future<Map<String, Object>> getPreference(Long userId, PreferenceTypeEnum type);
|
||||
Future<Map<String, Object>> getPreferenceAsync(Long userId, PreferenceTypeEnum type);
|
||||
|
||||
/**
|
||||
* 删除用户偏好
|
||||
|
||||
@@ -43,6 +43,6 @@ public interface SystemUserRoleService {
|
||||
* @param roleCode roleCode
|
||||
* @param userIdList userIdList
|
||||
*/
|
||||
void asyncDeleteUserCacheRole(String roleCode, List<Long> userIdList);
|
||||
void deleteUserCacheRoleAsync(String roleCode, List<Long> userIdList);
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public interface SystemUserService {
|
||||
* @param id id
|
||||
* @param username username
|
||||
*/
|
||||
void deleteSystemUserRel(Long id, String username);
|
||||
void deleteSystemUserRelAsync(Long id, String username);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.orion.ops.module.infra.entity.domain.DataGroupDO;
|
||||
import com.orion.ops.module.infra.entity.domain.DataGroupRelDO;
|
||||
import com.orion.ops.module.infra.entity.dto.DataGroupRelCacheDTO;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelCreateRequest;
|
||||
import com.orion.ops.module.infra.entity.request.data.DataGroupRelUpdateRequest;
|
||||
import com.orion.ops.module.infra.service.DataGroupRelService;
|
||||
import com.orion.spring.SpringHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -25,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
@@ -49,14 +49,14 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGroupRel(DataGroupRelUpdateRequest request) {
|
||||
Long groupId = request.getGroupId();
|
||||
public void updateGroupRel(Long groupId, List<Long> relIdList) {
|
||||
Valid.notNull(groupId);
|
||||
// 查询分组
|
||||
DataGroupDO group = dataGroupDAO.selectById(groupId);
|
||||
Valid.notNull(group, ErrorMessage.GROUP_ABSENT);
|
||||
List<Long> relIdList = request.getRelIdList();
|
||||
String type = group.getType();
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, group.getName());
|
||||
OperatorLogs.add(OperatorLogs.GROUP_NAME, group.getName());
|
||||
if (Lists.isEmpty(relIdList)) {
|
||||
// 为空删除
|
||||
dataGroupRelDAO.deleteByGroupId(groupId);
|
||||
@@ -84,21 +84,44 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
List<DataGroupRelDO> insertRecords = relIdList.stream()
|
||||
.map(s -> DataGroupRelDO.builder()
|
||||
.groupId(groupId)
|
||||
.type(group.getType())
|
||||
.type(type)
|
||||
.relId(s)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
dataGroupRelDAO.insertBatch(insertRecords);
|
||||
}
|
||||
}
|
||||
// 删除缓存
|
||||
this.deleteCache(type, Lists.of(groupId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addGroupRel(DataGroupRelCreateRequest request) {
|
||||
public void updateGroupRel(String type, List<Long> groupIdList, Long relId) {
|
||||
Valid.notNull(relId);
|
||||
// 删除引用
|
||||
this.deleteByRelId(type, relId);
|
||||
// 插入引用
|
||||
if (!Lists.isEmpty(groupIdList)) {
|
||||
List<DataGroupRelDO> relList = groupIdList.stream()
|
||||
.map(s -> DataGroupRelDO.builder()
|
||||
.type(type)
|
||||
.groupId(s)
|
||||
.relId(relId)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
dataGroupRelDAO.insertBatch(relList);
|
||||
// 删除缓存
|
||||
this.deleteCache(type, groupIdList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addGroupRel(Long groupId, Long relId) {
|
||||
DataGroupRelCreateRequest record = DataGroupRelCreateRequest.builder()
|
||||
.groupId(Valid.notNull(request.getGroupId()))
|
||||
.relId(Valid.notNull(request.getRelId()))
|
||||
.groupId(Valid.notNull(groupId))
|
||||
.relId(Valid.notNull(relId))
|
||||
.build();
|
||||
// 插入
|
||||
SpringHolder.getBean(DataGroupRelService.class)
|
||||
@@ -117,8 +140,7 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
// 查询分组信息
|
||||
List<DataGroupDO> groups = dataGroupDAO.selectBatchIds(groupMapping.keySet());
|
||||
Valid.eq(groups.size(), groupMapping.size(), ErrorMessage.GROUP_ABSENT);
|
||||
Map<Long, String> groupTypeMapping = groups.stream()
|
||||
.collect(Collectors.toMap(DataGroupDO::getId, DataGroupDO::getType));
|
||||
String type = groups.get(0).getType();
|
||||
// 查询关联是否存在
|
||||
groupMapping.forEach((k, v) -> {
|
||||
List<Long> relIdList = v.stream()
|
||||
@@ -144,23 +166,14 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
groupMapping.forEach((k, v) -> {
|
||||
v.forEach(s -> records.add(DataGroupRelDO.builder()
|
||||
.groupId(k)
|
||||
.type(groupTypeMapping.get(k))
|
||||
.type(type)
|
||||
.relId(s.getRelId())
|
||||
.build()));
|
||||
});
|
||||
// 插入
|
||||
dataGroupRelDAO.insertBatch(records);
|
||||
// 删除缓存
|
||||
List<String> groupKeyList = groups.stream()
|
||||
.map(DataGroupDO::getId)
|
||||
.map(DataGroupCacheKeyDefine.DATA_GROUP_REL_GROUP::format)
|
||||
.collect(Collectors.toList());
|
||||
groups.stream()
|
||||
.map(DataGroupDO::getType)
|
||||
.distinct()
|
||||
.map(DataGroupCacheKeyDefine.DATA_GROUP_REL_TYPE::format)
|
||||
.forEach(groupKeyList::add);
|
||||
RedisStrings.delete(groupKeyList);
|
||||
this.deleteCache(type, groupMapping.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -190,6 +203,16 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataGroupRelDO> getGroupRelByRelId(String type, Long relId) {
|
||||
return dataGroupRelDAO.of()
|
||||
.createWrapper()
|
||||
.eq(DataGroupRelDO::getType, type)
|
||||
.eq(DataGroupRelDO::getRelId, relId)
|
||||
.then()
|
||||
.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分组引用缓存
|
||||
*
|
||||
@@ -245,13 +268,8 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
.collect(Collectors.toList());
|
||||
// 删除数据库
|
||||
int effect = dataGroupRelDAO.deleteBatchIds(relIdList);
|
||||
// 获取缓存 key
|
||||
List<String> keyList = Lists.of(DataGroupCacheKeyDefine.DATA_GROUP_REL_TYPE.format(type));
|
||||
groupIdList.stream()
|
||||
.map(DataGroupCacheKeyDefine.DATA_GROUP_REL_GROUP::format)
|
||||
.forEach(keyList::add);
|
||||
// 删除缓存
|
||||
RedisStrings.delete(keyList);
|
||||
this.deleteCache(type, groupIdList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@@ -261,13 +279,27 @@ public class DataGroupRelServiceImpl implements DataGroupRelService {
|
||||
// 删除数据库
|
||||
int effect = dataGroupRelDAO.deleteByGroupId(groupIdList);
|
||||
// 删除缓存
|
||||
List<String> keyList = Lists.of(DataGroupCacheKeyDefine.DATA_GROUP_REL_TYPE.format(type));
|
||||
groupIdList.stream()
|
||||
.map(DataGroupCacheKeyDefine.DATA_GROUP_REL_GROUP::format)
|
||||
.forEach(keyList::add);
|
||||
// 删除缓存
|
||||
RedisStrings.delete(keyList);
|
||||
this.deleteCache(type, groupIdList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
*
|
||||
* @param type type
|
||||
* @param groupIdList groupIdList
|
||||
*/
|
||||
private void deleteCache(String type, Collection<Long> groupIdList) {
|
||||
// 类型缓存
|
||||
List<String> keyList = Lists.of(DataGroupCacheKeyDefine.DATA_GROUP_REL_TYPE.format(type));
|
||||
// 分组缓存
|
||||
if (!Lists.isEmpty(groupIdList)) {
|
||||
groupIdList.stream()
|
||||
.map(DataGroupCacheKeyDefine.DATA_GROUP_REL_GROUP::format)
|
||||
.forEach(keyList::add);
|
||||
}
|
||||
// 删除
|
||||
RedisStrings.delete(keyList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ public class DataGroupServiceImpl implements DataGroupService {
|
||||
RedisStrings.delete(DataGroupCacheKeyDefine.DATA_GROUP_LIST.format(type),
|
||||
DataGroupCacheKeyDefine.DATA_GROUP_TREE.format(type));
|
||||
// 添加日志参数
|
||||
OperatorLogs.add(OperatorLogs.NAME, record.getName());
|
||||
OperatorLogs.add(OperatorLogs.GROUP_NAME, record.getName());
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ public class PermissionServiceImpl implements PermissionService {
|
||||
UserCollectInfoVO user = SystemUserConvert.MAPPER.toCollectInfo(SecurityUtils.getLoginUser());
|
||||
Long id = user.getId();
|
||||
// 获取用户系统偏好
|
||||
Future<Map<String, Object>> systemPreference = preferenceService.getPreference(id, PreferenceTypeEnum.SYSTEM);
|
||||
Future<Map<String, Object>> systemPreference = preferenceService.getPreferenceAsync(id, PreferenceTypeEnum.SYSTEM);
|
||||
// 获取用户角色
|
||||
List<String> roles = this.getUserEnabledRoles();
|
||||
// 获取用户权限
|
||||
|
||||
@@ -90,7 +90,7 @@ public class PreferenceServiceImpl implements PreferenceService {
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public Future<Map<String, Object>> getPreference(Long userId, PreferenceTypeEnum type) {
|
||||
public Future<Map<String, Object>> getPreferenceAsync(Long userId, PreferenceTypeEnum type) {
|
||||
Map<String, Object> config = this.getPreferenceByCache(userId, type);
|
||||
return CompletableFuture.completedFuture(config);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class SystemRoleServiceImpl implements SystemRoleService {
|
||||
// 删除菜单缓存
|
||||
permissionService.getRoleMenuCache().remove(code);
|
||||
// 删除用户缓存中的角色
|
||||
systemUserRoleService.asyncDeleteUserCacheRole(code, userIdList);
|
||||
systemUserRoleService.deleteUserCacheRoleAsync(code, userIdList);
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public class SystemUserRoleServiceImpl implements SystemUserRoleService {
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void asyncDeleteUserCacheRole(String roleCode, List<Long> userIdList) {
|
||||
public void deleteUserCacheRoleAsync(String roleCode, List<Long> userIdList) {
|
||||
for (Long userId : userIdList) {
|
||||
RedisStrings.<LoginUser>processSetJson(UserCacheKeyDefine.USER_INFO, s -> {
|
||||
List<String> roles = s.getRoles();
|
||||
|
||||
@@ -211,13 +211,13 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
int effect = systemUserDAO.deleteById(id);
|
||||
log.info("SystemUserService-deleteSystemUserById id: {}, effect: {}", id, effect);
|
||||
// 异步删除额外信息
|
||||
SpringHolder.getBean(SystemUserService.class).deleteSystemUserRel(id, record.getUsername());
|
||||
SpringHolder.getBean(SystemUserService.class).deleteSystemUserRelAsync(id, record.getUsername());
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("asyncExecutor")
|
||||
public void deleteSystemUserRel(Long id, String username) {
|
||||
public void deleteSystemUserRelAsync(Long id, String username) {
|
||||
log.info("SystemUserService-deleteSystemUserRel id: {}", id);
|
||||
// 删除用户列表缓存
|
||||
RedisMaps.delete(UserCacheKeyDefine.USER_LIST, id);
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface HostCreateRequest {
|
||||
code?: string;
|
||||
address?: string;
|
||||
tags?: Array<number>;
|
||||
groupIdList?: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,8 +31,7 @@ export interface HostQueryRequest extends Pagination {
|
||||
address?: string;
|
||||
favorite?: boolean;
|
||||
tags?: Array<number>;
|
||||
extra?: boolean;
|
||||
config?: boolean;
|
||||
queryTag?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,9 +46,10 @@ export interface HostQueryResponse extends TableData {
|
||||
updateTime: number;
|
||||
creator: string;
|
||||
updater: string;
|
||||
// FIXME 删除
|
||||
favorite: boolean;
|
||||
tags: Record<number, string>;
|
||||
configs: Record<string, HostConfigQueryResponse>;
|
||||
tags: Array<{ id: number, name: string }>;
|
||||
groupIdList: Array<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +91,8 @@ export function updateHost(request: HostUpdateRequest) {
|
||||
/**
|
||||
* 通过 id 查询主机
|
||||
*/
|
||||
export function getHost(params: HostQueryRequest) {
|
||||
return axios.get<HostQueryResponse>('/asset/host/get', { params });
|
||||
export function getHost(id: number) {
|
||||
return axios.get<HostQueryResponse>('/asset/host/get', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</template>
|
||||
</a-alert>
|
||||
<!-- 保存按钮 -->
|
||||
<a-button v-permission="['asset:host-group:update-rel']"
|
||||
<a-button v-permission="['asset:host:update']"
|
||||
class="save-button"
|
||||
type="primary"
|
||||
:disabled="!group.key"
|
||||
|
||||
@@ -59,9 +59,10 @@
|
||||
import useLoading from '@/hooks/loading';
|
||||
import useVisible from '@/hooks/visible';
|
||||
import formRules from '../types/host.form.rules';
|
||||
import { createHost, updateHost } from '@/api/asset/host';
|
||||
import { createHost, getHost, updateHost } from '@/api/asset/host';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import TagMultiSelector from '@/components/meta/tag/tag-multi-selector.vue';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
const { visible, setVisible } = useVisible();
|
||||
const { loading, setLoading } = useLoading();
|
||||
@@ -76,6 +77,7 @@
|
||||
code: undefined,
|
||||
address: undefined,
|
||||
tags: undefined,
|
||||
groupIdList: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -93,12 +95,29 @@
|
||||
};
|
||||
|
||||
// 打开修改
|
||||
const openUpdate = (record: any) => {
|
||||
const openUpdate = async (id: number) => {
|
||||
title.value = '修改主机';
|
||||
isAddHandle.value = false;
|
||||
const tags = record?.hostTags?.map((s: { id: any; }) => s.id);
|
||||
renderForm({ ...defaultForm(), ...record, tags });
|
||||
renderForm({ ...defaultForm() });
|
||||
setVisible(true);
|
||||
await fetchHostRender(id);
|
||||
};
|
||||
|
||||
// 渲染主机
|
||||
const fetchHostRender = async (id: number) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data } = await getHost(id);
|
||||
const detail = Object.assign({} as Record<string, any>,
|
||||
pick(data, 'id', 'name', 'code', 'address', 'groupIdList'));
|
||||
// tag
|
||||
const tags = (data.tags || []).map(s => s.id);
|
||||
// 渲染
|
||||
renderForm({ ...detail, tags });
|
||||
} catch (e) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染表单
|
||||
|
||||
Reference in New Issue
Block a user