<?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="cn.pluss.platform.mapper.MccReflectMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.MccReflect">
        <id column="id" property="id"/>
        <result column="standard_mcc_code" property="standardMccCode"/>
        <result column="mcc_code" property="mccCode"/>
        <result column="channel_id" property="channelId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <select id="selectPageMccReflectVO" resultType="cn.pluss.platform.vo.MccReflectVO">
        SELECT mr.standard_mcc_code                standardMccCode,
               sxfmcc.F_mcc_txt                    sxfMccDesc,
               GROUP_CONCAT(ryxmcc.mcc)            ryxMcc,
               GROUP_CONCAT(ryxmcc.bankDetailDesc) ryxMccDesc,
               GROUP_CONCAT(ysmcc.mccCode)         ysMcc,
               GROUP_CONCAT(ysmcc.mccDesc)         ysMccDesc
        FROM tb_pluss_mcc_reflect mr
                 LEFT JOIN tb_pluss_sxf_mcc_info sxfmcc ON mr.standard_mcc_code = sxfmcc.F_mcc_code
                 LEFT JOIN (
            SELECT DISTINCT mcc, bankDetailDesc
            FROM tb_pluss_mcc_info_ryx
        ) ryxmcc ON ryxmcc.mcc = mr.mcc_code AND mr.channel_id = 3
                 LEFT JOIN tb_pluss_mcc_info_ys ysmcc ON ysmcc.mccCode = mr.mcc_code AND mr.channel_id = 4
            <if test="ew.mccCode != null and ew.mccCode != ''">
                <where>
                    mr.standard_mcc_code = #{ew.mccCode}
                </where>
            </if>
        GROUP BY mr.standard_mcc_code
        ORDER BY standard_mcc_code
    </select>
</mapper>
