| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?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.fs.company.mapper.CompanyDeptMapper">
- <resultMap type="CompanyDept" id="CompanyDeptResult">
- <result property="deptId" column="dept_id" />
- <result property="parentId" column="parent_id" />
- <result property="companyId" column="company_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" />
- </resultMap>
- <sql id="selectCompanyDeptVo">
- select dept_id, parent_id, company_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, create_by, create_time, update_by, update_time from company_dept
- </sql>
- <select id="selectCompanyDeptList" parameterType="CompanyDept" resultMap="CompanyDeptResult">
- <include refid="selectCompanyDeptVo"/>
- <where>
- <if test="parentId != null "> and parent_id = #{parentId}</if>
- <if test="companyId != null "> and company_id = #{companyId}</if>
- <if test="ancestors != null and ancestors != ''"> and ancestors = #{ancestors}</if>
- <if test="deptName != null and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
- <if test="orderNum != null "> and order_num = #{orderNum}</if>
- <if test="leader != null and leader != ''"> and leader = #{leader}</if>
- <if test="phone != null and phone != ''"> and phone = #{phone}</if>
- <if test="email != null and email != ''"> and email = #{email}</if>
- <if test="status != null and status != ''"> and status = #{status}</if>
- </where>
- </select>
- <select id="selectCompanyDeptById" parameterType="Long" resultMap="CompanyDeptResult">
- <include refid="selectCompanyDeptVo"/>
- where dept_id = #{deptId}
- </select>
- <insert id="insertCompanyDept" parameterType="CompanyDept" useGeneratedKeys="true" keyProperty="deptId">
- insert into company_dept
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="parentId != null">parent_id,</if>
- <if test="companyId != null">company_id,</if>
- <if test="ancestors != null">ancestors,</if>
- <if test="deptName != null">dept_name,</if>
- <if test="orderNum != null">order_num,</if>
- <if test="leader != null">leader,</if>
- <if test="phone != null">phone,</if>
- <if test="email != null">email,</if>
- <if test="status != null">status,</if>
- <if test="delFlag != null">del_flag,</if>
- <if test="createBy != null">create_by,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateBy != null">update_by,</if>
- <if test="updateTime != null">update_time,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="parentId != null">#{parentId},</if>
- <if test="companyId != null">#{companyId},</if>
- <if test="ancestors != null">#{ancestors},</if>
- <if test="deptName != null">#{deptName},</if>
- <if test="orderNum != null">#{orderNum},</if>
- <if test="leader != null">#{leader},</if>
- <if test="phone != null">#{phone},</if>
- <if test="email != null">#{email},</if>
- <if test="status != null">#{status},</if>
- <if test="delFlag != null">#{delFlag},</if>
- <if test="createBy != null">#{createBy},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateBy != null">#{updateBy},</if>
- <if test="updateTime != null">#{updateTime},</if>
- </trim>
- </insert>
- <update id="updateCompanyDept" parameterType="CompanyDept">
- update company_dept
- <trim prefix="SET" suffixOverrides=",">
- <if test="parentId != null">parent_id = #{parentId},</if>
- <if test="companyId != null">company_id = #{companyId},</if>
- <if test="ancestors != null">ancestors = #{ancestors},</if>
- <if test="deptName != null">dept_name = #{deptName},</if>
- <if test="orderNum != null">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">status = #{status},</if>
- <if test="delFlag != null">del_flag = #{delFlag},</if>
- <if test="createBy != null">create_by = #{createBy},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateBy != null">update_by = #{updateBy},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- </trim>
- where dept_id = #{deptId}
- </update>
- <delete id="deleteCompanyDeptById" parameterType="Long">
- delete from company_dept where dept_id = #{deptId}
- </delete>
- <delete id="deleteCompanyDeptByIds" parameterType="String">
- delete from company_dept where dept_id in
- <foreach item="deptId" collection="array" open="(" separator="," close=")">
- #{deptId}
- </foreach>
- </delete>
- <delete id="deleteCompanyDeptByCompanyIds">
- delete from company_dept where company_id in
- <foreach item="companyId" collection="array" open="(" separator="," close=")">
- #{companyId}
- </foreach>
- </delete>
- <select id="selectDeptListByRoleId" resultType="Integer">
- select d.dept_id
- from company_dept d
- left join company_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 company_dept d inner join company_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="checkDeptExistUser" parameterType="Long" resultType="int">
- select count(1) from company_user where dept_id = #{deptId} and del_flag = '0'
- </select>
- <select id="hasChildByDeptId" parameterType="Long" resultType="int">
- select count(1) from company_dept
- where del_flag = '0' and parent_id = #{deptId} limit 1
- </select>
- <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
- select count(*) from company_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
- </select>
- <update id="updateDeptChildren" parameterType="java.util.List">
- update company_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="updateDeptStatus" parameterType="CompanyDept">
- update company_dept
- <set>
- <if test="status != null and status != ''">status = #{status},</if>
- <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
- update_time = sysdate()
- </set>
- where dept_id in (${ancestors})
- </update>
- <select id="selectChildrenDeptById" parameterType="Long" resultMap="CompanyDeptResult">
- select * from company_dept where find_in_set(#{deptId}, ancestors)
- </select>
- <select id="selectCompanyDeptByIds" resultType="com.fs.company.domain.CompanyDept">
- <include refid="selectCompanyDeptVo"/>
- where dept_id in
- <foreach collection="depts" item="deptId" index="index"
- separator="," open="(" close=")">
- #{deptId}
- </foreach>
- </select>
- <select id="getCurrentDeptIdDownTreeIds" parameterType="Long" resultType="Long">
- WITH RECURSIVE cte AS (
- SELECT
- *,
- 0 AS level
- FROM company_dept
- WHERE dept_id = #{deptId}
- UNION ALL
- SELECT
- t.*,
- cte.level + 1 AS level
- FROM company_dept t
- INNER JOIN cte
- ON t.parent_id = cte.dept_id
- )
- SELECT dept_id FROM cte ORDER BY level;
- </select>
- <select id="getDeptFullPathList" parameterType="Long" resultType="com.fs.course.vo.DeptFullPathVO">
- WITH RECURSIVE dept_path AS (
- SELECT
- dept_id,
- parent_id,
- dept_name,
- company_id,
- dept_name AS full_path
- FROM company_dept
- WHERE parent_id = 0
- AND company_id = #{companyId}
- UNION ALL
- SELECT
- c.dept_id,
- c.parent_id,
- c.dept_name,
- c.company_id,
- CONCAT(d.full_path, '_', c.dept_name) AS full_path
- FROM company_dept c
- INNER JOIN dept_path d
- ON c.parent_id = d.dept_id
- WHERE c.company_id = #{companyId}
- )
- SELECT dept_id, dept_name, full_path
- FROM dept_path
- ORDER BY full_path
- </select>
- </mapper>
|