TdCCouponPersonSMapper.xml 10 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.TdCCouponPersonSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCCouponPerson">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="card_no" jdbcType="VARCHAR" property="cardNo" />
        <result column="cust_id" jdbcType="VARCHAR" property="custId" />
        <result column="begin_time" jdbcType="TIMESTAMP" property="beginTime" />
        <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
        <result column="is_uesed" jdbcType="INTEGER" property="isUesed" />
        <result column="used_time" jdbcType="TIMESTAMP" property="usedTime" />
        <result column="order_id" jdbcType="VARCHAR" property="orderId" />
        <result column="pay_order_id" jdbcType="VARCHAR" property="payOrderId" />
        <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" />
        <result column="org_id" jdbcType="BIGINT" property="orgId" />
        <result column="org_name" jdbcType="VARCHAR" property="orgName" />
    </resultMap>
    <sql id="Base_Column_List">
    id, card_no, cust_id, begin_time, end_time, is_uesed, used_time, order_id, pay_order_id,
    data_state, create_empid, create_date, modfiy_empid, modfiy_date, org_id, org_name
  </sql>



  <!-- 查询车主卡券信息 -->
  <select id="getCouponPersonState" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
  	resultType="com.zteits.pay.domain.TdCCouponPersonDO">
  	select
  	tp.id as id,
  	tp.cust_id as custId,
    tp.car_num as carNum,
  	tp.data_state as dataState,
  	tr.card_no as cardNo,
  	tr.card_name as cardName,
  	tr.card_res as cardRes,
  	tr.card_type as cardType,
  	tr.coupons_type as couponsType,
  	tr.use_rule as useRule,
    tr.disc_value as discValue,
    tr.full_cut_value as fullCutValue,
    tr.need_integral as needIntegral,
    tr.is_superp_use as isSuperpUse,
    tr.card_content as cardContent,
    tr.card_state as cardState,
    case when tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) then 1 else tp.is_uesed end as isUesed,
    tp.used_time as usedTime,
    tp.create_date as createDate,
    tp.begin_time as beginTime,
    tp.end_time as endTime,
    tr.org_id as orgId
    from
	td_c_coupon_rule tr, td_c_coupon_person tp
	where tp.cust_id = #{custId}
	and tr.card_no = tp.card_no
    <if test="dataState != null">
      and tp.data_state = #{dataState}
    </if>
    <if test="orgId != null">
      and tp.org_id = #{orgId}
    </if>
    <if test="isUesed != null and isUesed == 1">
      and (tp.is_uesed = #{isUesed} or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
    </if>
    <if test="isUesed != null and isUesed == 0">
        and tp.is_uesed = #{isUesed} and date(tp.end_time) >= date(#{queryDate})
    </if>
    <if test="isUesed != null and isUesed == 2">
        and ((tp.is_uesed = 1 or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
            or (tp.is_uesed = 0 and date(tp.end_time) >= date(#{queryDate})))
    </if>
    <if test="cardNos != null and cardNos.size > 0">
      and date(tp.create_date) = date(#{queryDate}) and tp.card_no in
      <foreach collection="cardNos" open="(" close=")" item="cardNo" separator=",">
          #{cardNo}
      </foreach>
    </if>
      <if test="cardTypes != null and cardTypes.size > 0 ">
          and tr.card_type in
          <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
              #{cardType}
          </foreach>
      </if>
      <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
          and tr.receive_channels in
          <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
              #{receiveChannels}
          </foreach>
      </if>
      <if test="day != null">
          and #{day} >= datediff(#{queryDate},tp.end_time)
      </if>
    order by tp.is_uesed ASC,tp.end_time desc
  </select>


    <!-- 查询车主卡券信息 -->
    <select id="getCouponPersonStateForShare" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
            resultType="com.zteits.pay.domain.TdCCouponPersonDO">
        select
        tp.id as id,
        tp.cust_id as custId,
        tp.car_num as carNum,
        tp.data_state as dataState,
        tr.card_no as cardNo,
        tr.card_name as cardName,
        tr.card_res as cardRes,
        tr.card_type as cardType,
        tr.coupons_type as couponsType,
        tr.use_rule as useRule,
        tr.disc_value as discValue,
        tr.full_cut_value as fullCutValue,
        tr.need_integral as needIntegral,
        tr.is_superp_use as isSuperpUse,
        tr.card_content as cardContent,
        tr.card_state as cardState,
        tp.is_uesed as isUesed,
        tp.used_time as usedTime,
        tp.create_date as createDate,
        tp.begin_time as beginTime,
        tp.end_time as endTime,
        tr.org_id as orgId
        from
        td_c_coupon_rule tr, td_c_coupon_person tp
        where tp.cust_id = #{custId}
        and tr.card_no = tp.card_no
        <if test="dataState != null">
            and tp.data_state = #{dataState}
        </if>
        <if test="orgId != null">
            and tp.org_id = #{orgId}
        </if>
        <if test="isUesed != null and isUesed == 1">
            and (tp.is_uesed = #{isUesed} or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
        </if>
        <if test="isUesed != null and isUesed == 0">
            and tp.is_uesed = #{isUesed} and date(tp.end_time) >= date(#{queryDate})
        </if>
        <if test="isUesed != null and isUesed == 2">
            and ((tp.is_uesed = 1 or (tp.is_uesed = 0 and date(#{queryDate}) > date(tp.end_time) ))
            or (tp.is_uesed = 0 and date(tp.end_time) >= date(#{queryDate})))
        </if>
        <if test="cardNos != null and cardNos.size > 0">
            and date(tp.create_date) = date(#{queryDate}) and tp.card_no in
            <foreach collection="cardNos" open="(" close=")" item="cardNo" separator=",">
                #{cardNo}
            </foreach>
        </if>
        <if test="cardTypes != null and cardTypes.size > 0 ">
            and tr.card_type in
            <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
                #{cardType}
            </foreach>
        </if>
        <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
            and tr.receive_channels in
            <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
                #{receiveChannels}
            </foreach>
        </if>
        <if test="day != null">
            and #{day} >= datediff(#{queryDate},tp.end_time)
        </if>
        <if test="owener != null">
            and tp.owener = #{owener}
        </if>
        <if test="hideOwener != null">
            and IFNULL(tp.owener, 0) != #{hideOwener}
        </if>
        order by tp.is_uesed ASC,tp.end_time desc
    </select>


    <!-- 查询车主卡券数量 -->
  <select id="getCouponPersonNum" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponPersonRequest"
  	resultType="java.lang.Integer">
  	select
	count(tr.id)
	from
	td_c_coupon_rule tr,td_c_coupon_person tp
	where tr.card_no = tp.card_no
	and tp.is_uesed = 0
	and date(tp.end_time) >= date(#{queryDate})
	and tp.cust_id = #{custId}
	and tp.data_state = 1
  </select>

  <!-- 车主平台查询车主卡券数量(全部、可用) -->
  <select id="getPersonCouponNum" parameterType="com.zteits.clouds.api.dto.owner.param.OwnerRequest"
  	resultType="com.zteits.clouds.api.dto.owner.dto.OwnerBaseDTO">
  	select
	count(id) as totalCouponNum,
	SUM(CASE WHEN (date(end_time) > SYSDATE() AND is_uesed = 0) THEN 1 ELSE 0 END)  AS validCouponNum
	from
	td_c_coupon_person
	where data_state = 1
	and cust_id = #{custId}
  </select>

  <select id="getCouponsPage" parameterType="com.zteits.clouds.api.dto.order.coupon.CouponPageRequest"
    resultType="com.zteits.clouds.api.dto.order.coupon.CouponPageVO">

      SELECT
          c.id AS couponId,
          r.card_name AS cardName,
          r.disc_value AS couponValue,
          IFNULL(c.order_discount_fee, 0) AS orderDiscountFee ,
          p.user_phone AS userPhone,
          IFNULL(c.car_num, '') AS carNum,
          c.begin_time AS beginTime,
          c.end_time AS endTime,
          c.is_uesed AS isUsed,
          c.used_time AS usedTime,
          IFNULL(c.owener_name, '') AS owenerName
      FROM
          td_c_coupon_person c,
          td_c_coupon_rule r,
          td_c_cust_person p
      WHERE
          c.card_no = r.card_no
          AND c.cust_id = p.cust_id
          <if test="ruleNo != null and ruleNo != ''">
              AND c.card_no = #{ruleNo}
          </if>
          <if test="userPhone != null and userPhone != ''">
              AND p.user_phone = #{userPhone}
          </if>
      ORDER BY c.id
  </select>

    <select id="getCouponsStatistics" parameterType="com.zteits.clouds.api.dto.order.coupon.CouponPageRequest"
            resultType="com.zteits.clouds.api.dto.order.coupon.CouponStatisticsVO">
        SELECT
        COUNT( * ) AS total,
        IFNULL(SUM( c.order_discount_fee ), 0 ) AS totalDiscount,
        IFNULL(SUM( c.is_uesed ), 0 ) AS totalUsed
        FROM
        td_c_coupon_person c,
        td_c_cust_person p
        WHERE
        c.cust_id = p.cust_id
        <if test="ruleNo != null and ruleNo != ''">
            AND c.card_no = #{ruleNo}
        </if>
        <if test="userPhone != null and userPhone != ''">
            AND p.user_phone = #{userPhone}
        </if>
    </select>



</mapper>