<?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.KwcContractLogisticsScoreDetailMapper">
    
    <resultMap type="com.sckw.contract.model.entity.KwcContractLogisticsScoreDetail" id="KwcContractLogisticsScoreDetailResult">
        <result property="id"    column="id"    />
        <result property="scoreId"    column="score_id"    />
        <result property="influenceBy"    column="influence_by"    />
        <result property="action"    column="action"    />
        <result property="scoreChange"    column="score_change"    />
        <result property="score"    column="score"    />
        <result property="status"    column="status"    />
        <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="selectKwcContractLogisticsScoreDetailVo">
        select id, score_id, influence_by, action, score_change, score, status, create_by, create_time, update_by, update_time from kwc_contract_logistics_score_detail
    </sql>

    <select id="selectKwcContractLogisticsScoreDetailList" parameterType="com.sckw.contract.model.dto.req.LogisticsScoreDetailQueryDto" resultMap="KwcContractLogisticsScoreDetailResult">
        <include refid="selectKwcContractLogisticsScoreDetailVo"/>
        <where>
            and score_id in
            <foreach collection="scoreIds" item="scoreId" open="(" separator="," close=")">
                #{scoreId}
            </foreach>
            <if test="status != null">and status = #{status}</if>
            <if test="action != null  and action != ''"> and action like concat('%', #{action}, '%')</if>
        </where>
        order by update_time desc
    </select>


    <select id="selectLogisticsPendingScoreDetail" parameterType="com.sckw.contract.model.dto.req.LogisticsScoreDetailQueryDto" resultType="com.sckw.contract.model.entity.KwcContractLogisticsScoreDetail">
        <include refid="selectKwcContractLogisticsScoreDetailVo"/>
        <where>
            and score_id = #{scoreId} and status = 0
        </where>
        order by update_time desc
    </select>
    
    <select id="selectKwcContractLogisticsScoreDetailById" parameterType="Long" resultMap="KwcContractLogisticsScoreDetailResult">
        <include refid="selectKwcContractLogisticsScoreDetailVo"/>
        where id = #{id}
    </select>

    <insert id="insertKwcContractLogisticsScoreDetail" parameterType="com.sckw.contract.model.entity.KwcContractLogisticsScoreDetail">
        insert into kwc_contract_logistics_score_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="scoreId != null">score_id,</if>
            <if test="influenceBy != null">influence_by,</if>
            <if test="action != null and action != ''">action,</if>
            <if test="scoreChange != null">score_change,</if>
            <if test="score != null">score,</if>
            <if test="status != null">status,</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="influenceBy != null">#{influenceBy},</if>
            <if test="action != null and action != ''">#{action},</if>
            <if test="scoreChange != null">#{scoreChange},</if>
            <if test="score != null">#{score},</if>
            <if test="status != null">#{status},</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="updateKwcContractLogisticsScoreDetail" parameterType="com.sckw.contract.model.entity.KwcContractLogisticsScoreDetail">
        update kwc_contract_logistics_score_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="score != null">score = #{score},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKwcContractLogisticsScoreDetailById">
        delete from kwc_contract_logistics_score_detail where id = #{id} and status = #{status}
    </delete>

    <delete id="deleteKwcContractLogisticsScoreDetailByScoreId">
        delete from kwc_contract_logistics_score_detail where score_id = #{scoreId} and status = #{status}
    </delete>

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