feat: 主机列表视图.

This commit is contained in:
lijiahang
2023-12-15 16:35:11 +08:00
parent 0cd8b3ae02
commit 59c8a7fd2f
14 changed files with 270 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.api;
import com.orion.ops.module.infra.enums.FavoriteTypeEnum;
import java.util.List;
import java.util.concurrent.Future;
/**
* 收藏 对外服务类
@@ -22,6 +23,15 @@ public interface FavoriteApi {
*/
List<Long> getFavoriteRelIdList(FavoriteTypeEnum type, Long userId);
/**
* 异步查询用户收藏
*
* @param type type
* @param userId userId
* @return relIdList
*/
Future<List<Long>> getFavoriteRelIdListAsync(FavoriteTypeEnum type, java.lang.Long userId);
/**
* 通过 relId 删除收藏
*

View File

@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
/**
* 收藏 对外服务实现类
@@ -38,6 +40,14 @@ public class FavoriteApiImpl implements FavoriteApi {
return favoriteService.getFavoriteRelIdList(request);
}
@Override
@Async("asyncExecutor")
public Future<List<Long>> getFavoriteRelIdListAsync(FavoriteTypeEnum type, Long userId) {
Valid.allNotNull(type, userId);
// 查询
return CompletableFuture.completedFuture(this.getFavoriteRelIdList(type, userId));
}
@Override
public void deleteByRelId(FavoriteTypeEnum type, Long relId) {
Valid.allNotNull(type, relId);

View File

@@ -46,16 +46,24 @@ public class FavoriteServiceImpl implements FavoriteService {
public Long addFavorite(FavoriteOperatorRequest request) {
String type = Valid.valid(FavoriteTypeEnum::of, request.getType()).name();
Long userId = SecurityUtils.getLoginUserId();
// 检查是否存在
FavoriteDO check = favoriteDAO.of()
.createWrapper()
.eq(FavoriteDO::getUserId, userId)
.eq(FavoriteDO::getType, request.getType())
.eq(FavoriteDO::getRelId, request.getRelId())
.then()
.getOne();
if (check != null) {
return check.getId();
}
// 转换
FavoriteDO record = FavoriteConvert.MAPPER.to(request);
record.setUserId(userId);
// 插入
int effect = favoriteDAO.insert(record);
// 设置缓存
String key = FavoriteCacheKeyDefine.FAVORITE.format(type, userId);
RedisLists.push(key, request.getRelId(), String::valueOf);
// 设置过期时间
RedisLists.setExpire(key, FavoriteCacheKeyDefine.FAVORITE);
// 删除缓存
RedisLists.delete(FavoriteCacheKeyDefine.FAVORITE.format(type, userId));
return record.getId();
}
@@ -67,8 +75,7 @@ public class FavoriteServiceImpl implements FavoriteService {
// 删除库
int effect = favoriteDAO.deleteFavorite(type, userId, relId);
// 删除缓存
String key = FavoriteCacheKeyDefine.FAVORITE.format(type, userId);
redisTemplate.opsForList().remove(key, 1, relId.toString());
RedisLists.delete(FavoriteCacheKeyDefine.FAVORITE.format(type, userId));
return effect;
}