|
@@ -46,6 +46,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
private final CommunityNewsMapper communityNewsMapper;
|
|
|
private final ICommunityNewsService communityNewsService;
|
|
|
private final CommentIndexMapper commentIndexMapper;
|
|
|
+
|
|
|
|
|
|
* 查询社区资讯点赞
|
|
|
*
|
|
@@ -53,7 +54,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
* @return 社区资讯点赞
|
|
|
*/
|
|
|
@Override
|
|
|
- public CommentLikesVo queryById(Long likesId){
|
|
|
+ public CommentLikesVo queryById(Long likesId) {
|
|
|
return baseMapper.selectVoById(likesId);
|
|
|
}
|
|
|
|
|
@@ -129,7 +130,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
|
|
|
* 保存前的数据校验
|
|
|
*/
|
|
|
- private void validEntityBeforeSave(CommentLikes entity){
|
|
|
+ private void validEntityBeforeSave(CommentLikes entity) {
|
|
|
|
|
|
}
|
|
|
|
|
@@ -142,7 +143,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
- if(isValid){
|
|
|
+ if (isValid) {
|
|
|
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
@@ -155,12 +156,14 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
*
|
|
|
*
|
|
|
*
|
|
|
+ * redis配置文件中增加 notify-keyspace-events Ex
|
|
|
*/
|
|
|
@Override
|
|
|
public R<Void> giveTheThumbs(CommentLikes commentLikes) {
|
|
|
String targetType = commentLikes.getTargetType();
|
|
|
Long targetId = commentLikes.getTargetId();
|
|
|
Long userId = commentLikes.getUserId();
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
|
|
|
|
|
|
|
CommentLikes commentLikesOld = baseMapper.selectCommentLikes(commentLikes);
|
|
@@ -174,20 +177,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
setCommentInteractionVo(commentLikes);
|
|
|
if (ONE.equals(targetType)) {
|
|
|
|
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
|
|
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
@@ -197,12 +200,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
} else {
|
|
|
|
|
|
userIdListValue = new ArrayList<>();
|
|
|
- userIdListValue.add(userId);
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
|
RedisUtils.setCacheList(likeOneKey, userIdListValue);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
|
|
|
|
|
|
- communityIdList.add(targetId);
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
|
|
|
|
RedisUtils.setCacheObject(likeOneCountKey, 1);
|
|
@@ -211,20 +214,20 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
} else {
|
|
|
|
|
|
|
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
|
|
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
@@ -234,12 +237,12 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
} else {
|
|
|
|
|
|
userIdListValue = new ArrayList<>();
|
|
|
- userIdListValue.add(userId);
|
|
|
+ userIdListValue.add(Math.toIntExact(userId));
|
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, Duration.ofSeconds(10));
|
|
|
|
|
|
- communityIdList.add(targetId);
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
|
|
|
|
RedisUtils.setCacheObject(likeTwoCountKey, 1);
|
|
@@ -260,60 +263,62 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
String targetType = commentLikes.getTargetType();
|
|
|
Long targetId = commentLikes.getTargetId();
|
|
|
Long userId = commentLikes.getUserId();
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
|
if (ONE.equals(targetType)) {
|
|
|
|
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
|
|
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT + targetId;
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeOneKey);
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
- communityIdList.add(targetId);
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
|
RedisUtils.setCacheList(myLikeOneKey, communityIdList);
|
|
|
|
|
|
Integer likeOneCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
|
likeOneCount = likeOneCount + 1;
|
|
|
RedisUtils.setCacheObject(likeOneCountKey, likeOneCount);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, Duration.ofSeconds(10));
|
|
|
return R.ok();
|
|
|
} else {
|
|
|
|
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
|
|
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
- List<Long> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
+ List<Integer> userIdListValue = RedisUtils.getCacheList(likeTwoKey);
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
- communityIdList.add(targetId);
|
|
|
+ communityIdList.add(Math.toIntExact(targetId));
|
|
|
RedisUtils.setCacheList(myLikeTwoKey, communityIdList);
|
|
|
|
|
|
Integer likeTwoCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
|
likeTwoCount = likeTwoCount + 1;
|
|
|
RedisUtils.setCacheObject(likeTwoCountKey, likeTwoCount);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, Duration.ofSeconds(10));
|
|
|
return R.ok();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
|
|
|
* 用户取消点赞
|
|
|
*
|
|
@@ -325,18 +330,19 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
String targetType = commentLikes.getTargetType();
|
|
|
Long targetId = commentLikes.getTargetId();
|
|
|
Long userId = commentLikes.getUserId();
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
|
if (ONE.equals(targetType)) {
|
|
|
|
|
|
- String likeOneCountKey = ONE_LIKE_COUNT + targetId;
|
|
|
+ String likeOneCountKey = tenantId + ":" + ONE_LIKE_COUNT + targetId;
|
|
|
|
|
|
- String likeOneCountTimeKey = ONE_LIKE_COUNT_TIME + targetId;
|
|
|
+ String likeOneCountTimeKey = tenantId + ":" + ONE_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
|
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
|
RedisUtils.deleteObject(likeOneKey);
|
|
@@ -345,10 +351,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
|
RedisUtils.deleteObject(myLikeOneKey);
|
|
@@ -358,23 +364,24 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
|
|
|
Integer likeCount = RedisUtils.getCacheObject(likeOneCountKey);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount - 1,0));
|
|
|
+ likeCount = likeCount -1;
|
|
|
+ RedisUtils.setCacheObject(likeOneCountKey, Math.max(likeCount, 0));
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
|
|
|
return R.ok();
|
|
|
} else {
|
|
|
|
|
|
|
|
|
- String likeTwoCountKey = TWO_LIKE_COUNT + targetId;
|
|
|
+ String likeTwoCountKey = tenantId + ":" + TWO_LIKE_COUNT + targetId;
|
|
|
|
|
|
- String likeTwoCountTimeKey = TWO_LIKE_COUNT_TIME + targetId;
|
|
|
+ String likeTwoCountTimeKey = tenantId + ":" + TWO_LIKE_COUNT_TIME + targetId;
|
|
|
|
|
|
|
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
|
RedisUtils.deleteObject(likeTwoKey);
|
|
@@ -382,10 +389,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
RedisUtils.setCacheList(likeTwoKey, userIdListValue);
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
} else {
|
|
|
RedisUtils.deleteObject(myLikeTwoKey);
|
|
@@ -395,9 +402,10 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
|
|
|
Integer likeCount = RedisUtils.getCacheObject(likeTwoCountKey);
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount - 1,0));
|
|
|
+ likeCount = likeCount - 1;
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountKey, Math.max(likeCount, 0));
|
|
|
|
|
|
- RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofMinutes(1));
|
|
|
+ RedisUtils.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, Duration.ofSeconds(10));
|
|
|
return R.ok();
|
|
|
}
|
|
|
}
|
|
@@ -414,6 +422,8 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
|
|
|
|
|
|
String targetType = commentLikes.getTargetType();
|
|
|
+ String tenantId = commentLikes.getTenantId();
|
|
|
+ commentInteractionVo.setTenantId(tenantId);
|
|
|
commentInteractionVo.setTargetType(TWO);
|
|
|
commentInteractionVo.setType(ONE);
|
|
|
if (ONE.equals(targetType)) {
|
|
@@ -423,13 +433,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
commentInteractionVo.setTargetUserId(communityNews.getUserId());
|
|
|
|
|
|
|
|
|
- String likeOneKey = ONE_LIKE + targetId;
|
|
|
+ String likeOneKey = tenantId + ":" + ONE_LIKE + targetId;
|
|
|
|
|
|
- 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);
|
|
|
}
|
|
@@ -445,13 +455,13 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
|
|
|
|
|
|
|
|
|
- String likeTwoKey = TWO_LIKE + targetId;
|
|
|
+ String likeTwoKey = tenantId + ":" + TWO_LIKE + targetId;
|
|
|
|
|
|
- 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);
|
|
|
}
|