<?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.OrderNoUserDao">
    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.OrderNoUser">
		<id column="id" jdbcType="BIGINT" property="id"/>
		<result column="user_id" jdbcType="BIGINT" property="userId"/>
		<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
		<result column="order_id" jdbcType="BIGINT" property="orderId"/>
	</resultMap>

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

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

    <sql id="cols_exclude_id">
		user_id,
		order_no,
		order_id
    </sql>

    <sql id="values">
    	#{id,jdbcType=BIGINT},
		#{userId,jdbcType=BIGINT},
		#{orderNo,jdbcType=VARCHAR},
		#{orderId,jdbcType=BIGINT}
    </sql>

    <insert id="insert" parameterType="com.zm.order.tool.server.model.OrderNoUser">
        insert into
        <include refid="tb"/>
        (<include refid="cols_all"/>)
        values
        (<include refid="values"/>)
    </insert>

    <select id="selectList" resultMap="ResultMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
            <if test="lastId != null">
                id > #{lastId}
            </if>
        </where>
        order by id
        limit 200
    </select>

    <delete id="delete" parameterType="long">
        delete from order_no_user where id = #{id}
    </delete>

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