package com.iformall.tenant;

import com.iformall.plugin.TenantInfo;
import com.iformall.shiro.UserSession;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.InvalidSessionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TenantInfoImpl implements TenantInfo {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public String getTenantId() {
        String tenantId = null;
        try {
            tenantId = (String) SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId);
        } catch (InvalidSessionException e) {
            logger.error("InvalidSession: " + e.getMessage());
        }
        return tenantId;
    }

    @Override
    public boolean doTableFilter(String tableName) {
        if ("mall_permission".equals(tableName)) {
            return true;
        }
        if ("mall_sale_type".equals(tableName)) {
            return true;
        }
        if ("mall_user_role".equals(tableName)) {
            return true;
        }
        if ("wx_channel".equals(tableName)) {
            return true;
        }
        if ("wx_business".equals(tableName)) {
            return true;
        }
        if ("wx_sub_business".equals(tableName)) {
            return true;
        }
        if ("wx_coupon_type".equals(tableName)) {
            return true;
        }
        if ("wx_game_template".equals(tableName)) {
            return true;
        }
        if ("wx_group".equals(tableName)) {
            return true;
        }
        if ("wx_mall_apply".equals(tableName)) {
            return true;
        }
        if ("wx_tags".equals(tableName)) {
            return true;
        }
        if ("wx_tags_group".equals(tableName)) {
            return true;
        }
        if ("wx_tags_type".equals(tableName)) {
            return true;
        }
        if ("wx_component_verify_ticket".equals(tableName)) {
            return true;
        }
        if ("wx_authorizer_info".equals(tableName)) {
            return true;
        }
        if ("wx_user_channel".equals(tableName)) {
            return true;
        }
        if ("wx_msg_record".equals(tableName)) {
            return true;
        }
        if ("wx_data_rule_target".equals(tableName)) {
            return true;
        }

        if ("wx_logic_permission".equals(tableName)) {
            return true;
        }
        return false;
    }

    @Override
    public boolean doMappedStatementFIlter(MappedStatement ms) {
        if ("com.iformall.mapper.MallUserInfoMapper.selectByUserName".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.MallUserInfoMapper.cntByUserName".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxCouponActionLogMapper.getCountByUserAndCoupon".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxShopMapper.rentRateHistory".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxLevelConfigMapper.insertBatch".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxLevelConfigMapper.batchUpdate".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillRentMapper.updateBills".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillPropertyMapper.updateBills".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxActivityJoinMapper.updateSendMsg".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxActivityJoinMapper.updateStatus".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxCouponMapper.findCouponList".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxCouponMapper.findCouponListCount".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxCouponMapper.findCouponListCount".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBusinessMapper.businessDataList".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBusinessMapper.devoteList".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillRentMapper.findLatePayBill".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillPropertyMapper.findLatePayBill".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillRentMapper.updateNotPaidStatus".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillPropertyMapper.updateNotPaidStatus".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillRentMapper.autoAddLatePayPrice".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillPropertyMapper.autoAddLatePayPrice".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillRentMapper.insertBillAction".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxBillPropertyMapper.insertBillAction".equals(ms.getId()))
            return true;
        if ("com.iformall.mapper.WxCouponPasswordMapper.updateStatus".equals(ms.getId()))
            return true;

        if ("com.iformall.mapper.WxBillAllMapper.getReceiveAndPayBillAsPage".equals(ms.getId()))
            return true;

        return false;
    }
}
