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

圈子消息通知-评论

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