Browse Source

部分接口去除token验证, 获取分享数据

fangzhen 4 months ago
parent
commit
8b578d1f51

+ 0 - 6
ruoyi-common/pom.xml

@@ -170,12 +170,6 @@
             <artifactId>spring-boot-starter-test</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.sejda.imageio</groupId>
-            <artifactId>webp-imageio</artifactId>
-            <version>0.1.6</version>
-        </dependency>
-
     </dependencies>
 
 </project>

+ 31 - 14
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -4,11 +4,11 @@ import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.constant.HttpStatus;
 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.domain.model.LoginUser;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.exception.user.ProjectException;
@@ -109,15 +109,18 @@ public class CommunityArticleController extends BaseController {
      */
     @ApiOperation("获取文章列表")
     @GetMapping("/list")
-    //@Anonymous
-    public TableDataInfo communityList(CommunityArticle communityArticle) {
+    @Anonymous
+    public TableDataInfo communityList(CommunityArticle communityArticle, @RequestParam(required = false) Long userId) {
         int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 0);
         TableDataInfo rspData = null;
+        if (userId == null) {
+            userId = SecurityUtils.getUserId();
+        }
         try {
             rspData = new TableDataInfo();
-            List<CommunityArticleVo> list = communityArticleService.selectCommunityArticleList(rspData, communityArticle, pageNum, pageSize, searchType);
+            List<CommunityArticleVo> list = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
             rspData.setCode(HttpStatus.SUCCESS);
             rspData.setMsg("查询成功");
             rspData.setRows(list);
@@ -617,7 +620,7 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("关注/取关用户")
     @PostMapping("/likeUser")
     @Transactional
-    public AjaxResult userLike(@RequestParam("likeUserId") Long likeUserId) {
+    public AjaxResult likeUser(@RequestParam("likeUserId") Long likeUserId) {
         if (Objects.isNull(likeUserId)) {
             return AjaxResult.error("参数失效!");
         }
@@ -639,12 +642,13 @@ public class CommunityArticleController extends BaseController {
 
     @ApiOperation("获取用户信息")
     @GetMapping("/userInfo")
+    @Anonymous
     public AjaxResult userInfo(@RequestParam(required = false) Long userId) {
         if (Objects.isNull(userId)) {
             userId = SecurityUtils.getLoginUser().getUserId();
         }
         //如果登录的是本人刷新下IP地址
-        if (userId != null && userId.equals(SecurityUtils.getLoginUser().getUserId())){
+        if (userId != null && userId.equals(SecurityUtils.getLoginUser().getUserId())) {
             SysUser sysUser = new SysUser();
             sysUser.setUserId(userId);
             sysUser.setLoginIp(IpUtils.getIpAddr());
@@ -717,13 +721,17 @@ public class CommunityArticleController extends BaseController {
 
     @ApiOperation("获取关注列表")
     @GetMapping("/likeUserList")
-    public AjaxResult likeUserList(String userName) {
+    @Anonymous
+    public AjaxResult likeUserList(String userName, @RequestParam(required = false) Long userId) {
         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;
+        if (userId == null) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
         try {
-            communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(SecurityUtils.getLoginUser().getUserId(), userName, pageNum, pageSize, searchType);
+            communityUserLikeVos = communityArticleService.selectCommunityUserLikeList(userId, userName, pageNum, pageSize, searchType);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -813,6 +821,7 @@ public class CommunityArticleController extends BaseController {
      */
     @ApiOperation("用户合集")
     @GetMapping("/userCollection")
+    @Anonymous
     public AjaxResult createCollection(Long userId, Long articleId) {
         if (Objects.isNull(userId)) {
             return AjaxResult.error("参数异常!");
@@ -1051,6 +1060,7 @@ public class CommunityArticleController extends BaseController {
      */
     @ApiOperation("查询用户合集")
     @GetMapping("/getCollection")
+    @Anonymous
     public AjaxResult getCollection(Long collectionId, Long searchType) {
         if (Objects.isNull(collectionId)) {
             return AjaxResult.error("合集不存在!");
@@ -1134,13 +1144,16 @@ public class CommunityArticleController extends BaseController {
 
     @ApiOperation("个人喜欢文章")
     @GetMapping("/userLike")
-    public AjaxResult userLike() {
+    public AjaxResult userLike(@RequestParam(required = false) Long userId) {
         int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 1);
         List<CommunityArticleVo> communityArticleVos = null;
+        if (userId == null) {
+            userId = SecurityUtils.getUserId();
+        }
         try {
-            communityArticleVos = communityArticleService.selectUserLike(pageNum, pageSize, searchType);
+            communityArticleVos = communityArticleService.selectUserLike(userId, pageNum, pageSize, searchType);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -1150,15 +1163,18 @@ public class CommunityArticleController extends BaseController {
 
     @ApiOperation("个人收藏文章")
     @GetMapping("/userCollect")
-    public AjaxResult userCollect() {
+    @Anonymous
+    public AjaxResult userCollect(@RequestParam(required = false) Long userId) {
         int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
         int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
         int searchType = Convert.toInt(ServletUtils.getParameter("searchType"), 1);
 
         List<CommunityArticleVo> communityArticleVos = null;
         try {
-            communityArticleVos = communityArticleService.selectUserCollect(pageNum, pageSize, searchType);
-
+            if (userId == null) {
+                userId = SecurityUtils.getUserId();
+            }
+            communityArticleVos = communityArticleService.selectUserCollect(userId, pageNum, pageSize, searchType);
         } catch (Exception e) {
             System.out.println(e.getMessage());
             throw new ProjectException();
@@ -1168,10 +1184,11 @@ public class CommunityArticleController extends BaseController {
 
     @ApiOperation("个人陪伴信息")
     @GetMapping("/userAccompany")
+    @Anonymous
     public AjaxResult userAccompany(Long userId) {
 
         if (Objects.isNull(userId)) {
-            userId = SecurityUtils.getLoginUser().getUserId();
+            userId = SecurityUtils.getUserId();
         }
 
         CommunityAccompany communityAccompany = null;

+ 12 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityCommentController.java

@@ -3,6 +3,7 @@ package com.ruoyi.generator.controller;
 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;
@@ -87,12 +88,20 @@ public class CommunityCommentController extends BaseController {
     @ApiOperation("获取文章评论")
     @GetMapping()
     @Transactional
-    //@Anonymous
-    public AjaxResult comment(String articleId, int currentPage, int limit) {
+    @Anonymous
+    public AjaxResult comment(String articleId,
+                              int currentPage,
+                              int limit,
+                              @RequestParam(required = false) Long userId) {
         if (Objects.isNull(articleId)) {
             return AjaxResult.error("参数异常!");
         }
         List<CommunityArticleCommentVo> commentVos = new ArrayList<>();
+
+        if (userId == null) {
+            userId = SecurityUtils.getUserId();
+        }
+
         try {
             Page<CommunityArticleComment> page = new Page<>(currentPage, limit);
             List<CommunityArticleComment> records = communityArticleCommentService.page(page, new QueryWrapper<CommunityArticleComment>()
@@ -113,7 +122,7 @@ public class CommunityCommentController extends BaseController {
                 commentVos.add(commentVo);
             }
 
-            Long userId = SecurityUtils.getUserId();
+
             List<Long> commentIds = new ArrayList<>();
             for (CommunityArticleCommentVo vo : commentVos) {
                 Long commentUserId = vo.getUserId();

+ 3 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunitySettingsController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.generator.controller;
 
+import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.exception.user.ProjectException;
 import com.ruoyi.common.utils.SecurityUtils;
@@ -81,10 +82,10 @@ public class CommunitySettingsController {
      */
     @ApiOperation("获取隐私权限")
     @GetMapping("/userPrivacy")
-    //@Anonymous
+    @Anonymous
     public AjaxResult userPrivacy(@RequestParam(required = false) Long userId) {
         if (Objects.isNull(userId)) {
-            userId = SecurityUtils.getLoginUser().getUserId();
+            userId = SecurityUtils.getUserId();
         }
 
         List<CommunityUserPrivacyVo> communityUserPrivacyVos = null;

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

@@ -122,6 +122,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
     @Autowired
     private CommunityArticleCircleMapper communityArticleCircleMapper;
+
     /**
      * 查询文章列表
      *
@@ -129,7 +130,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
      * @return 文章信息集合
      */
     @Override
-    public List<CommunityArticleVo> selectCommunityArticleList(TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
+    public List<CommunityArticleVo> selectCommunityArticleList(Long userId, TableDataInfo rspData, CommunityArticle communityArticle, int pageNum, int pageSize, int searchType) {
 
         List<CommunityArticleVo> communityArticleVos = null;
         //找出板块下的分类
@@ -146,7 +147,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             List<Long> likeUserIds = communityUserLikeVos.stream().map(CommunityUserLikeVo::getLikeUserId).collect(Collectors.toList());
             communityArticle.setUserIds(likeUserIds);
         }
-        Long userId = SecurityUtils.getUserId();
+
         if (Objects.nonNull(id)) {
             //获取指定文章详细内容,文章浏览量+1
             CommunityArticle article = communityArticleMapper.selectById(id);
@@ -165,10 +166,10 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
         //根据分类查找文章
         int offset = (pageNum - 1) * pageSize;
-        communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType,userId);
+        communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, classIds, offset, pageSize, searchType, userId);
 
         List<CommunityArticleVo> articleVos_copy = new ArrayList<>(communityArticleVos);
-        if (noCollection != null){
+        if (noCollection != null) {
             if (noCollection == 1) {
                 //剔除是否有合集文章
                 List<Long> ids = communityArticleVos.stream().map(CommunityArticleVo::getId).collect(Collectors.toList());
@@ -181,7 +182,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
 
                     for (CommunityArticleVo communityArticleVo : articleVos_copy) {
                         for (CommunityCollectionArticle collection : collections) {
-                            if(collection.getArticleId().equals(communityArticleVo.getId())){
+                            if (collection.getArticleId().equals(communityArticleVo.getId())) {
                                 communityArticleVos.remove(communityArticleVo);
                             }
                         }
@@ -265,8 +266,6 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             articleVo.setCollectionVo(communityCollectionMapper.selectCollectById(userId, articleVo.getId()));
 
 
-
-
             //设置中奖信息
             CommunityCommentRaffleVo communityCommentRaffleVo = new CommunityCommentRaffleVo();
             CommunityCommentRaffle communityCommentRaffle = communityCommentRaffleMapper.selectOne(
@@ -358,7 +357,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     public void insertCommunityArticle(CommunityArticle communityArticle) {
 
         //判断是否传ID 如果有ID贼删除原来的文章 重新插入一条新文章
-        if (communityArticle.getId() != null){
+        if (communityArticle.getId() != null) {
             //增加字段 文章编辑字段
             communityArticle.setIsDelete(true);
 
@@ -682,13 +681,12 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         communityUserInfoVo.setCompanionCount((int) daysDifference);
 
         communityUserInfoVo.setArticleCount(communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
-                .eq("user_id",userId)
+                .eq("user_id", userId)
                 .and((wrapper) -> {
                     wrapper.ne("is_delete", true).or().isNull("is_delete");
                 })).size());
 
 
-
         String address = null;
         try {
             address = AddressUtils.getAddress(sysUser.getLoginIp());
@@ -1088,8 +1086,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
     }
 
     @Override
-    public List<CommunityArticleVo> selectUserLike(int pageNum, int pageSize, int searchType) {
-        Long userId = SecurityUtils.getUserId();
+    public List<CommunityArticleVo> selectUserLike(Long userId,int pageNum, int pageSize, int searchType) {
         // 查询自己的通知列表
         List<CommunityLike> communityUserLike
                 = communityLikeMapper
@@ -1102,14 +1099,13 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             rspData = new TableDataInfo();
             communityArticle = new CommunityArticle();
             communityArticle.setArticleIds(articleIds);
-            communityArticleVos = communityArticleService.selectCommunityArticleList(rspData, communityArticle, pageNum, pageSize, searchType);
+            communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
         }
         return communityArticleVos;
     }
 
     @Override
-    public List<CommunityArticleVo> selectUserCollect(int pageNum, int pageSize, int searchType) {
-        Long userId = SecurityUtils.getUserId();
+    public List<CommunityArticleVo> selectUserCollect(Long userId,int pageNum, int pageSize, int searchType) {
         // 查询自己的通知列表
         List<CommunityArticleCollect> communityArticleCollects
                 = communityArticleCollectMapper
@@ -1124,7 +1120,7 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
             rspData = new TableDataInfo();
             communityArticle = new CommunityArticle();
             communityArticle.setArticleIds(articleIds);
-            communityArticleVos = communityArticleService.selectCommunityArticleList(rspData, communityArticle, pageNum, pageSize, searchType);
+            communityArticleVos = communityArticleService.selectCommunityArticleList(userId, rspData, communityArticle, pageNum, pageSize, searchType);
         }
         return communityArticleVos;
     }
@@ -1154,8 +1150,8 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
                         wrapper.ne("is_delete", true).or().isNull("is_delete");
                     })
             );
-            if (communityArticleComments.size() == 0 ){
-                return  communityCommentRaffleVo;
+            if (communityArticleComments.size() == 0) {
+                return communityCommentRaffleVo;
             }
             // 使用 Random 类生成一个随机索引
             Random random = new Random();

+ 0 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCollectionServiceImpl.java

@@ -110,9 +110,6 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         updateWrapper.setSql("heat = IFNULL(heat, 0) + 1");
         communityCollectionMapper.update(null, updateWrapper);
 
-
-
-
         //一级层级
         JSONObject collectionObject = new JSONObject();
         collectionObject.put("CollectionName", communityCollection.getCollectionName());

+ 3 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityArticleService.java

@@ -21,7 +21,7 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      * @param communityArticle 文章信息
      * @return 文章信息集合
      */
-    List<CommunityArticleVo> selectCommunityArticleList(TableDataInfo rspData,CommunityArticle communityArticle, int pageNum, int pageSize, int searchType);
+    List<CommunityArticleVo> selectCommunityArticleList(Long userId,TableDataInfo rspData,CommunityArticle communityArticle, int pageNum, int pageSize, int searchType);
 
     /**
      * 发布文章
@@ -191,7 +191,7 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      * @param searchType
      * @return
      */
-    List<CommunityArticleVo> selectUserLike(int pageNum, int pageSize, int searchType);
+    List<CommunityArticleVo> selectUserLike(Long userId,int pageNum, int pageSize, int searchType);
 
 
     /**
@@ -203,7 +203,7 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      * @param searchType
      * @return
      */
-    List<CommunityArticleVo> selectUserCollect(int pageNum, int pageSize, int searchType);
+    List<CommunityArticleVo> selectUserCollect(Long userId,int pageNum, int pageSize, int searchType);
 
     /**
      * 查询抽奖表