From c447386e06ce5927fb6e3ccb22ee673535b3f566 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期一, 08 七月 2024 18:21:26 +0800 Subject: [PATCH] 标签增加部门字段、分页调整(未做权限) --- src/main/resources/mapper/DepartmentMapper.xml | 68 ++++++++++++++++++++++++++------- 1 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/resources/mapper/DepartmentMapper.xml b/src/main/resources/mapper/DepartmentMapper.xml index db2d1fb..f1413a2 100644 --- a/src/main/resources/mapper/DepartmentMapper.xml +++ b/src/main/resources/mapper/DepartmentMapper.xml @@ -5,21 +5,23 @@ <id column="id" jdbcType="INTEGER" property="id"/> <result column="name" jdbcType="VARCHAR" property="name"/> <result column="deleted" jdbcType="VARCHAR" property="deleted"/> + <result column="parent_id" property="parentId"/> </resultMap> <sql id="Base_Column_List"> id - , name,deleted + , name,deleted,parent_id </sql> <insert id="add" parameterType="com.mindskip.xzs.domain.Department" useGeneratedKeys="true" keyProperty="id"> - insert into t_department (name, deleted) - values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR}) + insert into t_department (name, deleted, parent_id) + values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR}, #{parentId}) </insert> <update id="update" parameterType="com.mindskip.xzs.domain.Department"> update t_department <set> + parent_id = #{parentId}, <if test="name != null"> name = #{name,jdbcType=VARCHAR}, </if> @@ -37,15 +39,13 @@ SELECT td.id, td.name, - td.admin_id as adminId, - tu.real_name as adminName + td.parent_id FROM t_department td - LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 WHERE td.deleted = 0 - <if test="deptId != null"> - AND td.id = #{deptId} + <if test="deptId != null and deptId.size() > 0"> + AND td.id in <foreach collection="deptId" item="item" index="index" open="(" separator="," close=")"> #{item} </foreach> </if> </select> @@ -53,25 +53,44 @@ SELECT td.id, td.name, - td.admin_id as adminId, - tu.real_name as adminName + td.parent_id FROM t_department td - LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 WHERE td.id = #{id} AND td.deleted = 0 </select> - <select id="page" resultType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM" + <resultMap id="pageResult" type="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"> + <id column="id" property="id"/> + <result column="name" property="name"/> + <collection column="id" property="adminIds" ofType="integer" select="selectUserIdsByDeptId"></collection> + <collection column="id" property="adminNames" ofType="integer" select="selectUserNamesByDeptId"></collection> + </resultMap> + + <select id="selectUserIdsByDeptId" resultType="integer"> + SELECT + tu.id + FROM + t_user_department tud + INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1 + </select> + + <select id="selectUserNamesByDeptId" resultType="string"> + SELECT + tu.real_name + FROM + t_user_department tud + INNER JOIN t_user tu ON tud.user_id = tu.id AND tud.department_id = #{deptId} AND tu.status = 1 AND deleted = 0 AND tud.dept_admin = 1 + </select> + + <select id="page" resultMap="pageResult" parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"> SELECT td.id, td.name, - td.admin_id as adminId, - tu.real_name as adminName + td.parent_id FROM t_department td - LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 <where> AND td.deleted = 0 <if test="id != null "> @@ -88,6 +107,7 @@ SELECT td.id, td.name, + td.parent_id, td.admin_id as adminId, tu.real_name as adminName FROM @@ -105,4 +125,22 @@ SELECT count(*) FROM t_department WHERE admin_id = #{userId} AND deleted = 0 AND id != #{id} </select> + <select id="list" resultType="com.mindskip.xzs.domain.vo.CascaderDataVO"> + SELECT id as value, name as label, parent_id FROM t_department WHERE deleted = 0 + </select> + + <select id="getChilds" resultType="integer"> + WITH RECURSIVE temp_table AS ( + SELECT + id, name, parent_id FROM t_department WHERE id in <foreach collection="deptIds" open="(" item="deptId" close=")" separator=",">#{deptId}</foreach> + UNION ALL + SELECT + so.id, so.name, so.parent_id FROM t_department so INNER JOIN temp_table tb ON so.parent_id = tb.id + ) + SELECT + DISTINCT id + FROM + temp_table + </select> + </mapper> -- Gitblit v1.8.0