<?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.CmcTitleEvalMapper">
    
    <resultMap type="CmcTitleEval" id="CmcTitleEvalResult">
        <result property="titleEvalId"    column="title_eval_id"    />
        <result property="userId"    column="user_id"    />
        <result property="annual"    column="annual"    />
        <result property="institude"    column="institude"    />
        <result property="type"    column="type"    />
        <result property="level"    column="level"    />
        <result property="titleProfession"    column="title_profession"    />
        <result property="sheet"    column="sheet"    />
        <result property="sheetStamp"    column="sheet_stamp"    />
        <result property="material"    column="material"    />
        <result property="isApproved"    column="is_approved"    />
        <result property="publicityFile"    column="publicity_file"    />
        <result property="scanFile"    column="scan_file"    />
        <result property="obtainTime"    column="obtain_time"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="titleUserId"    column="title_user_id"    />
        <result property="titleTime"    column="title_time"    />
        <result property="titleComment"    column="title_comment"    />
        <result property="materialUploadTime"    column="material_upload_time"    />
        <result property="confirmer"    column="confirmer"    />
        <result property="confirmTime"    column="confirm_time"    />
        <result property="confirmStatus"    column="confirm_status"    />
        <result property="secretOpinion"    column="secret_opinion"    />
        <association property="applyUser"    javaType="SysUser"         resultMap="ApplyUserResult" />
        <association property="titleUser"    javaType="SysUser"         resultMap="TitleUserResult" />
        <association property="confirmUser"    javaType="SysUser"         resultMap="ConfirmUserResult" />
    </resultMap>

    <resultMap type="SysUser" id="ApplyUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="apply_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="TitleUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="title_nick_name"    />
    </resultMap>

    <resultMap type="SysUser" id="ConfirmUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="confirm_nick_name"    />
    </resultMap>

    <sql id="selectCmcTitleEvalVo">
        select te.title_eval_id, te.user_id, u.nick_name as apply_nick_name, te.annual, te.institude, te.type, te.level, te.title_profession, te.sheet, te.sheet_stamp, te.material, te.is_approved, te.publicity_file, te.scan_file,
               te.obtain_time, te.apply_time, te.title_user_id, u1.nick_name as title_nick_name, te.title_time, te.title_comment, te.material_upload_time, te.confirmer, u2.nick_name as confirm_nick_name, te.confirm_time,
               te.confirm_status, te.secret_opinion from cmc_title_eval as te
        left join sys_user as u on u.user_id = te.user_id
        left join sys_user as u1 on u1.user_id = te.title_user_id
        left join sys_user as u2 on u2.user_id = te.confirmer
    </sql>

    <select id="selectCmcTitleEvalList" parameterType="CmcTitleEval" resultMap="CmcTitleEvalResult">
        <include refid="selectCmcTitleEvalVo"/>
        <where>  
            <if test="userId != null "> and te.user_id = #{userId}</if>
            <if test="annual != null  and annual != ''"> and te.annual = #{annual}</if>
            <if test="institude != null  and institude != ''"> and te.institude = #{institude}</if>
            <if test="type != null  and type != ''"> and te.type = #{type}</if>
            <if test="level != null  and level != ''"> and te.level = #{level}</if>
            <if test="titleProfession != null  and titleProfession != ''"> and te.title_profession = #{titleProfession}</if>
            <if test="sheet != null  and sheet != ''"> and te.sheet = #{sheet}</if>
            <if test="sheetStamp != null  and sheetStamp != ''"> and te.sheet_stamp = #{sheetStamp}</if>
            <if test="material != null  and material != ''"> and te.material = #{material}</if>
            <if test="isApproved != null  and isApproved != ''"> and te.is_approved = #{isApproved}</if>
            <if test="publicityFile != null  and publicityFile != ''"> and te.publicity_file = #{publicityFile}</if>
            <if test="scanFile != null  and scanFile != ''"> and te.scan_file = #{scanFile}</if>
            <if test="obtainTime != null "> and te.obtain_time = #{obtainTime}</if>
            <if test="applyTime != null "> and te.apply_time = #{applyTime}</if>
            <if test="titleUserId != null "> and te.title_user_id = #{titleUserId}</if>
            <if test="titleTime != null "> and te.title_time = #{titleTime}</if>
            <if test="titleComment != null  and titleComment != ''"> and te.title_comment = #{titleComment}</if>
            <if test="materialUploadTime != null "> and te.material_upload_time = #{materialUploadTime}</if>
            <if test="confirmer != null "> and te.confirmer = #{confirmer}</if>
            <if test="confirmTime != null "> and te.confirm_time = #{confirmTime}</if>
            <if test="confirmStatus != null  and confirmStatus != ''"> and te.confirm_status = #{confirmStatus}</if>
        </where>
    </select>
    
    <select id="selectCmcTitleEvalByTitleEvalId" parameterType="String" resultMap="CmcTitleEvalResult">
        <include refid="selectCmcTitleEvalVo"/>
        where title_eval_id = #{titleEvalId}
    </select>
        
    <insert id="insertCmcTitleEval" parameterType="CmcTitleEval">
        insert into cmc_title_eval
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="titleEvalId != null">title_eval_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="annual != null">annual,</if>
            <if test="institude != null">institude,</if>
            <if test="type != null">type,</if>
            <if test="level != null">level,</if>
            <if test="titleProfession != null">title_profession,</if>
            <if test="sheet != null">sheet,</if>
            <if test="sheetStamp != null">sheet_stamp,</if>
            <if test="material != null">material,</if>
            <if test="isApproved != null">is_approved,</if>
            <if test="publicityFile != null">publicity_file,</if>
            <if test="scanFile != null">scan_file,</if>
            <if test="obtainTime != null">obtain_time,</if>
            <if test="applyTime != null">apply_time,</if>
            <if test="titleUserId != null">title_user_id,</if>
            <if test="titleTime != null">title_time,</if>
            <if test="titleComment != null">title_comment,</if>
            <if test="materialUploadTime != null">material_upload_time,</if>
            <if test="confirmer != null">confirmer,</if>
            <if test="confirmTime != null">confirm_time,</if>
            <if test="confirmStatus != null">confirm_status,</if>
            <if test="secretOpinion != null">secret_opinion,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="titleEvalId != null">#{titleEvalId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="annual != null">#{annual},</if>
            <if test="institude != null">#{institude},</if>
            <if test="type != null">#{type},</if>
            <if test="level != null">#{level},</if>
            <if test="titleProfession != null">#{titleProfession},</if>
            <if test="sheet != null">#{sheet},</if>
            <if test="sheetStamp != null">#{sheetStamp},</if>
            <if test="material != null">#{material},</if>
            <if test="isApproved != null">#{isApproved},</if>
            <if test="publicityFile != null">#{publicityFile},</if>
            <if test="scanFile != null">#{scanFile},</if>
            <if test="obtainTime != null">#{obtainTime},</if>
            <if test="applyTime != null">#{applyTime},</if>
            <if test="titleUserId != null">#{titleUserId},</if>
            <if test="titleTime != null">#{titleTime},</if>
            <if test="titleComment != null">#{titleComment},</if>
            <if test="materialUploadTime != null">#{materialUploadTime},</if>
            <if test="confirmer != null">#{confirmer},</if>
            <if test="confirmTime != null">#{confirmTime},</if>
            <if test="confirmStatus != null">#{confirmStatus},</if>
            <if test="secretOpinion != null">#{secretOpinion},</if>
         </trim>
    </insert>

    <update id="updateCmcTitleEval" parameterType="CmcTitleEval">
        update cmc_title_eval
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="annual != null">annual = #{annual},</if>
            <if test="institude != null">institude = #{institude},</if>
            <if test="type != null">type = #{type},</if>
            <if test="level != null">level = #{level},</if>
            <if test="titleProfession != null">title_profession = #{titleProfession},</if>
            <if test="sheet != null">sheet = #{sheet},</if>
            <if test="sheetStamp != null">sheet_stamp = #{sheetStamp},</if>
            <if test="material != null">material = #{material},</if>
            <if test="isApproved != null">is_approved = #{isApproved},</if>
            <if test="publicityFile != null">publicity_file = #{publicityFile},</if>
            <if test="scanFile != null">scan_file = #{scanFile},</if>
            <if test="obtainTime != null">obtain_time = #{obtainTime},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="titleUserId != null">title_user_id = #{titleUserId},</if>
            <if test="titleTime != null">title_time = #{titleTime},</if>
            <if test="titleComment != null">title_comment = #{titleComment},</if>
            <if test="materialUploadTime != null">material_upload_time = #{materialUploadTime},</if>
            <if test="confirmer != null">confirmer = #{confirmer},</if>
            <if test="confirmTime != null">confirm_time = #{confirmTime},</if>
            <if test="confirmStatus != null">confirm_status = #{confirmStatus},</if>
            <if test="secretOpinion != null">secret_opinion = #{secretOpinion},</if>
        </trim>
        where title_eval_id = #{titleEvalId}
    </update>

    <delete id="deleteCmcTitleEvalByTitleEvalId" parameterType="String">
        delete from cmc_title_eval where title_eval_id = #{titleEvalId}
    </delete>

    <delete id="deleteCmcTitleEvalByTitleEvalIds" parameterType="String">
        delete from cmc_title_eval where title_eval_id in 
        <foreach item="titleEvalId" collection="array" open="(" separator="," close=")">
            #{titleEvalId}
        </foreach>
    </delete>
</mapper>