Browse Source

fix: 搜索过滤问题

jackzhou 4 months ago
parent
commit
9515ece80e

+ 15 - 23
snowy-plugin/snowy-plugin-coldchain/src/main/java/vip/xiaonuo/coldchain/modular/monitortarget/mapper/mapping/MonitorTargetMapper.xml

@@ -31,10 +31,7 @@
         FROM monitor_target t
         LEFT JOIN monitor_target_region r ON r.monitor_target_id = t.id
         WHERE 1=1
-        <!-- 过滤条件:MonitorTarget 删除标志 -->
         AND t.DELETE_FLAG = 'NOT_DELETE'
-        <!-- 过滤条件:monitor_target_region 删除标志 -->
-        AND r.DELETE_FLAG = 'NOT_DELETE'
         <!-- 动态条件:按房间ID查询 -->
         <if test="roomId != null and roomId.trim() != ''">
             AND t.room_id = #{roomId}
@@ -45,8 +42,11 @@
         </if>
         <!-- 动态条件:按 sensor_code 或 name 模糊查询 -->
         <if test="name != null and name.trim() != ''">
-            AND (r.sensor_code LIKE CONCAT('%', #{name}, '%')
-            OR r.name LIKE CONCAT('%', #{name}, '%'))
+            AND (
+            t.name LIKE CONCAT('%', #{name}, '%')
+            OR r.sensor_code LIKE CONCAT('%', #{name}, '%')
+            OR r.name LIKE CONCAT('%', #{name}, '%')
+            )
         </if>
         GROUP BY t.status
     </select>
@@ -55,12 +55,14 @@
         SELECT t.*
         FROM monitor_target t
         LEFT JOIN monitor_target_region r ON r.monitor_target_id = t.id
-        WHERE 1=1
-        AND t.DELETE_FLAG = 'NOT_DELETE'
-        AND r.DELETE_FLAG = 'NOT_DELETE'
-        <!-- 动态条件:按名称模糊查询 -->
-        <if test="param.name != null and param.name.trim() != ''">
-            AND t.name LIKE CONCAT('%', #{param.name}, '%')
+        WHERE t.DELETE_FLAG = 'NOT_DELETE'
+        <!-- 动态条件:按名称或 sensor_code 或 name 模糊查询 -->
+        <if test="param.searchKey != null and param.searchKey.trim() != ''">
+            AND (
+            t.name LIKE CONCAT('%', #{param.searchKey}, '%')
+            OR r.sensor_code LIKE CONCAT('%', #{param.searchKey}, '%')
+            OR r.name LIKE CONCAT('%', #{param.searchKey}, '%')
+            )
         </if>
         <!-- 动态条件:按创建用户查询 -->
         <if test="param.userId != null and param.userId.trim() != ''">
@@ -74,22 +76,11 @@
         <if test="param.orgId != null and param.orgId.trim() != ''">
             AND t.create_org = #{param.orgId}
         </if>
-        <!-- 动态条件:按 sensor_code 或 name 模糊查询 -->
-        <if test="param.searchKey != null and param.searchKey.trim() != ''">
-            AND (r.sensor_code LIKE CONCAT('%', #{param.searchKey}, '%')
-            OR r.name LIKE CONCAT('%', #{param.searchKey}, '%'))
-        </if>
         GROUP BY t.id
         <!-- 动态排序 -->
         <choose>
             <when test="param.sortField != null and param.sortField.trim() != '' and param.sortOrder != null and param.sortOrder.trim() != ''">
-                ORDER BY ${param.sortField}
-                <if test="param.sortOrder == 'asc'">
-                    ASC
-                </if>
-                <if test="param.sortOrder == 'desc'">
-                    DESC
-                </if>
+                ORDER BY ${param.sortField} ${param.sortOrder}
             </when>
             <otherwise>
                 ORDER BY t.status ASC, t.name ASC
@@ -99,4 +90,5 @@
 
 
 
+
 </mapper>

+ 2 - 2
snowy-web-app/src/main/resources/application.properties

@@ -135,8 +135,8 @@ spring.data.redis.lettuce.pool.min-idle=0
 #########################################
 # mybatis-plus configuration
 #########################################
-#mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
-mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
+mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+#mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
 mybatis-plus.configuration.jdbc-type-for-null=null
 mybatis-plus.global-config.banner=false
 mybatis-plus.global-config.enable-sql-runner=true