<?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="cn.com.countrygarden.bi.main.dao.dataMigration.DispatchRecordMapper">
    <!--`dispatch_record_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',-->
    <!--`start_date` datetime DEFAULT NULL COMMENT '调度开始时间',-->
    <!--`end_date` datetime DEFAULT NULL COMMENT '调度结束时间',-->
    <!--`interface_code` varchar(32) DEFAULT NULL COMMENT '接口编码',-->
    <!--`batch_code` int(11) DEFAULT '0' COMMENT '插入批次号',-->
    <!--`end_sign_id` bigint(20) DEFAULT NULL COMMENT '末尾标记(用于删除靠前同步的数据)',-->
    <resultMap id="BaseDispatchRecordMap" type="cn.com.countrygarden.bi.main.model.dataMigration.DispatchRecord">
        <id column="dispatch_record_id" property="dispatchRecordId"/>
        <result column="start_date" property="startDate"/>
        <result column="end_date" property="endDate"/>
        <result column="interface_code" property="interfaceCode"/>
        <result column="end_sign_id" property="endSignId"/>
    </resultMap>

    <insert id="insert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="dispatchRecordId" keyColumn="dispatch_record_id">
        INSERT INTO `performance_app`.`dispatch_record`
        (`start_date`, `end_date`, `interface_code`,
        <if test="batchCode != null">
        `batch_code`,
        </if>
        `end_sign_id`) VALUES
        (
        #{startDate},
        #{endDate},
        #{interfaceCode},
        <if test="batchCode != null">
        #{batchCode},
        </if>
        #{endSignId});
    </insert>

    <update id="update">
        update performance_app.dispatch_record set end_date = #{endDate},  end_sign_id= #{endSignId} WHERE
        dispatch_record_id = #{id}
    </update>

    <select id="select" resultMap="BaseDispatchRecordMap">
        SELECT * FROM performance_app.dispatch_record WHERE start_date <![CDATA[>=]]> #{startDate} AND
        end_date <![CDATA[<=]]> #{endDate}
    </select>

    <select id="findMaxBatchCode" resultType="int">
        SELECT max(batch_code) FROM performance_app.dispatch_record WHERE interface_code = #{interfaceCode}
    </select>
</mapper>