PublishCommentController.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.ruoyi.app.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.ruoyi.app.annotation.LoginAppUser;
  4. import com.ruoyi.app.controller.base.AppBaseController;
  5. import com.ruoyi.app.domain.*;
  6. import com.ruoyi.app.domain.vo.AppMemberVo;
  7. import com.ruoyi.app.service.ITbFamilyMemberService;
  8. import com.ruoyi.app.service.ITbFamilyService;
  9. import com.ruoyi.app.service.ITbMyPublishService;
  10. import com.ruoyi.app.service.ITbPublishCommentService;
  11. import com.ruoyi.common.core.domain.AjaxResult;
  12. import com.ruoyi.common.utils.StringUtils;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.GetMapping;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.Date;
  21. import java.util.List;
  22. /**
  23. * 评论
  24. *
  25. * @author Alex
  26. * @date 2020-10-09
  27. */
  28. @Api(value = "评论管理", tags = "评论管理")
  29. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  30. @RestController
  31. @RequestMapping("/app/comment")
  32. public class PublishCommentController extends AppBaseController {
  33. private final ITbPublishCommentService commentService;
  34. private final ITbMyPublishService publishService;
  35. private final ITbFamilyService familyService;
  36. private final ITbFamilyMemberService memberService;
  37. /**
  38. * 添加评论
  39. *
  40. * @param comment
  41. * @return
  42. */
  43. @ApiOperation("添加评论")
  44. @GetMapping("/add")
  45. public AjaxResult addComment(TbPublishComment comment) {
  46. if (comment.getPublishId() == null || comment.getAppUserId() == null) {
  47. return AjaxResult.error("参数为空");
  48. }
  49. if (StringUtils.isBlank(comment.getContents())) {
  50. return AjaxResult.error("评论内容不能为空");
  51. }
  52. AppMemberVo user = getLoginUser().getUser();
  53. comment.setCreateBy(user.getUserId().toString());
  54. comment.setCreateTime(new Date());
  55. if (commentService.save(comment)) {
  56. Long familyId = null;
  57. // 获取登录人所在的家族id
  58. TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
  59. .eq(TbFamilyMember::getAppUserId,user.getUserId())
  60. .last("limit 1")
  61. );
  62. if (member != null) {
  63. TbFamily family = familyService.myFamily(member.getId());
  64. if (family != null) {
  65. familyId = family.getId();
  66. }
  67. }
  68. // 获取登录人的所有好友和所在家族的所有族友的id
  69. List<Long> fids = publishService.getMyFrientIds(user.getUserId(),familyId);
  70. //返回评论列表
  71. List<TbPublishComment> list = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
  72. .eq(TbPublishComment::getPublishId, comment.getPublishId())
  73. .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
  74. );
  75. return AjaxResult.success(list);
  76. }
  77. return AjaxResult.error("评论失败");
  78. }
  79. }