<?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.neusoft.smart.pos.trade.persistent.ext.mapper.GrantOrderMasterExtMapper">
  <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.trade.persistent.domain.GrantOrderMaster">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="grant_order_number" jdbcType="VARCHAR" property="grantOrderNumber" />
    <result column="outer_order_number" jdbcType="VARCHAR" property="outerOrderNumber" />
    <result column="auth_no" jdbcType="VARCHAR" property="authNo" />
    <result column="org_id" jdbcType="INTEGER" property="orgId" />
    <result column="shop_id" jdbcType="INTEGER" property="shopId" />
    <result column="serial_no" jdbcType="VARCHAR" property="serialNo" />
    <result column="device_name" jdbcType="VARCHAR" property="deviceName" />
    <result column="customer_number" jdbcType="VARCHAR" property="customerNumber" />
    <result column="seq_no" jdbcType="INTEGER" property="seqNo" />
    <result column="grant_amount" jdbcType="DECIMAL" property="grantAmount" />
    <result column="pay_amount" jdbcType="DECIMAL" property="payAmount" />
    <result column="unfreeze_amount" jdbcType="DECIMAL" property="unfreezeAmount" />
    <result column="pay_type" jdbcType="VARCHAR" property="payType" />
    <result column="grant_status" jdbcType="CHAR" property="grantStatus" />
    <result column="code_url" jdbcType="VARCHAR" property="codeUrl" />
    <result column="scan_code" jdbcType="VARCHAR" property="scanCode" />
    <result column="time_expire" jdbcType="TIMESTAMP" property="timeExpire" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="refund_number" jdbcType="VARCHAR" property="refundNumber" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="grant_time" jdbcType="TIMESTAMP" property="grantTime" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="VARCHAR" property="createdBy" />
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, grant_order_number, outer_order_number, auth_no, org_id, shop_id, serial_no, 
    device_name, customer_number, seq_no, grant_amount, pay_amount, unfreeze_amount, 
    pay_type, grant_status, code_url, scan_code, time_expire, version, refund_number, 
    remark, grant_time, created_at, created_by, updated_by, updated_at
  </sql>

  <update id="updateGrantOrderStatus" parameterType="com.neusoft.smart.pos.trade.persistent.domain.GrantOrderMaster">
    <![CDATA[
    update grant_order_master
    set grant_status = '7'
    where time_expire < now() and grant_status = '1';
    ]]>
  </update>

</mapper>