Pārlūkot izejas kodu

获取文章优化
获取用户信息接口开发

fangzhen 7 mēneši atpakaļ
vecāks
revīzija
15b0ca335e

+ 27 - 4
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -86,6 +86,14 @@ public class CommunityArticleController extends BaseController {
     @Transactional
     //@Anonymous
     public AjaxResult article(@RequestBody CommunityArticle communityArticle) {
+        if (communityArticle.getCircleIds().isEmpty()) {
+            return AjaxResult.error("圈子不能为空");
+        }
+
+        if (communityArticle.getCircleIds().size() > 5) {
+            return AjaxResult.error("只能绑定5个圈子!");
+        }
+
         communityArticleService.insertCommunityArticle(communityArticle);
         return AjaxResult.success("文章发布成功!");
     }
@@ -281,7 +289,9 @@ public class CommunityArticleController extends BaseController {
         Long userId = SecurityUtils.getLoginUser().getUserId();
         List<CommunityUserCircle> communityUserCircles = communityUserCircleMapper.selectList(new QueryWrapper<CommunityUserCircle>()
                 .eq("user_id", userId)
-                .ne("is_delete", 1).or().isNull("is_delete"));
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                }));
 
         List<Long> circleIds = new ArrayList<>();
         for (CommunityUserCircle communityUserCircle : communityUserCircles) {
@@ -369,6 +379,17 @@ public class CommunityArticleController extends BaseController {
         return AjaxResult.success(communityArticleService.selectCommunityUserInfoById(userId));
     }
 
+
+    @ApiOperation("查询用户")
+    @GetMapping("/userList")
+    public AjaxResult userList(String SearchValue) {
+        if (Objects.isNull(SearchValue)) {
+            return AjaxResult.error();
+        }
+        return AjaxResult.success(communityArticleService.selectUserBySearchValue(SearchValue));
+    }
+
+
     @ApiOperation("获取关注列表")
     @GetMapping("/likeUserList")
     public AjaxResult likeUserList() {
@@ -465,9 +486,11 @@ public class CommunityArticleController extends BaseController {
                 .getOne(new QueryWrapper<CommunityCollection>()
                         .eq("collection_name", communityCollection.getCollectionName())
                         .eq("user_id", SecurityUtils.getLoginUser().getUserId())
-                        .ne("is_delete", true)
-                        .or()
-                        .isNull("is_delete"));
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true)
+                                    .or()
+                                    .isNull("is_delete");
+                        }));
 
         if (!Objects.isNull(collection)) {
             return AjaxResult.error("合集名称不能重复!");

+ 9 - 2
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java

@@ -38,8 +38,15 @@ public class CommunityTagController extends BaseController {
     //@Anonymous
     public AjaxResult tags(String tagName) {
         Page<CommunityTag> page = new Page<>(1, 10);
-        List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>()
-                .ne("is_delete", 1).or().isNull("is_delete")
+//        List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>()
+//                .ne("is_delete", 1).or().isNull("is_delete")
+//                .like("tag_name", tagName)
+//                .orderByDesc("tag_hot")).getRecords();
+        List<CommunityTag> communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
+            wrapper.ne("is_delete", 1)
+                    .or()
+                    .isNull("is_delete");
+        })
                 .like("tag_name", tagName)
                 .orderByDesc("tag_hot")).getRecords();
         return AjaxResult.success(communityTags);

+ 10 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/CommunityUserInfoMapper.java

@@ -2,8 +2,18 @@ package com.ruoyi.generator.mapper.community;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.generator.domain.Community.CommunityUserInfo;
+import com.ruoyi.generator.vo.CommunityUserInfoVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 @Mapper
 public interface CommunityUserInfoMapper extends BaseMapper<CommunityUserInfo> {
+    /**
+     * 根据搜索值,搜索用户
+     *
+     * @param SearchValue 搜索值
+     * @return 用户
+     */
+    List<CommunityUserInfoVo> selectUserBySearchValue(String SearchValue);
 }

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

@@ -475,6 +475,17 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
         return communityUserInfoVo;
     }
 
+    /**
+     * 根据搜索值,搜索用户
+     *
+     * @param SearchValue 搜索值
+     * @return 用户
+     */
+    @Override
+    public List<CommunityUserInfoVo> selectUserBySearchValue(String SearchValue) {
+        return communityUserInfoMapper.selectUserBySearchValue(SearchValue);
+    }
+
     /**
      * 获取关注列表
      *

+ 20 - 15
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityCollectionServiceImpl.java

@@ -13,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.Objects;
 import java.util.stream.Collectors;
 
 @Service
@@ -67,10 +65,11 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         collectionArticle.setUpdateBy(SecurityUtils.getUserId());
         communityCollectionArticleMapper.update(collectionArticle, new UpdateWrapper<CommunityCollectionArticle>()
                 .eq("collection_id", collectionId)
-                .eq("article_id", articleId)
-                .ne("is_delete", true)
-                .or()
-                .isNull("is_delete"));
+                .eq("article_id", articleId).and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
     }
 
     /**
@@ -85,9 +84,11 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
                 .selectObjs(new QueryWrapper<CommunityCollectionArticle>()
                         .select("article_id")
                         .eq("collection_id", collectionId)
-                        .ne("is_delete", true)
-                        .or()
-                        .isNull("is_delete"));
+                        .and((wrapper) -> {
+                            wrapper.ne("is_delete", true)
+                                    .or()
+                                    .isNull("is_delete");
+                        }));
 
         if (articleIdsObj.isEmpty()) {
             return null;
@@ -138,9 +139,11 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         //1.更新合集状态
         CommunityCollection collection = communityCollectionMapper.selectOne(new QueryWrapper<CommunityCollection>()
                 .eq("id", collectionId)
-                .ne("is_delete", true)
-                .or()
-                .isNull("is_delete"));
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                }));
         collection.setDelete(true);
         collection.setUpdateBy(SecurityUtils.getLoginUser().getUserId());
         collection.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
@@ -148,9 +151,11 @@ public class CommunityCollectionServiceImpl extends ServiceImpl<CommunityCollect
         //2.更新合集关联的文章状态
         List<Long> ids = communityCollectionArticleMapper.selectObjs(new QueryWrapper<CommunityCollectionArticle>()
                 .eq("collection_id", collectionId)
-                .ne("is_delete", true)
-                .or()
-                .isNull("is_delete")).stream().map(item -> (Long) item).collect(Collectors.toList());
+                .and((wrapper) -> {
+                    wrapper .ne("is_delete", true)
+                            .or()
+                            .isNull("is_delete");
+                })).stream().map(item -> (Long) item).collect(Collectors.toList());
         CommunityCollectionArticle collectionArticle = new CommunityCollectionArticle();
         collectionArticle.setDelete(true);
         collectionArticle.setUpdateBy(SecurityUtils.getLoginUser().getUserId());

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

@@ -117,6 +117,14 @@ public interface ICommunityArticleService extends IService<CommunityArticle> {
      */
     CommunityUserInfoVo selectCommunityUserInfoById(Long userId);
 
+    /**
+     * 根据搜索值,搜索用户
+     *
+     * @param SearchValue 搜索值
+     * @return 用户
+     */
+    List<CommunityUserInfoVo> selectUserBySearchValue(String SearchValue);
+
     /**
      * 获取关注列表
      *

+ 4 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityUserInfoVo.java

@@ -60,6 +60,10 @@ public class CommunityUserInfoVo implements Serializable {
      */
     @ApiModelProperty("背景图")
     private String backImage;
+    /**
+     * 帖子数量
+     */
+    private int articleCount;
     /**
      * 关注数量
      */

+ 1 - 0
ruoyi-generator/src/main/resources/mapper/community/ArticleMapper.xml

@@ -161,6 +161,7 @@
         community_article a
         left join sys_user c on a.user_id = c.user_id
         left join community_article_circle e on e.article_id = a.id
+        left join community_article_tag f on f.article_id = a.id
         <where>
             <if test="communityArticle.id != null and communityArticle.id != ''">
                 AND a.id = #{communityArticle.id}