TdCCouponRuleSMapper.xml 15.5 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.TdCCouponRuleSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.pay.domain.TdCCouponRule">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="card_no" jdbcType="VARCHAR" property="cardNo" />
        <result column="card_name" jdbcType="VARCHAR" property="cardName" />
        <result column="card_res" jdbcType="INTEGER" property="cardRes" />
        <result column="card_type" jdbcType="INTEGER" property="cardType" />
        <result column="coupons_type" jdbcType="INTEGER" property="couponsType" />
        <result column="is_recommend" jdbcType="INTEGER" property="isRecommend" />
        <result column="use_rule" jdbcType="INTEGER" property="useRule" />
        <result column="disc_value" jdbcType="VARCHAR" property="discValue" />
        <result column="full_cut_value" jdbcType="INTEGER" property="fullCutValue" />
        <result column="need_integral" jdbcType="INTEGER" property="needIntegral" />
        <result column="is_superp_use" jdbcType="INTEGER" property="isSuperpUse" />
        <result column="begin_time" jdbcType="TIMESTAMP" property="beginTime" />
        <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
        <result column="card_rest_num" jdbcType="INTEGER" property="cardRestNum" />
        <result column="card_num" jdbcType="INTEGER" property="cardNum" />
        <result column="card_state" jdbcType="INTEGER" property="cardState" />
        <result column="card_remarks" jdbcType="VARCHAR" property="cardRemarks" />
        <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="card_content" jdbcType="VARCHAR" property="cardContent" />
        <result column="valid_days" jdbcType="INTEGER" property="validDays" />
        <result column="receive_channels" jdbcType="INTEGER" property="receiveChannels" />
        <result column="receive_num" jdbcType="INTEGER" property="receiveNum" />
        <result column="org_id" jdbcType="BIGINT" property="orgId" />
    </resultMap>

    <sql id="Base_Column_List">
        id, card_no, card_name, card_res, card_type, coupons_type, is_recommend, use_rule,
        disc_value, full_cut_value, need_integral, is_superp_use, begin_time, end_time, card_rest_num,
        card_num, card_state, card_remarks, data_state, create_empid, create_date, modfiy_empid,
        modfiy_date,card_content, valid_days, receive_channels, receive_num, org_id
    </sql>

    <!--根据卡类型查询优惠券规则表 langlw 2017-12-27 Query the coupon rule table based on the card type-->
    <select id="queryCouponRuleList" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponRuleRequest"
            resultType="com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO">
        select
        a.card_no as cardNo,
        a.card_name as cardName,
        a.card_type as cardType,
        a.coupons_type as couponsType,
        a.use_rule as useRule,
        a.disc_value as discValue,
        a.full_cut_value as fullCutValue,
        a.need_integral as needIntegral,
        a.is_superp_use as isSuperpUse,
        a.card_rest_num as cardRestNum,
        a.card_num as cardNum,
        a.card_state as cardState,
        a.begin_time as beginTime,
        a.end_time as endTime,
        a.create_date as createDate,
        a.card_content as cardContent,
        a.valid_days validDays,
        a.receive_channels receiveChannels,
        a.receive_num receiveNum,
        a.org_id orgId
        from
        td_c_coupon_rule a 
        where a.data_state=1
        and a.card_state =1     /**卡券状态:1、上架;2、下架 **/
        AND a.end_time >= #{queryDate} /***只查询在有效期内的券 **/
        AND #{queryDate} >= a.begin_time /***只查询在有效期内的券 **/
        <if test="orgId != null">
            and a.org_id = #{orgId}
        </if>
        <if test="cardType != null ">
            and a.card_type = #{cardType}
        </if>
        <if test="cardTypes != null and cardTypes.size > 0 ">
            and a.card_type in
            <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
                #{cardType}
            </foreach>
        </if>
        <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
            and a.receive_channels in
            <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
                #{receiveChannels}
            </foreach>
        </if>
        order by a.create_date , a.need_integral desc
    </select>

  <!-- 查询所有上架卡券 -->
  <select id="queryAllSellingCoupons"  parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponRuleRequest"
          resultType="com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO">
    SELECT
		a.id id, a.card_no cardNo, a.card_name cardName, card_res cardRes, card_type cardType, coupons_type couponsType, 
		is_recommend isRecommend, use_rule useRule,disc_value discValue, full_cut_value fullCutValue,
		need_integral needIntegral, is_superp_use isSuperpUse, begin_time beginTime, end_time endTime,
		card_rest_num cardRestNum, card_num cardNum, card_state cardState, card_remarks cardRemarks, 
		a.data_state dataState, a.create_empid createEmpid, a.create_date createDate, a.modfiy_empid modfiyEmpid, 
	    a.modfiy_date modfiyDate,GROUP_CONCAT(b.pl_no) plNos,a.card_content as cardContent,
        a.valid_days validDays, a.receive_channels receiveChannels, a.receive_num receiveNum,
      a.org_id orgId
	FROM
		td_c_coupon_rule a
	LEFT JOIN td_c_coupon_rule_park b ON a.card_no = b.card_no
	WHERE 1 = 1
	AND a.data_state = 1
	AND a.card_state = 1
    and a.receive_num > 0
    AND a.end_time >= #{queryDate} /***只查询在有效期内的券 **/
    AND #{queryDate} >= a.begin_time /***只查询在有效期内的券 **/
      <if test="orgId != null">
          and a.org_id = #{orgId}
      </if>
	<if test="cardNos != null and cardNos.size > 0 ">
	   and a.card_no in 
	   <foreach collection="cardNos" item="cardNo" open="(" close=")" separator=",">
	       #{cardNo}
	   </foreach>
	</if>
      <if test="cardTypes != null and cardTypes.size > 0 ">
          and a.card_type in
          <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
              #{cardType}
          </foreach>
      </if>
    <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
      and a.receive_channels in
      <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
          #{receiveChannels}
      </foreach>
    </if>
	GROUP BY
		a.id,a.card_no,a.card_name,card_res, card_type, coupons_type, is_recommend, use_rule, 
	    disc_value, full_cut_value, need_integral, is_superp_use, begin_time, end_time, card_rest_num, 
	    card_num, card_state, card_remarks, a.data_state, a.create_empid, a.create_date, a.modfiy_empid, 
	    a.modfiy_date,a.card_content,a.valid_days, a.receive_channels, a.receive_num,a.org_id
	ORDER BY card_res ASC ,card_type ASC,begin_time ASC
	
  </select>

    <!--查询热门优惠券 langlw 2017-12-28 Query the hot coupon -->
    <select id="queryHotCouponRuleForList" parameterType="com.zteits.clouds.api.dto.pay.param.QueryHotCouponRequest"
            resultType="com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO">
    SELECT
        a.card_no AS cardNo,
        a.card_name AS cardName,
        a.card_type AS cardType,
        a.coupons_type AS couponsType,
        a.use_rule AS useRule,
        a.disc_value AS discValue,
        a.full_cut_value AS fullCutValue,
        a.need_integral AS needIntegral,
        a.is_superp_use AS isSuperpUse,
        a.card_rest_num AS cardRestNum,
        a.card_num AS cardNum,
        a.card_state AS cardState,
        a.begin_time AS beginTime,
        a.end_time AS endTime,
        a.create_date AS createDate,
        a.card_content as cardContent,
        a.valid_days validDays,
        a.receive_channels receiveChannels,
        a.receive_num receiveNum,
        a.org_id orgId
    FROM
        td_c_coupon_rule a
    WHERE
        a.data_state = 1
        <if test="orgId != null">
            and a.org_id = #{orgId}
        </if>
        <if test="cardNos != null and cardNos.size > 0 ">
           and a.card_no in
           <foreach collection="cardNos" item="cardNo" open="(" close=")" separator=",">
               #{cardNo}
           </foreach>
        </if>
        <if test="cardTypes != null and cardTypes.size > 0 ">
            and a.card_type in
            <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
                #{cardType}
            </foreach>
        </if>
        <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
            and a.receive_channels in
            <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
                #{receiveChannels}
            </foreach>
        </if>
    AND a.card_state = 1 /**卡券状态:1、上架;2、下架 **/
    AND a.end_time >= #{queryDate} /***只查询在有效期内的券 **/
    AND #{queryDate} >= a.begin_time /***只查询在有效期内的券 **/
    and a.card_rest_num >0
    ORDER BY round(a.card_rest_num/a.card_num,3) ASC
	limit 3
    </select>


    <!--查询冷门优惠券 langlw 2017-12-28 Query the cold coupon -->
    <select id="queryColdCouponRuleForList" parameterType="com.zteits.clouds.api.dto.pay.param.QueryHotCouponRequest"
            resultType="com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO">
        SELECT
	        a.card_no AS cardNo,
	        a.card_name AS cardName,
	        a.card_type AS cardType,
	        a.coupons_type AS couponsType,
	        a.use_rule AS useRule,
	        a.disc_value AS discValue,
	        a.full_cut_value AS fullCutValue,
	        a.need_integral AS needIntegral,
	        a.is_superp_use AS isSuperpUse,
	        a.card_rest_num AS cardRestNum,
	        a.card_num AS cardNum,
	        a.card_state AS cardState,
	        a.begin_time AS beginTime,
	        a.end_time AS endTime,
	        a.create_date AS createDate,
	        a.card_content as cardContent,
            a.valid_days validDays,
            a.receive_channels receiveChannels,
            a.receive_num receiveNum,
            a.org_id orgId
	    FROM
	        td_c_coupon_rule a
	    WHERE
	        a.data_state = 1
        <if test="orgId != null">
            and a.org_id = #{orgId}
        </if>
	    <if test="cardNos != null and cardNos.size > 0 ">
		   and a.card_no in 
		   <foreach collection="cardNos" item="cardNo" open="(" close=")" separator=",">
		       #{cardNo}
		   </foreach>
		</if>
        <if test="cardTypes != null and cardTypes.size > 0 ">
            and a.card_type in
            <foreach collection="cardTypes" item="cardType" open="(" close=")" separator=",">
                #{cardType}
            </foreach>
        </if>
        <if test="receiveChannelsList != null and receiveChannelsList.size > 0 ">
            and a.receive_channels in
            <foreach collection="receiveChannelsList" item="receiveChannels" open="(" close=")" separator=",">
                #{receiveChannels}
            </foreach>
        </if>
	    AND a.card_state = 1 /**卡券状态:1、上架;2、下架 **/
        AND a.end_time >= #{queryDate} /***只查询在有效期内的券 **/
        AND #{queryDate} >= a.begin_time /***只查询在有效期内的券 **/
	    and a.is_recommend = 1
	    and a.card_rest_num > 0
	    order by a.create_date desc
	    limit 3
    </select>

    <!--根据卡类型查询优惠券详细信息 xiejp 2017-12-27 Query the coupon rule table based on the card type-->
    <select id="queryCouponRuleParkMsg" parameterType="com.zteits.clouds.api.dto.pay.param.TdCCouponRuleRequest"
            resultType="com.zteits.clouds.api.dto.pay.TdCCouponRuleDTO">
          SELECT
	        a.card_no AS cardNo,
	        a.card_name AS cardName,
	        a.card_type AS cardType,
	        a.coupons_type AS couponsType,
	        a.use_rule AS useRule,
	        a.disc_value AS discValue,
	        a.full_cut_value AS fullCutValue,
	        a.need_integral AS needIntegral,
	        a.is_superp_use AS isSuperpUse,
	        a.card_rest_num AS cardRestNum,
	        a.card_num AS cardNum,
	        a.card_state AS cardState,
	        a.begin_time AS beginTime,
	        a.end_time AS endTime,
	        a.create_date AS createDate,
	        a.card_content as cardContent,
	        a.valid_days validDays,
            a.receive_channels receiveChannels,
            a.receive_num receiveNum,
            a.org_id orgId,
		    b.pl_no as plNo
	    FROM
	        td_c_coupon_rule a LEFT JOIN td_c_coupon_rule_park b on a.card_no = b.card_no
	    WHERE  a.card_no = #{cardNo}
    </select>
    
  <select id="selectByCardNo" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from td_c_coupon_rule
    where card_no = #{cardNo,jdbcType=VARCHAR}
  </select>

    <!-- 查询是否存在重复的卡券编码 -->
    <select id="queryCouponRuleByCardNoList" resultMap="BaseResultMap">
        select 	card_no
        from td_c_coupon_rule
        where
        <if test="cardNos != null and cardNos.size > 0 ">
            card_no in
            <foreach collection="cardNos" item="cardNo" open="(" close=")" separator=",">
                #{cardNo}
            </foreach>
        </if>
    </select>


    <!-- 批量插入停车卡券 -->
    <insert id="saveCouponRuleList" parameterType="java.util.List">
        insert into td_c_coupon_rule (card_no, card_name, card_res,
        card_type, coupons_type, is_recommend,
        use_rule, disc_value, full_cut_value,
        need_integral, is_superp_use, begin_time,
        end_time, card_rest_num, card_num,
        card_state, card_remarks, data_state,
        create_empid, create_date, modfiy_empid,
        modfiy_date, card_content, valid_days,
        receive_channels, receive_num, org_id,
        is_uesed, batch_no)
        values
        <foreach collection="tdCCouponRuleList" item="item" index="index" separator=",">
        (#{item.cardNo,jdbcType=VARCHAR}, #{item.cardName,jdbcType=VARCHAR}, #{item.cardRes,jdbcType=INTEGER},
        #{item.cardType,jdbcType=INTEGER}, #{item.couponsType,jdbcType=INTEGER}, #{item.isRecommend,jdbcType=INTEGER},
        #{item.useRule,jdbcType=INTEGER}, #{item.discValue,jdbcType=VARCHAR}, #{item.fullCutValue,jdbcType=INTEGER},
        #{item.needIntegral,jdbcType=INTEGER}, #{item.isSuperpUse,jdbcType=INTEGER}, #{item.beginTime,jdbcType=TIMESTAMP},
        #{item.endTime,jdbcType=TIMESTAMP}, #{item.cardRestNum,jdbcType=INTEGER}, #{item.cardNum,jdbcType=INTEGER},
        #{item.cardState,jdbcType=INTEGER}, #{item.cardRemarks,jdbcType=VARCHAR}, #{item.dataState,jdbcType=INTEGER},
        #{item.createEmpid,jdbcType=VARCHAR}, #{item.createDate,jdbcType=TIMESTAMP}, #{item.modfiyEmpid,jdbcType=VARCHAR},
        #{item.modfiyDate,jdbcType=TIMESTAMP}, #{item.cardContent,jdbcType=VARCHAR}, #{item.validDays,jdbcType=INTEGER},
        #{item.receiveChannels,jdbcType=INTEGER}, #{item.receiveNum,jdbcType=INTEGER}, #{item.orgId,jdbcType=BIGINT},
        #{item.isUesed,jdbcType=INTEGER}, #{item.batchNo,jdbcType=VARCHAR})
        </foreach>
    </insert>
</mapper>