<?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.cirs.biz.mapper.TEvaluationMapper">
    
    <resultMap type="TEvaluation" id="TEvaluationResult">
        <result property="id"    column="id"    />
        <result property="searchCondition"    column="search_condition"    />
        <result property="componentId"    column="component_id"    />
        <result property="mark"    column="mark"    />
        <result property="usedBy"    column="used_by"    />
        <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"    />
    </resultMap>

    <sql id="selectTEvaluationVo">
        select id, search_condition, component_id, mark, used_by, create_by, create_time, update_by, update_time, remark from t_evaluation
    </sql>

    <select id="selectTEvaluationList" parameterType="TEvaluation" resultMap="TEvaluationResult">
        <include refid="selectTEvaluationVo"/>
        <where>  
            <if test="searchCondition != null  and searchCondition != ''"> and search_condition = #{searchCondition}</if>
            <if test="componentId != null  and componentId != ''"> and component_id = #{componentId}</if>
            <if test="mark != null "> and mark = #{mark}</if>
            <if test="usedBy != null  and usedBy != ''"> and used_by = #{usedBy}</if>
        </where>
    </select>
    
    <select id="selectTEvaluationById" parameterType="Long" resultMap="TEvaluationResult">
        <include refid="selectTEvaluationVo"/>
        where id = #{id}
    </select>
    <select id="getscore" resultType="java.lang.Float">
        select mark from t_evaluation where component_id=#{componentid} order by id desc limit 1
    </select>

    <insert id="insertTEvaluation" parameterType="TEvaluation" useGeneratedKeys="true" keyProperty="id">
        insert into t_evaluation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="searchCondition != null">search_condition,</if>
            <if test="componentId != null">component_id,</if>
            <if test="mark != null">mark,</if>
            <if test="usedBy != null">used_by,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="searchCondition != null">#{searchCondition},</if>
            <if test="componentId != null">#{componentId},</if>
            <if test="mark != null">#{mark},</if>
            <if test="usedBy != null">#{usedBy},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTEvaluation" parameterType="TEvaluation">
        update t_evaluation
        <trim prefix="SET" suffixOverrides=",">
            <if test="searchCondition != null">search_condition = #{searchCondition},</if>
            <if test="componentId != null">component_id = #{componentId},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="usedBy != null">used_by = #{usedBy},</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="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTEvaluationById" parameterType="Long">
        delete from t_evaluation where id = #{id}
    </delete>

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