zss
2 天以前 beaa6e8dcf350fc50320518b9c92986785a2fac9
src/main/resources/mapper/system/SysDeptMapper.xml
@@ -60,7 +60,8 @@
    
    <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
      select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
         (select dept_name from sys_dept where dept_id = d.parent_id) parent_name
         (select dept_name from sys_dept where dept_id = d.parent_id) parent_name,
         d.dept_nick
      from sys_dept d
      where d.dept_id = #{deptId}
   </select>
@@ -97,6 +98,7 @@
          <if test="leader != null and leader != ''">leader,</if>
          <if test="phone != null and phone != ''">phone,</if>
          <if test="email != null and email != ''">email,</if>
          <if test="deptNick != null and deptNick != ''">dept_nick,</if>
          <if test="status != null">status,</if>
          <if test="createBy != null and createBy != ''">create_by,</if>
          create_time
@@ -109,6 +111,7 @@
          <if test="leader != null and leader != ''">#{leader},</if>
          <if test="phone != null and phone != ''">#{phone},</if>
          <if test="email != null and email != ''">#{email},</if>
          <if test="deptNick != null and deptNick != '' ">#{deptNick},</if>
          <if test="status != null">#{status},</if>
          <if test="createBy != null and createBy != ''">#{createBy},</if>
          sysdate()
@@ -125,6 +128,7 @@
          <if test="leader != null">leader = #{leader},</if>
          <if test="phone != null">phone = #{phone},</if>
          <if test="email != null">email = #{email},</if>
         <if test="deptNick != null and deptNick != '' ">dept_nick = #{deptNick},</if>
          <if test="status != null and status != ''">status = #{status},</if>
          <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
          update_time = sysdate()
@@ -156,4 +160,23 @@
      update sys_dept set del_flag = '2' where dept_id = #{deptId}
   </delete>
   <select id="maxLevelDeptId">
      WITH RECURSIVE DepartmentHierarchy AS (
         SELECT dept_id, parent_id
         FROM sys_dept
         WHERE dept_id = #{deptId}
         UNION ALL
         -- 递归情况:加入当前部门的父级部门
         SELECT d.dept_id, d.parent_id
         FROM sys_dept d
                INNER JOIN DepartmentHierarchy dh ON d.dept_id = dh.parent_id
      )
      -- 查询最顶级的父级部门ID
      SELECT dept_id as top_level_department_id
      FROM DepartmentHierarchy
      WHERE parent_id = 100;
   </select>
</mapper>