Jiarenxiang | 25a45b7 | 2025-03-13 16:09:13 +0800 | [diff] [blame^] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <!DOCTYPE mapper |
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 5 | <mapper namespace="com.ruoyi.system.mapper.SysDeptMapper"> |
| 6 | |
| 7 | <resultMap type="SysDept" id="SysDeptResult"> |
| 8 | <id property="deptId" column="dept_id" /> |
| 9 | <result property="parentId" column="parent_id" /> |
| 10 | <result property="ancestors" column="ancestors" /> |
| 11 | <result property="deptName" column="dept_name" /> |
| 12 | <result property="orderNum" column="order_num" /> |
| 13 | <result property="leader" column="leader" /> |
| 14 | <result property="phone" column="phone" /> |
| 15 | <result property="email" column="email" /> |
| 16 | <result property="status" column="status" /> |
| 17 | <result property="delFlag" column="del_flag" /> |
| 18 | <result property="parentName" column="parent_name" /> |
| 19 | <result property="createBy" column="create_by" /> |
| 20 | <result property="createTime" column="create_time" /> |
| 21 | <result property="updateBy" column="update_by" /> |
| 22 | <result property="updateTime" column="update_time" /> |
| 23 | </resultMap> |
| 24 | |
| 25 | <sql id="selectDeptVo"> |
| 26 | select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time |
| 27 | from sys_dept d |
| 28 | </sql> |
| 29 | |
| 30 | <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult"> |
| 31 | <include refid="selectDeptVo"/> |
| 32 | where d.del_flag = '0' |
| 33 | <if test="deptId != null and deptId != 0"> |
| 34 | AND dept_id = #{deptId} |
| 35 | </if> |
| 36 | <if test="parentId != null and parentId != 0"> |
| 37 | AND parent_id = #{parentId} |
| 38 | </if> |
| 39 | <if test="deptName != null and deptName != ''"> |
| 40 | AND dept_name like concat('%', #{deptName}, '%') |
| 41 | </if> |
| 42 | <if test="status != null and status != ''"> |
| 43 | AND status = #{status} |
| 44 | </if> |
| 45 | <!-- 数据范围过滤 --> |
| 46 | ${params.dataScope} |
| 47 | order by d.parent_id, d.order_num |
| 48 | </select> |
| 49 | |
| 50 | <select id="selectDeptListByRoleId" resultType="Long"> |
| 51 | select d.dept_id |
| 52 | from sys_dept d |
| 53 | left join sys_role_dept rd on d.dept_id = rd.dept_id |
| 54 | where rd.role_id = #{roleId} |
| 55 | <if test="deptCheckStrictly"> |
| 56 | and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId}) |
| 57 | </if> |
| 58 | order by d.parent_id, d.order_num |
| 59 | </select> |
| 60 | |
| 61 | <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult"> |
| 62 | select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, |
| 63 | (select dept_name from sys_dept where dept_id = d.parent_id) parent_name |
| 64 | from sys_dept d |
| 65 | where d.dept_id = #{deptId} |
| 66 | </select> |
| 67 | |
| 68 | <select id="checkDeptExistUser" parameterType="Long" resultType="int"> |
| 69 | select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0' |
| 70 | </select> |
| 71 | |
| 72 | <select id="hasChildByDeptId" parameterType="Long" resultType="int"> |
| 73 | select count(1) from sys_dept |
| 74 | where del_flag = '0' and parent_id = #{deptId} limit 1 |
| 75 | </select> |
| 76 | |
| 77 | <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult"> |
| 78 | select * from sys_dept where find_in_set(#{deptId}, ancestors) |
| 79 | </select> |
| 80 | |
| 81 | <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int"> |
| 82 | select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors) |
| 83 | </select> |
| 84 | |
| 85 | <select id="checkDeptNameUnique" resultMap="SysDeptResult"> |
| 86 | <include refid="selectDeptVo"/> |
| 87 | where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1 |
| 88 | </select> |
| 89 | |
| 90 | <insert id="insertDept" parameterType="SysDept"> |
| 91 | insert into sys_dept( |
| 92 | <if test="deptId != null and deptId != 0">dept_id,</if> |
| 93 | <if test="parentId != null and parentId != 0">parent_id,</if> |
| 94 | <if test="deptName != null and deptName != ''">dept_name,</if> |
| 95 | <if test="ancestors != null and ancestors != ''">ancestors,</if> |
| 96 | <if test="orderNum != null">order_num,</if> |
| 97 | <if test="leader != null and leader != ''">leader,</if> |
| 98 | <if test="phone != null and phone != ''">phone,</if> |
| 99 | <if test="email != null and email != ''">email,</if> |
| 100 | <if test="status != null">status,</if> |
| 101 | <if test="createBy != null and createBy != ''">create_by,</if> |
| 102 | create_time |
| 103 | )values( |
| 104 | <if test="deptId != null and deptId != 0">#{deptId},</if> |
| 105 | <if test="parentId != null and parentId != 0">#{parentId},</if> |
| 106 | <if test="deptName != null and deptName != ''">#{deptName},</if> |
| 107 | <if test="ancestors != null and ancestors != ''">#{ancestors},</if> |
| 108 | <if test="orderNum != null">#{orderNum},</if> |
| 109 | <if test="leader != null and leader != ''">#{leader},</if> |
| 110 | <if test="phone != null and phone != ''">#{phone},</if> |
| 111 | <if test="email != null and email != ''">#{email},</if> |
| 112 | <if test="status != null">#{status},</if> |
| 113 | <if test="createBy != null and createBy != ''">#{createBy},</if> |
| 114 | sysdate() |
| 115 | ) |
| 116 | </insert> |
| 117 | |
| 118 | <update id="updateDept" parameterType="SysDept"> |
| 119 | update sys_dept |
| 120 | <set> |
| 121 | <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if> |
| 122 | <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if> |
| 123 | <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if> |
| 124 | <if test="orderNum != null">order_num = #{orderNum},</if> |
| 125 | <if test="leader != null">leader = #{leader},</if> |
| 126 | <if test="phone != null">phone = #{phone},</if> |
| 127 | <if test="email != null">email = #{email},</if> |
| 128 | <if test="status != null and status != ''">status = #{status},</if> |
| 129 | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| 130 | update_time = sysdate() |
| 131 | </set> |
| 132 | where dept_id = #{deptId} |
| 133 | </update> |
| 134 | |
| 135 | <update id="updateDeptChildren" parameterType="java.util.List"> |
| 136 | update sys_dept set ancestors = |
| 137 | <foreach collection="depts" item="item" index="index" |
| 138 | separator=" " open="case dept_id" close="end"> |
| 139 | when #{item.deptId} then #{item.ancestors} |
| 140 | </foreach> |
| 141 | where dept_id in |
| 142 | <foreach collection="depts" item="item" index="index" |
| 143 | separator="," open="(" close=")"> |
| 144 | #{item.deptId} |
| 145 | </foreach> |
| 146 | </update> |
| 147 | |
| 148 | <update id="updateDeptStatusNormal" parameterType="Long"> |
| 149 | update sys_dept set status = '0' where dept_id in |
| 150 | <foreach collection="array" item="deptId" open="(" separator="," close=")"> |
| 151 | #{deptId} |
| 152 | </foreach> |
| 153 | </update> |
| 154 | |
| 155 | <delete id="deleteDeptById" parameterType="Long"> |
| 156 | update sys_dept set del_flag = '2' where dept_id = #{deptId} |
| 157 | </delete> |
| 158 | |
| 159 | </mapper> |