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-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml |   85 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml b/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
index f2fcf1c..de3c689 100644
--- a/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
+++ b/drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml
@@ -34,6 +34,8 @@
         <result column="update_user" property="updateUser"/>
         <result column="update_time" property="updateTime"/>
         <result column="status" property="status"/>
+        <result column="use_date" property="useDate"/>
+        <result column="service_life" property="serviceLife"/>
 <!--        <result column="is_deleted" property="isDeleted"/>-->
     </resultMap>
 
@@ -45,6 +47,9 @@
         ja_fw_device
         <where>
             is_deleted = 0
+            <if test="param2.trackStatus != null ">
+                and track_status::text = #{param2.trackStatus}::text
+            </if>
             <if test="param2.id != null and param2.id != ''">
                 and id::text = #{param2.id}::text
             </if>
@@ -55,10 +60,10 @@
                 and device_type::text = #{param2.deviceType}::text
             </if>
             <if test="param2.deviceModel != null and param2.deviceModel != ''">
-                and device_model = #{param2.deviceModel}
+                and device_model::text = #{param2.deviceModel}::text
             </if>
             <if test="param2.deviceSpecification != null and param2.deviceSpecification != ''">
-                and device_specification = #{param2.deviceSpecification}
+                and device_specification::text = #{param2.deviceSpecification}::text
             </if>
             <if test="param2.effectiveRangeKmIsNotNull != null and param2.effectiveRangeKmIsNotNull == 1">
                 and effective_range_km is not null
@@ -68,13 +73,19 @@
                 and (effective_range_km is null or effective_range_km = 0)
             </if>
             <if test="param2.manufacturer != null and param2.manufacturer != ''">
-                and manufacturer = #{param2.manufacturer}
+                and manufacturer::text = #{param2.manufacturer}::text
             </if>
             <if test="param2.source != null and param2.source != ''">
-                and source = #{param2.source}
+                and source::text = #{param2.source}::text
             </if>
             <if test="param2.belongDept != null and param2.belongDept != ''">
-                and belong_dept = #{param2.belongDept}
+                and belong_dept::text = #{param2.belongDept}::text
+            </if>
+            <if test="param2.useDate != null">
+                and use_date = #{param2.useDate}
+            </if>
+            <if test="param2.serviceLife != null">
+                and service_life = #{param2.serviceLife}
             </if>
             <if test="param2.deviceStatusList != null and param2.deviceStatusList != ''">
                 and status::text in
@@ -97,10 +108,9 @@
                     #{deptId}::text
                 </foreach>
                 <if test="param2.currentDeptId != null and param2.currentDeptId != '' ">
-                    or id in (
-                    SELECT device_id FROM ja_fw_device_per_share
-                    WHERE
-                    loan_to_dept_id = #{param2.currentDeptId}::bigint
+                    or id::text in (
+                    SELECT device_id::text FROM ja_fw_device_per_share
+                    WHERE loan_to_dept_id = #{param2.currentDeptId}::bigint
                     AND is_deleted = 0
                     )
                 </if>
@@ -399,7 +409,7 @@
             ja_fw_device d
         WHERE
             d.is_deleted = 0
-            AND d.is_enabled = 1
+            AND d.track_status = 1
             AND d.final_outbound_area IS NOT NULL
         <if test="effectiveRangeKmIsNotNull != null and effectiveRangeKmIsNotNull == 2">
             and (d.effective_range_km is null or d.effective_range_km = 0)
@@ -638,7 +648,43 @@
 
     <select id="selectCockpitDevicePage" resultType="org.sxkj.fw.device.vo.CockpitFwDeviceVO">
         select
-        d.*,
+        d.id,
+        d.device_sn,
+        d.airport_id,
+        d.device_name,
+        d.device_type,
+        d.device_att,
+        d.device_model,
+        d.device_specification,
+        d.manufacturer,
+        d.source,
+        d.purpose,
+        d.belong_dept,
+        d.charger,
+        d.contact_phone,
+        d.remark,
+        d.battery_pct,
+        d.azimuth,
+        d.elevation,
+        d.detect_target_cnt,
+        d.effective_range_km,
+        d.work_mode,
+        d.area_code,
+        d.track_status,
+        d.final_outbound_area,
+        d.final_outbound_area_code,
+        d.is_enabled,
+        d.create_user,
+        d.create_dept,
+        d.create_time,
+        d.update_user,
+        d.update_time,
+        d.status,
+        d.is_deleted,
+        d.use_date,
+        d.service_life,
+        NULLIF(trim(d.latitude::text), '')::double precision AS latitude,
+        NULLIF(trim(d.longitude::text), '')::double precision AS longitude,
         min(ad.id) as area_divide_id,
         min(dsm.id) as defense_scene_manage_id
         from
@@ -781,7 +827,11 @@
         AND ad.is_deleted = 0
         WHERE
         d.is_deleted = 0
-        AND d.is_enabled = 1
+        AND d.track_status = 1
+        <if test="isEnabled != null">
+            AND d.is_enabled = #{isEnabled}
+        </if>
+        AND d.track_status = 1
         AND d.final_outbound_area IS NOT NULL
         <if test="regionCode != null and regionCode != ''">
             and ( d.final_outbound_area_code::text LIKE concat(#{regionCode}, '%')
@@ -816,4 +866,15 @@
         d.final_outbound_area
     </select>
 
+    <!-- 批量更新设备启用状态 -->
+    <update id="batchUpdateIsEnabled">
+        UPDATE ja_fw_device
+        SET is_enabled = #{isEnabled}
+        WHERE id IN
+        <foreach collection="deviceIds" item="id" open="(" separator="," close=")">
+            #{id}::bigint
+        </foreach>
+        AND is_deleted = 0
+    </update>
+
 </mapper>

--
Gitblit v1.9.3