<?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.dgtly.sync.mapper.SyncLogMapper">
    
    <resultMap type="SyncLog" id="SyncLogResult">
        <result property="packageId"    column="package_id"    />
        <result property="successCount"    column="success_count"    />
        <result property="faileCount"    column="faile_count"    />
        <result property="totalCount"    column="total_count"    />
        <result property="createTime"    column="create_time"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="syncType"    column="sync_type"    />
    </resultMap>

    <sql id="selectSyncLogVo">
        select package_id, success_count, faile_count, total_count, create_time, sync_type from sync_log
    </sql>

    <select id="selectSyncLogList" parameterType="SyncLog" resultMap="SyncLogResult">
        <include refid="selectSyncLogVo"/>
        <where>  
            <if test="params.beginCreateTime != null and params.beginCreateTime != ''"> and create_time &gt;= #{params.beginCreateTime} </if>
            <if test="params.endCreateTime != null and params.endCreateTime != '' ">and create_time &lt;= #{params.endCreateTime}</if>
            <if test="syncType != null  and syncType != ''"> and sync_type = #{syncType}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectSyncLogById" parameterType="String" resultMap="SyncLogResult">
        <include refid="selectSyncLogVo"/>
        where package_id = #{packageId}
    </select>
        
    <insert id="insertSyncLog" parameterType="SyncLog">
        insert into sync_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
           create_time,
            <if test="packageId != null  and packageId != ''">package_id,</if>
            <if test="successCount != null ">success_count,</if>
            <if test="faileCount != null ">faile_count,</if>
            <if test="totalCount != null ">total_count,</if>
            <if test="startTime != null ">start_time,</if>
            <if test="endTime != null ">end_time,</if>
            <if test="syncType != null  and syncType != ''">sync_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            now(),
            <if test="packageId != null  and packageId != ''">#{packageId},</if>
            <if test="successCount != null ">#{successCount},</if>
            <if test="faileCount != null ">#{faileCount},</if>
            <if test="totalCount != null ">#{totalCount},</if>
            <if test="startTime != null ">#{startTime},</if>
            <if test="endTime != null ">#{endTime},</if>
            <if test="syncType != null  and syncType != ''">#{syncType},</if>
         </trim>
    </insert>

    <update id="updateSyncLog" parameterType="SyncLog">
        update sync_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="successCount != null ">success_count = #{successCount},</if>
            <if test="faileCount != null ">faile_count = #{faileCount},</if>
            <if test="totalCount != null ">total_count = #{totalCount},</if>
            <if test="startTime != null ">start_time = #{startTime},</if>
            <if test="endTime != null ">end_time = #{endTime},</if>
            <if test="syncType != null  and syncType != ''">sync_type = #{syncType},</if>
        </trim>
        where package_id = #{packageId}
    </update>

    <delete id="deleteSyncLogById" parameterType="String">
        delete from sync_log where package_id = #{packageId}
    </delete>

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