From 8ac34cbae4ea8cc47194f51389a4e2dddebcc7d5 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Thu, 02 Apr 2026 13:55:20 +0800
Subject: [PATCH] opt: sql改造其他模块改造7

---
 drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml |   66 +++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml b/drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml
index 5974fb0..434ce18 100644
--- a/drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml
+++ b/drone-service/drone-system/src/main/java/org/sxkj/system/mapper/DeptMapper.xml
@@ -77,8 +77,11 @@
 
     <select id="tree" resultMap="treeNodeResultMap">
         select id, parent_id, dept_name as title, id as "value", id as "key" from blade_dept where is_deleted = 0
-        <if test="_parameter!=null and _parameter!=''">
-            and tenant_id = #{_parameter}
+        <if test="param1!=null and param1!=''">
+            and tenant_id = #{param1}
+        </if>
+        <if test="param2!=null and param2!=''">
+            and sys_type = #{param2}
         </if>
         ORDER BY sort
     </select>
@@ -150,7 +153,7 @@
     <!--自定义详情查询-根据系统配置id-->
     <select id="getDetailBySysConfigId" resultType="org.sxkj.system.vo.DeptVO">
         select bd.* from blade_dept bd
-        left join sys_config sc on sc.dept_id = bd.id and sc.is_deleted = 0
+        left join sys_config sc on sc.dept_id = bd.id::VARCHAR and sc.is_deleted = 0
         where bd.is_deleted = 0
         and sc.id = #{dept.sysConfigId}
     </select>
@@ -160,7 +163,7 @@
         select
         bd.*,sc.id as sysConfigId,sc.name as sysName
         from blade_dept bd
-        left join sys_config sc on sc.dept_id = bd.id and sc.is_deleted = 0
+        left join sys_config sc on sc.dept_id = bd.id::VARCHAR and sc.is_deleted = 0
         where bd.is_deleted = 0
         and (
         bd.id = #{deptId}
@@ -173,10 +176,10 @@
         select
         bd.*,sc.name as sysName
         from blade_dept bd
-        left join sys_config sc on sc.dept_id = bd.id and sc.is_deleted = 0
+        left join sys_config sc on sc.dept_id = bd.id::VARCHAR and sc.is_deleted = 0
         where bd.is_deleted = 0
         and (
-        bd.id = #{deptId}
+        bd.id = #{deptId}::bigint
         or bd.ancestors like concat('%',#{deptId},'%')
         )
         and bd.dept_category = 1
@@ -192,10 +195,10 @@
         bd.sort
         FROM
         blade_dept bd
-        left join manage_device_per_share ddps on ddps.loan_to_dept_id = bd.id
+        left join manage_device_per_share ddps on ddps.loan_to_dept_id = bd.id::VARCHAR
         where bd.is_deleted = 0
         and bd.id != #{deptId}
-        and ifnull(device_sn,'') != #{deviceSn}
+        and COALESCE(device_sn,'') != #{deviceSn}
         and bd.id not in (
             -- 排除当前部门的所有上级部门
             select parent_dept.id
@@ -244,8 +247,8 @@
         SELECT
         CONCAT(p.name, ' ', c.name, ' ', r.name) AS full_region_name
         FROM blade_region r
-        LEFT JOIN blade_region c ON r.parent_code = c.code  <!-- 市级 -->
-        LEFT JOIN blade_region p ON c.parent_code = p.code  <!-- 省级 -->
+        LEFT JOIN blade_region c ON r.parent_code = c.code::VARCHAR  <!-- 市级 -->
+        LEFT JOIN blade_region p ON c.parent_code = p.code::VARCHAR  <!-- 省级 -->
         WHERE r.code = #{areaCode}
     </select>
     <select id="getSingleRegionName" resultType="string">
@@ -260,7 +263,7 @@
         <!-- 市级:后 8 位为 0,且不是省级 -->
         SELECT CONCAT(p.name, ' ', c.name) AS full_region_name
         FROM blade_region c
-        LEFT JOIN blade_region p ON c.parent_code = p.code
+        LEFT JOIN blade_region p ON c.parent_code = p.code::VARCHAR
         WHERE SUBSTRING(#{areaCode}, 5, 8) = '00000000'
         AND SUBSTRING(#{areaCode}, 3, 10) != '0000000000'
         AND c.code = #{areaCode}
@@ -270,8 +273,8 @@
         <!-- 县级:后 8 位不全为 0 -->
         SELECT CONCAT(p.name, ' ', c.name, ' ', r.name) AS full_region_name
         FROM blade_region r
-        LEFT JOIN blade_region c ON r.parent_code = c.code
-        LEFT JOIN blade_region p ON c.parent_code = p.code
+        LEFT JOIN blade_region c ON r.parent_code = c.code::VARCHAR
+        LEFT JOIN blade_region p ON c.parent_code = p.code::VARCHAR
         WHERE SUBSTRING(#{areaCode}, 5, 8) != '00000000'
         AND r.code = #{areaCode}
     </select>
@@ -281,17 +284,17 @@
             bd.*,
             br.name AS area_name
         FROM
-            blade_dept bd LEFT JOIN blade_region br ON br.code = bd.area_code
+            blade_dept bd LEFT JOIN blade_region br ON br.code = bd.area_code::VARCHAR
         WHERE
             bd.is_deleted = 0
         <if test="param2.deptName!=null and param2.deptName!=''">
             and bd.dept_name like concat(concat('%', #{param2.deptName}),'%')
         </if>
-        <if test="param2.fullName!=null and param2.fullName!=''">
-            and bd.full_name like concat(concat('%', #{param2.fullName}),'%')
-        </if>
         <if test="param2.areaCode!=null and param2.areaCode!=''">
-            and bd.area_code = #{param2.areaCode}
+            and bd.area_code like concat(concat('%', #{param2.areaCode}),'%')
+        </if>
+        <if test="param2.deptCode!=null and param2.deptCode!=''">
+            and bd.dept_code = #{param2.deptCode}
         </if>
             ORDER BY bd.create_time DESC
     </select>
@@ -303,7 +306,7 @@
         FROM
             blade_dept bd
         LEFT JOIN
-            blade_region br ON br.code = bd.area_code
+            blade_region br ON br.code = bd.area_code::VARCHAR
         WHERE
             bd.is_deleted = 0
         <if test="deptName!=null and deptName!=''">
@@ -315,6 +318,31 @@
         <if test="areaCode!=null and areaCode!=''">
             and bd.area_code = #{areaCode}
         </if>
+        <if test="deptIds!=null and deptIds.size()>0">
+            and bd.id in
+            <foreach item="item" index="index" collection="deptIds" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
+    <!--获取部门详情(包含区域名称)-->
+    <select id="getDetailWithAreaName" resultType="org.sxkj.system.vo.DeptVO">
+        SELECT
+            bd.*,
+            br.name AS area_name
+        FROM
+            blade_dept bd
+        LEFT JOIN
+            blade_region br ON br.code = bd.area_code::VARCHAR
+        WHERE
+            bd.is_deleted = 0
+        <if test="dept.id!=null">
+            and bd.id = #{dept.id}
+        </if>
+        <if test="dept.deptCode!=null and dept.deptCode!=''">
+            and bd.dept_code = #{dept.deptCode}
+        </if>
     </select>
 
 

--
Gitblit v1.9.3