| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?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.zksy.system.mapper.SysDeptMapper">
- <resultMap type="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="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="createBy" column="create_by"/>
- <result property="createTime" column="create_time"/>
- <result property="updateBy" column="update_by"/>
- <result property="updateTime" column="update_time"/>
- <result property="remark" column="remark"/>
- </resultMap>
- <sql id="selectDeptVo">
- 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,d.remark
- from sys_dept d
- </sql>
- <select id="selectDeptList" parameterType="SysDept" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where d.del_flag = '0'
- <if test="deptId != null and deptId != 0">
- AND dept_id = #{deptId}
- </if>
- <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="selectDeptListByRoleId" resultType="Long">
- 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" parameterType="Long" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_id = #{deptId}
- </select>
- <select id="checkDeptExistUser" parameterType="Long" resultType="int">
- select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
- </select>
- <select id="hasChildByDeptId" parameterType="Long" resultType="int">
- select count(1) from sys_dept
- where del_flag = '0' and parent_id = #{deptId} limit 1
- </select>
- <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
- select * from sys_dept where find_in_set(#{deptId}, ancestors)
- </select>
- <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
- select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
- </select>
- <select id="checkDeptNameUnique" resultMap="SysDeptResult">
- <include refid="selectDeptVo"/>
- where dept_name=#{deptName} and parent_id = #{parentId} limit 1
- </select>
- <insert id="insertDept" parameterType="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="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="orgType != null and orgType != ''">org_type,</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="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="orgType != null and orgType != ''">#{orgType},</if>-->
- <if test="createBy != null and createBy != ''">#{createBy},</if>
- sysdate()
- )
- </insert>
- <update id="updateDept" parameterType="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="orgType != null and orgType != ''">org_type = #{orgType},</if>-->
- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</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" parameterType="Long">
- update sys_dept set status = '0' where dept_id in
- <foreach collection="array" item="deptId" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </update>
- <delete id="deleteDeptById" parameterType="Long">
- update sys_dept set del_flag = '2' where dept_id = #{deptId}
- </delete>
- <!--查看下级部门-->
- <select id="selectFindNextDept" resultType="com.zksy.system.model.respone.FindNextDeptRes"
- parameterType="com.zksy.system.model.request.NextDeptReq">
- SELECT
- s.dept_id deptId,
- s.dept_name deptName,
- ( SELECT dept_name FROM sys_dept WHERE dept_id = s.parent_id ) superiorDept,
- sdd.dict_value deptType,
- sdd.dict_label deptTypeValue,
- s.charge_person chargePerson,
- s.charge_phone chargePhone,
- s.establish_time establishTime,
- s.status,
- res.num memRs
- FROM
- sys_dept s
- LEFT JOIN (
- SELECT
- count(0) num,
- u.dept_id
- FROM
- sys_user u
- WHERE
- u.del_flag = '0'
- AND u.user_source IN ( 0, 1 )
- AND user_type = '2'
- and u.`status`= '0'
- GROUP BY u.dept_id
- ) res ON s.dept_id = res.dept_id
- LEFT JOIN sys_dict_data sdd ON sdd.dict_value = s.dept_type
- WHERE
- s.parent_id = #{deptId} AND s.del_flag = '0' AND sdd.dict_type = 'dept_type' AND
- s.`status` = '0'
- <if test="deptName != null and deptName != '' ">
- AND s.dept_Name LIKE concat('%',#{deptName,jdbcType=VARCHAR},'%')
- </if>
- <if test="deptType != null and deptType != '' ">
- AND s.dept_type = #{deptType}
- </if>
- </select>
- <!-- 查看部门资料-->
- <select id="findDataDept" resultType="com.zksy.system.model.respone.DataDeptRecord" parameterType="string">
- SELECT
- s.*,
- dd.dict_label deptTypeValue,
- sd.dept_name superiorDept,
- sd.dept_id superiorDeptId,
- res.num memRs
- FROM
- sys_dept s
- LEFT JOIN (
- SELECT
- count(0) num,
- u.dept_id
- FROM
- sys_user u
- WHERE
- u.del_flag = '0'
- AND u.user_source IN ( 0, 1 )
- AND user_type = '2'
- GROUP BY u.dept_id
- ) res ON s.dept_id = res.dept_id
- LEFT JOIN sys_dict_data dd ON dd.dict_value = s.dept_type
- LEFT JOIN sys_dept sd ON sd.dept_id = s.parent_id -- 查上级部门名字
- WHERE s.dept_id = #{deptId} AND dd.dict_type = 'dept_type'
- </select>
- <select id="selectLevelAndChild" parameterType="Long" resultType="com.zksy.common.core.domain.entity.SysDept">
- SELECT
- ID.LEVEL,
- DATA.dept_id id,
- DATA.dept_name label,
- DATA.*
- FROM
- (
- SELECT
- @ids AS _ids,
- ( SELECT @ids := GROUP_CONCAT( dept_id ) FROM sys_dept WHERE FIND_IN_SET( parent_id , @ids ) /*and approve_status='1'*/ and del_flag='0') AS cids,
- @l := @l + 1 AS LEVEL
- FROM
- sys_dept,
- ( SELECT @ids := #{deptId} , @l := 0 ) b
- WHERE
- @ids IS NOT NULL
- ) ID,
- sys_dept DATA
- WHERE
- FIND_IN_SET( DATA.dept_id, ID._ids ) /*and DATA.approve_status='1'*/ and DATA.del_flag='0'
- ORDER BY
- LEVEL,
- DATA.dept_type,
- dept_id
- </select>
- <!--导出下级单位-->
- <select id="exportDept" resultType="com.zksy.system.model.respone.NextDeptExport"
- parameterType="com.zksy.system.model.request.NextDeptExportReq">
- SELECT
- s.dept_name deptName,
- ( SELECT dept_name FROM sys_dept WHERE dept_id = s.parent_id ) superiorDept,
- sdd.dict_label deptTypeValue,
- s.charge_person chargePerson,
- s.charge_phone chargePhone,
- s.establish_time establishTime,
- res.num memRs
- FROM
- sys_dept s
- LEFT JOIN (
- SELECT
- count(0) num,
- u.dept_id
- FROM
- sys_user u
- WHERE
- u.del_flag = '0'
- AND u.user_source IN ( 0, 1 )
- AND user_type = '2'
- and u.`status`= '0'
- GROUP BY u.dept_id
- ) res ON s.dept_id = res.dept_id
- LEFT JOIN sys_dict_data sdd ON sdd.dict_value = s.dept_type
- WHERE
- s.parent_id = #{deptId} AND s.del_flag = '0' AND sdd.dict_type = 'dept_type'
- <if test="deptName != null and deptName != '' ">
- AND s.dept_Name LIKE concat('%',#{deptName,jdbcType=VARCHAR},'%')
- </if>
- <if test="deptType != null and deptType != '' ">
- AND s.dept_type = #{deptType}
- </if>
- </select>
- <select id="findupDept" resultType="com.zksy.system.model.respone.FindUpDeptRes">
- SELECT
- dept_id,
- parent_id,
- dept_name
- FROM
- sys_dept
- WHERE
- dept_id = #{deptId}
- </select>
- <select id="findUpId" resultType="com.zksy.system.model.respone.FindUpDeptRes">
- SELECT
- dept_id,
- parent_id,
- dept_name
- FROM
- sys_dept
- WHERE
- dept_id = #{deptId}
- </select>
- <select id="findPare" resultType="com.zksy.system.model.respone.FindUpDeptRes">
- SELECT
- dept_id,
- parent_id,
- dept_name
- FROM
- sys_dept
- WHERE
- parent_id = #{parentId}
- </select>
- </mapper>
|