TradeBillsMapper.xml 7.71 KB
<?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.yohoufo.dal.order.TradeBillsMapper">
  <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.TradeBills">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="INTEGER" property="uid" />
    <result column="order_code" jdbcType="BIGINT" property="orderCode" />
    <result column="paid_order_code" jdbcType="BIGINT" property="paidOrderCode" />
    <result column="pay_level" jdbcType="TINYINT" property="payLevel" />
    <result column="user_type" jdbcType="TINYINT" property="userType" />
    <result column="pay_type" jdbcType="TINYINT" property="payType" />
    <result column="trade_type" jdbcType="INTEGER" property="tradeType" />
    <result column="income_outcome" jdbcType="TINYINT" property="incomeOutcome" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="system_amount" jdbcType="DECIMAL" property="systemAmount" />
    <result column="trade_status" jdbcType="TINYINT" property="tradeStatus" />
    <result column="create_time" jdbcType="INTEGER" property="createTime" />

    <result column="deal_uid" jdbcType="INTEGER" property="dealUid" />
    <result column="deal_status" jdbcType="TINYINT" property="dealStatus" />
    <result column="deal_time" jdbcType="INTEGER" property="dealTime" />
    <result column="deal_relate_id" jdbcType="INTEGER" property="dealRelateId" />
    <result column="deal_user_name" jdbcType="VARCHAR" property="dealUserName" />
    <result column="pay_error_code" jdbcType="VARCHAR" property="payErrorCode" />
  </resultMap>
  <sql id="Base_Column_List">
    id,uid, order_code,paid_order_code,pay_level, user_type,pay_type,trade_type,income_outcome,amount,system_amount,trade_status,create_time,
    deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name,pay_error_code
  </sql>

  <select id="selectById" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from trade_bills
    where id = #{id,jdbcType=INTEGER}
  </select>
  
  <select id="selectByDealRelateId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from trade_bills
    where deal_relate_id = #{dealRelateId,jdbcType=INTEGER}
  </select>

  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.TradeBills" useGeneratedKeys="true">
    insert into trade_bills (id, uid, order_code, paid_order_code,pay_level, user_type,pay_type,trade_type,
    income_outcome,amount,system_amount,trade_status,create_time
    ,deal_uid,deal_status,deal_time,deal_relate_id,deal_user_name,pay_error_code)
    values (#{id},#{uid},#{orderCode},#{paidOrderCode},#{payLevel},#{userType},#{payType},#{tradeType},
    #{incomeOutcome},#{amount},#{systemAmount},
    #{tradeStatus},#{createTime},#{dealUid},#{dealStatus},
    #{dealTime},#{dealRelateId},#{dealUserName},#{payErrorCode})
  </insert>

  <update id="updateById" parameterType="com.yohoufo.dal.order.model.TradeBills" >
    update trade_bills
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=INTEGER},
      </if>
      <if test="orderCode != null" >
        order_code = #{orderCode,jdbcType=BIGINT},
      </if>
      <if test="userType != null" >
        user_type = #{userType,jdbcType=INTEGER},
      </if>
      <if test="payType != null" >
        pay_type = #{payType,jdbcType=INTEGER},
      </if>
      <if test="tradeType != null" >
        trade_type = #{tradeType,jdbcType=INTEGER},
      </if>
      <if test="incomeOutcome != null" >
        income_outcome = #{incomeOutcome,jdbcType=INTEGER},
      </if>
      <if test="amount != null" >
        amount = #{amount,jdbcType=DECIMAL},
      </if>
      <if test="systemAmount != null" >
        system_amount = #{systemAmount,jdbcType=DECIMAL},
      </if>
      <if test="tradeStatus != null" >
        trade_status = #{tradeStatus,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=INTEGER},
      </if>
      <if test="dealUid != null" >
        deal_uid = #{dealUid,jdbcType=INTEGER},
      </if>
      <if test="dealUserName != null" >
        deal_user_name = #{dealUserName,jdbcType=VARCHAR},
      </if>
      <if test="dealStatus != null" >
        deal_status = #{dealStatus,jdbcType=INTEGER},
      </if>
      <if test="dealTime != null" >
        deal_time = #{dealTime,jdbcType=INTEGER},
      </if>
      <if test="dealRelateId != null" >
        deal_relate_id = #{dealRelateId,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>


  <update id="updateLock">
    update trade_bills
    set deal_status = 1
    where id = #{id,jdbcType=INTEGER} and deal_status = 0
  </update>

  <update id="updateUnlock">
    update trade_bills
    set deal_status = 0
    where id = #{id,jdbcType=INTEGER} and deal_status = 1
  </update>

  <select id="selectByOrderCodeAndTradeType" parameterType="com.yohoufo.dal.order.model.TradeBills" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from trade_bills
    where  order_code = #{orderCode,jdbcType=BIGINT}
    and trade_type = #{tradeType,jdbcType=INTEGER}
  </select>


  <select id="selectByOrderCodeList" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from trade_bills
    where 1=1 and order_code in
    <foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
      #{orderCode,jdbcType=BIGINT}
    </foreach>

  </select>


  <update id="updateLockOfUidTradeStatusAndDealTime" >
    update trade_bills
    set trade_status = #{tagTradeStatus,jdbcType=INTEGER},deal_time = #{tagDealTime,jdbcType=INTEGER}
    where
    uid = #{uid,jdbcType=INTEGER}
    and trade_status = #{tradeStatus,jdbcType=INTEGER}
    and deal_time = #{dealTime,jdbcType=INTEGER}
  </update>

  <select id="selectByUidTradeStatusAndDealTime" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from trade_bills
    where
    uid = #{uid,jdbcType=INTEGER}
    and trade_status = #{tradeStatus,jdbcType=INTEGER}
    and deal_time = #{dealTime,jdbcType=INTEGER}
  </select>


  <sql id="Assets_Details_View_Query_Condition_Sql" >
    uid = #{uid,jdbcType=INTEGER} and income_outcome = 1  and deal_status != 1
    and ( (user_type =1 and trade_type = 3)  or (user_type =2 and trade_type = 2) or (user_type =2 and trade_type = 3) )
    <if test="queryType == 1" >
      and trade_status = 10
    </if>
    <if test="queryType == 2" >
      and trade_status != 10
    </if>
  </sql>

  <select id="selectCountForAssetsDetailsView" parameterType="com.yohoufo.dal.order.model.AssetsDetailsViewRequest" resultType="java.lang.Integer" >
    select
    count(id)
    from trade_bills
    where <include refid="Assets_Details_View_Query_Condition_Sql" />
  </select>

  <select id="selectForAssetsDetailsView" parameterType="com.yohoufo.dal.order.model.AssetsDetailsViewRequest" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from trade_bills
    where <include refid="Assets_Details_View_Query_Condition_Sql" />
    order by id desc
    limit  #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
  </select>


  <select id="selectIncomeAmountForAssetsDetailsView" parameterType="com.yohoufo.dal.order.model.AssetsDetailsViewRequest" resultType="com.yohoufo.dal.order.model.AssetsDetailsViewIncomeAmount">
    select trade_status as tradeStatus, trade_type as tradeType,sum(amount) as amount from trade_bills
    where <include refid="Assets_Details_View_Query_Condition_Sql" />
    group by trade_status, trade_type
  </select>

</mapper>