<?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="org.springblade.imports.mapper.VRecentVippoolCostsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.springblade.imports.entity.VRecentVippoolCosts">
        <result column="VIPPOOL" property="vippool" />
        <result column="CP" property="cp" />
        <result column="PTYPE" property="ptype" />
        <result column="QYTYPE" property="qytype" />
        <result column="ID_CP" property="idCp" />
        <result column="NUMS" property="nums" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        VIPPOOL, CP, PTYPE, QYTYPE, ID_CP, NUMS
    </sql>

    <select id="supplierList" resultType="java.lang.String">
        SELECT
            CP
        FROM
            ( SELECT CP, sum( nums ) nums FROM V_RECENT_VIPPOOL_COSTS GROUP BY CP )
        ORDER BY
            nums DESC
    </select>

    <select id="ptypeList" resultType="java.lang.String">
        SELECT
            PTYPE
        FROM
            ( SELECT PTYPE, sum( nums ) nums FROM V_RECENT_VIPPOOL_COSTS WHERE CP = #{supplier} GROUP BY PTYPE )
        ORDER BY
            nums DESC
    </select>

    <select id="contractIdList" resultType="java.lang.String">
        SELECT
            CONTRACT_NO
        FROM
            DIM_VIPPOOL_CONTRACT_NO
        WHERE
            CP = #{supplier}
        ORDER BY
            nums DESC
    </select>

    <select id="qytypeList" resultType="java.lang.String">
        SELECT
            QYTYPE
        FROM
            ( SELECT QYTYPE, sum( nums ) nums FROM V_RECENT_VIPPOOL_COSTS WHERE CP = #{supplier} AND PTYPE = #{ptype} GROUP BY QYTYPE )
        ORDER BY
            nums DESC
    </select>


    <select id="cpIdList" resultType="java.lang.String">
        SELECT
            ID_CP
        FROM
            (
            SELECT
                ID_CP,
                sum( nums ) nums
            FROM
                V_RECENT_VIPPOOL_COSTS
            WHERE
                CP = #{supplier}
                AND PTYPE = #{ptype}
                AND QYTYPE = #{qytype}
                AND ID_CP IS NOT NULL
            GROUP BY
                ID_CP
            )
        ORDER BY
            nums DESC
    </select>

</mapper>
