Przeglądaj źródła

fix 文章分类

zwhui 2 lat temu
rodzic
commit
1d6a4f3a80

+ 4 - 0
netflix-dao/src/main/java/com/cyksj/mapper/InformationCategoryMapper.java

@@ -3,9 +3,13 @@ package com.cyksj.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.InformationCategory;
 
+import java.util.List;
+
 /**
  * @author zwhui
  * @date 2023/10/12 15:47
  */
 public interface InformationCategoryMapper extends BaseMapper<InformationCategory> {
+    List<InformationCategory> getInformationCategory();
+
 }

+ 11 - 0
netflix-dao/src/main/resources/mapper/InformationCategoryMapper.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.cyksj.mapper.InformationCategoryMapper">
+
+
+    <select id="getInformationCategory" resultType="com.cyksj.model.entity.InformationCategory">
+        select ic.* from information_category ic, information i where JSON_CONTAINS(i.category_ids, CONCAT('"',ic.id,'"')) = 1 GROUP BY id,sort_by order by sort_by
+    </select>
+
+</mapper>

+ 3 - 0
netflix-service/src/main/java/com/cyksj/service/information/InformationCategoryService.java

@@ -3,9 +3,12 @@ package com.cyksj.service.information;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cyksj.model.entity.InformationCategory;
 
+import java.util.List;
+
 /**
  * @author zwhui
  * @date 2023/10/12 15:48
  */
 public interface InformationCategoryService extends IService<InformationCategory> {
+    List<InformationCategory> getInformationCategory();
 }

+ 6 - 0
netflix-service/src/main/java/com/cyksj/service/information/impl/InformationCategoryServiceImpl.java

@@ -6,10 +6,16 @@ import com.cyksj.model.entity.InformationCategory;
 import com.cyksj.service.information.InformationCategoryService;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * @author zwhui
  * @date 2023/10/12 15:48
  */
 @Service
 public class InformationCategoryServiceImpl extends ServiceImpl<InformationCategoryMapper, InformationCategory> implements InformationCategoryService {
+    @Override
+    public List<InformationCategory> getInformationCategory() {
+        return baseMapper.getInformationCategory();
+    }
 }

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

@@ -65,14 +65,7 @@ public class InformationController {
      */
     @GetMapping("/get/category")
     public Result<List<InformationCategory>> getInformationCategory() {
-        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);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(informationCategoryService.getInformationCategory());
     }
 
     /**