<?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.srs.workstudy.mapper.QgzxPostChangeMapper">

    <resultMap type="QgzxPostChange" id="QgzxPostChangeResult">
        <result property="id" column="id"/>
        <result property="postId" column="post_id"/>
        <result property="applyReason" column="apply_reason"/>
        <result property="newCount" column="new_count"/>
        <result property="applyTime" column="apply_time"/>
        <result property="applyStatus" column="apply_status"/>
        <result property="deptNo" column="dept_no"/>
        <result property="deptCmt" column="dept_cmt"/>
        <result property="deptSign" column="dept_sign"/>
        <result property="highNo" column="high_no"/>
        <result property="highCmt" column="high_cmt"/>
        <result property="highSign" column="high_sign"/>
        <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="delFlag" column="del_flag"/>
        <result property="status" column="status"/>
    </resultMap>

    <sql id="selectQgzxPostChangeVo">
        select id,
               post_id,
               apply_reason,
               new_count,
               apply_time,
               apply_status,
               dept_no,
               dept_cmt,
               dept_sign,
               high_no,
               high_cmt,
               high_sign,
               create_by,
               create_time,
               update_by,
               update_time,
               del_flag,
               status
        from qgzx_post_change
    </sql>

    <select id="selectQgzxPostChangeList" parameterType="QgzxPostChange" resultMap="QgzxPostChangeResult">
        <include refid="selectQgzxPostChangeVo"/>
        <where>
            <if test="postId != null ">and post_id = #{postId}</if>
            <if test="applyReason != null  and applyReason != ''">and apply_reason = #{applyReason}</if>
            <if test="newCount != null ">and new_count = #{newCount}</if>
            <if test="applyTime != null ">and apply_time = #{applyTime}</if>
            <if test="applyStatus != null  and applyStatus != ''">and apply_status = #{applyStatus}</if>
            <if test="deptNo != null  and deptNo != ''">and dept_no = #{deptNo}</if>
            <if test="deptCmt != null  and deptCmt != ''">and dept_cmt = #{deptCmt}</if>
            <if test="deptSign != null  and deptSign != ''">and dept_sign = #{deptSign}</if>
            <if test="highNo != null  and highNo != ''">and high_no = #{highNo}</if>
            <if test="highCmt != null  and highCmt != ''">and high_cmt = #{highCmt}</if>
            <if test="highSign != null  and highSign != ''">and high_sign = #{highSign}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="selectQgzxPostChangeById" parameterType="Long" resultMap="QgzxPostChangeResult">
        <include refid="selectQgzxPostChangeVo"/>
        where id = #{id}
    </select>

    <insert id="insertQgzxPostChange" parameterType="QgzxPostChange" useGeneratedKeys="true" keyProperty="id">
        insert into qgzx_post_change
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="postId != null">post_id,</if>
            <if test="applyReason != null">apply_reason,</if>
            <if test="newCount != null">new_count,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="applyStatus != null">apply_status,</if>
            <if test="deptNo != null">dept_no,</if>
            <if test="deptCmt != null">dept_cmt,</if>
            <if test="deptSign != null">dept_sign,</if>
            <if test="highNo != null">high_no,</if>
            <if test="highCmt != null">high_cmt,</if>
            <if test="highSign != null">high_sign,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
            <if test="status != null">status,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="postId != null">#{postId},</if>
            <if test="applyReason != null">#{applyReason},</if>
            <if test="newCount != null">#{newCount},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="applyStatus != null">#{applyStatus},</if>
            <if test="deptNo != null">#{deptNo},</if>
            <if test="deptCmt != null">#{deptCmt},</if>
            <if test="deptSign != null">#{deptSign},</if>
            <if test="highNo != null">#{highNo},</if>
            <if test="highCmt != null">#{highCmt},</if>
            <if test="highSign != null">#{highSign},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
            <if test="status != null">#{status},</if>
        </trim>
    </insert>

    <update id="updateQgzxPostChange" parameterType="QgzxPostChange">
        update qgzx_post_change
        <trim prefix="SET" suffixOverrides=",">
            <if test="postId != null">post_id = #{postId},</if>
            <if test="applyReason != null">apply_reason = #{applyReason},</if>
            <if test="newCount != null">new_count = #{newCount},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="applyStatus != null">apply_status = #{applyStatus},</if>
            <if test="deptNo != null">dept_no = #{deptNo},</if>
            <if test="deptCmt != null">dept_cmt = #{deptCmt},</if>
            <if test="deptSign != null">dept_sign = #{deptSign},</if>
            <if test="highNo != null">high_no = #{highNo},</if>
            <if test="highCmt != null">high_cmt = #{highCmt},</if>
            <if test="highSign != null">high_sign = #{highSign},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQgzxPostChangeById" parameterType="Long">
        delete
        from qgzx_post_change
        where id = #{id}
    </delete>

    <delete id="deleteQgzxPostChangeByIds" parameterType="String">
        delete from qgzx_post_change where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="listView" resultType="QgzxPostChange" parameterType="QgzxPostChange">
        select a.*,b.post_name,c.dept_name
        from qgzx_post_change as a
        left join qgzx_post as b on a.post_id = b.id
        left join sys_dept as c on b.dept_code = c.dept_code
        <where>
            <if test="postId != null ">and a.post_id = #{postId}</if>
            <if test="applyStatus != null  and applyStatus != ''">and a.apply_status = #{applyStatus}</if>
            <if test="applyNo != null  and applyNo != ''">and b.apply_no = #{applyNo}</if>
            <if test="deptId != null ">and c.dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''">and c.dept_name like concat('%',#{deptName},'%')</if>

        </where>

    </select>
</mapper>