From 3cbe09c3d14734798ba8662aeac633289afa2cf6 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 02 Apr 2026 15:19:36 +0800
Subject: [PATCH] opt: sql改造其他模块改造10

---
 drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml b/drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml
index 7d28d2d..07d04d3 100644
--- a/drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml
+++ b/drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml
@@ -23,30 +23,34 @@
     <!--自定义分页查询-->
     <select id="selectAttachPage" resultType="org.sxkj.resource.vo.AttachVO">
         select
-            ba.*,
-            bd.dept_name,
-            coalesce(ba.nick_name,ba.original_name) nickName
+        ba.*,
+        bd.dept_name,
+        coalesce(ba.nick_name,ba.original_name) nickName
         from
-            blade_attach ba
+        blade_attach ba
         left join
-                blade_dept bd on ba.create_dept = bd.id::VARCHAR
+        /* 修改点1:双向转为 text 对齐 */
+        blade_dept bd on ba.create_dept::text = bd.id::text
         where
-            ba.is_deleted = 0
+        ba.is_deleted = 0
         <if test="attach.originalName!=null and attach.originalName!=''">
-            and original_name like concat('%',#{attach.originalName},'%')
+            and ba.original_name like concat('%',#{attach.originalName},'%')
         </if>
         <if test="attach.resultType!=null">
-            and result_type = #{attach.resultType}
+            /* 修改点2:如果 resultType 是字符串传入,也需加权转 */
+            and ba.result_type::text = #{attach.resultType}::text
         </if>
         <if test="attach.deptList != null and attach.deptList.size > 0">
-            and ba.create_dept in
+            and ba.create_dept::text in
             <foreach collection="attach.deptList" item="deptId" open="(" separator="," close=")">
-                #{deptId}
+                #{deptId}::text
             </foreach>
         </if>
-            and result_type in (1,2,3,4,5)
-        order by create_time desc,id desc
+        /* 修改点3:result_type 如果是字符型字段,数字必须加单引号 */
+        and ba.result_type::text in ('1','2','3','4','5')
+        order by ba.create_time desc, ba.id desc
     </select>
+
     <select id="findAiAttachImages" resultType="org.sxkj.resource.vo.AttachVO">
         select
         DISTINCT attach.id,

--
Gitblit v1.9.3