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

  <resultMap id="BaseResultMap" type="com.zm.order.tool.server.model.OrderPayDetails">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="user_id" jdbcType="BIGINT" property="userId" />
    <result column="seller_id" jdbcType="BIGINT" property="sellerId" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="pay_type" jdbcType="INTEGER" property="payType" />
    <result column="amount" jdbcType="INTEGER" property="amount" />
    <result column="pay_no" jdbcType="VARCHAR" property="payNo"/>
    <result column="third_pay_no" jdbcType="VARCHAR" property="thirdPayNo"/>
    <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="order_at" jdbcType="TIMESTAMP" property="orderAt" />
    <result column="pay_at" jdbcType="TIMESTAMP" property="payAt" />
    <result column="source" jdbcType="TIMESTAMP" property="source" />
    <result column="order_type" jdbcType="TIMESTAMP" property="orderType" />
    <result column="features" jdbcType="TIMESTAMP" property="features" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="biz_type" jdbcType="INTEGER" property="bizType" />
    <result column="performance_type" jdbcType="INTEGER" property="performanceType" />
  </resultMap>

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

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

  <sql id="cols_exclude_id">
    order_no, user_id, seller_id, store_id, pay_type, amount, pay_no, third_pay_no, created_at,
    updated_at, is_deleted, order_at, pay_at, source, order_type, features, status, biz_type, performance_type
  </sql>

  <sql id="values">
    #{id,jdbcType=BIGINT}, #{orderNo,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT},
    #{sellerId,jdbcType=BIGINT}, #{storeId,jdbcType=BIGINT}, #{payType,jdbcType=INTEGER},
    #{amount,jdbcType=INTEGER}, #{payNo}, #{thirdPayNo}, now(), now(), 0, #{orderAt}, #{payAt},
    #{source}, #{orderType}, #{features}, #{status}, #{bizType}, #{performanceType}
  </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="orderAtStart != null">
        <![CDATA[ AND order_at >= #{orderAtStart} ]]>
      </if>
      <if test="orderAtEnd != null">
        <![CDATA[ AND order_at <= #{orderAtEnd} ]]>
      </if>
    </where>
    order by id
    limit #{size}
  </select>

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

</mapper>