|
@@ -46,6 +46,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
private final CommunityNewsMapper communityNewsMapper;
|
|
private final CommunityNewsMapper communityNewsMapper;
|
|
private final ICommunityNewsService communityNewsService;
|
|
private final ICommunityNewsService communityNewsService;
|
|
private final CommentIndexMapper commentIndexMapper;
|
|
private final CommentIndexMapper commentIndexMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询社区资讯点赞
|
|
* 查询社区资讯点赞
|
|
*
|
|
*
|
|
@@ -53,7 +54,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
* @return 社区资讯点赞
|
|
* @return 社区资讯点赞
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public CommentLikesVo queryById(Long likesId){
|
|
|
|
|
|
+ public CommentLikesVo queryById(Long likesId) {
|
|
return baseMapper.selectVoById(likesId);
|
|
return baseMapper.selectVoById(likesId);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -129,7 +130,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
/**
|
|
/**
|
|
* 保存前的数据校验
|
|
* 保存前的数据校验
|
|
*/
|
|
*/
|
|
- private void validEntityBeforeSave(CommentLikes entity){
|
|
|
|
|
|
+ private void validEntityBeforeSave(CommentLikes entity) {
|
|
//TODO 做一些数据校验,如唯一约束
|
|
//TODO 做一些数据校验,如唯一约束
|
|
}
|
|
}
|
|
|
|
|
|
@@ -142,7 +143,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
- if(isValid){
|
|
|
|
|
|
+ if (isValid) {
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
}
|
|
}
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
@@ -155,12 +156,14 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
* //文章需要统计点赞的数量和当前登录用户是否已经点赞
|
|
* //文章需要统计点赞的数量和当前登录用户是否已经点赞
|
|
* //点赞之前应该去查一遍该文章或者回复的点赞key,value应该是点赞的人员id判断用户是否已经点赞过了,点赞过了就取消,没点赞过就加入
|
|
* //点赞之前应该去查一遍该文章或者回复的点赞key,value应该是点赞的人员id判断用户是否已经点赞过了,点赞过了就取消,没点赞过就加入
|
|
* //还需要同步到数据库,需要一个完整的点赞key 一个设置过期时间的监听key
|
|
* //还需要同步到数据库,需要一个完整的点赞key 一个设置过期时间的监听key
|
|
|
|
+ * redis配置文件中增加 notify-keyspace-events Ex
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public R<Void> giveTheThumbs(CommentLikes commentLikes) {
|
|
public R<Void> giveTheThumbs(CommentLikes commentLikes) {
|
|
String targetType = commentLikes.getTargetType();
|
|
String targetType = commentLikes.getTargetType();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long userId = commentLikes.getUserId();
|
|
Long userId = commentLikes.getUserId();
|
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
//保存点赞信息
|
|
//保存点赞信息
|
|
//根据点赞目标id' 点赞目标类型(1:资讯 2:回复) 用户id查询是否已经点赞过
|
|
//根据点赞目标id' 点赞目标类型(1:资讯 2:回复) 用户id查询是否已经点赞过
|
|
CommentLikes commentLikesOld = baseMapper.selectCommentLikes(commentLikes);
|
|
CommentLikes commentLikesOld = baseMapper.selectCommentLikes(commentLikes);
|
|
@@ -174,20 +177,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
setCommentInteractionVo(commentLikes);
|
|
setCommentInteractionVo(commentLikes);
|
|
if (ONE.equals(targetType)) {
|
|
if (ONE.equals(targetType)) {
|
|
// 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
// 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
|
|
//文章永久点赞的数量key
|
|
//文章永久点赞的数量key
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
//该用户点赞文章的key
|
|
//该用户点赞文章的key
|
|
- String myLikeOneKey = ONE_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
|
|
|
|
- if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
|
|
|
+ String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
|
|
|
|
+ if (userIdListValue != null && !userIdListValue.isEmpty()) {
|
|
//说明该文章被点过赞
|
|
//说明该文章被点过赞
|
|
//判断该用户是否点过赞
|
|
//判断该用户是否点过赞
|
|
- if (userIdListValue.contains(userId)) {
|
|
|
|
|
|
+ if (userIdListValue.contains(Math.toIntExact(userId))) {
|
|
//进行取消点赞
|
|
//进行取消点赞
|
|
return unLike(commentLikes);
|
|
return unLike(commentLikes);
|
|
} else {
|
|
} else {
|
|
@@ -197,12 +200,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
} else {
|
|
} else {
|
|
//该文章没有被点过赞直接新增
|
|
//该文章没有被点过赞直接新增
|
|
userIdListValue = new ArrayList<>();
|
|
userIdListValue = new ArrayList<>();
|
|
- userIdListValue.add(userId);
|
|
|
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
RedisUtils.setCacheList(likeOneKey, userIdListValue);
|
|
RedisUtils.setCacheList(likeOneKey, userIdListValue);
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间 key=like_one_count_time:{文章id}#{数量}
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间 key=like_one_count_time:{文章id}#{数量}
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
|
|
//给该用户点赞文章的key添加值
|
|
//给该用户点赞文章的key添加值
|
|
- communityIdList.add(targetId);
|
|
|
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
//给该文章永久点赞数量的key添加值
|
|
//给该文章永久点赞数量的key添加值
|
|
RedisUtils.setCacheObject(likeOneCountKey, 1);
|
|
RedisUtils.setCacheObject(likeOneCountKey, 1);
|
|
@@ -211,20 +214,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
} else {
|
|
} else {
|
|
//对回复进行点赞
|
|
//对回复进行点赞
|
|
// 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
// 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
//社区资讯回复点赞的数量数据库同步的key
|
|
//社区资讯回复点赞的数量数据库同步的key
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
//回复永久点赞的数量key
|
|
//回复永久点赞的数量key
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
//该用户点赞回复的key
|
|
//该用户点赞回复的key
|
|
- String myLikeTwoKey = TWO_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
|
|
|
|
- if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
|
|
|
+ String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
|
|
|
|
+ if (userIdListValue != null && !userIdListValue.isEmpty()) {
|
|
//说明该回复被点过赞
|
|
//说明该回复被点过赞
|
|
//判断该用户是否点过赞
|
|
//判断该用户是否点过赞
|
|
- if (userIdListValue.contains(userId)) {
|
|
|
|
|
|
+ if (userIdListValue.contains(Math.toIntExact(userId))) {
|
|
//进行取消点赞
|
|
//进行取消点赞
|
|
return unLike(commentLikes);
|
|
return unLike(commentLikes);
|
|
} else {
|
|
} else {
|
|
@@ -234,12 +237,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
} else {
|
|
} else {
|
|
//该回复没有被点过赞直接新增
|
|
//该回复没有被点过赞直接新增
|
|
userIdListValue = new ArrayList<>();
|
|
userIdListValue = new ArrayList<>();
|
|
- userIdListValue.add(userId);
|
|
|
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
|
|
//给该用户点赞回复的key添加值
|
|
//给该用户点赞回复的key添加值
|
|
- communityIdList.add(targetId);
|
|
|
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
//给该回复永久点赞数量的key添加值
|
|
//给该回复永久点赞数量的key添加值
|
|
RedisUtils.setCacheObject(likeTwoCountKey, 1);
|
|
RedisUtils.setCacheObject(likeTwoCountKey, 1);
|
|
@@ -260,60 +263,62 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
String targetType = commentLikes.getTargetType();
|
|
String targetType = commentLikes.getTargetType();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long userId = commentLikes.getUserId();
|
|
Long userId = commentLikes.getUserId();
|
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
if (ONE.equals(targetType)) {
|
|
if (ONE.equals(targetType)) {
|
|
// 社区资讯文章点赞的人员集合的key key = ONE_LIKE:{targetId} value = [userId,userId];
|
|
// 社区资讯文章点赞的人员集合的key key = ONE_LIKE:{targetId} value = [userId,userId];
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
//文章永久点赞的数量key
|
|
//文章永久点赞的数量key
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
//该用户点赞文章的key
|
|
//该用户点赞文章的key
|
|
- String myLikeOneKey = ONE_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
|
|
|
|
|
|
+ String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdList = RedisUtils.getCacheList(myLikeOneKey);
|
|
//新增点赞信息
|
|
//新增点赞信息
|
|
// 新增社区资讯文章点赞的人员集合
|
|
// 新增社区资讯文章点赞的人员集合
|
|
- userIdListValue.add(userId);
|
|
|
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
RedisUtils.setCacheList(likeOneKey, userIdListValue);
|
|
RedisUtils.setCacheList(likeOneKey, userIdListValue);
|
|
//新增该用户点赞文章
|
|
//新增该用户点赞文章
|
|
- communityIdList.add(targetId);
|
|
|
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
//新增文章永久点赞数量的key更新值
|
|
//新增文章永久点赞数量的key更新值
|
|
Integer likeOneCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
Integer likeOneCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
likeOneCount = likeOneCount + 1;
|
|
likeOneCount = likeOneCount + 1;
|
|
RedisUtils.setCacheObject(likeOneCountKey, likeOneCount);
|
|
RedisUtils.setCacheObject(likeOneCountKey, likeOneCount);
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofSeconds(10));
|
|
return R.ok();
|
|
return R.ok();
|
|
} else {
|
|
} else {
|
|
// 社区资讯文章回复的人员集合的key key = TWO_LIKE:{targetId} value = [userId,userId];
|
|
// 社区资讯文章回复的人员集合的key key = TWO_LIKE:{targetId} value = [userId,userId];
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
//社区资讯文章回复的数量数据库同步的key
|
|
//社区资讯文章回复的数量数据库同步的key
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
//文章永久回复的数量key
|
|
//文章永久回复的数量key
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
//该用户点赞回复的key
|
|
//该用户点赞回复的key
|
|
- String myLikeTwoKey = TWO_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
|
|
|
|
|
|
+ String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdList = RedisUtils.getCacheList(myLikeTwoKey);
|
|
//新增点赞信息
|
|
//新增点赞信息
|
|
// 新增社区资讯回复点赞的人员集合
|
|
// 新增社区资讯回复点赞的人员集合
|
|
- userIdListValue.add(userId);
|
|
|
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
//新增该用户点赞回复
|
|
//新增该用户点赞回复
|
|
- communityIdList.add(targetId);
|
|
|
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
//新增回复永久点赞数量的key更新值
|
|
//新增回复永久点赞数量的key更新值
|
|
Integer likeTwoCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
Integer likeTwoCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
likeTwoCount = likeTwoCount + 1;
|
|
likeTwoCount = likeTwoCount + 1;
|
|
RedisUtils.setCacheObject(likeTwoCountKey, likeTwoCount);
|
|
RedisUtils.setCacheObject(likeTwoCountKey, likeTwoCount);
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofSeconds(10));
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 用户取消点赞
|
|
* 用户取消点赞
|
|
*
|
|
*
|
|
@@ -325,18 +330,19 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
String targetType = commentLikes.getTargetType();
|
|
String targetType = commentLikes.getTargetType();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long targetId = commentLikes.getTargetId();
|
|
Long userId = commentLikes.getUserId();
|
|
Long userId = commentLikes.getUserId();
|
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
if (ONE.equals(targetType)) {
|
|
if (ONE.equals(targetType)) {
|
|
//文章永久点赞的数量key
|
|
//文章永久点赞的数量key
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
//社区资讯文章点赞的数量数据库同步的key
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
|
|
//-------------------------删除 社区资讯文章点赞的人员集合value中的userId
|
|
//-------------------------删除 社区资讯文章点赞的人员集合value中的userId
|
|
// key = ONE_LIKE:{targetId} value = [userId,userId];
|
|
// key = ONE_LIKE:{targetId} value = [userId,userId];
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
//先去查看key对应的value集合
|
|
//先去查看key对应的value集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
- userIdListValue.remove(userId);
|
|
|
|
- if (userIdListValue.size() == 0) {
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
+ userIdListValue.removeIf(s -> s == Math.toIntExact(userId));
|
|
|
|
+ if (userIdListValue.isEmpty()) {
|
|
RedisUtils.deleteObject(likeOneKey);
|
|
RedisUtils.deleteObject(likeOneKey);
|
|
} else {
|
|
} else {
|
|
RedisUtils.deleteObject(likeOneKey);
|
|
RedisUtils.deleteObject(likeOneKey);
|
|
@@ -345,10 +351,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
}
|
|
}
|
|
|
|
|
|
//-------------------------删除 该用户点赞文章value中的文章id
|
|
//-------------------------删除 该用户点赞文章value中的文章id
|
|
- String myLikeOneKey = ONE_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdListValue = RedisUtils.getCacheList(myLikeOneKey);
|
|
|
|
- communityIdListValue.remove(targetId);
|
|
|
|
- if (communityIdListValue.size() == 0) {
|
|
|
|
|
|
+ String myLikeOneKey = tenantId + ":" + ONE_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdListValue = RedisUtils.getCacheList(myLikeOneKey);
|
|
|
|
+ communityIdListValue.removeIf(s -> s == Math.toIntExact(targetId));
|
|
|
|
+ if (communityIdListValue.isEmpty()) {
|
|
RedisUtils.deleteObject(myLikeOneKey);
|
|
RedisUtils.deleteObject(myLikeOneKey);
|
|
} else {
|
|
} else {
|
|
RedisUtils.deleteObject(myLikeOneKey);
|
|
RedisUtils.deleteObject(myLikeOneKey);
|
|
@@ -358,23 +364,24 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
//先获取永久点赞数量的值
|
|
//先获取永久点赞数量的值
|
|
Integer likeCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
Integer likeCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
//更新永久点赞数量
|
|
//更新永久点赞数量
|
|
- RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount - 1,0));
|
|
|
|
|
|
+ likeCount = likeCount -1;
|
|
|
|
+ RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount, 0));
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
|
|
return R.ok();
|
|
return R.ok();
|
|
} else {
|
|
} else {
|
|
//评论的删除
|
|
//评论的删除
|
|
//评论永久点赞的数量key
|
|
//评论永久点赞的数量key
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
//社区资讯评论点赞的数量数据库同步的key
|
|
//社区资讯评论点赞的数量数据库同步的key
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
//-------------------------删除 社区资讯文章评论的人员集合value中的userId
|
|
//-------------------------删除 社区资讯文章评论的人员集合value中的userId
|
|
// key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
// key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
//先去查看key对应的value集合
|
|
//先去查看key对应的value集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
- userIdListValue.remove(userId);
|
|
|
|
- if (userIdListValue.size() == 0) {
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
+ userIdListValue.removeIf(s -> s == Math.toIntExact(userId));
|
|
|
|
+ if (userIdListValue.isEmpty()) {
|
|
RedisUtils.deleteObject(likeTwoKey);
|
|
RedisUtils.deleteObject(likeTwoKey);
|
|
} else {
|
|
} else {
|
|
RedisUtils.deleteObject(likeTwoKey);
|
|
RedisUtils.deleteObject(likeTwoKey);
|
|
@@ -382,10 +389,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
}
|
|
}
|
|
//-------------------------删除 该用户点赞评论value中的文章id
|
|
//-------------------------删除 该用户点赞评论value中的文章id
|
|
- String myLikeTwoKey = TWO_MY_LIKE + userId;
|
|
|
|
- List<Long> communityIdListValue = RedisUtils.getCacheList(myLikeTwoKey);
|
|
|
|
- communityIdListValue.remove(targetId);
|
|
|
|
- if (communityIdListValue.size() == 0) {
|
|
|
|
|
|
+ String myLikeTwoKey = tenantId + ":" + TWO_MY_LIKE + userId;
|
|
|
|
+ List<Integer> communityIdListValue = RedisUtils.getCacheList(myLikeTwoKey);
|
|
|
|
+ communityIdListValue.removeIf(s -> s == Math.toIntExact(targetId));
|
|
|
|
+ if (communityIdListValue.isEmpty()) {
|
|
RedisUtils.deleteObject(myLikeTwoKey);
|
|
RedisUtils.deleteObject(myLikeTwoKey);
|
|
} else {
|
|
} else {
|
|
RedisUtils.deleteObject(myLikeTwoKey);
|
|
RedisUtils.deleteObject(myLikeTwoKey);
|
|
@@ -395,9 +402,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
//先获取永久点赞数量的值
|
|
//先获取永久点赞数量的值
|
|
Integer likeCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
Integer likeCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
//更新永久点赞数量
|
|
//更新永久点赞数量
|
|
- RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount - 1,0));
|
|
|
|
|
|
+ likeCount = likeCount - 1;
|
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount, 0));
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
|
|
|
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -414,6 +422,8 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
|
|
CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
|
|
//先判断是资讯点赞还是回复点赞
|
|
//先判断是资讯点赞还是回复点赞
|
|
String targetType = commentLikes.getTargetType();
|
|
String targetType = commentLikes.getTargetType();
|
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
|
|
+ commentInteractionVo.setTenantId(tenantId);
|
|
commentInteractionVo.setTargetType(TWO);
|
|
commentInteractionVo.setTargetType(TWO);
|
|
commentInteractionVo.setType(ONE);
|
|
commentInteractionVo.setType(ONE);
|
|
if (ONE.equals(targetType)) {
|
|
if (ONE.equals(targetType)) {
|
|
@@ -423,13 +433,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
commentInteractionVo.setTargetUserId(communityNews.getUserId());
|
|
commentInteractionVo.setTargetUserId(communityNews.getUserId());
|
|
//-------------判断是点赞还是取消点赞-------------------
|
|
//-------------判断是点赞还是取消点赞-------------------
|
|
// 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
// 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
- if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
+ if (userIdListValue != null && !userIdListValue.isEmpty()) {
|
|
//说明该文章被点过赞
|
|
//说明该文章被点过赞
|
|
//判断该用户是否点过赞
|
|
//判断该用户是否点过赞
|
|
- if (userIdListValue.contains(userId)) {
|
|
|
|
|
|
+ if (userIdListValue.contains(Math.toIntExact(userId))) {
|
|
//设置取消点赞
|
|
//设置取消点赞
|
|
commentInteractionVo.setType(TWO);
|
|
commentInteractionVo.setType(TWO);
|
|
}
|
|
}
|
|
@@ -445,13 +455,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
|
|
|
//-------------判断是点赞还是取消点赞-------------------
|
|
//-------------判断是点赞还是取消点赞-------------------
|
|
// 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
// 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
//先去查看key对应的value集合 value = 点赞人员的id集合
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
- if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
+ if (userIdListValue != null && !userIdListValue.isEmpty()) {
|
|
//说明该回复被点过赞
|
|
//说明该回复被点过赞
|
|
//判断该用户是否点过赞
|
|
//判断该用户是否点过赞
|
|
- if (userIdListValue.contains(userId)) {
|
|
|
|
|
|
+ if (userIdListValue.contains(Math.toIntExact(userId))) {
|
|
//设置取消点赞
|
|
//设置取消点赞
|
|
commentInteractionVo.setType(TWO);
|
|
commentInteractionVo.setType(TWO);
|
|
}
|
|
}
|