refactor: 规范化代码.

This commit is contained in:
lijiahang
2023-11-14 18:38:46 +08:00
parent 4202890d07
commit d4c21a2324
32 changed files with 309 additions and 301 deletions

View File

@@ -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);
/**
* 删除数据分组关联

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
/**
* 删除数据分组关联
*

View File

@@ -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);
/**
* 删除用户偏好

View File

@@ -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);
}

View File

@@ -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);
/**
* 重置密码

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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();
// 获取用户权限

View File

@@ -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);
}

View File

@@ -177,7 +177,7 @@ public class SystemRoleServiceImpl implements SystemRoleService {
// 删除菜单缓存
permissionService.getRoleMenuCache().remove(code);
// 删除用户缓存中的角色
systemUserRoleService.asyncDeleteUserCacheRole(code, userIdList);
systemUserRoleService.deleteUserCacheRoleAsync(code, userIdList);
return effect;
}

View File

@@ -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();

View File

@@ -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);