Commit b551b892 authored by 刘基明's avatar 刘基明

消息通知添加themeId

parent 49f1f220
......@@ -63,7 +63,7 @@ public class NotificationController {
if (!"admin".equals(userHolder.getUserId())){
return CommonResp.failed("权限不足");
}
notificationManager.init();
notificationManager.initAllData();
return CommonResp.success();
}
......
......@@ -136,25 +136,25 @@ public class NotificationManager {
}
// 查询消息通知概览
public NotificationQo queryBriefInfo(String userId) {
String count = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + userId);
String lastMsg = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + userId);
String lastTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + userId);
return NotificationQo.builder().message(lastMsg).updateCount(count == null ? 0 : Integer.parseInt(count)).updateTime(lastTime).build();
}
// 初始化所有消息通知
public void init() {
public void initAllData() {
notificationService.truncate();
// 关注
List<FollowRelEntity> followRelEntities = followRelService.queryAll();
for (FollowRelEntity followRelEntity : followRelEntities) {
notificationService.insert(followRelEntity.getFansId(), followRelEntity.getIdolId(), NotificationTypeEnum.FOLLOW
, followRelEntity.getFansId(), "", followRelEntity.getUpdateTime());
notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId());
notificationService.putNotifyCacheFollow(followRelEntity.getIdolId(), followRelEntity.getFansId(),followRelEntity.getUpdateTime());
}
// 转发
List<ThemeEntity> themeEntities = themeService.queryAllForward();
......@@ -169,7 +169,7 @@ public class NotificationManager {
NotificationForwardDO content = NotificationForwardDO.builder().content(s.length() > 500 ? s.substring(0, 500) : s).topicId(themeEntity.getTopicId()).build();
notificationService.insert(themeEntity.getAuthorId(), former.getAuthorId(), NotificationTypeEnum.FORWARD
, themeEntity.getFormerThemeId(), JsonUtil.toJson(content), themeEntity.getUpdateTime());
notificationService.putNotifyCache(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD);
notificationService.putNotifyCache(former.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.FORWARD,themeEntity.getUpdateTime());
}
// 评论
List<CommentEntity> commentEntities = commentService.queryAll();
......@@ -181,7 +181,7 @@ public class NotificationManager {
String s = commentEntity.getContent();
notificationService.insert(commentEntity.getAuthorId(), themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT
, commentEntity.getThemeId(), s, commentEntity.getUpdateTime());
notificationService.putNotifyCache(themeEntity.getAuthorId(), commentEntity.getAuthorId(), NotificationTypeEnum.COMMENT);
notificationService.putNotifyCache(themeEntity.getAuthorId(), commentEntity.getAuthorId(), NotificationTypeEnum.COMMENT, commentEntity.getUpdateTime());
}
// 点赞
......@@ -192,7 +192,7 @@ public class NotificationManager {
continue;
}
notificationService.insertLike(collectionEntity.getUserId(), themeEntity.getAuthorId(), collectionEntity.getTargetId(), collectionEntity.getUpdateTime());
notificationService.putNotifyCache(themeEntity.getAuthorId(), collectionEntity.getUserId(), NotificationTypeEnum.LIKE);
notificationService.putNotifyCache(themeEntity.getAuthorId(), collectionEntity.getUserId(), NotificationTypeEnum.LIKE, collectionEntity.getUpdateTime());
}
}
......
......@@ -42,7 +42,7 @@ public class NotificationService {
private RedisCache redisCache;
public void insert(String operatorId,String notifierId,NotificationTypeEnum type,String targetId,String content){
public void insert(String operatorId, String notifierId, NotificationTypeEnum type, String targetId, String content) {
NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId)
.notificationId(uuidGenHelper.getUuidStr())
.notifiedUserId(notifierId)
......@@ -55,7 +55,7 @@ public class NotificationService {
}
public void insert(String operatorId, String notifierId, NotificationTypeEnum type, String targetId, String content
, LocalDateTime createTime){
, LocalDateTime createTime) {
NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId)
.notificationId(uuidGenHelper.getUuidStr())
.notifiedUserId(notifierId)
......@@ -70,7 +70,7 @@ public class NotificationService {
}
public void insertForward(String operatorId,String notifierId,String forwardThemeId,String topicId,String text,String themeId){
public void insertForward(String operatorId, String notifierId, String forwardThemeId, String topicId, String text, String themeId) {
NotificationForwardDO forwardDO = NotificationForwardDO.builder().topicId(topicId).content(text).themeId(themeId).build();
NotificationEntity entity = NotificationEntity.builder().operatorId(operatorId)
.notificationId(uuidGenHelper.getUuidStr())
......@@ -85,18 +85,18 @@ public class NotificationService {
}
public void insertLike(String operatorId,String notifierId,String targetId){
public void insertLike(String operatorId, String notifierId, String targetId) {
NotificationEntity entity = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.LIKE.getCode())
.eq(NotificationEntity::getTargetId,targetId)
.eq(NotificationEntity::getTargetId, targetId)
.eq(NotificationEntity::getNotifiedUserId, notifierId));
if (entity!=null){
if (entity != null) {
NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class);
notificationLikeDO.addItem(operatorId);
entity.setContent(JsonUtil.toJson(notificationLikeDO));
entity.setUpdateTime(LocalDateTime.now());
notificationMapper.updateById(entity);
}else {
} else {
NotificationLikeDO notificationLikeDO = new NotificationLikeDO();
notificationLikeDO.addItem(operatorId);
NotificationEntity build = NotificationEntity.builder().operatorId(operatorId)
......@@ -113,31 +113,31 @@ public class NotificationService {
}
@Transactional
public void insert(NotificationEntity entity){
public void insert(NotificationEntity entity) {
notificationMapper.insert(entity);
}
public NotificationEntity queryById(String notificationId){
public NotificationEntity queryById(String notificationId) {
return notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getNotificationId,notificationId));
.eq(NotificationEntity::getNotificationId, notificationId));
}
public List<NotificationEntity> query(String userId, Integer type, String lastId, Integer pageSize){
public List<NotificationEntity> query(String userId, Integer type, String lastId, Integer pageSize) {
LambdaQueryWrapper<NotificationEntity> queryWrapper = new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getNotifiedUserId, userId)
.orderByDesc(NotificationEntity::getUpdateTime)
.last("limit " + pageSize);
if (StringUtils.isNotBlank(lastId)){
if (StringUtils.isNotBlank(lastId)) {
NotificationEntity lastOne = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getNotificationId, lastId));
queryWrapper.lt(NotificationEntity::getUpdateTime, lastOne.getCreateTime());
}
if (!NotificationTypeEnum.ALL.getCode().equals(type)){
queryWrapper.eq(NotificationEntity::getMessageType,type);
if (!NotificationTypeEnum.ALL.getCode().equals(type)) {
queryWrapper.eq(NotificationEntity::getMessageType, type);
}
return notificationMapper.selectList(queryWrapper);
}
......@@ -148,19 +148,19 @@ public class NotificationService {
.eq(NotificationEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode()));
}
public void insertLike(String operatorId, String notifierId, String targetId, LocalDateTime updateTime){
public void insertLike(String operatorId, String notifierId, String targetId, LocalDateTime updateTime) {
NotificationEntity entity = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.LIKE.getCode())
.eq(NotificationEntity::getTargetId,targetId)
.eq(NotificationEntity::getTargetId, targetId)
.eq(NotificationEntity::getNotifiedUserId, notifierId));
if (entity!=null){
if (entity != null) {
NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class);
notificationLikeDO.addItem(operatorId);
entity.setContent(JsonUtil.toJson(notificationLikeDO));
entity.setUpdateTime(updateTime);
notificationMapper.updateById(entity);
}else {
} else {
NotificationLikeDO notificationLikeDO = new NotificationLikeDO();
notificationLikeDO.addItem(operatorId);
NotificationEntity build = NotificationEntity.builder().operatorId(operatorId)
......@@ -179,10 +179,10 @@ public class NotificationService {
}
// 消息通知队列缓存
public void putNotifyCache(String notifyUserId, String operatorId, NotificationTypeEnum type){
public void putNotifyCache(String notifyUserId, String operatorId, NotificationTypeEnum type) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName()+type.getType()+"了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + type.getType() + "了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
......@@ -203,4 +203,27 @@ public class NotificationService {
return userInfoNewCommonResp.getData();
}
// init用
public void putNotifyCache(String notifyUserId, String operatorId, NotificationTypeEnum type, LocalDateTime updateTime) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
String cacheTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId);
if (StringUtils.isBlank(cacheTime) || TimeUtils.lessThan(cacheTime, updateTime)) {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + type.getType() + "了你的内容", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
}
// init用
public void putNotifyCacheFollow(String notifyUserId, String operatorId, LocalDateTime updateTime) {
UserInfoResp userInfo = getUserInfo(operatorId);
redisCache.incr(RedisKeyConstant.MESSAGE_NOTIFY_COUNT + notifyUserId);
String cacheTime = redisCache.get(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId);
if (StringUtils.isBlank(cacheTime) || TimeUtils.lessThan(cacheTime, updateTime)) {
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_MSG + notifyUserId, userInfo.getNickName() + "关注了你", 60 * 60 * 24 * 30);
redisCache.set(RedisKeyConstant.MESSAGE_NOTIFY_LAST_TIME + notifyUserId, TimeUtils.format(LocalDateTime.now()), 60 * 60 * 24 * 30);
}
}
}
package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.common.uuid.UuidGenHelper;
import com.tanpu.community.api.enums.StatusEnum;
import com.tanpu.community.dao.entity.community.TopicEntity;
......@@ -44,36 +43,6 @@ public class TopicService {
public void updateTopicToTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotTop(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsTop(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicToConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(StatusEnum.TRUE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public void updateTopicNotConceal(String topicId) {
TopicEntity topicEntity = new TopicEntity();
topicEntity.setIsConceal(StatusEnum.FALSE.getCode());
topicMapper.update(topicEntity, new LambdaUpdateWrapper<TopicEntity>()
.eq(TopicEntity::getId, topicId));
}
public TopicEntity queryById(String topicId) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>()
.eq(TopicEntity::getTopicId, topicId)
......@@ -95,7 +64,4 @@ public class TopicService {
return topicMapper.selectList(new LambdaQueryWrapper<TopicEntity>().in(TopicEntity::getTopicId, topicIds));
}
public TopicEntity queryByTitile(String topicTitle) {
return topicMapper.selectOne(new LambdaQueryWrapper<TopicEntity>().eq(TopicEntity::getTopicTitle, topicTitle));
}
}
......@@ -42,6 +42,11 @@ public class TimeUtils {
return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
public static LocalDateTime reFormat(String time) {
return LocalDateTime.parse(time,DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
//计算迄今分钟
public static long calMinuteTillNow(LocalDateTime start) {
if (start==null){
......@@ -93,4 +98,8 @@ public class TimeUtils {
System.out.println(calUpToNowTime(LocalDateTime.now().minusSeconds(12)));
}
public static boolean lessThan(String cacheTime, LocalDateTime updateTime) {
if (calMillisTillNow(reFormat(cacheTime))<calMillisTillNow(updateTime)) return true;
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment