Commit 67864f98 authored by 刘基明's avatar 刘基明

圈子消息通知-评论

parent 4fd648e9
...@@ -13,12 +13,12 @@ import java.util.TreeSet; ...@@ -13,12 +13,12 @@ import java.util.TreeSet;
@NoArgsConstructor @NoArgsConstructor
public class NotificationLikeDO { public class NotificationLikeDO {
private Integer count; private Integer count=0;
private TreeSet<String> set; private TreeSet<String> set=new TreeSet<>();
public void addItem(String item){ public void addItem(String item) {
if (this.set.size()>=3){ if (this.set.size() >= 3) {
set.pollFirst(); set.pollFirst();
} }
set.add(item); set.add(item);
......
...@@ -10,14 +10,17 @@ import com.tanpu.community.api.beans.req.comment.CreateCommentReq; ...@@ -10,14 +10,17 @@ import com.tanpu.community.api.beans.req.comment.CreateCommentReq;
import com.tanpu.community.api.beans.req.comment.LikeCommentReq; import com.tanpu.community.api.beans.req.comment.LikeCommentReq;
import com.tanpu.community.api.beans.req.comment.ReportCommentReq; import com.tanpu.community.api.beans.req.comment.ReportCommentReq;
import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp; import com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp;
import com.tanpu.community.api.enums.NotificationTypeEnum;
import com.tanpu.community.api.enums.OperationTypeEnum; import com.tanpu.community.api.enums.OperationTypeEnum;
import com.tanpu.community.cache.RedisCache; import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.dao.entity.community.CommentEntity; import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.feign.fatools.FeignClientForFatools; import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.service.CollectionService; import com.tanpu.community.service.CollectionService;
import com.tanpu.community.service.CommentService; import com.tanpu.community.service.CommentService;
import com.tanpu.community.service.NotificationService; import com.tanpu.community.service.NotificationService;
import com.tanpu.community.service.ReportLogService; import com.tanpu.community.service.ReportLogService;
import com.tanpu.community.service.ThemeService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -51,7 +54,11 @@ public class CommentManager { ...@@ -51,7 +54,11 @@ public class CommentManager {
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
@Autowired
private NotificationService notificationService;
@Autowired
private ThemeService themeService;
// 评论(对主题) // 评论(对主题)
// 发表评论(对主题) // 发表评论(对主题)
...@@ -79,6 +86,10 @@ public class CommentManager { ...@@ -79,6 +86,10 @@ public class CommentManager {
commentService.insertComment(commentEntity); commentService.insertComment(commentEntity);
CommentQo commentQo = ConvertUtil.commentEntity2Qo(commentEntity); CommentQo commentQo = ConvertUtil.commentEntity2Qo(commentEntity);
buildUserInfo(commentQo); buildUserInfo(commentQo);
// 消息通知
ThemeEntity themeEntity = themeService.queryByThemeId(req.getThemeId());
notificationService.insert(userId,themeEntity.getAuthorId(), NotificationTypeEnum.COMMENT,req.getThemeId(),req.getComment());
return commentQo; return commentQo;
} }
......
...@@ -27,11 +27,13 @@ import com.tanpu.community.feign.fatools.FeignClientForFatools; ...@@ -27,11 +27,13 @@ import com.tanpu.community.feign.fatools.FeignClientForFatools;
import com.tanpu.community.feign.product.FeignForFund; import com.tanpu.community.feign.product.FeignForFund;
import com.tanpu.community.feign.product.FeignForPublicFund; import com.tanpu.community.feign.product.FeignForPublicFund;
import com.tanpu.community.service.FollowRelService; import com.tanpu.community.service.FollowRelService;
import com.tanpu.community.service.NotificationService;
import com.tanpu.community.util.ConvertUtil; import com.tanpu.community.util.ConvertUtil;
import com.tanpu.community.util.PageUtils; import com.tanpu.community.util.PageUtils;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -61,6 +63,9 @@ public class HomePageManager { ...@@ -61,6 +63,9 @@ public class HomePageManager {
@Resource @Resource
private RedisCache redisCache; private RedisCache redisCache;
@Autowired
private NotificationService notificationService;
//查询 个人中心 相关信息 //查询 个人中心 相关信息
public UserInfoResp queryUsersInfo(String userIdMyself, String userId) { public UserInfoResp queryUsersInfo(String userIdMyself, String userId) {
CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUserInfoNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself); CommonResp<UserInfoResp> queryUsersListNew = feignClientForFatools.queryUserInfoNew(StringUtils.isNotBlank(userId) ? userId : userIdMyself);
...@@ -227,7 +232,9 @@ public class HomePageManager { ...@@ -227,7 +232,9 @@ public class HomePageManager {
public void addFollowRel(FollowRelReq req, String followerId) { public void addFollowRel(FollowRelReq req, String followerId) {
if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) { if (OperationTypeEnum.CONFIRM.getCode().equals(req.getType())) {
followRelService.addFollowRel(req.getFollowUserId(), followerId); if(followRelService.addFollowRel(req.getFollowUserId(), followerId)){
notificationService.insert(followerId,req.getFollowUserId(),NotificationTypeEnum.FOLLOW,req.getFollowUserId(),null);
}
} else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) { } else if (OperationTypeEnum.CANCEL.getCode().equals(req.getType())) {
followRelService.deleteFollowRel(req.getFollowUserId(), followerId); followRelService.deleteFollowRel(req.getFollowUserId(), followerId);
} }
......
...@@ -135,9 +135,9 @@ public class ThemeManager { ...@@ -135,9 +135,9 @@ public class ThemeManager {
@Resource @Resource
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Autowired @Autowired
private NotificationService notificationService; private NotificationService notificationService;
@PostConstruct @PostConstruct
public void init() throws IOException { public void init() throws IOException {
File f = new File(tmpDir); File f = new File(tmpDir);
......
...@@ -77,7 +77,7 @@ public class FollowRelService { ...@@ -77,7 +77,7 @@ public class FollowRelService {
} }
@Transactional @Transactional
public void addFollowRel(String idolId, String followerId) { public boolean addFollowRel(String idolId, String followerId) {
FollowRelEntity searchResult = queryRecord(idolId, followerId); FollowRelEntity searchResult = queryRecord(idolId, followerId);
if (searchResult == null) { if (searchResult == null) {
FollowRelEntity entity = FollowRelEntity.builder() FollowRelEntity entity = FollowRelEntity.builder()
...@@ -87,10 +87,12 @@ public class FollowRelService { ...@@ -87,10 +87,12 @@ public class FollowRelService {
.build(); .build();
followRelMapper.insert(entity); followRelMapper.insert(entity);
return true;
} else { } else {
searchResult.setFollowTime(LocalDateTime.now()); searchResult.setFollowTime(LocalDateTime.now());
searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode()); searchResult.setDeleteTag(DeleteTagEnum.NOT_DELETED.getCode());
followRelMapper.updateById(searchResult); followRelMapper.updateById(searchResult);
return false;
} }
} }
......
...@@ -10,9 +10,11 @@ import com.tanpu.community.dao.entity.community.NotificationEntity; ...@@ -10,9 +10,11 @@ import com.tanpu.community.dao.entity.community.NotificationEntity;
import com.tanpu.community.dao.mapper.community.NotificationMapper; import com.tanpu.community.dao.mapper.community.NotificationMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.TreeSet;
@Service @Service
public class NotificationService { public class NotificationService {
...@@ -23,6 +25,7 @@ public class NotificationService { ...@@ -23,6 +25,7 @@ public class NotificationService {
@Autowired @Autowired
private UuidGenHelper uuidGenHelper; private UuidGenHelper uuidGenHelper;
@Transactional
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.builder().operatorId(operatorId) NotificationEntity.builder().operatorId(operatorId)
.notificationId(uuidGenHelper.getUuidStr()) .notificationId(uuidGenHelper.getUuidStr())
...@@ -30,10 +33,9 @@ public class NotificationService { ...@@ -30,10 +33,9 @@ public class NotificationService {
.messageType(type.getCode()) .messageType(type.getCode())
.content(content) .content(content)
.operatorId(targetId).build(); .operatorId(targetId).build();
} }
@Transactional
public void insertForward(String operatorId,String notifierId,String themeId,String topicId,String text){ public void insertForward(String operatorId,String notifierId,String themeId,String topicId,String text){
NotificationForwardDO forwardDO = NotificationForwardDO.builder().topicId(topicId).content(text).build(); NotificationForwardDO forwardDO = NotificationForwardDO.builder().topicId(topicId).content(text).build();
NotificationEntity.builder().operatorId(operatorId) NotificationEntity.builder().operatorId(operatorId)
...@@ -48,7 +50,7 @@ public class NotificationService { ...@@ -48,7 +50,7 @@ public class NotificationService {
} }
@Transactional
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>() NotificationEntity entity = notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
.eq(NotificationEntity::getMessageType, NotificationTypeEnum.LIKE.getCode()) .eq(NotificationEntity::getMessageType, NotificationTypeEnum.LIKE.getCode())
...@@ -56,6 +58,7 @@ public class NotificationService { ...@@ -56,6 +58,7 @@ public class NotificationService {
if (entity!=null){ if (entity!=null){
NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class); NotificationLikeDO notificationLikeDO = JsonUtil.toBean(entity.getContent(), NotificationLikeDO.class);
notificationLikeDO.addItem(operatorId); notificationLikeDO.addItem(operatorId);
entity.setContent(JsonUtil.toJson(notificationLikeDO)); entity.setContent(JsonUtil.toJson(notificationLikeDO));
notificationMapper.updateById(entity); notificationMapper.updateById(entity);
}else { }else {
...@@ -70,16 +73,10 @@ public class NotificationService { ...@@ -70,16 +73,10 @@ public class NotificationService {
.operatorId(operatorId) .operatorId(operatorId)
.build(); .build();
} }
} }
public void insert(NotificationEntity entity){
notificationMapper.insert(entity);
}
public NotificationEntity queryById(String notificationId){ public NotificationEntity queryById(String notificationId){
return notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>() return notificationMapper.selectOne(new LambdaQueryWrapper<NotificationEntity>()
......
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