From 774c8b2ee14eef5fd10bbd46d85a180e7b19ab21 Mon Sep 17 00:00:00 2001
From: lin <sbla5888@163.com>
Date: Fri, 22 Mar 2024 14:34:12 +0800
Subject: [PATCH] 查询过滤优化

---
 src/main/java/org/springblade/modules/discuss/mapper/TopicsMapper.xml |   24 +++++++++---------------
 1 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/springblade/modules/discuss/mapper/TopicsMapper.xml b/src/main/java/org/springblade/modules/discuss/mapper/TopicsMapper.xml
index c95330c..650945c 100644
--- a/src/main/java/org/springblade/modules/discuss/mapper/TopicsMapper.xml
+++ b/src/main/java/org/springblade/modules/discuss/mapper/TopicsMapper.xml
@@ -45,6 +45,7 @@
         <include refid="selectTopics"/>
         <where>
             <if test="id != null "> parent_id = #{id}</if>
+             and delete_flag = 0
         </where>
     </select>
 
@@ -64,7 +65,9 @@
             public_discuss_id,
             parent_id,
             level,
-            selected
+            selected,
+            article_id,
+            option_number
         from
             jczz_topics
     </sql>
@@ -74,20 +77,10 @@
 
     <select id="selectTopicsList" parameterType="org.springblade.modules.discuss.dto.TopicsDTO" resultMap="TopicsDTOResult">
         SELECT
-        jt.id,
-        jt.discuss_content,
-        jt.option_range,
-        jt.sort,
-        jt.option_content,
-        jt.option_detail,
-        jt.number,
-        jt.create_time,
-        jt.update_time,
-        jt.delete_flag,
-        jt.public_discuss_id,
-        jt.parent_id,
-        jt.LEVEL,
-        ( SELECT jut.selected FROM jczz_user_topics jut WHERE jut.topics_id = jt.id AND jut.user_id = #{userId} ) selected
+        jt.*,
+        ( SELECT jut.selected FROM jczz_user_topics jut WHERE jut.article_id = jt.article_id AND jut.user_id = #{userId}
+        limit 1
+        ) selected
         FROM
         jczz_topics jt
         <where>
@@ -104,6 +97,7 @@
             <if test="publicDiscussId != null "> and jt.public_discuss_id = #{publicDiscussId}</if>
             <if test="parentId != null "> and jt.parent_id = #{parentId}</if>
             <if test="level != null "> and jt.level = #{level}</if>
+            <if test="articleId != null ">and jt.article_id = #{articleId}</if>
             and jt.delete_flag = 0
         </where>
     </select>

--
Gitblit v1.9.3