package cn.pluss.platform.mapper;

import cn.pluss.platform.entity.MerchantBaseInfo;
import cn.pluss.platform.entity.MerchantChannelStatus;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TestMapper {

    @Select("SELECT mbi.* FROM tb_pluss_merchant_base_info mbi\n" +
            "LEFT JOIN tb_pluss_account a ON a.userId = mbi.userId\n" +
            "LEFT JOIN tb_pluss_merchant_channel_status mcs ON mbi.merchantCode = mcs.merchantCode AND mcs.channel IN (1, 3)\n" +
            "LEFT JOIN tb_pluss_merchant_channel_status mcs2 ON mbi.merchantCode = mcs2.merchantCode AND mcs2.channel = 4\n" +
            "WHERE  mcs2.id IS NULL AND mbi.district = '云霄县' AND mcs.`status` = 3 AND mbi.merchantType != 1\n" +
            "AND SUBSTR(a.settleType, 1, 2) = '01'")
    List<MerchantBaseInfo> getYXMerchant();

    @Select("SELECT DISTINCT\n" +
            "mbi.*,\n" +
            "b.count\n" +
            "FROM\n" +
            "tb_pluss_merchant_base_info mbi\n" +
            "LEFT JOIN tb_pluss_account a ON a.userId = mbi.userId\n" +
            "LEFT JOIN tb_pluss_id_card ic ON a.userId = ic.userId\n" +
            "LEFT JOIN tb_pluss_risk_blacklist rb ON rb.idcardNo = ic.certNo \n" +
            "LEFT JOIN (SELECT merchantCode,count(merchantCode) AS 'count' FROM tb_pluss_merchant_order  GROUP BY merchantCode HAVING count(merchantCode) > 0) AS b ON mbi.merchantCode = b.merchantCode\n" +
            "LEFT JOIN tb_pluss_merchant_channel_status mcs ON mbi.merchantCode = mcs.merchantCode \n" +
            "AND mcs.channel IN ( 1, 3 )\n" +
            "LEFT JOIN tb_pluss_merchant_channel_status mcs2 ON mbi.merchantCode = mcs2.merchantCode \n" +
            "AND mcs2.channel = 4 \n" +
            "WHERE\n" +
            "mcs2.id IS NULL \n" +
            "AND b.count > 0\n" +
            "AND mbi.district != '云霄县' \n" +
            "AND mcs.`status` = 3 \n" +
            "AND mbi.merchantType != 1 \n" +
            "AND rb.id IS NULL \n" +
            "AND SUBSTR(a.settleType, 1, 2 ) = '01' ORDER BY createDt desc limit 0,50")
    List<MerchantBaseInfo> getYXMerchant1();

    @Select("SELECT mcs.merchantId FROM tb_pluss_merchant_channel_status mcs\n" +
            "LEFT JOIN tb_pluss_sub_merchant sm ON mcs.merchantId = sm.merchantId AND mcs.channel = sm.channelTypeId\n" +
            "WHERE mcs.channel = #{channel} AND mcs.`status` = 3 AND sm.id IS NULL")
    List<String> getNoSubMerchant(@Param("channel") String channel);

    @Select("SELECT mcs.* FROM tb_pluss_merchant_channel_status mcs\n" +
            "LEFT JOIN tb_pluss_sub_merchant_apply_order tpsmao ON mcs.merchantCode = tpsmao.merchantCode AND mcs.channel = tpsmao.applyNo\n" +
            "WHERE mcs.channel = 3 AND mcs.authorizationStatus = '0' AND mcs.extra ->> '$.merInId' IS NOT NULL;")
    List<MerchantChannelStatus> getRyxNoCert();

    @Select("SELECT DISTINCT mcs.merchantCode FROM tb_pluss_merchant_channel_status mcs\n" +
            "LEFT JOIN tb_pluss_sub_merchant sm ON mcs.merchantId = sm.merchantId\n" +
            "WHERE mcs.channel = #{channel} AND sm.id IS NULL AND mcs.`status` IN (3, 7)")
    List<String> getNoSmMerchant(String channel);

    @Select("SELECT mcs.* FROM tb_pluss_merchant_channel_status mcs \n" +
            "LEFT JOIN tb_pluss_merchant_rate_new_record mrnr ON mcs.merchantId = mrnr.merchantId AND mrnr.channel = mcs.channel\n" +
            "LEFT JOIN tb_pluss_merchant_rate_new mrn ON mrn.merchantId = mcs.merchantId AND mrn.channel = mcs.channel\n" +
            "WHERE mcs.channel = 4 AND mcs.`status` = 3 AND mcs.applicationId LIKE '27%'\n" +
            "AND (mrnr.`status` != 1 OR mrnr.`status` IS NULL)")
    List<MerchantChannelStatus> getYsNoRateChangeMerc();
}
