123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package com.ruoyi.app.controller;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.ruoyi.app.annotation.LoginAppUser;
- import com.ruoyi.app.controller.base.AppBaseController;
- import com.ruoyi.app.domain.*;
- import com.ruoyi.app.domain.vo.AppMemberVo;
- import com.ruoyi.app.service.ITbFamilyMemberService;
- import com.ruoyi.app.service.ITbFamilyService;
- import com.ruoyi.app.service.ITbMyPublishService;
- import com.ruoyi.app.service.ITbPublishCommentService;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.utils.StringUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.Date;
- import java.util.List;
- /**
- * 评论
- *
- * @author Alex
- * @date 2020-10-09
- */
- @Api(value = "评论管理", tags = "评论管理")
- @RequiredArgsConstructor(onConstructor_ = @Autowired)
- @RestController
- @RequestMapping("/app/comment")
- public class PublishCommentController extends AppBaseController {
- private final ITbPublishCommentService commentService;
- private final ITbMyPublishService publishService;
- private final ITbFamilyService familyService;
- private final ITbFamilyMemberService memberService;
- /**
- * 添加评论
- *
- * @param comment
- * @return
- */
- @ApiOperation("添加评论")
- @GetMapping("/add")
- public AjaxResult addComment(TbPublishComment comment) {
- if (comment.getPublishId() == null || comment.getAppUserId() == null) {
- return AjaxResult.error("参数为空");
- }
- if (StringUtils.isBlank(comment.getContents())) {
- return AjaxResult.error("评论内容不能为空");
- }
- AppMemberVo user = getLoginUser().getUser();
- comment.setCreateBy(user.getUserId().toString());
- comment.setCreateTime(new Date());
- if (commentService.save(comment)) {
- Long familyId = null;
- // 获取登录人所在的家族id
- TbFamilyMember member = memberService.getOne(new LambdaQueryWrapper<TbFamilyMember>()
- .eq(TbFamilyMember::getAppUserId,user.getUserId())
- .last("limit 1")
- );
- if (member != null) {
- TbFamily family = familyService.myFamily(member.getId());
- if (family != null) {
- familyId = family.getId();
- }
- }
- // 获取登录人的所有好友和所在家族的所有族友的id
- List<Long> fids = publishService.getMyFrientIds(user.getUserId(),familyId);
- //返回评论列表
- List<TbPublishComment> list = commentService.selectList(new LambdaQueryWrapper<TbPublishComment>()
- .eq(TbPublishComment::getPublishId, comment.getPublishId())
- .in(fids.size() > 0,TbPublishComment::getAppUserId, fids)
- );
- return AjaxResult.success(list);
- }
- return AjaxResult.error("评论失败");
- }
- }
|