From 1c3d9f4f6d0dc330a80b199cfb824f41a048fe6c Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Sat, 31 Jan 2026 16:39:33 +0800
Subject: [PATCH] 设备权限优化

---
 drone-service/drone-fw/src/main/java/org/sxkj/fw/device/mapper/FwDeviceMapper.xml |  212 +++++++---------------------------------------------
 1 files changed, 30 insertions(+), 182 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 65f68e1..69d48af 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
@@ -245,29 +245,13 @@
                 split_device_type
             FROM
                 ja_fw_device d
-            LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                    PARTITION BY
-                    device_id
-                    ORDER BY
-                    create_time DESC
-                    ) AS rn
-                FROM
-                    ja_fw_device_track
-                WHERE
-                    out_target IS NOT NULL
-                ) t ON d.id = t.device_id AND t.rn = 1
             WHERE
                 d.is_deleted = 0
-            AND status != 3
-            AND track_status = 1
-            AND effective_range_km is not null
-            AND effective_range_km > 0
+                AND d.is_enabled = 1
+                AND status != 3
+                AND track_status = 1
             <if test="regionName != null and regionName != ''">
-                and (t.out_target = #{regionName}
+                and (d.final_outbound_area = #{regionName}
                 <!-- 或者设备是共享给当前部门的 -->
                 <if test="currentDeptId != null and currentDeptId != '' ">
                     or d.id in (
@@ -292,30 +276,14 @@
                 split_device_type
             FROM
                 ja_fw_device d
-            LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                    PARTITION BY
-                    device_id
-                    ORDER BY
-                    create_time DESC
-                ) AS rn
-            FROM
-                ja_fw_device_track
-            WHERE
-                out_target IS NOT NULL
-            ) t ON d.id = t.device_id AND t.rn = 1
             WHERE
                 d.is_deleted = 0
-            AND status != 3
-            AND device_type = '3'
-            AND track_status = 1
-            AND effective_range_km is not null
-            AND effective_range_km > 0
+                AND is_enabled = 1
+                AND status != 3
+                AND device_type = '3'
+                AND track_status = 1
             <if test="regionName != null and regionName != ''">
-                and (t.out_target = #{regionName}
+                and (d.final_outbound_area = #{regionName}
                 <!-- 或者设备是共享给当前部门的 -->
                 <if test="currentDeptId != null and currentDeptId != '' ">
                     or d.id in (
@@ -355,29 +323,14 @@
     <!-- 设备出库去向统计 -->
     <select id="getDeviceOutStatistics" resultType="org.sxkj.fw.cockpit.vo.DeviceStatisticsVO">
         SELECT
-            t.out_target AS type,
+            d.final_outbound_area AS type,
             COUNT(*) AS count
         FROM
             ja_fw_device d
-                LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                        PARTITION BY
-                            device_id
-                        ORDER BY
-                            create_time DESC
-                        ) AS rn
-                FROM
-                    ja_fw_device_track
-                WHERE
-                    out_target IS NOT NULL
-            ) t ON d.id = t.device_id
-                AND t.rn = 1
         WHERE
             d.is_deleted = 0
-          AND t.out_target IS NOT NULL
+            AND d.is_enabled = 1
+            AND d.final_outbound_area IS NOT NULL
         <if test="effectiveRangeKmIsNotNull != null and effectiveRangeKmIsNotNull == 1">
             and d.effective_range_km is not null
             and d.effective_range_km > 0
@@ -392,7 +345,7 @@
             </foreach>
         </if>
         GROUP BY
-            t.out_target
+            d.final_outbound_area
     </select>
 
     <!--  设备生产厂商统计  -->
@@ -422,29 +375,14 @@
                  COUNT(*)
              FROM
                  ja_fw_device d
-            LEFT JOIN (
-            SELECT
-                device_id,
-                out_target,
-                ROW_NUMBER() OVER (
-                PARTITION BY
-                device_id
-                ORDER BY
-                create_time DESC
-                ) AS rn
-            FROM
-                ja_fw_device_track
-            WHERE
-            out_target IS NOT NULL
-            ) t
-                ON d.id = t.device_id AND t.rn = 1
              WHERE
                  d.is_deleted = 0
+               and d.is_enabled = 1
                and effective_range_km is not null
                and effective_range_km > 0
                 AND track_status = 1
                 <if test="regionName != null and regionName != ''">
-                    and (t.out_target = #{regionName}
+                    and (d.final_outbound_area = #{regionName}
                     <!-- 或者设备是共享给当前部门的 -->
                     <if test="currentDeptId != null and currentDeptId != '' ">
                         or d.id in (
@@ -461,30 +399,15 @@
                  COUNT(*)
              FROM
                  ja_fw_device d
-            LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                    PARTITION BY
-                    device_id
-                    ORDER BY
-                    create_time DESC
-                    ) AS rn
-                FROM
-                    ja_fw_device_track
-                WHERE
-                    out_target IS NOT NULL
-                ) t
-                ON d.id = t.device_id AND t.rn = 1
              WHERE
                  d.is_deleted = 0
+               and d.is_enabled = 1
                AND device_att = '1'
                and effective_range_km is not null
                and effective_range_km > 0
                AND track_status = 1
                 <if test="regionName != null and regionName != ''">
-                and (t.out_target = #{regionName}
+                and (d.final_outbound_area = #{regionName}
                 <!-- 或者设备是共享给当前部门的 -->
                     <if test="currentDeptId != null and currentDeptId != '' ">
                         or d.id in (
@@ -501,29 +424,14 @@
                  COUNT(*)
              FROM
                  ja_fw_device d
-            LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                    PARTITION BY
-                    device_id
-                    ORDER BY
-                    create_time DESC
-                    ) AS rn
-                FROM
-                    ja_fw_device_track
-                WHERE
-                    out_target IS NOT NULL
-                ) t
-                ON d.id = t.device_id AND t.rn = 1
              WHERE d.is_deleted = 0
+               and d.is_enabled = 1
                AND device_att = '2'
                and effective_range_km is not null
                and effective_range_km > 0
                AND track_status = 1
             <if test="regionName != null and regionName != ''">
-                and (t.out_target = #{regionName}
+                and (d.final_outbound_area = #{regionName}
                 <!-- 或者设备是共享给当前部门的 -->
                 <if test="currentDeptId != null and currentDeptId != '' ">
                     or d.id in (
@@ -539,29 +447,14 @@
             (SELECT
                  COUNT(*)
              FROM ja_fw_device d
-            LEFT JOIN (
-            SELECT
-                device_id,
-                out_target,
-                ROW_NUMBER() OVER (
-                PARTITION BY
-                device_id
-                ORDER BY
-                create_time DESC
-                ) AS rn
-            FROM
-                ja_fw_device_track
-            WHERE
-            out_target IS NOT NULL
-            ) t
-            ON d.id = t.device_id AND t.rn = 1
              WHERE d.is_deleted = 0
+               and d.is_enabled = 1
                AND device_att = '3'
                and effective_range_km is not null
                and effective_range_km > 0
                AND track_status = 1
                 <if test="regionName != null and regionName != ''">
-                    and (t.out_target = #{regionName}
+                    and (d.final_outbound_area = #{regionName}
                     <!-- 或者设备是共享给当前部门的 -->
                     <if test="currentDeptId != null and currentDeptId != '' ">
                         or d.id in (
@@ -576,30 +469,15 @@
             -- 设备告警
             (SELECT
                  COUNT(*)
-             FROM ja_fw_device  d
-            LEFT JOIN (
-                SELECT
-                    device_id,
-                    out_target,
-                    ROW_NUMBER() OVER (
-                    PARTITION BY
-                    device_id
-                    ORDER BY
-                    create_time DESC
-                    ) AS rn
-                FROM
-                    ja_fw_device_track
-                WHERE
-                    out_target IS NOT NULL
-                ) t
-                ON d.id = t.device_id AND t.rn = 1
+             FROM ja_fw_device d
              WHERE d.is_deleted = 0
+               and d.is_enabled = 1
                AND status in ('1', '2', '3' )
                and effective_range_km is not null
                and effective_range_km > 0
                AND track_status = 1
                 <if test="regionName != null and regionName != ''">
-                    and (t.out_target = #{regionName}
+                    and (d.final_outbound_area = #{regionName}
                     <!-- 或者设备是共享给当前部门的 -->
                     <if test="currentDeptId != null and currentDeptId != '' ">
                         or d.id in (
@@ -618,29 +496,14 @@
             d.*
         from
             ja_fw_device d
-        LEFT JOIN (
-            SELECT
-                device_id,
-                out_target,
-                ROW_NUMBER() OVER (
-                PARTITION BY
-                device_id
-                ORDER BY
-                create_time DESC
-                ) AS rn
-            FROM
-                ja_fw_device_track
-            WHERE
-                out_target IS NOT NULL
-            ) t
-            ON d.id = t.device_id AND t.rn = 1
         <where>
             d.is_deleted = 0
-            and d.effective_range_km is not null
-            and d.effective_range_km > 0
+--             and d.effective_range_km is not null
+--             and d.effective_range_km > 0
             and d.track_status = 1
+            and d.is_enabled = 1
             <if test="param2.regionName != null and param2.regionName != ''">
-                and (t.out_target = #{param2.regionName}
+                and (d.final_outbound_area = #{param2.regionName}
                 <!-- 或者设备是共享给当前部门的 -->
                 <if test="param2.currentDeptId != null and param2.currentDeptId != '' ">
                     or d.id in (
@@ -720,31 +583,16 @@
             END AS isShared
         FROM
             ja_fw_device d
-            LEFT JOIN (
-            SELECT
-            device_id,
-            out_target,
-            ROW_NUMBER() OVER (
-            PARTITION BY
-            device_id
-            ORDER BY
-            create_time DESC
-            ) AS rn
-            FROM
-            ja_fw_device_track
-            WHERE
-            out_target IS NOT NULL
-            ) t ON d.id = t.device_id
-            AND t.rn = 1
             LEFT JOIN ja_fw_device_per_share ps ON ps.device_id = d.id
             AND ps.loan_to_dept_id = #{currentDeptId}
             AND ps.is_deleted = 0
         WHERE
             d.is_deleted = 0
+          and d.is_enabled = 1
           and d.effective_range_km is not null
           and d.effective_range_km > 0
           and d.track_status = 1
-          AND t.out_target != #{regionName}
+          AND d.final_outbound_area != #{regionName}
     </select>
 
 </mapper>

--
Gitblit v1.9.3