<?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.lightinit.hsdataplatform.mapper.UserAccountTransactionMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="account_id" jdbcType="BIGINT" property="accountId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="trans_time" jdbcType="TIMESTAMP" property="transTime" />
    <result column="trans_state" jdbcType="VARCHAR" property="transState" />
    <result column="trans_type" jdbcType="VARCHAR" property="transType" />
    <result column="trans_method" jdbcType="VARCHAR" property="transMethod" />
    <result column="business_type" jdbcType="VARCHAR" property="businessType" />
    <result column="trans_result" jdbcType="VARCHAR" property="transResult" />
    <result column="trans_amount" jdbcType="DECIMAL" property="transAmount" />
    <result column="balance" jdbcType="DECIMAL" property="balance" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    <result column="remark" jdbcType="LONGVARCHAR" property="remark" />
  </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, account_id, order_id, trans_time, trans_state, trans_type, trans_method, business_type, 
    trans_result, trans_amount, balance, created_at, created_by, deleted_at, deleted_by
  </sql>
  <sql id="Blob_Column_List">
    remark
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransactionExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from user_account_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransactionExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from user_account_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from user_account_transaction
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from user_account_transaction
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransactionExample">
    delete from user_account_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into user_account_transaction (account_id, order_id, trans_time, 
      trans_state, trans_type, trans_method, 
      business_type, trans_result, trans_amount, 
      balance, created_at, created_by, 
      deleted_at, deleted_by, remark
      )
    values (#{accountId,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, #{transTime,jdbcType=TIMESTAMP}, 
      #{transState,jdbcType=VARCHAR}, #{transType,jdbcType=VARCHAR}, #{transMethod,jdbcType=VARCHAR}, 
      #{businessType,jdbcType=VARCHAR}, #{transResult,jdbcType=VARCHAR}, #{transAmount,jdbcType=DECIMAL}, 
      #{balance,jdbcType=DECIMAL}, #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, 
      #{deletedAt,jdbcType=TIMESTAMP}, #{deletedBy,jdbcType=BIGINT}, #{remark,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into user_account_transaction
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="accountId != null">
        account_id,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="transTime != null">
        trans_time,
      </if>
      <if test="transState != null">
        trans_state,
      </if>
      <if test="transType != null">
        trans_type,
      </if>
      <if test="transMethod != null">
        trans_method,
      </if>
      <if test="businessType != null">
        business_type,
      </if>
      <if test="transResult != null">
        trans_result,
      </if>
      <if test="transAmount != null">
        trans_amount,
      </if>
      <if test="balance != null">
        balance,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
      <if test="remark != null">
        remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="accountId != null">
        #{accountId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="transTime != null">
        #{transTime,jdbcType=TIMESTAMP},
      </if>
      <if test="transState != null">
        #{transState,jdbcType=VARCHAR},
      </if>
      <if test="transType != null">
        #{transType,jdbcType=VARCHAR},
      </if>
      <if test="transMethod != null">
        #{transMethod,jdbcType=VARCHAR},
      </if>
      <if test="businessType != null">
        #{businessType,jdbcType=VARCHAR},
      </if>
      <if test="transResult != null">
        #{transResult,jdbcType=VARCHAR},
      </if>
      <if test="transAmount != null">
        #{transAmount,jdbcType=DECIMAL},
      </if>
      <if test="balance != null">
        #{balance,jdbcType=DECIMAL},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransactionExample" resultType="java.lang.Long">
    select count(*) from user_account_transaction
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update user_account_transaction
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.accountId != null">
        account_id = #{record.accountId,jdbcType=BIGINT},
      </if>
      <if test="record.orderId != null">
        order_id = #{record.orderId,jdbcType=BIGINT},
      </if>
      <if test="record.transTime != null">
        trans_time = #{record.transTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.transState != null">
        trans_state = #{record.transState,jdbcType=VARCHAR},
      </if>
      <if test="record.transType != null">
        trans_type = #{record.transType,jdbcType=VARCHAR},
      </if>
      <if test="record.transMethod != null">
        trans_method = #{record.transMethod,jdbcType=VARCHAR},
      </if>
      <if test="record.businessType != null">
        business_type = #{record.businessType,jdbcType=VARCHAR},
      </if>
      <if test="record.transResult != null">
        trans_result = #{record.transResult,jdbcType=VARCHAR},
      </if>
      <if test="record.transAmount != null">
        trans_amount = #{record.transAmount,jdbcType=DECIMAL},
      </if>
      <if test="record.balance != null">
        balance = #{record.balance,jdbcType=DECIMAL},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
      <if test="record.remark != null">
        remark = #{record.remark,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update user_account_transaction
    set id = #{record.id,jdbcType=BIGINT},
      account_id = #{record.accountId,jdbcType=BIGINT},
      order_id = #{record.orderId,jdbcType=BIGINT},
      trans_time = #{record.transTime,jdbcType=TIMESTAMP},
      trans_state = #{record.transState,jdbcType=VARCHAR},
      trans_type = #{record.transType,jdbcType=VARCHAR},
      trans_method = #{record.transMethod,jdbcType=VARCHAR},
      business_type = #{record.businessType,jdbcType=VARCHAR},
      trans_result = #{record.transResult,jdbcType=VARCHAR},
      trans_amount = #{record.transAmount,jdbcType=DECIMAL},
      balance = #{record.balance,jdbcType=DECIMAL},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      remark = #{record.remark,jdbcType=LONGVARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update user_account_transaction
    set id = #{record.id,jdbcType=BIGINT},
      account_id = #{record.accountId,jdbcType=BIGINT},
      order_id = #{record.orderId,jdbcType=BIGINT},
      trans_time = #{record.transTime,jdbcType=TIMESTAMP},
      trans_state = #{record.transState,jdbcType=VARCHAR},
      trans_type = #{record.transType,jdbcType=VARCHAR},
      trans_method = #{record.transMethod,jdbcType=VARCHAR},
      business_type = #{record.businessType,jdbcType=VARCHAR},
      trans_result = #{record.transResult,jdbcType=VARCHAR},
      trans_amount = #{record.transAmount,jdbcType=DECIMAL},
      balance = #{record.balance,jdbcType=DECIMAL},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    update user_account_transaction
    <set>
      <if test="accountId != null">
        account_id = #{accountId,jdbcType=BIGINT},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="transTime != null">
        trans_time = #{transTime,jdbcType=TIMESTAMP},
      </if>
      <if test="transState != null">
        trans_state = #{transState,jdbcType=VARCHAR},
      </if>
      <if test="transType != null">
        trans_type = #{transType,jdbcType=VARCHAR},
      </if>
      <if test="transMethod != null">
        trans_method = #{transMethod,jdbcType=VARCHAR},
      </if>
      <if test="businessType != null">
        business_type = #{businessType,jdbcType=VARCHAR},
      </if>
      <if test="transResult != null">
        trans_result = #{transResult,jdbcType=VARCHAR},
      </if>
      <if test="transAmount != null">
        trans_amount = #{transAmount,jdbcType=DECIMAL},
      </if>
      <if test="balance != null">
        balance = #{balance,jdbcType=DECIMAL},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=LONGVARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    update user_account_transaction
    set account_id = #{accountId,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      trans_time = #{transTime,jdbcType=TIMESTAMP},
      trans_state = #{transState,jdbcType=VARCHAR},
      trans_type = #{transType,jdbcType=VARCHAR},
      trans_method = #{transMethod,jdbcType=VARCHAR},
      business_type = #{businessType,jdbcType=VARCHAR},
      trans_result = #{transResult,jdbcType=VARCHAR},
      trans_amount = #{transAmount,jdbcType=DECIMAL},
      balance = #{balance,jdbcType=DECIMAL},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT},
      remark = #{remark,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.UserAccountTransaction">
    update user_account_transaction
    set account_id = #{accountId,jdbcType=BIGINT},
      order_id = #{orderId,jdbcType=BIGINT},
      trans_time = #{transTime,jdbcType=TIMESTAMP},
      trans_state = #{transState,jdbcType=VARCHAR},
      trans_type = #{transType,jdbcType=VARCHAR},
      trans_method = #{transMethod,jdbcType=VARCHAR},
      business_type = #{businessType,jdbcType=VARCHAR},
      trans_result = #{transResult,jdbcType=VARCHAR},
      trans_amount = #{transAmount,jdbcType=DECIMAL},
      balance = #{balance,jdbcType=DECIMAL},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="queryRechargeList" parameterType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeDtoModel" resultType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeVOModel">
    <if test="username != null and username.length() > 0">
      <bind name="username" value="'%' + _parameter.username + '%'" />
    </if>
    SELECT u.username,u.user_type,uat.trans_method,uat.trans_amount,uat.balance,uat.created_at
    FROM user u
    JOIN user_account ua
    on ua.id = u.id
    JOIN user_account_transaction uat
    ON ua.id = uat.account_id
    <where>
      <if test="username != null and username.length() > 0">
        u.username like #{username}
      </if>
      <if test="transType != null and transType.length() > 0">
        AND uat.trans_type = #{transType}
      </if>
      <if test="rechargeFrom != null">
        AND r.created_at &gt;= #{rechargeFrom}
      </if>
      <if test="rechargeTo != null">
        AND r.created_at &lt; #{rechargeTo}
      </if>
    </where>
    ORDER BY u.id DESC
    <if test="page != null" >
      LIMIT #{page.beginIndex},#{page.pageSize}
    </if>
  </select>
  <select id="queryRechargeCount" parameterType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeDtoModel" resultType="java.lang.Long">
    <if test="username != null and username.length() > 0">
      <bind name="username" value="'%' + _parameter.username + '%'" />
    </if>
    SELECT count(*)
    FROM user u
    JOIN user_account ua
    on ua.id = u.id
    JOIN user_account_transaction uat
    ON ua.id = uat.account_id
    <where>
      <if test="username != null and username.length() > 0">
        u.username like #{username}
      </if>
      <if test="transType != null and transType.length() > 0">
       AND uat.trans_type = #{transType}
      </if>
      <if test="rechargeFrom != null">
        AND r.created_at &gt;= #{rechargeFrom}
      </if>
      <if test="rechargeTo != null">
        AND r.created_at &lt; #{rechargeTo}
      </if>
    </where>
  </select>
  <select id="querySumTransAmount" parameterType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeDtoModel" resultType="java.lang.Long">
    <if test="username != null and username.length() > 0">
      <bind name="username" value="'%' + _parameter.username + '%'" />
    </if>
    SELECT sum(uat.trans_amount)
    FROM user u
    JOIN user_account ua
    on ua.id = u.id
    JOIN user_account_transaction uat
    ON ua.id = uat.account_id
    <where>
      <if test="username != null and username.length() > 0">
        u.username like #{username}
      </if>
      <if test="transType != null and transType.length() > 0">
        AND uat.trans_type = #{transType}
      </if>
      <if test="rechargeFrom != null">
        AND r.created_at &gt;= #{rechargeFrom}
      </if>
      <if test="rechargeTo != null">
        AND r.created_at &lt; #{rechargeTo}
      </if>
    </where>
  </select>
  <select id="queryTransactionList" parameterType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeDtoModel" resultType="com.lightinit.hsdataplatform.model.admin.AccountManageTransactionVOModel">
    <if test="username != null and username.length() > 0">
      <bind name="username" value="'%' + _parameter.username + '%'" />
    </if>
    SELECT u.username,u.user_type,uat.trans_method,uat.trans_amount,uat.balance,uat.created_at,uat.remark
    FROM user u
    JOIN user_account ua
    on ua.id = u.id
    JOIN user_account_transaction uat
    ON ua.id = uat.account_id
    <where>
      <if test="username != null and username.length() > 0">
        u.username like #{username}
      </if>
      <if test="transType != null and transType.length() > 0">
        AND uat.trans_type = #{transType}
      </if>
      <if test="rechargeFrom != null">
        AND r.created_at &gt;= #{rechargeFrom}
      </if>
      <if test="rechargeTo != null">
        AND r.created_at &lt; #{rechargeTo}
      </if>
    </where>
    ORDER BY u.id DESC
    <if test="page != null" >
      LIMIT #{page.beginIndex},#{page.pageSize}
    </if>
  </select>
  <select id="queryTransactionCount" parameterType="com.lightinit.hsdataplatform.model.admin.AccountManageRechargeDtoModel" resultType="java.lang.Long">
    <if test="username != null and username.length() > 0">
      <bind name="username" value="'%' + _parameter.username + '%'" />
    </if>
    SELECT count(*)
    FROM user u
    JOIN user_account ua
    on ua.id = u.id
    JOIN user_account_transaction uat
    ON ua.id = uat.account_id
    <where>
      <if test="username != null and username.length() > 0">
        u.username like #{username}
      </if>
      <if test="transType != null and transType.length() > 0">
        AND uat.trans_type = #{transType}
      </if>
      <if test="rechargeFrom != null">
        AND r.created_at &gt;= #{rechargeFrom}
      </if>
      <if test="rechargeTo != null">
        AND r.created_at &lt; #{rechargeTo}
      </if>
    </where>
  </select>
</mapper>