jk-GitHub-coder před 4 roky
rodič
revize
56987ad99e

+ 136 - 13
YijiaRestful/src/main/java/com/platform/yijia/controller/PayOrderController.java

@@ -39,6 +39,8 @@ public class PayOrderController {
     private  CustomerManagerService customerManagerService;
     @Resource
     private SysDictDataService sysDictDataService;
+    @Resource
+    private LabelService labelService;
 
     //小程序支付生成订单
     @RequestMapping(value = "/AddPayOrderInfoNew", consumes = "application/json", method = RequestMethod.POST)
@@ -82,6 +84,7 @@ public class PayOrderController {
                     payOrderRequest.setUnionId(appUserInfos.getUnionId());                                  //客户UnionId;注:此处存放unionId用于获取客户电子卡参数查询
                     payOrderRequest.setCustomerName(appUserInfos.getBlogNickName());                        //昵称
                     payOrderRequest.setGroupId(stationInfos.getGroupId());                                  //集团ID
+                    payOrderRequest.setLabelFlag(stationInfos.getLabelFlag());                              //油站是否开启标签功能
 
                     payOrder.setConsumer(appUserInfos.getBlogNickName());             //昵称
                     payOrder.setConsumerId(appUserInfos.getUserId());                 //用户id
@@ -229,23 +232,143 @@ public class PayOrderController {
         params.put("cardRuleFlagGroup", payOrderRequest.getCardRuleFlagGroup());
         params.put("cardEnabledFlagGroup", payOrderRequest.getCardEnabledFlagGroup());
 
-        switch (discountSetting){
-            case "0":   //不执营销方案时 计算等级优惠
-                payOrderResultInfo = this.calculateGradeDiscount(params);
-                break;
-            case "1":    //满减方案
-                payOrderResultInfo = this.calculateManJianDiscount(params);
-                break;
-            case "2":    //立减方案
-                payOrderResultInfo = this.calculateLiJianDiscount(params);
-                break;
-            case "3":    //独立直降
-                payOrderResultInfo = this.calculateZhiJiangDiscount(params);
-                break;
+        CustomerLabel customerLabel = new CustomerLabel();
+        customerLabel.setPhone(payOrderRequest.getCustomerPhone());
+        customerLabel.setStationId(payOrderRequest.getStationId());
+        //获取该用户是否在标签组内
+        CustomerLabel customerLabelInfo = labelService.getCustomerLabel(customerLabel);
+        if(payOrderRequest.getLabelFlag().equals("1") && customerLabelInfo !=null){
+            //表示此用户为标签用户,计算标签用户优惠
+            payOrderResultInfo = this.calculateLabelDiscount(params);
+        }else {
+            //不为标签用户时
+            switch (discountSetting){
+                case "0":   //不执营销方案时 计算等级优惠
+                    payOrderResultInfo = this.calculateGradeDiscount(params);
+                    break;
+                case "1":    //满减方案
+                    payOrderResultInfo = this.calculateManJianDiscount(params);
+                    break;
+                case "2":    //立减方案
+                    payOrderResultInfo = this.calculateLiJianDiscount(params);
+                    break;
+                case "3":    //独立直降
+                    payOrderResultInfo = this.calculateZhiJiangDiscount(params);
+                    break;
+            }
         }
         return  payOrderResultInfo;
     }
 
+    //计算标签用户优惠
+    public PayOrderResultInfo calculateLabelDiscount(Map<String ,Object> params){
+        BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString());    //油品价格
+        BigDecimal receivableAmt = new BigDecimal(params.get("receivableAmt").toString());   //应收金额
+        BigDecimal oilLiters = new BigDecimal("0.00");  //加油升数
+        BigDecimal discountAmt = new BigDecimal(0);     //标签方案优惠金额
+        BigDecimal dzkDiscountAmt = new BigDecimal(0);  //电子卡优惠金额
+        BigDecimal amt = new BigDecimal(0);
+        BigDecimal discountPrice = oilPrice;
+
+        //加油升数
+        oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_HALF_UP);
+        if(!oilLiters.toString().substring(oilLiters.toString().indexOf(".") + 1).equals("00")){
+            oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_UP);
+        }
+        PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
+        //获取该油站的标签规则
+        LabelRule labelRule = new LabelRule();
+        labelRule.setStationId(Integer.valueOf(params.get("stationId").toString()));        //油站ID
+        labelRule.setOilName(params.get("oilName").toString());                         //oilName
+        List<LabelRule> labelRuleList = labelService.getLabelRuleList(labelRule);
+        if(labelRuleList !=null && labelRuleList.size()> 0){
+            //获取该油品的优惠明细
+            List<LabelRuleDetail> labelRuleDetailList = labelRuleList.get(0).getLabelRuleDetailList();
+            if(labelRuleDetailList !=null && labelRuleDetailList.size() ==1){
+                BigDecimal discountLitersAmt = new BigDecimal(labelRuleDetailList.get(0).getDiscountLitersAmt());
+                String discountTerm = labelRuleDetailList.get(0).getDiscountTerm();
+                switch (discountTerm){
+                    case "1":   //按加油升数
+                        if(oilLiters.compareTo(discountLitersAmt) ==1 || oilLiters.compareTo(discountLitersAmt) ==0 ){
+                            discountAmt = oilLiters.multiply(new BigDecimal(labelRuleDetailList.get(0).getDiscountAmt()));
+                            discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                        }
+                        break;
+                    case "2":   //按加油金额
+                        if(receivableAmt.compareTo(discountLitersAmt) ==1 || receivableAmt.compareTo(discountLitersAmt) ==0 ){
+                            discountAmt = oilLiters.multiply(new BigDecimal(labelRuleDetailList.get(0).getDiscountAmt()));
+                            discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                        }
+                        break;
+                }
+                dzkDiscountAmt = discountAmt;       //赋值电子卡优惠金额
+            }
+            amt = receivableAmt.subtract(discountAmt);  //应收金额
+            amt =amt.signum() == -1 ? new BigDecimal("0.01"): amt;
+            discountPrice = oilLiters.equals(new BigDecimal("0.00")) ? discountPrice : amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);  //优惠价格
+        }
+        payOrderResultInfo.setAmt(amt.toString());
+        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
+        payOrderResultInfo.setDiscountAmt(discountAmt.toString());
+        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
+        payOrderResultInfo.setOilLiters(oilLiters.toString());
+        payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
+        payOrderResultInfo.setOilPrice(oilPrice.toString());
+        payOrderResultInfo.setDzkAmt(amt.toString());
+        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmt.toString());
+        payOrderResultInfo.setOilsCardFlag("0");
+        if(params.get("cardRuleFlagGroup").toString().equals("1")){
+            //表示开启共享
+            if(params.get("cardEnabledFlagGroup").toString().equals("1")){  //表示开启电子卡功能
+                payOrderResultInfo.setCardEnabledFlag("1");
+            }else {
+                payOrderResultInfo.setCardEnabledFlag("0");
+            }
+        }else {
+            //不共享,则查看油站电子卡是否开启
+            if(params.get("cardEnabledFlag").toString().equals("1")){
+                payOrderResultInfo.setCardEnabledFlag("1");
+            }else {
+                payOrderResultInfo.setCardEnabledFlag("0");
+            }
+        }
+        logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
+        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
+            CustomerCardSetting customerCardSetting = new CustomerCardSetting();
+            customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
+            if(params.get("cardRuleFlagGroup").toString().equals("1")){
+                customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").toString()));
+            }
+            List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
+            if(cardRechargeSettingList !=null && cardRechargeSettingList.size() >0){
+                String isLabel = cardRechargeSettingList.get(0).getIsLabel(); //标签用户支付时是否享受标签优惠
+                if(isLabel.equals("1")){
+                    //电子卡支付金额 = 应收金额 - 标签优惠金额
+                    BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt);
+                    dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;     //如果为负数,则默认设置0.01元
+                    payOrderResultInfo.setDzkAmt(dzkAmt.toString());
+                    BigDecimal dzkDiscountAmtSum = dzkDiscountAmt; //电子卡总优惠金额
+                    payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmtSum.toString());
+                }else {
+                    payOrderResultInfo.setDzkAmt(receivableAmt.toString());
+                    payOrderResultInfo.setDzkDiscountAmt("0");
+                }
+            }
+            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
+            customerElectronicCard.setStationId(Integer.valueOf(params.get("stationId").toString()));
+            customerElectronicCard.setCardOilsType(params.get("cardOilsType").toString());
+            customerElectronicCard.setUnionId(params.get("unionId").toString());
+            customerElectronicCard.setMobilePhone(params.get("userPhone").toString());
+            customerElectronicCard.setCustomerName(params.get("customerName").toString());
+            //查询客户余额和卡的类型
+            Map<String, String> map = this.selectCardBalance(customerElectronicCard, params);
+            payOrderResultInfo.setBalance(map.get("balance"));
+            payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
+            payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
+        }
+        return payOrderResultInfo;
+    }
+
     //计算独立直降
     public PayOrderResultInfo calculateZhiJiangDiscount(Map<String ,Object> params){
         BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString());    //油品价格

+ 16 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/LabelMapper.java

@@ -0,0 +1,16 @@
+package com.platform.yijia.dao;
+
+import com.platform.yijia.pojo.CustomerLabel;
+import com.platform.yijia.pojo.LabelRule;
+
+import java.util.List;
+
+public interface LabelMapper {
+
+    //获取油站标签规则
+    List<LabelRule> getLabelRuleList(LabelRule labelRule);
+
+    //获取油站标签用户列
+    CustomerLabel getCustomerLabel(CustomerLabel customerLabel);
+
+}

+ 1 - 0
YijiaRestful/src/main/java/com/platform/yijia/param/request/PayOrderRequest.java

@@ -52,6 +52,7 @@ public class PayOrderRequest {
     private String integralFlagGroup;       //集团是否开启积分功能
     private String cardRuleFlagGroup;       //集团是否共享电子卡充值规则
     private String cardEnabledFlagGroup;    //集团是否开启电子卡
+    private String labelFlag;               //油站是否开启标签功能
 
 
 

+ 1 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/CustomerCardSetting.java

@@ -23,6 +23,7 @@ public class CustomerCardSetting {
     private Date createTime;
     private String isMarket;            //是否叠加营销方案
     private String isGradeSetting;      //是否叠加等级优惠
+    private String isLabel;             //标签用户电子卡支付时是否可享受标签优惠:0、否;1,是;
     private String delFlag;             //改充值规则是否删除
 
     private String orderBy;         //查询结果排序方式

+ 21 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/CustomerLabel.java

@@ -0,0 +1,21 @@
+package com.platform.yijia.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 标签客户实体类
+ */
+@Data
+public class CustomerLabel {
+    private Integer id;               //表亲客户ID
+    private String phone;             //手机号
+    private String labelId;           //所属标签ID
+    private Integer stationId;        //油站ID
+    private String createBy;          //创建人
+    private Date createTime;          //创建时间
+    private String update_by;         //修改人
+    private Date updateTime;          //修改人
+    private String delFlag;           //删除 1是 0否
+}

+ 25 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/LabelRule.java

@@ -0,0 +1,25 @@
+package com.platform.yijia.pojo;
+
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/***
+ * 标签规则实体类
+ */
+@Data
+public class LabelRule {
+    private Integer id;              //'标签主表id',
+    private String labelName;        //'标签名',
+    private Integer stationId;       //'油站id',
+    private String delFlag;          //'删除标识1 是 0 否',
+    private String createBy;         //'创建人',
+    private Date createTime;         //'创建时间',
+    private String updateBy;         //'修改人',
+    private Date updateTime;         //'修改时间',
+    private List<LabelRuleDetail> labelRuleDetailList;  //规则明细
+
+    //查询参数
+    private String oilName;         //油品名称
+}

+ 24 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/LabelRuleDetail.java

@@ -0,0 +1,24 @@
+package com.platform.yijia.pojo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/***
+ * 标签规则明细
+ */
+@Data
+public class LabelRuleDetail {
+    private  Integer labelRuleDetailId;                    //id
+    private  Integer parentId;              //规则主表主键id
+    private  String oilName;                //`油品
+    private  String discountTerm;           //`优惠条件当为1按金额优惠;2按升数优惠
+    private  String discountLitersAmt;      //规则满足条件(满足多少升,多少元
+    private  String discountAmt;            //优惠金额
+    private  String createBy;               //创建人
+    private Date createTime;                //创建时间
+    private  String updateBy;               //更新人
+    private  Date updateTime;               //更新时间
+    private  String delFlag;                //'删除标识 1是 0 否',
+}

+ 9 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/StationInfo.java

@@ -136,12 +136,21 @@ public class StationInfo {
     private String image3;
     private String image4;
     private String image5;
+    private String labelFlag;               //油站是否开启标签功能
     private String printDeviceType;         //小票打印方式的选择
     private String integralRuleFlagGroup;   //集团积分规则是否共享
     private String integralFlagGroup;       //集团是否开启积分功能
     private String cardRuleFlagGroup;       //集团是否共享电子卡充值规则
     private String cardEnabledFlagGroup;    //集团是否开启电子卡
 
+    public String getLabelFlag() {
+        return labelFlag;
+    }
+
+    public void setLabelFlag(String labelFlag) {
+        this.labelFlag = labelFlag;
+    }
+
     public String getIntegralFlagGroup() {
         return integralFlagGroup;
     }

+ 17 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/LabelService.java

@@ -0,0 +1,17 @@
+package com.platform.yijia.service;
+
+
+import com.platform.yijia.pojo.CustomerLabel;
+import com.platform.yijia.pojo.LabelRule;
+
+import java.util.List;
+
+public interface LabelService {
+
+    //获取油站标签规则
+    List<LabelRule> getLabelRuleList(LabelRule labelRule);
+
+    //获取油站标签用户列
+    CustomerLabel getCustomerLabel(CustomerLabel customerLabel);
+
+}

+ 28 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/LabelServiceImpl.java

@@ -0,0 +1,28 @@
+package com.platform.yijia.service.impl;
+
+import com.platform.yijia.dao.LabelMapper;
+import com.platform.yijia.pojo.CustomerLabel;
+import com.platform.yijia.pojo.LabelRule;
+import com.platform.yijia.service.LabelService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service("labelService")
+public class LabelServiceImpl implements LabelService {
+    @Resource
+    private LabelMapper labelMapper;
+
+    //获取标签优惠规则
+    @Override
+    public List<LabelRule> getLabelRuleList(LabelRule labelRule) {
+        return labelMapper.getLabelRuleList(labelRule);
+    }
+
+    //获取标签用户信息
+    @Override
+    public CustomerLabel getCustomerLabel(CustomerLabel customerLabel) {
+        return labelMapper.getCustomerLabel(customerLabel);
+    }
+}

+ 1 - 1
YijiaRestful/src/main/resources/application.yml

@@ -30,7 +30,7 @@ yijia:
 spring:
     datasource:
 #        url: jdbc:mysql://47.105.116.204:3306/jiaduoduo_db?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&serverTimezone=GMT%2b8&useSSL=true
-        url: jdbc:mysql://115.28.211.17:3306/jiaduoduo_db_demo?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&serverTimezone=GMT%2b8&useSSL=true
+        url: jdbc:mysql://115.28.211.17:3306/jiaduoduo_db_test?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&serverTimezone=GMT%2b8&useSSL=true
         username: develop
         password: 1234.Abcd
         driver-class-name: com.mysql.cj.jdbc.Driver

+ 2 - 0
YijiaRestful/src/main/resources/mapper/ElectronicMembershipCardMapper.xml

@@ -56,6 +56,7 @@
         <result column="create_time"                jdbcType="VARCHAR"    property="createTime" />
         <result column="is_market"                  jdbcType="VARCHAR"    property="isMarket" />
         <result column="is_grade_setting"           jdbcType="VARCHAR"    property="isGradeSetting" />
+        <result column="is_label"                   jdbcType="VARCHAR"    property="isLabel" />
         <collection property="customerCardSettingDetailList" resultMap="CardSettingDetailResultMap"/>
     </resultMap>
 
@@ -86,6 +87,7 @@
             T1.create_time,
             T1.is_market,
             T1.is_grade_setting,
+            T1.is_label,
             T2.id                   AS      cardSettingDetailId,
             T2.parent_id,
             T2.setting_rule_type,

+ 92 - 0
YijiaRestful/src/main/resources/mapper/LabelMapper.xml

@@ -0,0 +1,92 @@
+<?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.platform.yijia.dao.LabelMapper">
+    <!--标签用户返回结果-->
+    <resultMap id="CustomerLabelBaseResultMap" type="com.platform.yijia.pojo.CustomerLabel">
+        <id     column="id"               jdbcType="INTEGER" property="id" />
+        <result column="station_id"       jdbcType="INTEGER" property="stationId" />
+        <result column="phone"            jdbcType="VARCHAR" property="phone" />
+        <result column="label_id"         jdbcType="VARCHAR" property="labelId" />
+        <result column="create_time"      jdbcType="DATE"    property="createTime" />
+        <result column="update_by"        jdbcType="VARCHAR" property="updateBy" />
+        <result column="update_time"      jdbcType="DATE"    property="updateTime" />
+        <result column="del_flag"         jdbcType="VARCHAR" property="delFlag" />
+    </resultMap>
+
+  <!--标签规则返回结果-->
+  <resultMap id="LabelRuleBaseResultMap" type="com.platform.yijia.pojo.LabelRule">
+      <id     column="id"               jdbcType="INTEGER"      property="id" />
+      <result column="station_id"       jdbcType="INTEGER"      property="stationId" />
+      <result column="label_name"       jdbcType="VARCHAR"      property="labelName" />
+      <result column="create_by"        jdbcType="VARCHAR"      property="createBy" />
+      <result column="create_time"      jdbcType="TIMESTAMP"    property="createTime" />
+      <result column="update_by"        jdbcType="VARCHAR"      property="updateBy" />
+      <result column="update_time"      jdbcType="TIMESTAMP"    property="updateTime" />
+      <result column="del_flag"         jdbcType="VARCHAR"      property="delFlag" />
+      <collection property="labelRuleDetailList" resultMap="LabelRuleDetailResultMap"/>
+  </resultMap>
+
+  <!--标签规则明细表-->
+  <resultMap id="LabelRuleDetailResultMap" type="com.platform.yijia.pojo.LabelRuleDetail">
+      <id     column="labelRuleDetailId"      jdbcType="INTEGER"   property="labelRuleDetailId" />
+      <result column="parent_id"              jdbcType="INTEGER"   property="parentId"/>
+      <result column="oil_name"               jdbcType="VARCHAR"   property="oilName" />
+      <result column="discount_term"          jdbcType="VARCHAR"   property="discountTerm" />
+      <result column="discount_liters_amt"    jdbcType="VARCHAR"   property="discountLitersAmt" />
+      <result column="discount_amt"           jdbcType="VARCHAR"   property="discountAmt" />
+      <result column="create_by"              jdbcType="VARCHAR"   property="createBy" />
+      <result column="create_time"            jdbcType="TIMESTAMP" property="createTime" />
+      <result column="update_by"              jdbcType="VARCHAR"   property="updateBy" />
+      <result column="update_time"            jdbcType="TIMESTAMP" property="updateTime" />
+      <result column="del_flag"               jdbcType="VARCHAR"   property="delFlag" />
+  </resultMap>
+
+  <!--查询油站标签规则信息-->
+  <select id="getLabelRuleList" resultMap="LabelRuleBaseResultMap" parameterType="com.platform.yijia.pojo.LabelRule">
+    SELECT
+        T1.id,
+        T1.station_id,
+        T1.label_name,
+        T2.id                           AS      labelRuleDetailId,
+        T2.parent_id,
+        T2.oil_name,
+        T2.discount_term,
+        T2.discount_amt,
+        T2.discount_liters_amt,
+        T2.create_by,
+        T2.create_time
+    FROM
+      label_rule AS T1 LEFT JOIN label_rule_detail AS T2 ON T1.id = T2.parent_id
+    <where>
+            T2.del_flag ="0"
+          <if test="stationId !=null and stationId !=''">
+             AND T1.station_id = #{stationId}
+          </if>
+          <if test="oilName !=null and oilName !=''">
+            AND T2.oil_name = #{oilName}
+          </if>
+    </where>
+  </select>
+
+    <!--查询油站标签用户信息-->
+    <select id="getCustomerLabel" resultMap="CustomerLabelBaseResultMap" parameterType="com.platform.yijia.pojo.CustomerLabel">
+        SELECT
+            id,
+            phone,
+            label_id,
+            station_id,
+            del_flag
+        FROM
+            customer_label
+        <where>
+                del_flag = "0"
+            <if test="stationId !=null and stationId !=''">
+                AND station_id = #{stationId}
+            </if>
+            <if test="phone !=null and phone !=''">
+                AND phone = #{phone}
+            </if>
+        </where>
+    </select>
+
+</mapper>

+ 2 - 0
YijiaRestful/src/main/resources/mapper/StationInfoMapper.xml

@@ -26,6 +26,7 @@
     <result column="discount_setting"     jdbcType="VARCHAR" property="discountSetting" />
     <result column="card_enabled_flag"    jdbcType="VARCHAR" property="cardEnabledFlag" />
     <result column="integral_flag"        jdbcType="VARCHAR" property="integralFlag" />
+    <result column="label_flag"           jdbcType="VARCHAR" property="labelFlag" />
     <result column="integral_print_flag"  jdbcType="VARCHAR" property="integralPrintFlag" />
     <result column="integral_rule_flag"   jdbcType="VARCHAR" property="integralRuleFlag" />
 
@@ -141,6 +142,7 @@
         T1.print_device_type,
         T1.card_enabled_flag,
         T1.integral_flag,
+        T1.label_flag,
         T2.card_enabled_flag    AS card_enabled_flag_group,
         T2.card_rule_flag       AS card_rule_flag_group,
         T2.integral_flag        AS integral_flag_group,