吉安感知网项目-后端
linwei
2026-04-22 de09889cb97fcd7e9ae3236d3cb0d9f2f752e439
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>
@@ -143,14 +146,14 @@
        blade_dept
        where is_deleted = 0
        <if test="deptId!=null and deptId!=''">
            and (id = #{deptId} or ancestors like concat('%',#{deptId},'%'))
            and (id = #{deptId}::bigint or ancestors like concat('%',#{deptId},'%'))
        </if>
    </select>
    <!--自定义详情查询-根据系统配置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::VARCHAR = bd.id::VARCHAR and sc.is_deleted = 0
        where bd.is_deleted = 0
        and sc.id = #{dept.sysConfigId}
    </select>
@@ -160,10 +163,10 @@
        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::VARCHAR = 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},'%')
        )
    </select>
@@ -173,10 +176,12 @@
        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::VARCHAR = 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 +197,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::VARCHAR = 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 +249,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::VARCHAR = c.code::VARCHAR  <!-- 市级 -->
        LEFT JOIN blade_region p ON c.parent_code::VARCHAR = p.code::VARCHAR  <!-- 省级 -->
        WHERE r.code = #{areaCode}
    </select>
    <select id="getSingleRegionName" resultType="string">
@@ -260,7 +265,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 +275,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 +286,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 like concat(concat('%', #{param2.deptCode}),'%')
        </if>
            ORDER BY bd.create_time DESC
    </select>
@@ -303,7 +308,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 +320,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>