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

    <resultMap id="ResultMap" type="com.zm.order.tool.server.model.OrderBaoZhu">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="type" jdbcType="VARCHAR" property="type"/>
        <result column="status_txt" jdbcType="VARCHAR" property="statusTxt"/>
        <result column="pay_status_txt" jdbcType="VARCHAR" property="payStatusTxt"/>
        <result column="order_at" jdbcType="TIMESTAMP" property="orderAt"/>
        <result column="pay_at" jdbcType="TIMESTAMP" property="payAt"/>
        <result column="source_txt" jdbcType="VARCHAR" property="sourceTxt"/>
        <result column="order_type_txt" jdbcType="VARCHAR" property="orderTypeTxt"/>
        <result column="total_amount" jdbcType="DECIMAL" property="totalAmount"/>
        <result column="lost_amount" jdbcType="DECIMAL" property="lostAmount"/>
        <result column="shop_discount_amount" jdbcType="DECIMAL" property="shopDiscountAmount"/>
        <result column="platform_discount_amount" jdbcType="DECIMAL" property="platformDiscountAmount"/>
        <result column="pay_amount" jdbcType="DECIMAL" property="payAmount"/>
    </resultMap>

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

    <sql id="cols_all">
        id,
        order_no,
        type,
        status_txt,
        pay_status_txt,
        order_at,
        pay_at,
        source_txt,
        order_type_txt,
        total_amount,
        lost_amount,
        shop_discount_amount,
        platform_discount_amount,
        pay_amount
    </sql>

    <select id="selectList" parameterType="map" resultMap="ResultMap">
        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="selectOrderList" parameterType="map" resultMap="ResultMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
             type = "销货单"
            <if test="lastId != null">
                and id > #{lastId}
            </if>
        </where>
            order by id asc limit #{size}
    </select>

    <select id="selectRefundList" parameterType="map" resultMap="ResultMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
             type in ("退货单", "部分退款退货单")
            <if test="lastId != null">
                and id > #{lastId}
            </if>
        </where>
            order by id asc limit #{size}
    </select>
</mapper>