<?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.ruoyi.oa.mapper.CmcUserHistoryMapper">
    
    <resultMap type="CmcUserHistory" id="CmcUserHistoryResult">
        <result property="historyId"    column="history_id"    />
        <result property="userId"    column="user_id"    />
        <result property="titiles"    column="titiles"    />
        <result property="pmLevel"    column="pm_level"    />
        <result property="engineerLevel"    column="engineer_level"    />
        <result property="postLevel"    column="post_level"    />
        <result property="salaryLevel"    column="salary_level"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateReason"    column="update_reason"    />
    </resultMap>

    <sql id="selectCmcUserHistoryVo">
        select history_id, user_id, titiles, pm_level, engineer_level, post_level, salary_level, update_time, update_reason from cmc_user_history
    </sql>

    <select id="selectCmcUserHistoryList" parameterType="CmcUserHistory" resultMap="CmcUserHistoryResult">
        <include refid="selectCmcUserHistoryVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="titiles != null  and titiles != ''"> and titiles = #{titiles}</if>
            <if test="pmLevel != null  and pmLevel != ''"> and pm_level = #{pmLevel}</if>
            <if test="engineerLevel != null  and engineerLevel != ''"> and engineer_level = #{engineerLevel}</if>
            <if test="postLevel != null  and postLevel != ''"> and post_level = #{postLevel}</if>
            <if test="salaryLevel != null  and salaryLevel != ''"> and salary_level = #{salaryLevel}</if>
            <if test="updateReason != null  and updateReason != ''"> and update_reason = #{updateReason}</if>
        </where>
    </select>
    
    <select id="selectCmcUserHistoryByUserId" parameterType="Long" resultMap="CmcUserHistoryResult">
        <include refid="selectCmcUserHistoryVo"/>
        where user_id = #{userId}
    </select>
        
    <insert id="insertCmcUserHistory" parameterType="CmcUserHistory">
        insert into cmc_user_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="titiles != null">titiles,</if>
            <if test="pmLevel != null">pm_level,</if>
            <if test="engineerLevel != null">engineer_level,</if>
            <if test="postLevel != null">post_level,</if>
            <if test="salaryLevel != null">salary_level,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateReason != null">update_reason,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="titiles != null">#{titiles},</if>
            <if test="pmLevel != null">#{pmLevel},</if>
            <if test="engineerLevel != null">#{engineerLevel},</if>
            <if test="postLevel != null">#{postLevel},</if>
            <if test="salaryLevel != null">#{salaryLevel},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateReason != null">#{updateReason},</if>
         </trim>
    </insert>

    <update id="updateCmcUserHistory" parameterType="CmcUserHistory">
        update cmc_user_history
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="titiles != null">titiles = #{titiles},</if>
            <if test="pmLevel != null">pm_level = #{pmLevel},</if>
            <if test="engineerLevel != null">engineer_level = #{engineerLevel},</if>
            <if test="postLevel != null">post_level = #{postLevel},</if>
            <if test="salaryLevel != null">salary_level = #{salaryLevel},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateReason != null">update_reason = #{updateReason},</if>
        </trim>
        where history_id  = #{historyId}
    </update>

    <delete id="deleteCmcUserHistoryByUserId" parameterType="Long">
        delete from cmc_user_history where user_id = #{userId}
    </delete>

    <delete id="deleteCmcUserHistoryByUserIds" parameterType="String">
        delete from cmc_user_history where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
</mapper>