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

    <resultMap id="IdOrderMap" type="com.zm.order.tool.server.model.OrderData">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <id column="body" jdbcType="VARCHAR" property="body"/>
        <id column="status" jdbcType="BIGINT" property="status"/>
    </resultMap>

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

    <sql id="cols_with_id">
        id,
        body,
        status
    </sql>

    <sql id="cols_all">
        id,
        body,
        status
    </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.storeId}
            )
        </foreach>
    </insert>

    <select id="selectList" 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
    </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="selectOne" parameterType="map" resultMap="IdOrderMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        where order_no = #{orderNo}
    </select>

    <update id="update" parameterType="map">
        update
        <include refid="tb"/>
        <set>
            status = #{status}
        </set>
        where id = #{id}
    </update>
</mapper>