From 8585b431e9257333413358eb37c30ae58f74db76 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 13 Aug 2026 15:46:10 +0800
Subject: [PATCH] refactor(database): 优化数据库查询中的字段映射

---
 drone-ops/drone-resource/src/main/java/org/sxkj/resource/mapper/AttachMapper.xml |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 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 2fb7415..d9af54b 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
@@ -18,10 +18,11 @@
         <result column="original_name" property="originalName"/>
         <result column="extension" property="extension"/>
         <result column="attach_size" property="attachSize"/>
+        <result column="result_type" property="resultType" typeHandler="org.sxkj.common.handler.GenericListTypeHandler"/>
     </resultMap>
 
     <!--自定义分页查询-->
-    <select id="selectAttachPage" resultType="org.sxkj.resource.vo.AttachVO">
+    <select id="selectAttachPage" resultMap="attachResultMap" >
         select
         ba.*,
         bd.dept_name,
@@ -33,12 +34,17 @@
         blade_dept bd on ba.create_dept::text = bd.id::text
         where
         ba.is_deleted = 0
-        <if test="attach.originalName!=null and attach.originalName!=''">
-            and ba.original_name like concat('%',#{attach.originalName},'%')
+        <if test="attach.nickName!=null and attach.nickName!=''">
+            and ba.nick_name like concat('%',#{attach.nickName},'%')
         </if>
-        <if test="attach.resultType!=null">
-            /* 修改点2:如果 resultType 是字符串传入,也需加权转 */
-            and ba.result_type::text = #{attach.resultType}::text
+        <if test="attach.resultType!=null and attach.resultType!='' ">
+            /* 将逗号分隔的字符串转换为带引号的格式,如 "road,road1" 转为 "\"road\",\"road1\"" */
+            and ba.result_type like concat('%',
+            (
+            select string_agg(concat('"', trim(arr_val), '"'), ',')
+            from unnest(string_to_array(#{attach.resultType}, ',')) as arr_val
+            ),
+            '%')
         </if>
         <if test="attach.deptList != null and attach.deptList.size > 0">
             and ba.create_dept::text in
@@ -46,9 +52,7 @@
                 #{deptId}::text
             </foreach>
         </if>
-        /* 修改点3:result_type 如果是字符型字段,数字必须加单引号 */
-        and ba.result_type::text in ('1','2','3','4','5')
-        order by ba.create_time desc, ba.id desc
+          order by ba.create_time desc, ba.id desc
     </select>
 
     <select id="findAiAttachImages" resultType="org.sxkj.resource.vo.AttachVO">
@@ -273,7 +277,7 @@
         and job.job_info_id is not null
         <if test="attach.startTime!=null and attach.startTime!='' and attach.endTime!=null and attach.endTime!=''">
             and (DATE_FORMAT(FROM_UNIXTIME(job.execute_time/1000,'%Y-%m-%d %H:%i:%s'),'%Y-%m-%d %H:%i:%s') between
-            #{attach.startTime} and #{attach.endTime} or rela.create_time between #{attach.startTime} and #{attach.endTime} )
+            #{attach.startTime} and #{attach.endTime} or rela.create_time between #{attach.startTime}::timestamp and #{attach.endTime}::timestamp )
         </if>
         <if test="attach.name!=null and attach.name!=''">
             and COALESCE(attach.nick_name, SUBSTRING_INDEX(SUBSTRING_INDEX(attach.NAME, '/', -1), '.', 1))
@@ -457,7 +461,7 @@
         '$.shootPosition.lat') ) AS latitude
         <if test="resultType!=null and resultType!='' and resultType==4">
             ,odm.orthoimage_api 'url',
-            ST_AsText ( odm.geom ) "geom"
+            public.st_astext ( odm.geom ) "geom"
         </if>
         from blade_attach attach
         left join manage_device device on attach.device_sn = device.device_sn::VARCHAR

--
Gitblit v1.9.3