龚焕茏
2024-07-16 7f25606654ebe94b5d82cfd9f74275989c71538d
src/main/resources/mapper/DepartmentMapper.xml
@@ -5,21 +5,25 @@
        <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
        , 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_department
        <set>
            parent_id = #{parentId},
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
@@ -29,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>
@@ -36,7 +46,10 @@
    <select id="gets" resultMap="BaseResultMap">
        SELECT
            td.id,
            td.name
            td.name,
            td.parent_id,
            td.special,
            td.level
        FROM
            t_department td
        WHERE
@@ -49,7 +62,10 @@
    <select id="getById" resultMap="BaseResultMap">
        SELECT
            td.id,
            td.name
            td.name,
            td.parent_id,
            td.special,
            td.level
        FROM
            t_department td
        WHERE
@@ -83,7 +99,10 @@
            parameterType="com.mindskip.xzs.viewmodel.admin.department.DepartmentResponseVM">
        SELECT
            td.id,
            td.name
            td.name,
            td.parent_id,
            td.special,
            td.level
        FROM
             t_department td
        <where>
@@ -102,6 +121,9 @@
        SELECT
            td.id,
            td.name,
            td.parent_id,
            td.special,
            td.level,
            td.admin_id as adminId,
            tu.real_name as adminName
        FROM
@@ -119,4 +141,40 @@
        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>