Ver código fonte

提交分享接口

zhaohingliang 3 meses atrás
pai
commit
bcff69681d

+ 261 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/ShareController.java

@@ -0,0 +1,261 @@
+package com.ruoyi.generator.controller;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.common.utils.*;
+import com.ruoyi.generator.domain.Community.*;
+import com.ruoyi.generator.mapper.community.*;
+import com.ruoyi.generator.service.*;
+import com.ruoyi.generator.vo.*;
+import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.service.impl.SysUserServiceImpl;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 分享
+ *
+ * @author zhl
+ */
+@Api(tags = "分享")
+@RestController
+@RequestMapping("/community/share")
+public class ShareController extends BaseController {
+    @Autowired
+    private ICommunityArticleService communityArticleService;
+
+    @Autowired
+    private ICommunityArticleCommentService communityArticleCommentService;
+
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private ICommunityCommentReplyService communityCommentReplyService;
+
+    @Autowired
+    private SysUserServiceImpl sysUserService;
+
+    @Autowired
+    private CommunityCommentLikeMapper communityCommentLikeMapper;
+
+    @Autowired
+    private ICommunityCollectionService communityCollectionService;
+
+    @Autowired
+    private ICommunityPrivacyService communityPrivacyService;
+
+    @Autowired
+    private ICommunityAccompanyService communityAccompanyService;
+
+    @ApiOperation("获取分享信息")
+    @GetMapping("/share")
+    @Anonymous
+    public AjaxResult shareInfo(@RequestParam(required = false) Long userId, String userName, CommunityArticle communityArticle
+            , String articleId, Long collectionId, Long searchTypeCollection) {
+
+        ShareInfoVo shareInfoVo = new ShareInfoVo();
+        // 获取用户信息
+        CommunityUserInfoVo communityUserInfoVo = null;
+        try {
+            communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(userId,false);
+            shareInfoVo.setUserInfoVo(communityUserInfoVo);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 获取关注列表
+        int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
+        int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
+        int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 0);
+        List<CommunityUserLikeVo> communityUserLikeVos = null;
+        try {
+            communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(userId, userName, pageNum, pageSize, searchType);
+            shareInfoVo.setCommunityUserLikeVos(communityUserLikeVos);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 获取文章列表detail页面
+        if (communityArticle.getId() != null || communityArticle.getClassIds() != null) {
+            try {
+                TableDataInfo rspData = new TableDataInfo();
+                communityArticle.setUserId(null);
+                List<CommunityArticleVo> list = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
+                shareInfoVo.setCommunityArticleVos(list);
+            } catch (Exception e) {
+                System.out.println(e.getMessage());
+            }
+        }
+
+        // 获取文章列表个人中心页面
+        try {
+            TableDataInfo rspData = new TableDataInfo();
+            List<CommunityArticleVo> listForDetail = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
+            shareInfoVo.setCommunityArticleVosForUserDetail(listForDetail);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+
+        // 获取文章评论
+        List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
+
+        try {
+            Page<CommunityArticleComment> page = new Page<>(1, 10);
+            List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>()
+                    .eq("article_id", articleId)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }).orderByDesc("create_time")).getRecords();
+
+            CommunityArticleCommentVo commentVo = null;
+
+            for (CommunityArticleComment record : records) {
+                if (record.getAddress() == null) {
+                    record.setAddress("未知");
+                }
+
+                commentVo = new CommunityArticleCommentVo();
+                BeanUtils.copyProperties(record, commentVo);
+                commentVos.add(commentVo);
+            }
+
+
+            List<Long> commentIds = new ArrayList<>();
+            for (CommunityArticleCommentVo vo : commentVos) {
+                Long commentUserId = vo.getUserId();
+                //获取评论的用户信息
+                SysUser sysUser = sysUserMapper.selectUserById(commentUserId);
+                vo.setNickName(sysUser.getNickName());
+                vo.setAvatar(sysUser.getAvatar());
+                //当前登录用户是否已点赞
+                List<CommunityCommentLike> commentLikes = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                        .eq("comment_id", vo.getId())
+                        .eq("user_id", userId));
+                vo.setCommentLike(!commentLikes.isEmpty());
+                //该评论的点赞数量
+                vo.setCommentLikeCount(communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                                .eq("comment_id", vo.getId()))
+                        .size());
+                //设置首条评论
+                List<CommunityCommentReply> replies = communityCommentReplyService.list(new QueryWrapper<CommunityCommentReply>()
+                        .eq("comment_id", vo.getId())
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true).or().isNull("is_delete");
+                        }).orderByAsc("create_time"));
+
+                //如果评价用户id与当前登录用户id相符,则标记为已读
+                if (vo.getUserId().equals(userId) && !vo.isRead()) {
+                    commentIds.add(vo.getId());
+                }
+
+                CommunityCommentReplyVo replyVo = null;
+                List<CommunityCommentReplyVo> replyVos = new ArrayList<>();
+                for (CommunityCommentReply reply : replies) {
+                    replyVo = new CommunityCommentReplyVo();
+                    BeanUtils.copyProperties(reply, replyVo);
+                    replyVo.setNickName(sysUserService.selectUserById(replyVo.getUserId()).getNickName());
+                    replyVo.setReply(true);
+                    replyVo.setAvatar(sysUserService.selectUserById(replyVo.getUserId()).getAvatar());
+                    replyVos.add(replyVo);
+                    //设置点赞数量和当前登录用户是否已点赞
+                    List<CommunityCommentLike> commentLikeList = communityCommentLikeMapper.selectList(new QueryWrapper<CommunityCommentLike>()
+                            .eq("reply_id", replyVo.getId()));
+                    replyVo.setLikeCount(commentLikeList.size());
+                    replyVo.setLike(commentLikeList.stream().anyMatch(item -> SecurityUtils.getUserId().equals(item.getUserId())));
+                    break;
+                }
+                vo.setFirstReply(replyVos);
+                //设置还剩多少评论
+                vo.setReplyCount(replies.isEmpty() ? 0 : replies.size() - 1);
+                vo.setReply(false);
+            }
+
+            //更新为已读
+            if (!commentIds.isEmpty()) {
+                communityArticleCommentService.update(new UpdateWrapper<CommunityArticleComment>().set("is_read", true).in("id", commentIds));
+            }
+            shareInfoVo.setCommunityArticleCommentVos(commentVos);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 个人陪伴信息
+        CommunityAccompany communityAccompany = null;
+        try {
+            communityAccompany = communityAccompanyService.selectCommunityAccompanyById(userId);
+            shareInfoVo.setCommunityAccompany(communityAccompany);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        // 查询用户合集
+        List<CommunityCollectionArticleVo> collectionArticleVos = null;
+        JSONArray jsonArray;
+        try {
+            jsonArray = communityCollectionService.selectArticleInfoInCollection(userId,collectionId, searchTypeCollection);
+            shareInfoVo.setCollection(jsonArray);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 所有合集
+        List<CommunityCollectionVo> communityCollectionVos = null;
+        try {
+            communityCollectionVos = communityCollectionService.selectUserCollection(userId, null, pageNum, pageSize, searchType);
+            shareInfoVo.setCommunityCollectionVos(communityCollectionVos);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 获取隐私权限
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = null;
+        try {
+            communityUserPrivacyVos = communityPrivacyService.selectUserPrivacy(userId);
+            shareInfoVo.setCommunityUserPrivacyVos(communityUserPrivacyVos);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 个人喜欢文章
+        List<CommunityArticleVo> communityArticleVosForPerson = null;
+        if (userId == null) {
+            userId = SecurityUtils.getUserId();
+        }
+        try {
+            communityArticleVosForPerson = communityArticleService.selectUserLike(userId, pageNum, pageSize, searchType);
+            shareInfoVo.setCommunityArticleVosForPerson(communityArticleVosForPerson);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        // 个人收藏文章
+        List<CommunityArticleVo> communityArticleVosForPersonCollect = null;
+        try {
+            if (userId == null) {
+                userId = SecurityUtils.getUserId();
+            }
+            communityArticleVosForPersonCollect = communityArticleService.selectUserCollect(userId, pageNum, pageSize, searchType);
+            shareInfoVo.setCommunityArticleVosForPersonCollect(communityArticleVosForPersonCollect);
+        } catch (Exception e) {
+            System.out.println(e.getMessage());
+        }
+
+        return AjaxResult.success(shareInfoVo);
+    }
+}

+ 1 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityArticleServiceImpl.java

@@ -289,7 +289,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                             }));
             if (communityCommentRaffle != null) {
                 BeanUtils.copyProperties(communityCommentRaffle, communityCommentRaffleVo);
-                CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(),true);
+                CommunityUserInfoVo communityUserInfoVo = communityArticleService.selectCommunityUserInfoById(communityCommentRaffle.getUserId(),false);
                 communityCommentRaffleVo.setUserName(communityUserInfoVo.getNickName());
                 communityCommentRaffleVo.setUserAvatar(communityUserInfoVo.getAvatar());
                 articleVo.setCommentRaffleVo(communityCommentRaffleVo);

+ 77 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/ShareInfoVo.java

@@ -0,0 +1,77 @@
+package com.ruoyi.generator.vo;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.ruoyi.generator.domain.Community.CommunityAccompany;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+*
+* @TableName community_user_info
+*/
+@Data
+public class ShareInfoVo implements Serializable {
+
+    /**
+    * 用户信息
+    */
+    private CommunityUserInfoVo userInfoVo;
+
+    /**
+     * 关注列表
+     */
+    private List<CommunityUserLikeVo> communityUserLikeVos;
+
+    /**
+     * 文章列表
+     */
+    private List<CommunityArticleVo> communityArticleVos;
+
+    /**
+     * 文章列表个人中心页面
+     */
+    private List<CommunityArticleVo> communityArticleVosForUserDetail;
+
+    /**
+     * 文章评论
+     */
+    private List<CommunityArticleCommentVo> communityArticleCommentVos;
+
+    /**
+     * 个人陪伴信息
+     */
+    private CommunityAccompany communityAccompany;
+
+    /**
+     * 合集
+     */
+    private JSONArray collection;
+
+    /**
+     * 所有合集
+     */
+    private List<CommunityCollectionVo> communityCollectionVos;
+
+    /**
+     * 隐私权
+     */
+    private List<CommunityUserPrivacyVo> communityUserPrivacyVos;
+
+    /**
+     * 个人喜欢文章
+     */
+    private List<CommunityArticleVo> communityArticleVosForPerson;
+
+    /**
+     * 个人喜欢文章
+     */
+    private List<CommunityArticleVo> communityArticleVosForPersonCollect;
+}