<?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.contract.dao.KwcContractLogisticsScoreMapper">
    
    <resultMap type="com.sckw.contract.model.entity.KwcContractLogisticsScore" id="KwcContractLogisticsScoreResult">
        <result property="id"    column="id"    />
        <result property="providerEntId"    column="provider_ent_id"    />
        <result property="logisticsEntId"    column="logistics_ent_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="selectKwcContractLogisticsScoreVo">
        select id, provider_ent_id, logistics_ent_id, score, create_by, create_time, update_by, update_time from kwc_contract_logistics_score
    </sql>

    <select id="selectKwcContractLogisticsScoreList" parameterType="com.sckw.contract.model.dto.req.LogisticsScoreQueryDto" resultMap="KwcContractLogisticsScoreResult">
        <include refid="selectKwcContractLogisticsScoreVo"/>
        <where>  
            provider_ent_id = #{providerEntId}
            and logistics_ent_id in
            <foreach collection="logisticsEntIds" item="logisticsEntId" open="(" separator="," close=")">
                #{logisticsEntId}
            </foreach>
        </where>
        order by score desc
    </select>
    
    <select id="selectKwcContractLogisticsScoreById" parameterType="Long" resultMap="KwcContractLogisticsScoreResult">
        <include refid="selectKwcContractLogisticsScoreVo"/>
        where id = #{id}
    </select>
    <select id="selectLogisticsScoreByEntId" resultMap="KwcContractLogisticsScoreResult">
        <include refid="selectKwcContractLogisticsScoreVo"/>
         where provider_ent_id = #{providerEntId} and logistics_ent_id = #{logisticsEntId}
    </select>

    <select id="selectLogisticsScoreByEntIdAndScoreId" resultMap="KwcContractLogisticsScoreResult">
        <include refid="selectKwcContractLogisticsScoreVo"/>
        where id = #{scoreId} and provider_ent_id = #{providerEntId}
    </select>

    <insert id="insertKwcContractLogisticsScore" parameterType="com.sckw.contract.model.entity.KwcContractLogisticsScore">
        insert into kwc_contract_logistics_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="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="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>

    <update id="updateKwcContractLogisticsScore" parameterType="com.sckw.contract.model.entity.KwcContractLogisticsScore">
        update kwc_contract_logistics_score
        <trim prefix="SET" suffixOverrides=",">
            <if test="score != null">score = #{score},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKwcContractLogisticsScoreById" parameterType="Long">
        delete from kwc_contract_logistics_score where id = #{id}
    </delete>

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