InviteSettlementItemMapper.xml 6.88 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.InviteSettlementItemMapper" >
  <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.InviteSettlementItem" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="uid" property="uid" jdbcType="INTEGER" />
    <result column="buyer_uid" property="buyerUid" jdbcType="INTEGER" />
    <result column="buyer_order_code" property="buyerOrderCode" jdbcType="BIGINT" />
    <result column="seller_uid" property="sellerUid" jdbcType="INTEGER" />
    <result column="order_amount" property="orderAmount" jdbcType="DECIMAL" />
    <result column="order_create_time" property="orderCreateTime" jdbcType="INTEGER" />
    <result column="type" property="type" jdbcType="INTEGER" />
    <result column="settle_amount" property="settleAmount" jdbcType="DECIMAL" />
    <result column="invite_settlement_id" property="inviteSettlementId" jdbcType="INTEGER" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="status_desc" property="statusDesc" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="INTEGER" />
    <result column="order_num" property="orderNum" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, buyer_uid, buyer_order_code, seller_uid, order_amount,order_create_time,type,settle_amount, invite_settlement_id,
    status, status_desc, create_time
  </sql>
  <insert id="insert" parameterType="com.yohoufo.dal.order.model.InviteSettlementItem" >
    insert into invite_settlement_item (id,
      uid,
      buyer_uid,
      buyer_order_code,
      seller_uid,
      order_amount,
      order_create_time,
      type,
      settle_amount,
      invite_settlement_id,
      status,
      status_desc,
      create_time)
    values (#{id,jdbcType=INTEGER},
      #{uid,jdbcType=INTEGER},
      #{buyerUid,jdbcType=INTEGER},
      #{buyerOrderCode,jdbcType=BIGINT},
      #{sellerUid,jdbcType=INTEGER},
      #{orderAmount,jdbcType=DECIMAL},
      #{orderCreateTime,jdbcType=INTEGER},
      #{type,jdbcType=INTEGER},
      #{settleAmount,jdbcType=DECIMAL},
      #{inviteSettlementId,jdbcType=INTEGER},
      #{status,jdbcType=INTEGER},
      #{statusDesc,jdbcType=VARCHAR},
      #{createTime,jdbcType=INTEGER})
  </insert>

  <update id="updateToSettled">
    update invite_settlement_item
      set status = #{tagStatus,jdbcType=INTEGER},
      invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
    where uid = #{uid,jdbcType=INTEGER}
      and type = #{type,jdbcType=INTEGER}
      and status = #{srcStatus,jdbcType=INTEGER}
      and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
  </update>

  <update id="updateToSettledRollback">
    update invite_settlement_item
    set status = #{tagStatus,jdbcType=INTEGER},
    invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and status = #{srcStatus,jdbcType=INTEGER}
    and id in
    <foreach collection="ids" item="id" open="(" separator="," close=")">
      #{id}
    </foreach>
  </update>

  <update id="updateStatusByUidAndInviteSettlementId">
    update invite_settlement_item
      set status = #{status,jdbcType=INTEGER}
    where uid = #{uid,jdbcType=INTEGER}
      and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
  </update>

  <select id="selectByUidAndBuyerOrderCode" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER} and buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT}
  </select>

  <select id="selectOneByUidTypeAndStatus" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and status = #{status,jdbcType=INTEGER}
    limit 1
  </select>

  <select id="selectCountByUidTypeAndInviteSettlementId" resultType="java.lang.Integer" >
    select
    count(1)
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER} and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
     and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
  </select>

  <select id="selectStatsByUidTypeAndInviteSettlementIdGroupBySellerUid" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
    select
    seller_uid as 'sellerUid',
    count(1) as 'totalElements',
    sum(order_amount) as 'totalOrderAmount',
    sum(settle_amount) as 'totalSettleAmount'
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
    and <![CDATA[ create_time <= #{settlementTime,jdbcType=INTEGER}]]>
    group by seller_uid
  </select>



  <select id="selectByUidTypeInviteSettlementIdAndSellerUid" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and invite_settlement_id = #{inviteSettlementId,jdbcType=INTEGER}
    and seller_uid = #{sellerUid,jdbcType=INTEGER}
  </select>



  <select id="selectOrderNumByInviterUid" resultMap="BaseResultMap" >
    select
    seller_uid, count(buyer_order_code) order_num
    from invite_settlement_item
    where uid = #{inviterUid,jdbcType=INTEGER}
    and type = 1
    and status in (1,3,4)
    GROUP by seller_uid
  </select>

  <select id="selectStats" resultType="com.yohoufo.dal.order.model.InviteSettlementItemStats" >
    select
    count(1) as 'totalElements',
    sum(order_amount) as 'totalOrderAmount',
    sum(settle_amount) as 'totalSettleAmount',
    sum(if(status=4,settle_amount,0)) as 'totalPaidAmount',
    sum(if(status!=4,settle_amount,0)) as 'totalWaitPayAmount'
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and status in
    <foreach collection="statusList" item="status" open="(" separator="," close=")">
      #{status}
    </foreach>
    and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
  </select>

  <select id="select" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from invite_settlement_item
    where uid = #{uid,jdbcType=INTEGER}
    and type = #{type,jdbcType=INTEGER}
    and status in
    <foreach collection="statusList" item="status" open="(" separator="," close=")">
      #{status}
    </foreach>
    and order_create_time between #{startTime,jdbcType=INTEGER} and #{endTime,jdbcType=INTEGER}
    order by order_create_time desc
    limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
  </select>

</mapper>