From 7f25606654ebe94b5d82cfd9f74275989c71538d Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期二, 16 七月 2024 11:47:40 +0800 Subject: [PATCH] feat:默认选中当前部门 --- src/main/resources/mapper/DepartmentMapper.xml | 155 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 141 insertions(+), 14 deletions(-) diff --git a/src/main/resources/mapper/DepartmentMapper.xml b/src/main/resources/mapper/DepartmentMapper.xml index 43083d2..bb6a0ff 100644 --- a/src/main/resources/mapper/DepartmentMapper.xml +++ b/src/main/resources/mapper/DepartmentMapper.xml @@ -5,49 +5,176 @@ <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"/> + <result column="special" property="special"/> + <result column="level" property="level"/> </resultMap> <sql id="Base_Column_List"> - id, name,deleted + id + , name,deleted,parent_id,special,level </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,special,level) + values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR}, #{parentId}, #{special.value},#{level}) </insert> <update id="update" parameterType="com.mindskip.xzs.domain.Department"> - update t_user + update t_department <set> + parent_id = #{parentId}, <if test="name != null"> name = #{name,jdbcType=VARCHAR}, </if> + <if test="adminId != null"> + admin_id = #{adminId}, + </if> <if test="deleted != null"> - name = #{deleted,jdbcType=VARCHAR}, + deleted = #{deleted,jdbcType=VARCHAR}, + </if> + <if test="special != null and special != ''"> + special = #{special.value}, + </if> + <if test="level != null"> + level = #{level}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <select id="gets" resultMap="BaseResultMap"> - select - <include refid="Base_Column_List"/> - from t_department where deleted=0 + SELECT + td.id, + td.name, + td.parent_id, + td.special, + td.level + FROM + t_department td + WHERE + td.deleted = 0 + <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> - <select id="page" resultMap="BaseResultMap" parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM"> + <select id="getById" resultMap="BaseResultMap"> SELECT - <include refid="Base_Column_List"/> - FROM t_department + td.id, + td.name, + td.parent_id, + td.special, + td.level + FROM + t_department td + WHERE + td.id = #{id} AND td.deleted = 0 + </select> + + <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.parent_id, + td.special, + td.level + FROM + t_department td <where> - and deleted=0 + AND td.deleted = 0 <if test="id != null "> - and id= #{id} + AND td.id= #{id} </if> <if test="name != null "> - and name like concat('%',#{name},'%') + AND td.name like concat('%',#{name},'%') </if> </where> </select> + + <select id="getName" resultMap="BaseResultMap"> + SELECT + td.id, + td.name, + td.parent_id, + td.special, + td.level, + td.admin_id as adminId, + tu.real_name as adminName + FROM + t_department td + LEFT JOIN t_user tu ON td.admin_id = tu.id AND tu.deleted = 0 + WHERE + td.name = #{name} AND td.deleted = 0 + </select> + + <select id="selectByAdminId" resultType="integer"> + SELECT id FROM t_department WHERE admin_id = #{userId} AND deleted = 0 + </select> + + <select id="countByAdminId" resultType="integer"> + 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, special, level FROM t_department WHERE deleted = 0 + </select> + + <select id="getChilds" resultType="integer"> + WITH RECURSIVE temp_table AS ( + SELECT + id, name, parent_id,special,level 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, so.special, so.level FROM t_department so INNER JOIN temp_table tb ON so.parent_id = tb.id + ) + SELECT + DISTINCT id + FROM + temp_table + </select> + + <select id="getFather" resultType="integer"> + WITH RECURSIVE temp_table AS ( + SELECT + id, name, parent_id,special,level FROM t_department WHERE id = #{deptId} + UNION ALL + SELECT + so.id, so.name, so.parent_id, so.special, so.level FROM t_department so INNER JOIN temp_table tb ON so.id = tb.parent_id + ) + SELECT + DISTINCT id + FROM + temp_table + </select> + + <select id="getLevelDeptList" resultType="com.mindskip.xzs.domain.vo.CascaderDataVO"> + SELECT id as value, name as label, parent_id, special, level FROM t_department WHERE level = #{level} + </select> + </mapper> -- Gitblit v1.8.0