TdCRechargeCardSMapper.xml 7.36 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.zteits.pay.mapper.smapper.TdCRechargeCardSMapper">
  <resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCRechargeCard">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="card_no" jdbcType="VARCHAR" property="cardNo" />
    <result column="card_secret" jdbcType="VARCHAR" property="cardSecret" />
    <result column="card_name" jdbcType="VARCHAR" property="cardName" />
    <result column="card_type" jdbcType="INTEGER" property="cardType" />
    <result column="total_fee" jdbcType="BIGINT" property="totalFee" />
    <result column="act_fee" jdbcType="BIGINT" property="actFee" />
    <result column="disc_fee" jdbcType="BIGINT" property="discFee" />
    <result column="begin_time" jdbcType="TIMESTAMP" property="beginTime" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="card_state" jdbcType="INTEGER" property="cardState" />
    <result column="org_id" jdbcType="BIGINT" property="orgId" />
    <result column="sale_state" jdbcType="INTEGER" property="saleState" />
    <result column="sale_date" jdbcType="TIMESTAMP" property="saleDate" />
    <result column="sale_phone" jdbcType="VARCHAR" property="salePhone" />
    <result column="sale_remark" jdbcType="VARCHAR" property="saleRemark" />
    <result column="is_used" jdbcType="INTEGER" property="isUsed" />
    <result column="used_cust_id" jdbcType="VARCHAR" property="usedCustId" />
    <result column="used_phone" jdbcType="VARCHAR" property="usedPhone" />
    <result column="used_date" jdbcType="TIMESTAMP" property="usedDate" />
    <result column="rlt_order_id" jdbcType="VARCHAR" property="rltOrderId" />
    <result column="rlt_pay_order_id" jdbcType="VARCHAR" property="rltPayOrderId" />
    <result column="batch_no" jdbcType="VARCHAR" property="batchNo" />
    <result column="create_reason" jdbcType="VARCHAR" property="createReason" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="data_state" jdbcType="INTEGER" property="dataState" />
    <result column="create_empid" jdbcType="VARCHAR" property="createEmpid" />
    <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
    <result column="modfiy_empid" jdbcType="VARCHAR" property="modfiyEmpid" />
    <result column="modfiy_date" jdbcType="TIMESTAMP" property="modfiyDate" />
  </resultMap>

  <sql id="Base_Column_List">
    id, card_no, card_secret, card_name, card_type, total_fee, act_fee, disc_fee, begin_time, 
    end_time, card_state, org_id, sale_state, sale_date, sale_phone, sale_remark, is_used,
    used_cust_id, used_phone, used_date, rlt_order_id, rlt_pay_order_id, batch_no, create_reason, remark,
    data_state, create_empid, create_date, modfiy_empid, modfiy_date
  </sql>

  <!-- 批量插入充值卡券 -->
  <insert id="saveRechargeCardList" parameterType="java.util.List">
    insert into td_c_recharge_card (card_no, card_secret, card_name,
    card_type, total_fee, act_fee,
    disc_fee, begin_time, end_time,
    card_state, org_id, sale_state,
    sale_date, sale_phone, sale_remark,
    is_used, used_cust_id, used_phone,
    used_date, rlt_order_id, rlt_pay_order_id,
    batch_no, create_reason, remark, data_state,
    create_empid, create_date, modfiy_empid,
    modfiy_date)
    values
    <foreach collection="tdCRechargeCards" item="item" index="index" separator=",">
      (#{item.cardNo,jdbcType=VARCHAR}, #{item.cardSecret,jdbcType=VARCHAR}, #{item.cardName,jdbcType=VARCHAR},
      #{item.cardType,jdbcType=INTEGER}, #{item.totalFee,jdbcType=BIGINT}, #{item.actFee,jdbcType=BIGINT},
      #{item.discFee,jdbcType=BIGINT}, #{item.beginTime,jdbcType=TIMESTAMP}, #{item.endTime,jdbcType=TIMESTAMP},
      #{item.cardState,jdbcType=INTEGER}, #{item.orgId,jdbcType=BIGINT}, #{item.saleState,jdbcType=INTEGER},
      #{item.saleDate,jdbcType=TIMESTAMP}, #{item.salePhone,jdbcType=VARCHAR}, #{item.saleRemark,jdbcType=VARCHAR},
      #{item.isUsed,jdbcType=INTEGER}, #{item.usedCustId,jdbcType=VARCHAR}, #{item.usedPhone,jdbcType=VARCHAR},
      #{item.usedDate,jdbcType=TIMESTAMP}, #{item.rltOrderId,jdbcType=VARCHAR}, #{item.rltPayOrderId,jdbcType=VARCHAR},
      #{item.batchNo,jdbcType=VARCHAR}, #{item.createReason,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR}, #{item.dataState,jdbcType=INTEGER},
      #{item.createEmpid,jdbcType=VARCHAR}, #{item.createDate,jdbcType=TIMESTAMP}, #{item.modfiyEmpid,jdbcType=VARCHAR},
      #{item.modfiyDate,jdbcType=TIMESTAMP})
    </foreach>
  </insert>

  <sql id="common_where_if">
    org_id=#{orgId} and data_state = 1
    <if test="beginSaleDate != null" >
      and  begin_time >= #{beginSaleDate}
    </if>
    <if test="endSaleDate != null" >
      and  begin_time &lt;= #{endSaleDate}
    </if>
    <if test="beginUsedDate != null" >
      and  used_date >= #{beginUsedDate}
    </if>
    <if test="endUsedDate != null" >
      and  used_date &lt;= #{endUsedDate}
    </if>
    <if test="cardNo != null and cardNo != ''" >
      and card_no = #{cardNo}
    </if>
    <if test="id != null" >
      and id like concat('%',#{id},'%')
    </if>
    <if test="batchNo != null and batchNo != ''" >
      and batch_no = #{batchNo}
    </if>
    <if test="cardType != null">
      and card_type = #{cardType,jdbcType=INTEGER}
    </if>
    <if test="cardTypeList != null and cardTypeList.size > 0">
      and card_type in
      <foreach collection="cardTypeList" open="(" close=")" item="card_type" separator=",">
        #{card_type}
      </foreach>
    </if>
    <if test="saleState != null">
      and sale_state = #{saleState,jdbcType=INTEGER}
    </if>
    <if test="isUsed != null">
      and is_used = #{isUsed,jdbcType=INTEGER}
    </if>
    <!-- 生效-->
    <if test="dataState != null and dataState == 1">
      and sale_state = 1 and end_time &gt;= #{nowDate} and is_used != 1
    </if>
    <!-- 未生效-->
    <if test="dataState != null and dataState == 2">
      and sale_state = 0 and end_time &gt;= #{nowDate}
    </if>
    <!-- 失效 -->
    <if test="dataState != null and dataState == 0">
      and ( end_time &lt; #{nowDate} or is_used = 1)
    </if>
  </sql>

  <!-- 充值卡分页查询 -->
  <select id="queryTdCRechargeCardForPage" resultMap="BaseResultMap"
          parameterType="com.zteits.clouds.api.dto.pay.param.TdCRechargeCardQueryRequest">
    select
    <include refid="Base_Column_List" />
    from td_c_recharge_card
    <where>
      <include refid="common_where_if"/>
    </where>
    order by id desc
  </select>
  <!-- 充值卡统计查询 -->
  <select id="queryTdCRechargeCardStatistic" resultType="com.zteits.clouds.api.dto.pay.dto.TdCRechargeCardStatisticDTO"
          parameterType="com.zteits.clouds.api.dto.pay.param.TdCRechargeCardQueryRequest">
    select
    sum(case when sale_state = 1 then act_fee else 0 end ) saleFee,
    sum(case when sale_state = 1 and card_type = 2 then act_fee else 0 end ) chuzkSaleFee,
    sum(case when sale_state = 1 and card_type = 3 then act_fee else 0 end ) shkSaleFee,
    sum(case when is_used = 1 then act_fee else 0 end ) usedFee,
    sum(case when is_used = 1 and card_type = 2 then act_fee else 0 end ) chuzkUsedFee,
    sum(case when is_used = 1 and card_type = 3 then act_fee else 0 end ) shkUsedFee
    from td_c_recharge_card
    <where>
      <include refid="common_where_if"/>
    </where>
  </select>
</mapper>