<?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.tb.TbRefundDao">

    <resultMap id="RefundMap" type="com.zm.order.tool.server.model.Refund">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="biz_type" jdbcType="INTEGER" property="bizType"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="order_type" jdbcType="INTEGER" property="orderType"/>
        <result column="order_sub_type" jdbcType="INTEGER" property="orderSubType"/>
        <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
        <result column="refund_no" jdbcType="VARCHAR" property="refundNo"/>
        <result column="refund_way" jdbcType="INTEGER" property="refundWay"/>
        <result column="refund_level" jdbcType="INTEGER" property="refundLevel"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="store_id" jdbcType="BIGINT" property="storeId"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="source" jdbcType="INTEGER" property="source"/>
        <result column="source_no" jdbcType="VARCHAR" property="sourceNo"/>
        <result column="refund_type" jdbcType="INTEGER" property="refundType"/>
        <result column="refund_amount" jdbcType="INTEGER" property="refundAmount"/>
        <result column="amount" jdbcType="INTEGER" property="amount"/>
        <result column="wallet_amount" jdbcType="INTEGER" property="walletAmount"/>
        <result column="refund_amount_details" jdbcType="VARCHAR" property="refundAmountDetails"/>
        <result column="applicant" jdbcType="BIGINT" property="applicant"/>
        <result column="images" jdbcType="VARCHAR" property="images"/>
        <result column="apply_at" jdbcType="TIMESTAMP" property="applyAt"/>
        <result column="apply_reason" jdbcType="VARCHAR" property="applyReason"/>
        <result column="order_at" jdbcType="TIMESTAMP" property="orderAt"/>
        <result column="is_alone" jdbcType="INTEGER" property="isAlone"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="from_system" jdbcType="INTEGER" property="fromSystem"/>
        <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="version" jdbcType="INTEGER" property="version"/>
        <result column="deal_at" jdbcType="TIMESTAMP" property="dealAt"/>
        <result column="pay_type" jdbcType="INTEGER" property="payType"/>
        <result column="review_status" jdbcType="INTEGER" property="reviewStatus"/>
        <result column="gift_card_amount" jdbcType="INTEGER" property="giftCardAmount"/>
        <result column="refund_detail_info" jdbcType="VARCHAR" property="refundDetailInfo"/>
        <result column="mobile_cipher" jdbcType="VARCHAR" property="mobileCipher"/>
    </resultMap>

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

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

    <sql id="values">
        #{id}, #{bizType}, #{orderNo}, #{orderType},#{orderSubType}, #{refundNo}, #{refundWay}, #{refundLevel},
        #{sellerId},
        #{storeId}, #{userId}, #{mobile}, #{source}, #{sourceNo}, #{refundType}, #{refundAmount}, #{amount},
        #{walletAmount},
        #{refundAmountDetails}, #{applicant}, #{images}, #{applyAt}, #{orderAt},
        #{applyReason}, #{features}, #{isAlone}, #{status}, #{fromSystem},
        now(), now(), 0, 0, #{dealAt}, #{payType}, #{reviewStatus}, #{giftCardAmount}, #{performanceType},
        #{refundDetailInfo}, #{mobileCipher}
    </sql>

    <sql id="cols_exclude_id">
        biz_type, order_no, order_type, order_sub_type, refund_no, refund_way, refund_level, seller_id, store_id,
        user_id, mobile,
        source, source_no, refund_type,
        refund_amount, amount, wallet_amount, refund_amount_details, applicant, images, apply_at, order_at,
        apply_reason, features, is_alone,
        status, from_system, created_at, updated_at, is_deleted, version, deal_at, pay_type, review_status,
        gift_card_amount, performance_type, refund_detail_info, mobile_cipher
    </sql>

    <select id="selectId" parameterType="map" resultType="long">
        select
        id
        from
        <include refid="tb"/>
        <where>
            <if test="lastId != null">
                and id > #{lastId}
            </if>
            <if test="maxId != null">
                <![CDATA[ AND id < #{maxId} ]]>
            </if>
            <if test="updatedAtStart != null">
                <![CDATA[ AND updated_at >= #{updatedAtStart} ]]>
            </if>
            <if test="updatedAtEnd != null">
                <![CDATA[ AND updated_at <= #{updatedAtEnd} ]]>
            </if>
        </where>
        order by id
        limit #{size}
    </select>

    <select id="selectById" parameterType="map" resultMap="RefundMap">
        select
        features
        from
        <include refid="tb"/>
        <where>
            id in
            <foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </where>
    </select>
</mapper>