Explorar o código

获取标签信息(附带拉黑信息)代码优化

fangqing hai 5 días
pai
achega
e654d4146e

+ 24 - 3
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityTagController.java

@@ -72,7 +72,7 @@ public class CommunityTagController extends BaseController {
             int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
             int pageNum = Convert.toInt(ServletUtils.getParameter("pageNum"), 1);
             int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
             int pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10);
             int offset = (pageNum - 1) * pageSize;
             int offset = (pageNum - 1) * pageSize;
-            Page<CommunityTag> page = new Page<>(offset, pageSize);
+            Page<CommunityTag> page = new Page<>(pageNum, pageSize);
             communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
             communityTags = communityTagService.page(page, new QueryWrapper<CommunityTag>().and((wrapper) -> {
                         wrapper.ne("is_delete", 1)
                         wrapper.ne("is_delete", 1)
                                 .or()
                                 .or()
@@ -233,7 +233,7 @@ public class CommunityTagController extends BaseController {
     @GetMapping("/tagsTakeBlock")
     @GetMapping("/tagsTakeBlock")
     @Transactional
     @Transactional
     //@Anonymous
     //@Anonymous
-    public AjaxResult tagsTakeBlock(Long userId) {
+    public AjaxResult tagsTakeBlock(String tagName,Long userId, boolean isToken) {
        /* List<CommunityTagVo> communityTagVos = new ArrayList<>();
        /* List<CommunityTagVo> communityTagVos = new ArrayList<>();
         try {
         try {
             Page<CommunityTag> page = new Page<>(1, 10);
             Page<CommunityTag> page = new Page<>(1, 10);
@@ -283,6 +283,12 @@ public class CommunityTagController extends BaseController {
         if (userId == null) {
         if (userId == null) {
             userId = SecurityUtils.getUserId();
             userId = SecurityUtils.getUserId();
         }
         }
+
+        //tagName 为空的话全文搜索
+        if (tagName == null) {
+            tagName = "%%";
+        }
+
         List<CommunityTag> communityTags = null;
         List<CommunityTag> communityTags = null;
         try {
         try {
             //获取拉黑标签ID
             //获取拉黑标签ID
@@ -301,8 +307,23 @@ public class CommunityTagController extends BaseController {
                     .in("id", tagList)
                     .in("id", tagList)
                     .and((wrapper) -> {
                     .and((wrapper) -> {
                         wrapper.ne("is_delete", 1).or().isNull("is_delete");
                         wrapper.ne("is_delete", 1).or().isNull("is_delete");
-                    }));
+                    })
+                    .like("tag_name", tagName));
+
+            if (isToken) {
+                for (CommunityTag communityTag : communityTags) {
+                    CommunityUserTag userTag = communityUserTagMapper
+                            .selectOne(new QueryWrapper<CommunityUserTag>()
+                                    .eq("tag_id", communityTag.getId())
+                                    .eq("user_id", userId)
+                                    .eq("is_delete", 0));
+
+                    if (userTag != null){
+                        communityTag.setIsLike(true);
+                    }
+                }
 
 
+            }
 
 
         } catch (Exception e) {
         } catch (Exception e) {
             System.out.println(e.getMessage());
             System.out.println(e.getMessage());