Browse Source

fix 文章列表

zwhui 2 years ago
parent
commit
bea1482dad

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/views/InformationListView.java

@@ -14,6 +14,8 @@ import java.util.Date;
 @Getter
 @Setter
 public class InformationListView {
+
+    private Long id;
     /**
      * 文章标题
      */

+ 2 - 2
netflix-dao/src/main/resources/mapper/InformationMapper.xml

@@ -5,7 +5,7 @@
 
 
     <select id="getInformation" resultType="com.cyksj.model.views.InformationListView">
-        select title,thumbnail,created_time,content from information where status is true and deleted is true
+        select id,title,thumbnail,created_time,content from information where status is true and deleted is true
         <choose>
             <when test="categoryId != null">
                 and JSON_CONTAINS(category_ids,'"${categoryId}"') = 1
@@ -18,7 +18,7 @@
     </select>
 
     <select id="getInformationByTitle" resultType="com.cyksj.model.views.InformationListView">
-        select title,thumbnail,created_time,content
+        select id,title,thumbnail,created_time,content
         from information
         where title like '%${title}%'
           and status is true

+ 9 - 1
netflix-web/src/main/java/com/cyksj/web/controller/information/InformationController.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
+import com.cyksj.model.entity.Information;
 import com.cyksj.model.entity.InformationCategory;
 import com.cyksj.model.views.GoodsFrontListView;
 import com.cyksj.model.views.InformationDetailView;
@@ -64,7 +65,14 @@ public class InformationController {
      */
     @GetMapping("/get/category")
     public Result<List<InformationCategory>> getInformationCategory() {
-        return GatewayResponse.SUCCESS.newBuilder().toResult(informationCategoryService.list(Wrappers.lambdaQuery(InformationCategory.class).orderByAsc(InformationCategory::getSortBy)));
+        List<InformationCategory> list = informationCategoryService.list(Wrappers.lambdaQuery(InformationCategory.class).orderByAsc(InformationCategory::getSortBy));
+        list.forEach(category -> {
+            int count = informationService.count(Wrappers.lambdaQuery(Information.class).apply("JSON_CONTAINS(category_ids,'\"" + category.getId() + "\"')").eq(Information::getStatus, true).eq(Information::getDeleted, true));
+            if (count == 0){
+                list.remove(category);
+            }
+        });
+        return GatewayResponse.SUCCESS.newBuilder().toResult(list);
     }
 
     /**