<?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.history.HistoryDataOrderDiscountDao">

    <resultMap id="OrderDiscountMap" type="com.zm.order.tool.server.model.OrderDiscount">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="biz_type" jdbcType="INTEGER" property="bizType"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="item_id" jdbcType="VARCHAR" property="itemId"/>
        <result column="discount_level" jdbcType="INTEGER" property="discountLevel"/>
        <result column="discount_id" jdbcType="VARCHAR" property="discountId"/>
        <result column="discount_type" jdbcType="INTEGER" property="discountType"/>
        <result column="discount_name" jdbcType="VARCHAR" property="discountName"/>
        <result column="discount_summary" jdbcType="VARCHAR" property="discountSummary"/>
        <result column="discount_amount" jdbcType="INTEGER" property="discountAmount"/>
        <result column="features" jdbcType="VARCHAR" property="features"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="discount_text" jdbcType="VARCHAR" property="discountText"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
    </resultMap>

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

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

    <sql id="cols_exclude_id">
        biz_type, user_id, order_no, item_id, discount_level, discount_id, discount_type,
        discount_name, discount_summary, discount_amount, features,
        created_at, updated_at, is_deleted, seller_id, discount_text, status
    </sql>

    <select id="selectByOrderNo" parameterType="map" resultMap="OrderDiscountMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        where order_no = #{orderNo}
        and user_id = #{userId}
        and is_deleted = 0
    </select>

    <select id="selectList" parameterType="map" resultMap="OrderDiscountMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        <where>
            user_id = #{userId}
            <if test="orderNo != null and orderNo != ''">
                AND order_no = #{orderNo}
            </if>
            AND is_deleted = 0
        </where>
        <if test="start != null">
            limit ${start}, ${pageSize}
        </if>
    </select>

</mapper>