<?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.IdOrderNoDao">

    <resultMap id="IdOrderMap" type="com.zm.order.tool.server.model.IdOrderNo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <id column="user_id" jdbcType="BIGINT" property="userId"/>
        <id column="order_id" jdbcType="BIGINT" property="orderId"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="store_id" jdbcType="BIGINT" property="storeId"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="order_at" jdbcType="TIMESTAMP" property="orderAt"/>
    </resultMap>

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

    <sql id="cols_with_id">
        order_id,
        user_id,
        order_no,
        seller_id,
        store_id,
        order_type,
        order_at
    </sql>

    <sql id="cols_all">
        id,
        order_id,
        user_id,
        order_no,
        seller_id,
        store_id,
        order_type
    </sql>

    <insert id="insertList" parameterType="list">
        insert into
        <include refid="tb"/>
        (<include refid="cols_with_id"/>)
        values
        <foreach collection="list" item="order" index="index" separator=",">
            (
            #{order.orderId}, #{order.userId}, #{order.orderNo}, #{order.sellerId}, #{order.storeId}, #{order.orderType}, #{order.orderAt}
            )
        </foreach>
    </insert>

    <select id="selectList" parameterType="map" resultMap="IdOrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            <if test="orderId != null">
                order_id > #{orderId}
            </if>
        </where>
        order by order_id asc limit 1000
    </select>

    <select id="selectListById" parameterType="map" resultMap="IdOrderMap">
        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>

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

    <select id="selectOne" parameterType="map" resultMap="IdOrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        where order_no = #{orderNo}
    </select>

    <update id="update" parameterType="com.zm.order.tool.server.model.Order">
        update
        <include refid="tb"/>
        <set>
            order_id = #{orderId}
        </set>
        where order_no = #{orderNo}
    </update>
</mapper>