| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.zd.system.mapper.SysDeptMapper">
- <resultMap type="com.zd.model.entity.SysDept" id="SysDeptResult">
- <id property="deptId" column="dept_id"/>
- <result property="parentId" column="parent_id"/>
- <result property="ancestors" column="ancestors"/>
- <result property="deptName" column="dept_name"/>
- <result property="deptNum" column="dept_num"/>
- <result property="orderNum" column="order_num"/>
- <result property="leader" column="leader"/>
- <result property="phone" column="phone"/>
- <result property="email" column="email"/>
- <result property="status" column="status"/>
- <result property="delFlag" column="del_flag"/>
- <result property="parentName" column="parent_name"/>
- <result property="createBy" column="create_by"/>
- <result property="createTime" column="create_time"/>
- <result property="updateBy" column="update_by"/>
- <result property="updateTime" column="update_time"/>
- <result property="deptImg" column="dept_img"/>
- <result property="deptSign" column="dept_sign"/>
- <result property="isLower" column="is_lower"/>
- </resultMap>
- <sql id="selectDeptVo">
- select d.dept_id,
- d.parent_id,
- d.ancestors,
- d.dept_name,
- d.dept_num,
- d.order_num,
- d.leader,
- d.phone,
- d.email,
- d.status,
- d.del_flag,
- d.create_by,
- d.create_time,
- d.dept_img,
- d.dept_sign,
- d.is_lower
- from sys_dept d
- </sql>
- <select id="selectDeptList" parameterType="com.zd.model.entity.SysDept" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.del_flag = '0'
- <if test="parentId != null and parentId != 0">
- AND parent_id = #{parentId}
- </if>
- <if test="deptName != null and deptName != ''">
- AND dept_name like concat('%', #{deptName}, '%')
- </if>
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- order by d.parent_id, d.order_num
- </select>
- <select id="treeselectByUser" parameterType="com.zd.model.entity.SysDept" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.del_flag = '0'
- <if test="parentId != null and parentId != 0">
- AND find_in_set(#{parentId}, ancestors)
- </if>
- <if test="deptName != null and deptName != ''">
- AND dept_name like concat('%', #{deptName}, '%')
- </if>
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- order by d.parent_id, d.order_num
- </select>
- <select id="selectDeptListByRoleId" resultType="java.lang.Integer">
- select d.dept_id
- from sys_dept d
- left join sys_role_dept rd on d.dept_id = rd.dept_id
- where rd.role_id = #{roleId}
- <if test="deptCheckStrictly">
- 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})
- </if>
- order by d.parent_id, d.order_num
- </select>
- <select id="selectDeptById" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_id = #{deptId}
- </select>
- <select id="checkDeptExistUser" resultType="int">
- select count(1)
- from sys_user
- where dept_id = #{deptId}
- and del_flag = '0'
- </select>
- <select id="hasChildByDeptId" resultType="int">
- select count(1)
- from sys_dept
- where del_flag = '0'
- and parent_id = #{deptId}
- </select>
- <select id="selectChildrenDeptById" resultMap="SysDeptResult">
- select *
- from sys_dept
- where find_in_set(#{deptId}, ancestors)
- </select>
- <select id="selectNormalChildrenDeptById" resultType="java.lang.Integer">
- select count(*)
- from sys_dept
- where status = 0
- and del_flag = '0'
- and find_in_set(#{deptId}, ancestors)
- </select>
- <select id="selectDownDeptListById" resultMap="SysDeptResult">
- SELECT *
- FROM sys_dept WHERE STATUS = 0 AND del_flag = '0' AND parent_id = #{parentId} order by order_num asc
- </select>
- <select id="selectMaxNumChildrenDeptById" resultType="java.lang.Integer">
- SELECT CASE WHEN MAX(order_num) IS NOT NULL THEN MAX(order_num)+1 ELSE 0 END
- FROM sys_dept WHERE STATUS = 0 AND del_flag = '0' AND parent_id = #{parentId}
- </select>
- <select id="selectChildrenDeptListById" resultMap="SysDeptResult">
- SELECT dt.* FROM sys_dept dt WHERE dt.STATUS = 0 AND dt.del_flag = '0'
- AND FIND_IN_SET(#{deptId}, dt.ancestors) ORDER BY dt.order_num ASC
- </select>
- <select id="checkDeptNameUnique" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_name=#{deptName}
- and parent_id = #{parentId}
- <if test="delFlag != null and delFlag != ''">
- AND del_flag = #{delFlag}
- </if>
- limit 1
- </select>
- <select id="getDeptNameUnique" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_name=#{deptName} limit 1
- </select>
- <select id="selectLayoutOrderByUserId" resultType="java.util.Map">
- select dept_id deptId,
- dept_class_name name,
- case
- when parent_id = (select dept_id from sys_user where user_id = #{userId})
- then 0
- else data_sort end as dataSort
- from sys_dept
- where dept_class_name is not null
- ORDER BY dataSort
- </select>
- <select id="selectAllParentId" resultType="java.lang.String">
- select group_concat(ancestors) from sys_dept where dept_id in
- <foreach item="id" collection="ids" open="(" separator="," close=")">
- #{id}
- </foreach>
- </select>
- <select id="selectBuildsList" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.del_flag = '0' and
- d.parent_id in (select dept_id from sys_dept where parent_id = 100)
- ${params.dataScope}
- </select>
- <select id="selectLevelByUserId" resultType="java.lang.Integer">
- select count(1) from sys_dept where dept_id = (select dept_id from sys_user where user_id = #{userId} and user_type = '11' limit 1) and parent_id = 0
- </select>
- <select id="queryDeptSignByUserId" resultType="java.lang.String">
- select
- case when a.dept_sign is not null then a.dept_sign
- when (select dept_sign from sys_dept where dept_id = a.parent_id and is_lower = 1) is not null
- then (select dept_sign from sys_dept where dept_id = a.parent_id and is_lower = 1)
- else (select dept_sign from sys_dept where dept_id = replace(replace(a.ancestors, concat(',', a.parent_id), ''), '0,', '') and is_lower = 1)
- end
- from (
- select dept_sign, dept_id, parent_id, ancestors
- from sys_dept
- where dept_id = (select dept_id from sys_user where user_id = #{userId})
- )a
- </select>
- <select id="selectDeptListByCollege" resultType="com.zd.model.entity.SysDept">
- <include refid="selectDeptVo"/>
- where d.del_flag = '0' AND parent_id in (select dept_id from sys_dept where parent_id = 0)
- <if test="deptName != null and deptName != ''">
- AND dept_name like concat('%', #{deptName}, '%')
- </if>
- <if test="status != null and status != ''">
- AND status = #{status}
- </if>
- <!-- 数据范围过滤 -->
- ${params.dataScope}
- order by d.parent_id, d.order_num
- </select>
- <insert id="insertDept" parameterType="com.zd.model.entity.SysDept">
- insert into sys_dept(
- <if test="deptId != null and deptId != 0">dept_id,</if>
- <if test="parentId != null and parentId != 0">parent_id,</if>
- <if test="deptNum != null and deptNum != ''">dept_num,</if>
- <if test="deptName != null and deptName != ''">dept_name,</if>
- <if test="ancestors != null and ancestors != ''">ancestors,</if>
- <if test="orderNum != null and orderNum != ''">order_num,</if>
- <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="status != null">status,</if>
- <if test="createBy != null and createBy != ''">create_by,</if>
- create_time
- )values(
- <if test="deptId != null and deptId != 0">#{deptId},</if>
- <if test="parentId != null and parentId != 0">#{parentId},</if>
- <if test="deptNum != null and deptNum != ''">#{deptNum},</if>
- <if test="deptName != null and deptName != ''">#{deptName},</if>
- <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
- <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
- <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="status != null">#{status},</if>
- <if test="createBy != null and createBy != ''">#{createBy},</if>
- sysdate()
- )
- </insert>
- <update id="updateDept" parameterType="com.zd.model.entity.SysDept">
- update sys_dept
- <set>
- <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
- <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
- <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
- <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
- <if test="leader != null">leader = #{leader},</if>
- <if test="phone != null">phone = #{phone},</if>
- <if test="email != null">email = #{email},</if>
- <if test="status != null and status != ''">status = #{status},</if>
- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
- <if test="deptSign != null and deptSign != ''">dept_sign = #{deptSign},</if>
- <if test="isLower != null">is_lower = #{isLower},</if>
- update_time = sysdate()
- </set>
- where dept_id = #{deptId}
- </update>
- <update id="updateDeptChildren" parameterType="java.util.List">
- update sys_dept set ancestors =
- <foreach collection="depts" item="item" index="index"
- separator=" " open="case dept_id" close="end">
- when #{item.deptId} then #{item.ancestors}
- </foreach>
- where dept_id in
- <foreach collection="depts" item="item" index="index"
- separator="," open="(" close=")">
- #{item.deptId}
- </foreach>
- </update>
- <update id="updateDeptStatusNormal" >
- update sys_dept set status = '0' where dept_id in
- <foreach collection="array" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </update>
- <delete id="deleteDeptById" >
- update sys_dept
- set del_flag = '2'
- where dept_id = #{deptId}
- </delete>
- </mapper>
|