|
@@ -4,13 +4,20 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.system.domain.communityNews.CommentIndex;
|
|
|
import com.ruoyi.system.domain.communityNews.CommentLikes;
|
|
|
+import com.ruoyi.system.domain.communityNews.CommunityNews;
|
|
|
+import com.ruoyi.system.domain.communityNews.vo.CommentInteractionVo;
|
|
|
+import com.ruoyi.system.mapper.CommentIndexMapper;
|
|
|
import com.ruoyi.system.mapper.CommentLikesMapper;
|
|
|
+import com.ruoyi.system.mapper.CommunityNewsMapper;
|
|
|
import com.ruoyi.system.service.ICommentLikesService;
|
|
|
+import com.ruoyi.system.service.ICommunityNewsService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -27,10 +34,17 @@ import static com.ruoyi.common.constant.Constants.*;
|
|
|
public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
@Autowired
|
|
|
private CommentLikesMapper commentLikesMapper;
|
|
|
+ @Autowired
|
|
|
+ private CommentIndexMapper commentIndexMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ICommunityNewsService iCommunityNewsService;
|
|
|
+ @Resource
|
|
|
+ private CommunityNewsMapper communityNewsMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询社区资讯点赞
|
|
|
*
|
|
@@ -116,13 +130,15 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
//保存点赞信息
|
|
|
//根据点赞目标id' 点赞目标类型(1:资讯 2:回复) 用户id查询是否已经点赞过
|
|
|
CommentLikes commentLikesOld = commentLikesMapper.selectCommentLikes(commentLikes);
|
|
|
- if (commentLikesOld != null){
|
|
|
+ if (commentLikesOld != null) {
|
|
|
commentLikesOld.setDelFlag("Y");
|
|
|
commentLikesMapper.updateCommentLikes(commentLikesOld);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
commentLikesMapper.insertCommentLikes(commentLikes);
|
|
|
}
|
|
|
if (StringUtils.isNotBlank(targetType)) {
|
|
|
+ //设置未读点赞互动的方法
|
|
|
+ setCommentInteractionVo(commentLikes);
|
|
|
if (ONE.equals(targetType)) {
|
|
|
// 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
|
String likeOneKey = ONE_LIKE + targetId;
|
|
@@ -151,7 +167,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
userIdListValue.add(userId);
|
|
|
redisCache.setCacheList(likeOneKey, userIdListValue);
|
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间 key=like_one_count_time:{文章id}#{数量}
|
|
|
- redisCache.setCacheObject(likeOneCountTimeKey+"#"+1, 1, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeOneCountTimeKey + "#" + 1, 1, 1, TimeUnit.MINUTES);
|
|
|
//给该用户点赞文章的key添加值
|
|
|
communityIdList.add(targetId);
|
|
|
redisCache.setCacheList(myLikeOneKey, communityIdList);
|
|
@@ -188,7 +204,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
userIdListValue.add(userId);
|
|
|
redisCache.setCacheList(likeTwoKey, userIdListValue);
|
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
|
- redisCache.setCacheObject(likeTwoCountTimeKey+"#"+1, 1, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeTwoCountTimeKey + "#" + 1, 1, 1, TimeUnit.MINUTES);
|
|
|
//给该用户点赞回复的key添加值
|
|
|
communityIdList.add(targetId);
|
|
|
redisCache.setCacheList(myLikeTwoKey, communityIdList);
|
|
@@ -235,7 +251,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
likeOneCount = likeOneCount + 1;
|
|
|
redisCache.setCacheObject(likeOneCountKey, likeOneCount);
|
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
|
- redisCache.setCacheObject(likeOneCountTimeKey+"#"+likeOneCount, likeOneCount, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeOneCountTimeKey + "#" + likeOneCount, likeOneCount, 1, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success();
|
|
|
} else {
|
|
|
// 社区资讯文章回复的人员集合的key key = TWO_LIKE:{targetId} value = [userId,userId];
|
|
@@ -261,7 +277,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
likeTwoCount = likeTwoCount + 1;
|
|
|
redisCache.setCacheObject(likeTwoCountKey, likeTwoCount);
|
|
|
//新增数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
|
- redisCache.setCacheObject(likeTwoCountTimeKey+"#"+likeTwoCount, likeTwoCount, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeTwoCountTimeKey + "#" + likeTwoCount, likeTwoCount, 1, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
}
|
|
@@ -288,9 +304,9 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
//先去查看key对应的value集合
|
|
|
List<Long> userIdListValue = redisCache.getCacheList(likeOneKey);
|
|
|
userIdListValue.remove(userId);
|
|
|
- if (userIdListValue.size() == 0){
|
|
|
+ if (userIdListValue.size() == 0) {
|
|
|
redisCache.deleteObject(likeOneKey);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
redisCache.deleteObject(likeOneKey);
|
|
|
// 社区资讯文章点赞的人员集合中删除该用户
|
|
|
redisCache.setCacheList(likeOneKey, userIdListValue);
|
|
@@ -300,9 +316,9 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
String myLikeOneKey = ONE_MY_LIKE + userId;
|
|
|
List<Long> communityIdListValue = redisCache.getCacheList(myLikeOneKey);
|
|
|
communityIdListValue.remove(targetId);
|
|
|
- if (communityIdListValue.size() == 0){
|
|
|
+ if (communityIdListValue.size() == 0) {
|
|
|
redisCache.deleteObject(myLikeOneKey);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
redisCache.deleteObject(myLikeOneKey);
|
|
|
redisCache.setCacheList(myLikeOneKey, communityIdListValue);
|
|
|
}
|
|
@@ -316,7 +332,7 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
//更新永久点赞数量
|
|
|
redisCache.setCacheObject(likeOneCountKey, likeCount);
|
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
|
- redisCache.setCacheObject(likeOneCountTimeKey+"#"+likeCount, likeCount, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeOneCountTimeKey + "#" + likeCount, likeCount, 1, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success();
|
|
|
} else {
|
|
|
//评论的删除
|
|
@@ -330,9 +346,9 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
//先去查看key对应的value集合
|
|
|
List<Long> userIdListValue = redisCache.getCacheList(likeTwoKey);
|
|
|
userIdListValue.remove(userId);
|
|
|
- if (userIdListValue.size() == 0){
|
|
|
+ if (userIdListValue.size() == 0) {
|
|
|
redisCache.deleteObject(likeTwoKey);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
redisCache.deleteObject(likeTwoKey);
|
|
|
// 社区资讯文章评论的人员集合中删除该用户
|
|
|
redisCache.setCacheList(likeTwoKey, userIdListValue);
|
|
@@ -341,9 +357,9 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
String myLikeTwoKey = TWO_MY_LIKE + userId;
|
|
|
List<Long> communityIdListValue = redisCache.getCacheList(myLikeTwoKey);
|
|
|
communityIdListValue.remove(targetId);
|
|
|
- if (communityIdListValue.size() == 0){
|
|
|
+ if (communityIdListValue.size() == 0) {
|
|
|
redisCache.deleteObject(myLikeTwoKey);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
redisCache.deleteObject(myLikeTwoKey);
|
|
|
redisCache.setCacheList(myLikeTwoKey, communityIdListValue);
|
|
|
}
|
|
@@ -357,8 +373,74 @@ public class CommentLikesServiceImpl implements ICommentLikesService {
|
|
|
//更新永久点赞数量
|
|
|
redisCache.setCacheObject(likeTwoCountKey, likeCount);
|
|
|
//给数据库同步数据在 redis中增加一个有过期时间的key 1分钟过期时间
|
|
|
- redisCache.setCacheObject(likeTwoCountTimeKey+"#"+likeCount, likeCount, 1, TimeUnit.MINUTES);
|
|
|
+ redisCache.setCacheObject(likeTwoCountTimeKey + "#" + likeCount, likeCount, 1, TimeUnit.MINUTES);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置未读点赞互动的方法
|
|
|
+ *
|
|
|
+ * @param commentLikes
|
|
|
+ */
|
|
|
+ public void setCommentInteractionVo(CommentLikes commentLikes) {
|
|
|
+ Long userId = commentLikes.getUserId();
|
|
|
+ Long targetId = commentLikes.getTargetId();
|
|
|
+ //------设置未读收藏,在redis中新增一条未读的互动--------
|
|
|
+ CommentInteractionVo commentInteractionVo = new CommentInteractionVo();
|
|
|
+ //先判断是资讯点赞还是回复点赞
|
|
|
+ String targetType = commentLikes.getTargetType();
|
|
|
+ commentInteractionVo.setTargetType(TWO);
|
|
|
+ commentInteractionVo.setType(ONE);
|
|
|
+ if (ONE.equals(targetType)) {
|
|
|
+ //说明是资讯点赞
|
|
|
+ //根据targetId获取该资讯的内容
|
|
|
+ CommunityNews communityNews = communityNewsMapper.selectCommunityNewsByCommunityId(targetId);
|
|
|
+ commentInteractionVo.setTargetUserId(communityNews.getUserId());
|
|
|
+ //-------------判断是点赞还是取消点赞-------------------
|
|
|
+ // 社区资讯文章点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
|
+ String likeOneKey = ONE_LIKE + targetId;
|
|
|
+ //先去查看key对应的value集合 value = 点赞人员的id集合
|
|
|
+ List<Long> userIdListValue = redisCache.getCacheList(likeOneKey);
|
|
|
+ if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
+ //说明该文章被点过赞
|
|
|
+ //判断该用户是否点过赞
|
|
|
+ if (userIdListValue.contains(userId)) {
|
|
|
+ //设置取消点赞
|
|
|
+ commentInteractionVo.setType(TWO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //-------------判断是点赞还是取消点赞结束-------------------
|
|
|
+ } else if (TWO.equals(targetType)) {
|
|
|
+ //说明是回复点赞
|
|
|
+ commentInteractionVo.setTargetType(FIV);
|
|
|
+ //根据targetId获取该评论的内容
|
|
|
+ CommentIndex commentIndex = commentIndexMapper.selectCommentIndexByCommentId(targetId);
|
|
|
+ commentInteractionVo.setTargetUserId(commentIndex.getUserId());
|
|
|
+ commentInteractionVo.setCommunityId(commentLikes.getCommunityId());
|
|
|
+
|
|
|
+ //-------------判断是点赞还是取消点赞-------------------
|
|
|
+ // 社区资讯回复点赞的人员集合的key key = LIKE_ONE:{targetId} value = [userId,userId];
|
|
|
+ String likeTwoKey = TWO_LIKE + targetId;
|
|
|
+ //先去查看key对应的value集合 value = 点赞人员的id集合
|
|
|
+ List<Long> userIdListValue = redisCache.getCacheList(likeTwoKey);
|
|
|
+ if (userIdListValue != null && userIdListValue.size() > 0) {
|
|
|
+ //说明该回复被点过赞
|
|
|
+ //判断该用户是否点过赞
|
|
|
+ if (userIdListValue.contains(userId)) {
|
|
|
+ //设置取消点赞
|
|
|
+ commentInteractionVo.setType(TWO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //-------------判断是点赞还是取消点赞-------------------
|
|
|
+ }
|
|
|
+ commentInteractionVo.setTargetTitle(commentLikes.getTargetTitle());
|
|
|
+ commentInteractionVo.setUserId(commentLikes.getUserId());
|
|
|
+ commentInteractionVo.setAvatar(commentLikes.getAvatar());
|
|
|
+ commentInteractionVo.setNickName(commentLikes.getNickName());
|
|
|
+ commentInteractionVo.setCreateTime(DateUtils.getNowDate());
|
|
|
+ commentInteractionVo.setTargetId(commentLikes.getTargetId());
|
|
|
+ iCommunityNewsService.setCommentInteraction(commentInteractionVo);
|
|
|
+ //----------------------设置未读互动完成--------
|
|
|
+ }
|
|
|
}
|