<?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.sckw.fleet.dao.KwfDriverScoreDetailMapper">
    
    <resultMap type="com.sckw.fleet.model.KwfDriverScoreDetail" id="KwfDriverScoreDetailResult">
        <result property="id"    column="id"    />
        <result property="scoreId"    column="score_id"    />
        <result property="driverId"    column="driver_id"    />
        <result property="action"    column="action"    />
        <result property="scoreChange"    column="score_change"    />
        <result property="score"    column="score"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectKwfDriverScoreDetailVo">
        select id, score_id, driver_id, action, score_change, score, create_by, create_time, update_by, update_time from kwf_driver_score_detail
    </sql>

    <select id="selectKwfDriverScoreDetailList" parameterType="com.sckw.fleet.model.KwfDriverScoreDetail" resultMap="KwfDriverScoreDetailResult">
        <include refid="selectKwfDriverScoreDetailVo"/>
        <where>  
            <if test="scoreId != null "> and score_id = #{scoreId}</if>
            <if test="driverId != null "> and driver_id = #{driverId}</if>
            <if test="action != null  and action != ''"> and action = #{action}</if>
        </where>
    </select>
    
    <select id="selectKwfDriverScoreDetailById" parameterType="Long" resultMap="KwfDriverScoreDetailResult">
        <include refid="selectKwfDriverScoreDetailVo"/>
        where id = #{id}
    </select>

    <insert id="insertKwfDriverScoreDetail" parameterType="com.sckw.fleet.model.KwfDriverScoreDetail">
        insert into kwf_driver_score_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="scoreId != null">score_id,</if>
            <if test="driverId != null">driver_id,</if>
            <if test="action != null and action != ''">action,</if>
            <if test="scoreChange != null">score_change,</if>
            <if test="score != null">score,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="scoreId != null">#{scoreId},</if>
            <if test="driverId != null">#{driverId},</if>
            <if test="action != null and action != ''">#{action},</if>
            <if test="scoreChange != null">#{scoreChange},</if>
            <if test="score != null">#{score},</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>
         </trim>
    </insert>

    <insert id="insertBatch">
        insert into kwf_driver_score_detail  (id,score_id,driver_id,action,score_change,score,create_by,create_time,update_by,update_time)
        values
        <foreach collection="driverScoreDetails" item="scoreDetail" separator=",">
            (
             #{scoreDetail.id},
             #{scoreDetail.scoreId},
             #{scoreDetail.driverId},
             #{scoreDetail.action},
             #{scoreDetail.scoreChange},
             #{scoreDetail.score},
             #{scoreDetail.createBy},
             #{scoreDetail.createTime},
             #{scoreDetail.updateBy},
             #{scoreDetail.updateTime}
            )
        </foreach>
    </insert>

    <update id="updateKwfDriverScoreDetail" parameterType="com.sckw.fleet.model.KwfDriverScoreDetail">
        update kwf_driver_score_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="scoreId != null">score_id = #{scoreId},</if>
            <if test="driverId != null">driver_id = #{driverId},</if>
            <if test="action != null and action != ''">action = #{action},</if>
            <if test="scoreChange != null">score_change = #{scoreChange},</if>
            <if test="score != null">score = #{score},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKwfDriverScoreDetailById" parameterType="Long">
        delete from kwf_driver_score_detail where id = #{id}
    </delete>

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