<?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.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizPvPointProcessVariableClassificationMapper">
    <select id="gateWayIdListPv" resultType="java.lang.String">
        select GATEWAY_ID from idx_biz_pv_point_process_variable_classification group by GATEWAY_ID;
    </select>

    <select id="getInfluxDBData" resultType="com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizPvPointProcessVariableClassificationDto">
        SELECT
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
            ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
            ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
            ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
            (
                SELECT
                    *
                FROM
                    idx_biz_pv_point_process_variable_classification uxfv
                WHERE
                        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT1_ID FROM idx_biz_pv_point_var_central_value WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
            ) AS b,
            idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
            b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT1_ID
        GROUP BY
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID,
            ibfpvcv.PROCESS_POINT2_ID,
            ibfpvcv.PROCESS_POINT3_ID,
            ibfpvcv.ANALYSIS_POINT_ID UNION ALL
        SELECT
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
            ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
            ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
            ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
            (
                SELECT
                    *
                FROM
                    idx_biz_pv_point_process_variable_classification uxfv
                WHERE
                        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT2_ID FROM idx_biz_pv_point_var_central_value WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
            ) AS b,
            idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
            b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT2_ID
        GROUP BY
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID,
            ibfpvcv.PROCESS_POINT2_ID,
            ibfpvcv.PROCESS_POINT3_ID,
            ibfpvcv.ANALYSIS_POINT_ID UNION ALL
        SELECT
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
            ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
            ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
            ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
            (
                SELECT
                    *
                FROM
                    idx_biz_pv_point_process_variable_classification uxfv
                WHERE
                        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT3_ID FROM idx_biz_pv_point_var_central_value WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
            ) AS b,
            idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
            b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT3_ID
        GROUP BY
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID,
            ibfpvcv.PROCESS_POINT2_ID,
            ibfpvcv.PROCESS_POINT3_ID,
            ibfpvcv.ANALYSIS_POINT_ID UNION ALL
        SELECT
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
            ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
            ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
            ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
            (
                SELECT
                    *
                FROM
                    idx_biz_pv_point_process_variable_classification uxfv
                WHERE
                        uxfv.SEQUENCE_NBR IN ( SELECT ANALYSIS_POINT_ID FROM idx_biz_pv_point_var_central_value WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
            ) AS b,
            idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
            b.SEQUENCE_NBR = ibfpvcv.ANALYSIS_POINT_ID
        GROUP BY
            b.SEQUENCE_NBR,
            b.INDEX_ADDRESS,
            b.GATEWAY_ID,
            ibfpvcv.PROCESS_POINT1_ID,
            ibfpvcv.PROCESS_POINT2_ID,
            ibfpvcv.PROCESS_POINT3_ID,
            ibfpvcv.ANALYSIS_POINT_ID
    </select>
    <select id="getInfluxDBDataByGatewayId" resultType="com.yeejoin.amos.boot.module.jxiop.biz.dto.IdxBizPvPointProcessVariableClassificationDto">
        SELECT
        b.*,
        ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
        ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
        ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
        ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
        (
        SELECT
        *
        FROM
        idx_biz_pv_point_process_variable_classification uxfv
        WHERE
        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT1_ID FROM `idx_biz_pv_point_var_central_value` WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
        ) AS b,
        idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
        b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT1_ID
        GROUP BY
        b.SEQUENCE_NBR UNION ALL
        SELECT
        b.*,
        ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
        ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
        ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
        ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
        (
        SELECT
        *
        FROM
        idx_biz_pv_point_process_variable_classification uxfv
        WHERE
        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT2_ID FROM `idx_biz_pv_point_var_central_value` WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
        ) AS b,
        idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
        b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT2_ID
        GROUP BY
        b.SEQUENCE_NBR UNION ALL
        SELECT
        b.*,
        ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
        ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
        ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
        ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
        (
        SELECT
        *
        FROM
        idx_biz_pv_point_process_variable_classification uxfv
        WHERE
        uxfv.SEQUENCE_NBR IN ( SELECT PROCESS_POINT3_ID FROM `idx_biz_pv_point_var_central_value` WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
        ) AS b,
        idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
        b.SEQUENCE_NBR = ibfpvcv.PROCESS_POINT3_ID

        GROUP BY
        b.SEQUENCE_NBR UNION ALL
        SELECT
        b.*,
        ibfpvcv.PROCESS_POINT1_ID AS pointOneId,
        ibfpvcv.PROCESS_POINT2_ID AS pointTwoId,
        ibfpvcv.PROCESS_POINT3_ID AS pointThreeId,
        ibfpvcv.ANALYSIS_POINT_ID AS pointId
        FROM
        (
        SELECT
        *
        FROM
        idx_biz_pv_point_process_variable_classification uxfv
        WHERE
        uxfv.SEQUENCE_NBR IN ( SELECT ANALYSIS_POINT_ID FROM `idx_biz_pv_point_var_central_value` WHERE ANALYSIS_POINT_ID IS NOT NULL GROUP BY ANALYSIS_POINT_ID, PROCESS_POINT1_ID, PROCESS_POINT3_ID, PROCESS_POINT2_ID )
        ) AS b,
        idx_biz_pv_point_var_central_value ibfpvcv
        WHERE
        b.SEQUENCE_NBR = ibfpvcv.ANALYSIS_POINT_ID
        and b.GATEWAY_ID = #{gatewayId}
        GROUP BY
        b.SEQUENCE_NBR
    </select>

</mapper>
