TdCBusinessCouponSMapper.xml 12.7 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.business.mapper.smapper.TdCBusinessCouponSMapper">


    <insert id="batchSaveTdCBusinessCoupon">

        <foreach collection="list" item="item" separator =";">

            insert into td_c_business_coupon
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="item.businessId != null">
                    business_id,
                </if>
                <if test="item.businessName != null">
                    business_name,
                </if>
                <if test="item.cardRuleNo != null">
                    card_rule_no,
                </if>
                <if test="item.cardRuleName != null">
                    card_rule_name,
                </if>
                <if test="item.cardNo != null">
                    card_no,
                </if>
                <if test="item.plNo != null">
                    pl_no,
                </if>
                <if test="item.plName != null">
                    pl_name,
                </if>
                <if test="item.cardType != null">
                    card_type,
                </if>
                <if test="item.couponsType != null">
                    coupons_type,
                </if>
                <if test="item.useRule != null">
                    use_rule,
                </if>
                <if test="item.discValue != null">
                    disc_value,
                </if>
                <if test="item.fullCutValue != null">
                    full_cut_value,
                </if>
                <if test="item.isSuperpUse != null">
                    is_superp_use,
                </if>
                <if test="item.isTLimit != null">
                    is_t_limit,
                </if>
                <if test="item.effDate != null">
                    eff_date,
                </if>
                <if test="item.expDate != null">
                    exp_date,
                </if>
                <if test="item.beginTime != null">
                    begin_time,
                </if>
                <if test="item.endTime != null">
                    end_time,
                </if>
                <if test="item.validH != null">
                    valid_h,
                </if>
                <if test="item.issuedChannels != null">
                    issued_channels,
                </if>
                <if test="item.issued != null">
                    issued,
                </if>
                <if test="item.issuedEffDate != null">
                    issued_eff_date,
                </if>
                <if test="item.issuedExpDate != null">
                    issued_exp_date,
                </if>
                <if test="item.isUesed != null">
                    is_uesed,
                </if>
                <if test="item.carNumber != null">
                    car_number,
                </if>
                <if test="item.orderId != null">
                    order_id,
                </if>
                <if test="item.payOrderId != null">
                    pay_order_id,
                </if>
                <if test="item.cardRemarks != null">
                    card_remarks,
                </if>
                <if test="item.orgId != null">
                    org_id,
                </if>
                <if test="item.dataState != null">
                    data_state,
                </if>
                <if test="item.createEmpid != null">
                    create_empid,
                </if>
                <if test="item.createDate != null">
                    create_date,
                </if>
                <if test="item.modfiyEmpid != null">
                    modfiy_empid,
                </if>
                <if test="item.modfiyDate != null">
                    modfiy_date,
                </if>
                <if test="item.cardRelParkNo != null">
                    card_rel_park_no,
                </if>

            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="item.businessId != null">
                    #{item.businessId,jdbcType=VARCHAR},
                </if>
                <if test="item.businessName != null">
                    #{item.businessName,jdbcType=VARCHAR},
                </if>
                <if test="item.cardRuleNo != null">
                    #{item.cardRuleNo,jdbcType=VARCHAR},
                </if>
                <if test="item.cardRuleName != null">
                    #{item.cardRuleName,jdbcType=VARCHAR},
                </if>
                <if test="item.cardNo != null">
                    #{item.cardNo,jdbcType=VARCHAR},
                </if>
                <if test="item.plNo != null">
                    #{item.plNo,jdbcType=VARCHAR},
                </if>
                <if test="item.plName != null">
                    #{item.plName,jdbcType=VARCHAR},
                </if>
                <if test="item.cardType != null">
                    #{item.cardType,jdbcType=INTEGER},
                </if>
                <if test="item.couponsType != null">
                    #{item.couponsType,jdbcType=INTEGER},
                </if>
                <if test="item.useRule != null">
                    #{item.useRule,jdbcType=INTEGER},
                </if>
                <if test="item.discValue != null">
                    #{item.discValue,jdbcType=VARCHAR},
                </if>
                <if test="item.fullCutValue != null">
                    #{item.fullCutValue,jdbcType=INTEGER},
                </if>
                <if test="item.isSuperpUse != null">
                    #{item.isSuperpUse,jdbcType=INTEGER},
                </if>
                <if test="item.isTLimit != null">
                    #{item.isTLimit,jdbcType=INTEGER},
                </if>
                <if test="item.effDate != null">
                    #{item.effDate,jdbcType=TIME},
                </if>
                <if test="item.expDate != null">
                    #{item.expDate,jdbcType=TIME},
                </if>
                <if test="item.beginTime != null">
                    #{item.beginTime,jdbcType=TIMESTAMP},
                </if>
                <if test="item.endTime != null">
                    #{item.endTime,jdbcType=TIMESTAMP},
                </if>
                <if test="item.validH != null">
                    #{item.validH,jdbcType=INTEGER},
                </if>
                <if test="item.issuedChannels != null">
                    #{item.issuedChannels,jdbcType=INTEGER},
                </if>
                <if test="item.issued != null">
                    #{item.issued,jdbcType=INTEGER},
                </if>
                <if test="item.issuedEffDate != null">
                    #{item.issuedEffDate,jdbcType=TIMESTAMP},
                </if>
                <if test="item.issuedExpDate != null">
                    #{item.issuedExpDate,jdbcType=TIMESTAMP},
                </if>
                <if test="item.isUesed != null">
                    #{item.isUesed,jdbcType=INTEGER},
                </if>
                <if test="item.carNumber != null">
                    #{item.carNumber,jdbcType=VARCHAR},
                </if>
                <if test="item.orderId != null">
                    #{item.orderId,jdbcType=VARCHAR},
                </if>
                <if test="item.payOrderId != null">
                    #{item.payOrderId,jdbcType=VARCHAR},
                </if>
                <if test="item.cardRemarks != null">
                    #{item.cardRemarks,jdbcType=VARCHAR},
                </if>
                <if test="item.orgId != null">
                    #{item.orgId,jdbcType=BIGINT},
                </if>
                <if test="item.dataState != null">
                    #{item.dataState,jdbcType=INTEGER},
                </if>
                <if test="item.createEmpid != null">
                    #{item.createEmpid,jdbcType=VARCHAR},
                </if>
                <if test="item.createDate != null">
                    #{item.createDate,jdbcType=TIMESTAMP},
                </if>
                <if test="item.modfiyEmpid != null">
                    #{item.modfiyEmpid,jdbcType=VARCHAR},
                </if>
                <if test="item.modfiyDate != null">
                    #{item.modfiyDate,jdbcType=TIMESTAMP},
                </if>
                <if test="item.cardRelParkNo != null">
                    #{item.cardRelParkNo,jdbcType=VARCHAR},
                </if>

            </trim>

        </foreach>

    </insert>


    <!-- 批量更新 -->
    <update id="batchUpdateCouponUsedStatus">
        <foreach collection="list" item="item" separator =";">
              update  td_c_business_coupon
              set
                       is_uesed = 1,
                     car_number =  #{item.carNumber,jdbcType=VARCHAR},
                       order_id = #{item.orderId,jdbcType=VARCHAR},
                   pay_order_id =  #{item.payOrderId,jdbcType=VARCHAR}
               where
                        card_no =  #{item.cardNo,jdbcType=VARCHAR}
        </foreach>
    </update>

    <!-- 卡券申领明细总览 -->
    <select id="couponDetailSummary" resultType="java.lang.String">
            select
            sum(b.full_cut_value) as totalFee
            from td_c_business_coupon b
            where b.issued = '1'
            and b.card_type = #{cardType}
            and b.is_uesed = #{isUesed}
            and b.used_date >= #{beginTime}
            and b.used_date &lt; #{endTime}
    </select>

    <!-- 被领取张数 -->
    <select id="getIssuedCount" resultType="java.lang.Integer">
        select count(*)
        from td_c_business_coupon b
        where b.issued = '1'
            and b.card_type = #{cardType}
            and b.is_uesed = #{isUesed}
            and b.used_date >= #{beginTime}
            and b.used_date &lt; #{endTime}
    </select>

    <!-- 被使用张数 -->
    <select id="getUsedCount" resultType="java.lang.Integer">
        select count(*)
        from td_c_business_coupon b
        where b.issued = '1'
            and b.card_type = #{cardType}
            and b.is_uesed = #{isUesed}
            and b.used_date >= #{beginTime}
            and b.used_date &lt; #{endTime}
    </select>

    <!-- 被使用张数 -->
    <select id="getRemainingCount" resultType="java.lang.Integer">
        select count(*)
        from td_c_business_coupon b
        where b.issued = #{issued}
          and b.data_state = #{dataState}
          and b.card_rel_park_no = #{cardRelParkNo}
    </select>

    <select id="queryTdCBusinessCouponSumStaForPage" resultType="com.zteits.clouds.api.dto.business.dto.TdCBusinessCouponSumStaDTO">
        select
               A.businessId,
               A.businessName,
               A.cardRuleNo,
               A.cardRuleName,
               A.plNo,
               A.plName,
               A.buyNum,
               A.surplusNum,
               A.usedNum,
               B.value,
               (B.value * A.buyNum) as totalTotalFee,
               A.payTime
        from (
            select tcbc.business_id as businessId,
                   tcbc.business_name as businessName,
                   tcbc.card_rel_park_no as cardRuleNo,
                   tcbc.card_rule_name as cardRuleName,
                   tcbc.pl_no as plNo,
                   tcbc.pl_name as plName,
                    IFNULL(SUM(CASE WHEN tcbc.is_uesed in(0,1) THEN 1 ELSE 0 END), 0) as  buyNum,
                    IFNULL(SUM(CASE WHEN tcbc.is_uesed = 0 THEN 1 ELSE 0 END), 0) as surplusNum,
                    IFNULL(SUM(CASE WHEN tcbc.is_uesed = 1 THEN 1 ELSE 0 END), 0) as  usedNum,
                   tcbc.create_date as payTime,
                   tcbc.card_rel_park_no
            from td_c_business_coupon as tcbc
            where tcbc.data_state =1
            <if test="startTime !=null">
                AND tcbc.create_date &gt; #{startTime}
            </if>
            <if test="endTime !=null">
                AND tcbc.create_date &lt; #{endTime}
            </if>
            <if test="businessName !=null and businessName !=''">
                AND tcbc.business_name LIKE CONCAT('%',#{businessName},'%')
            </if>
            <if test="cardRuleName !=null and cardRuleName !=''">
                AND tcbc.card_rule_name LIKE CONCAT('%',#{cardRuleName},'%')
            </if>
            <if test="plNo !=null and plNo !=''">
                AND tcbc.pl_no LIKE CONCAT('%',#{plNo},'%')
            </if>
                GROUP BY business_name,card_rule_name,pl_no
        ) A
        left join td_c_business_coupon_rule_park_rel as B
        on A.card_rel_park_no = B.card_rel_park_no
    </select>

</mapper>