From 86603282c0cc5f005b740112311d89e99b8fc570 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期一, 08 七月 2024 17:39:10 +0800
Subject: [PATCH] feat:部门树形结构

---
 src/main/resources/mapper/DepartmentMapper.xml |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/main/resources/mapper/DepartmentMapper.xml b/src/main/resources/mapper/DepartmentMapper.xml
index ea69ef0..2900432 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>
@@ -36,20 +38,22 @@
     <select id="gets" resultMap="BaseResultMap">
         SELECT
             td.id,
-            td.name
+            td.name,
+            td.parent_id
         FROM
             t_department td
         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>
 
     <select id="getById" resultMap="BaseResultMap">
         SELECT
             td.id,
-            td.name
+            td.name,
+            td.parent_id
         FROM
             t_department td
         WHERE
@@ -83,7 +87,8 @@
             parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
         SELECT
             td.id,
-            td.name
+            td.name,
+            td.parent_id
         FROM
              t_department td
         <where>
@@ -102,6 +107,7 @@
         SELECT
             td.id,
             td.name,
+            td.parent_id,
             td.admin_id as adminId,
             tu.real_name as adminName
         FROM
@@ -119,4 +125,8 @@
         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>
+
 </mapper>

--
Gitblit v1.8.0