<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.willalp.system.mapper.SysDeptPostMapper">

    <resultMap type="SysDeptPost" id="SysDeptPostResult">
        <result property="postId" column="post_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="ancestors" column="ancestors"/>
        <result property="postCode" column="post_code"/>
        <result property="postName" column="post_name"/>
        <result property="status" column="status"/>
        <result property="jgid" column="jgid"/>
        <result property="deptId" column="dept_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
        <result property="isDelete" column="is_delete"/>
    </resultMap>

    <sql id="selectSysDeptPostVo">
        select post_id,
               parent_id,
               ancestors,
               post_code,
               post_name,
               status,
               jgid,
               dept_id,
               create_by,
               create_time,
               update_by,
               update_time,
               remark,
               is_delete
        from sys_dept_post
    </sql>

    <select id="selectSysDeptPostList" parameterType="SysDeptPost" resultMap="SysDeptPostResult">
        <include refid="selectSysDeptPostVo"/>
        <where>
            is_delete = 0
            <if test="parentId != null ">
                and parent_id = #{parentId}
            </if>
            <!--            <if test="ancestors != null  and ancestors != ''">-->
            <!--                and ancestors = #{ancestors}-->
            <!--            </if>-->
            <if test="postCode != null  and postCode != ''">
                and post_code = #{postCode}
            </if>
            <if test="postName != null  and postName != ''">
                and post_name like concat('%', #{postName}, '%')
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
            <if test="jgid != null  and jgid != ''">
                and jgid = #{jgid}
            </if>
            <if test="deptId != null  and deptId != ''">
                and dept_id = #{deptId}
            </if>
        </where>
    </select>

    <select id="selectById" parameterType="SysDeptPost" resultMap="SysDeptPostResult">
        <include refid="selectSysDeptPostVo"/>
        where is_delete = 0 and post_id = #{postId}
    </select>

    <update id="updateSysDeptPost" parameterType="SysDeptPost">
        update sys_dept_post
        <set>
            <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
            <if test="postCode != null and postCode != ''">post_code = #{postCode},</if>
            <if test="postName != null and postName != ''">post_name = #{postName},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="status != null and status  != ''">status = #{status},</if>
            <if test="jgid != null and jgid != ''">jgid = #{jgid},</if>
            <if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            update_time = sysdate()
        </set>
        where post_id = #{postId}
    </update>

    <update id="deleteSysDeptPostByPostId">
        update sys_dept_post
        set is_delete = 1
        where post_id = #{postId}
    </update>
</mapper>
