hanfucheng 1 年間 前
コミット
833cd6e77e

+ 17 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/asking/JnbQuestionController.java

@@ -95,7 +95,11 @@ public class JnbQuestionController extends BaseController {
     */
     @PutMapping("/updateWhetherShow")
     public R updateWhetherShow(@RequestBody JnbQuestion jnbQuestion) {
-        return R.ok(jnbQuestionService.updateWhetherShow(jnbQuestion));
+        int result = jnbQuestionService.updateWhetherShow(jnbQuestion);
+        if (result==-1){
+            return R.fail("是否首页展示数量超过最大限制数");
+        }
+        return R.ok(result);
     }
 
     /**
@@ -133,14 +137,24 @@ public class JnbQuestionController extends BaseController {
     }
 
     /*
-    * 小程序-获取热门问答列表
+    * 小程序-获取首页展示列表
+    *
+    * @author 韩福成
+    * @date 2024/3/18 9:34
+    */
+    @GetMapping("/getShowList")
+    public AjaxResult getShowList(JnbQuestion jnbQuestion) {
+        return AjaxResult.success(jnbQuestionService.getShowList(jnbQuestion));
+    }
+
+    /*
+    * 小程序-获取热门问题列表
     *
     * @author 韩福成
     * @date 2024/3/11 11:21
     */
     @GetMapping("/getHotQuestionList")
     public TableDataInfo getHotQuestionList(JnbQuestion jnbQuestion) {
-        startPage();
         List<JnbQuestion> list = jnbQuestionService.getHotQuestionList(jnbQuestion);
         return getDataTable(list);
     }

+ 17 - 1
sooka-jnb/src/main/java/com/sooka/jnb/asking/mapper/JnbQuestionMapper.java

@@ -44,6 +44,14 @@ public interface JnbQuestionMapper {
      */
     public int updateJnbQuestion(JnbQuestion jnbQuestion);
 
+    /*
+    * 查询首页展示个数
+    *
+    * @author 韩福成
+    * @date 2024/3/18 10:43
+    */
+    public int getNum();
+
     /**
      * 删除问答列-问题
      *
@@ -77,7 +85,15 @@ public interface JnbQuestionMapper {
     public int deleteQuestionImg(String id);
 
     /*
-    * 小程序-获取热门问答列表
+    * 小程序-获取首页展示列表
+    *
+    * @author 韩福成
+    * @date 2024/3/18 9:39
+    */
+    public List<JnbQuestion> getShowList(JnbQuestion jnbQuestion);
+
+    /*
+    * 小程序-获取热门问题列表
     *
     * @author 韩福成
     * @date 2024/3/11 14:31

+ 9 - 1
sooka-jnb/src/main/java/com/sooka/jnb/asking/service/IJnbQuestionService.java

@@ -77,7 +77,15 @@ public interface IJnbQuestionService {
     public int through(JnbQuestion jnbQuestion);
 
     /*
-    * 小程序-获取热门问答列表
+    * 小程序-获取首页展示列表
+    *
+    * @author 韩福成
+    * @date 2024/3/18 9:36
+    */
+    public List<JnbQuestion> getShowList(JnbQuestion jnbQuestion);
+
+    /*
+    * 小程序-获取热门问题列表
     *
     * @author 韩福成
     * @date 2024/3/11 14:27

+ 25 - 2
sooka-jnb/src/main/java/com/sooka/jnb/asking/service/impl/JnbQuestionServiceImpl.java

@@ -137,6 +137,11 @@ public class JnbQuestionServiceImpl implements IJnbQuestionService {
     */
     @Override
     public int updateWhetherShow(JnbQuestion jnbQuestion) {
+        int num = jnbQuestionMapper.getNum();
+        Long showNum = Long.valueOf(redisCache.getCacheObject(SYS_CONFIG_KEY + "show_num").toString());
+        if (jnbQuestion.getWhetherShow().equals("Y") && num>=showNum){
+            return -1;
+        }
         return jnbQuestionMapper.updateJnbQuestion(jnbQuestion);
     }
 
@@ -194,14 +199,32 @@ public class JnbQuestionServiceImpl implements IJnbQuestionService {
     }
 
     /*
-    * 小程序-获取热门问答列表
+    * 小程序-获取首页展示列表
+    *
+    * @author 韩福成
+    * @date 2024/3/18 9:36
+    */
+    @Override
+    public List<JnbQuestion> getShowList(JnbQuestion jnbQuestion) {
+        List<JnbQuestion> list = jnbQuestionMapper.getShowList(jnbQuestion);
+        for (JnbQuestion ques : list){
+            if (StringUtils.isNotEmpty(ques.getPath())){
+                String[] split = ques.getPath().split(",");
+                ques.setPaths(split);
+            }
+        }
+        return list;
+    }
+
+    /*
+    * 小程序-获取热门问题列表
     *
     * @author 韩福成
     * @date 2024/3/11 14:28
     */
     @Override
     public List<JnbQuestion> getHotQuestionList(JnbQuestion jnbQuestion) {
-        Long hotNum = Long.valueOf(redisCache.getCacheObject(SYS_CONFIG_KEY + "init_socre").toString());
+        Long hotNum = Long.valueOf(redisCache.getCacheObject(SYS_CONFIG_KEY + "hot_question").toString());
         jnbQuestion.setBrowse(hotNum);
         return jnbQuestionMapper.getHotQuestionList(jnbQuestion);
     }

+ 35 - 4
sooka-jnb/src/main/resources/mapper/asking/JnbQuestionMapper.xml

@@ -138,6 +138,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </update>
 
+    <select id="getNum" parameterType="String" resultType="int">
+        SELECT
+            count( a.id )
+        FROM
+            jnb_question a
+        WHERE
+            a.whether_show = 'Y'
+            AND a.data_status = 1
+            AND a.`status` = 1
+    </select>
+
     <delete id="deleteJnbQuestionById" parameterType="String">
         delete from jnb_question where id = #{id}
     </delete>
@@ -154,6 +165,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </update>
 
+    <select id="getShowList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
+        SELECT
+            a.id,
+            a.title,
+            a.type,
+            a.score,
+            a.browse,
+            GROUP_CONCAT(d.path) path,
+            a.create_by,
+            count(DISTINCT b.id) comment,
+            count(DISTINCT c.id) collect
+        FROM
+            jnb_question a
+            LEFT JOIN jnb_answer b on a.id = b.question_id and b.data_status = 1
+            LEFT JOIN jnb_question_collect c on a.id = c.question_id
+            left join jnb_question_img d on a.id = d.question_id
+        WHERE
+            a.data_status = 1
+            and a.status = 1
+            and a.whether_show ='Y'
+        GROUP BY a.id
+        order by a.create_time desc
+    </select>
+
     <select id="getHotQuestionList" parameterType="JnbQuestion" resultMap="JnbQuestionResult">
         SELECT
             a.id,
@@ -170,7 +205,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             a.data_status = 1
             and a.status = 1
-            and a.whether_show = 'Y'
             and a.browse >= #{browse}
             GROUP BY a.id
     </select>
@@ -194,7 +228,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             a.data_status = 1
             and a.`status` = 1
-            and a.whether_show = 'Y'
             and a.type_id = #{id}
             GROUP BY a.id
             order by a.create_time desc
@@ -219,7 +252,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             a.data_status = 1
             and a.`status` = 1
-            and a.whether_show = 'Y'
             and a.type_id = #{id}
             GROUP BY a.id
             order by count(d.id) desc,comment desc,a.browse desc,a.create_time desc
@@ -244,7 +276,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             a.data_status = 1
             and a.`status` = 1
-            and a.whether_show = 'Y'
             and a.type_id = #{id}
             GROUP BY a.id
             order by a.score desc