<?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.KwfDriverScoreMapper">
    
    <resultMap type="com.sckw.fleet.model.KwfDriverScore" id="KwfDriverScoreResult">
        <result property="id"    column="id"    />
        <result property="providerEntId"    column="provider_ent_id"    />
        <result property="logisticsEntId"    column="logistics_ent_id"    />
        <result property="driverId"    column="driver_id"    />
        <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="selectKwfDriverScoreVo">
        select id, provider_ent_id, logistics_ent_id, driver_id, score, create_by, create_time, update_by, update_time from kwf_driver_score
    </sql>

    <select id="selectKwfDriverScoreList" parameterType="com.sckw.fleet.model.KwfDriverScore" resultMap="KwfDriverScoreResult">
        <include refid="selectKwfDriverScoreVo"/>
        <where>  
            <if test="providerEntId != null "> and provider_ent_id = #{providerEntId}</if>
            <if test="logisticsEntId != null "> and logistics_ent_id = #{logisticsEntId}</if>
            <if test="driverId != null "> and driver_id = #{driverId}</if>
        </where>
    </select>

    <select id="selectKwfDriverScoreCount" resultType="java.math.BigDecimal">
        select sum(score) from kwf_driver_score
        <where>
            <if test="providerEntId != null "> and provider_ent_id = #{providerEntId}</if>
            <if test="logisticsEntId != null "> and logistics_ent_id = #{logisticsEntId}</if>
        </where>
    </select>
    
    <select id="selectKwfDriverScoreById" parameterType="Long" resultMap="KwfDriverScoreResult">
        <include refid="selectKwfDriverScoreVo"/>
        where id = #{id}
    </select>

    <insert id="insertKwfDriverScore" parameterType="com.sckw.fleet.model.KwfDriverScore">
        insert into kwf_driver_score
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="providerEntId != null">provider_ent_id,</if>
            <if test="logisticsEntId != null">logistics_ent_id,</if>
            <if test="driverId != null">driver_id,</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="providerEntId != null">#{providerEntId},</if>
            <if test="logisticsEntId != null">#{logisticsEntId},</if>
            <if test="driverId != null">#{driverId},</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 (id,provider_ent_id,logistics_ent_id,driver_id,score,create_by,create_time,update_by,update_time)
        values
        <foreach collection="driverScores" item="driverScore" separator=",">
            (
             #{driverScore.id},#{driverScore.providerEntId},#{driverScore.logisticsEntId},#{driverScore.driverId},#{driverScore.score},#{driverScore.createBy},#{driverScore.createTime},#{driverScore.updateBy},#{driverScore.updateTime}
            )
        </foreach>
    </insert>

    <update id="updateKwfDriverScore" parameterType="com.sckw.fleet.model.KwfDriverScore">
        update kwf_driver_score
        <trim prefix="SET" suffixOverrides=",">
            <if test="providerEntId != null">provider_ent_id = #{providerEntId},</if>
            <if test="logisticsEntId != null">logistics_ent_id = #{logisticsEntId},</if>
            <if test="driverId != null">driver_id = #{driverId},</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>


    <update id="updateScoreBatch">
        <foreach collection="driverScores" item="driverScore" separator=";">
            update kwf_driver_score
            <set>
                <if test="driverScore.score != null">score = #{driverScore.score},</if>
                <if test="driverScore.updateBy != null">update_by = #{driverScore.updateBy},</if>
                <if test="driverScore.updateTime != null">update_time = #{driverScore.updateTime},</if>
            </set>
            WHERE id = #{driverScore.id}
        </foreach>
    </update>

    <delete id="deleteKwfDriverScoreById" parameterType="Long">
        delete from kwf_driver_score where id = #{id}
    </delete>

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