<?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.zm.order.tool.server.tempdb.ThirdOrderDao">

    <resultMap id="OrderItemMap" type="com.zm.order.tool.server.model.ThirdOrder">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_data" jdbcType="VARCHAR" property="orderData"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
    </resultMap>

    <sql id="tb">
        new_third_order
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        order_data,
        user_id,
        mobile
    </sql>

    <insert id="insertList" parameterType="com.zm.order.tool.server.model.ThirdOrder">
        insert into
        <include refid="tb"/>
        (<include refid="cols_exclude_id"/>)
        values
        <foreach collection="list" item="order" index="index" separator=",">
            (
                #{order.orderData},
                #{order.userId},
                #{order.mobile}
            )
        </foreach>
    </insert>

    <select id="scanList" parameterType="map" resultMap="OrderItemMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="lastId != null">
                id > #{lastId}
            </if>
        </where>
        order by id asc
        limit 200
    </select>

    <update id="updateUserId" parameterType="map">
        update
        <include refid="tb"/>
        set user_id = #{customerId} where user_id = #{userId}
    </update>
</mapper>