From 97709e81fbbab13b9b36bec3126b0590b7de1984 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期五, 12 七月 2024 18:09:04 +0800 Subject: [PATCH] 部门增加层级字段、部门修改bug --- src/main/resources/mapper/DepartmentMapper.xml | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/main/resources/mapper/DepartmentMapper.xml b/src/main/resources/mapper/DepartmentMapper.xml index f1413a2..7577d5c 100644 --- a/src/main/resources/mapper/DepartmentMapper.xml +++ b/src/main/resources/mapper/DepartmentMapper.xml @@ -6,16 +6,18 @@ <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" typeHandler="com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler"/> + <result column="level" property="level"/> </resultMap> <sql id="Base_Column_List"> id - , name,deleted,parent_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, parent_id) - values (#{name,jdbcType=VARCHAR}, #{deleted,jdbcType=VARCHAR}, #{parentId}) + 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"> @@ -31,6 +33,12 @@ <if test="deleted != null"> 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> @@ -39,7 +47,9 @@ SELECT td.id, td.name, - td.parent_id + td.parent_id, + td.special, + td.level FROM t_department td WHERE @@ -53,7 +63,9 @@ SELECT td.id, td.name, - td.parent_id + td.parent_id, + td.special, + td.level FROM t_department td WHERE @@ -88,7 +100,9 @@ SELECT td.id, td.name, - td.parent_id + td.parent_id, + td.special, + td.level FROM t_department td <where> @@ -108,6 +122,8 @@ td.id, td.name, td.parent_id, + td.special, + td.level, td.admin_id as adminId, tu.real_name as adminName FROM @@ -126,16 +142,16 @@ </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 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 FROM t_department WHERE id in <foreach collection="deptIds" open="(" item="deptId" close=")" separator=",">#{deptId}</foreach> + 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 FROM t_department so INNER JOIN temp_table tb ON so.parent_id = tb.id + 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 @@ -143,4 +159,18 @@ 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> + </mapper> -- Gitblit v1.8.0