<?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="deptId"    column="dept_id"    />
        <result property="titles"    column="titles"    />
        <result property="certificates"    column="certificates"    />
        <result property="roleIds"    column="roleIds"    />
        <result property="postIds"    column="postIds"    />
        <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="operatorLevel"    column="operator_level"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateReason"    column="update_reason"    />
        <result property="politicalAffiliation"    column="political_affiliation"    />
        <result property="graduateSchool"    column="graduate_school"    />
        <result property="major"    column="major"    />
        <result property="degree"    column="degree"    />
        <result property="contractSign"    column="contract_sign"    />
        <result property="contractExpire"    column="contract_expire"    />
    </resultMap>

    <sql id="selectCmcUserHistoryVo">
        select history_id, user_id, dept_id, titles, certificates, roleIds, postIds, pm_level, engineer_level, post_level, salary_level, operator_level, update_time, update_reason,
            political_affiliation, graduate_school, major, degree, contract_sign, contract_expire 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="titles != null  and titles != ''"> and titles = #{titles}</if>
            <if test="certificates != null  and certificates != ''"> and certificates = #{certificates}</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>
        order by update_time desc
    </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="deptId != null">dept_id,</if>
            <if test="titles != null">titles,</if>
            <if test="certificates != null">certificates,</if>
            <if test="roleIds != null">roleIds,</if>
            <if test="postIds != null">postIds,</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="operatorLevel != null">operator_level,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateReason != null">update_reason,</if>
            <if test="politicalAffiliation != null">political_affiliation,</if>
            <if test="graduateSchool != null">graduate_school,</if>
            <if test="major != null">major,</if>
            <if test="degree != null">degree,</if>
            <if test="contractSign != null">contract_sign,</if>
            <if test="contractExpire != null">contract_expire,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="titles != null">#{titles},</if>
            <if test="certificates != null">#{certificates},</if>
            <if test="roleIds != null">#{roleIds},</if>
            <if test="postIds != null">#{postIds},</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="operatorLevel != null">#{operatorLevel},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateReason != null">#{updateReason},</if>
            <if test="politicalAffiliation != null">#{politicalAffiliation},</if>
            <if test="graduateSchool != null">#{graduateSchool},</if>
            <if test="major != null">#{major},</if>
            <if test="degree != null">#{degree},</if>
            <if test="contractSign != null">#{contractSign},</if>
            <if test="contractExpire != null">#{contractExpire},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="titles != null">titles = #{titles},</if>
            <if test="certificates != null">certificates = #{certificates},</if>
            <if test="roleIds != null">roleIds = #{roleIds},</if>
            <if test="postIds != null">postIds = #{postIds},</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="operatorLevel != null and operatorLevel != ''">#{operatorLevel},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateReason != null">update_reason = #{updateReason},</if>
            <if test="politicalAffiliation != null">#{politicalAffiliation},</if>
            <if test="graduateSchool != null">#{graduateSchool},</if>
            <if test="major != null">#{major},</if>
            <if test="degree != null">#{degree},</if>
            <if test="contractSign != null">#{contractSign},</if>
            <if test="contractExpire != null">#{contractExpire},</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>