diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 5015030..72cd4ff 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -177,9 +177,9 @@ public class CommentController extends BaseController { comment.setNickName(userLoginDto.getNickName()); comment.setAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); comment.setLocation(IpUtil.getIpLocation(getIpAddr(request))); - commentService.save(comment,userLoginDto); + Comment commentResp = commentService.save(comment,userLoginDto); - return Result.success(); + return Result.success(commentResp); } diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index f66c66d..f7d6965 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -51,7 +51,7 @@ public class CommentService { return commentDao.findById(id).get(); } - public void save(Comment comment, UserLoginDto userLoginDto) { + public Comment save(Comment comment, UserLoginDto userLoginDto) { comment.set_id(idWorker.nextId()+""); comment.setPublishTime(new Date()); comment.setThumbupCount(0); //点赞数 @@ -102,6 +102,7 @@ public class CommentService { } commentDao.save(comment); + return comment; } public void update (Comment comment) { @@ -152,7 +153,7 @@ public class CommentService { * 向被点赞者发消息 */ UserMessageDto userMessageDto = new UserMessageDto(); - userMessageDto.setType(MessageTypeEnum.COMMENT.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 + userMessageDto.setType(MessageTypeEnum.THUMB_UP.getType()); //消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 userMessageDto.setUserId(parentComment.getUserId()); userMessageDto.setContent(userLoginDto.getNickName()+" 点赞了你的评论"); userMessageDto.setTitle("您有新的点赞"); diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java index bcc3f2e..21290e6 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserMessageController.java @@ -18,7 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/userMessage") @@ -60,9 +62,9 @@ public class UserMessageController extends BaseController { } - @ApiOperation(value = "获取消息分页列表") - @GetMapping("/list/{page}/{size}") - public Result list(@PathVariable int page,@PathVariable int size,@RequestHeader(value = "Authorization", required = true) String authorization){ + @ApiOperation(value = "获取消息") + @GetMapping("/list") + public Result list(@RequestHeader(value = "Authorization", required = true) String authorization){ // List list = userMessageService.findByUserId(userId); //验证是否登录,并且拿到ID UserLoginDto userLoginDto = getUserLoginDto(authorization); @@ -70,8 +72,25 @@ public class UserMessageController extends BaseController { return Result.unauthorized(null); } String userId = userLoginDto.getUserId(); - Page pageList = userMessageService.findSearch(userId,page,size); - return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); + + Map map = new HashMap(); + map.put("comment",""); + map.put("follow",""); + map.put("thumbup",""); + + /** + * 消息类型 消息类型 1私信 ,2新赞,3新关注, 4新评论 5.系统消息 + */ + + UserMessage userMessageComment = userMessageService.findByUseridAndType(userId,MessageTypeEnum.COMMENT.getType());// 评论 + UserMessage userMessageFollow = userMessageService.findByUseridAndType(userId,MessageTypeEnum.FOLLOW.getType());// + UserMessage userMessageThumbup = userMessageService.findByUseridAndType(userId,MessageTypeEnum.THUMB_UP.getType());// + map.put("comment",userMessageComment); + map.put("follow",userMessageFollow); + map.put("thumbup",userMessageThumbup); +// Page pageList = userMessageService.findSearch(userId,page,size); +// return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); + return Result.success(map); } @ApiOperation(value = "更新消息状态为已读") diff --git a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java index cd3f9f2..f1993c6 100644 --- a/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java +++ b/luoo_user/src/main/java/com/luoo/user/dao/UserMessageDao.java @@ -15,5 +15,7 @@ public interface UserMessageDao extends MongoRepository { Page findByUserIdOrderBySendTimeDesc(String userId, Pageable pageable); + UserMessage findTopByUserIdAndTypeOrderBySendTimeDesc(String userId,int type); + } diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java index 5ec6e24..40e97d1 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserMessageService.java @@ -87,4 +87,8 @@ public class UserMessageService { BulkWriteResult result = bulkOps.execute(); } + + public UserMessage findByUseridAndType(String userId, int type) { + return userMessageDao.findTopByUserIdAndTypeOrderBySendTimeDesc(userId,type); + } }