<?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.interplug.qcast.biz.pwrGnrSimulation.PwrGnrSimMapper">

    <select id="selectPlanInfo" parameterType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRequest"
            resultType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimPlanResponse">
        /* sqlid : com.interplug.qcast.api.pwrGnrSimulation.selectPlanInfo (견적서 정보 조회) */
        SELECT
            A.OBJECT_NO /* 물건번호 */
            , A.PLAN_NO /* 물건번호 */
            , A.DRAWING_ESTIMATE_CREATE_DATE/* 작성일 */
            , A.CAPACITY /* 시스템 용량 */
            , A.SNOWFALL/* 적설조건 */
            , A.STANDARD_WIND_SPEED_ID /* 풍속조건 */
            , B.PREF_ID  /* 도도부현 */
            , (SELECT PREF_NAME FROM M_PREFECTURE WHERE PREF_ID = B.PREF_ID ) AS PREF_NAME
            , B.AREA_ID  /* 일사량 관측지점 */
            , (SELECT AREA_NAME FROM M_PREFECTURE_AREA WHERE AREA_ID = B.AREA_ID ) AS AREA_NAME
        FROM T_PLAN A
        INNER JOIN T_OBJECT B
            ON A.OBJECT_NO = B.OBJECT_NO
        WHERE B.AREA_ID IS NOT NULL
        AND A.DRAWING_ESTIMATE_CREATE_DATE IS NOT NULL
        AND A.OBJECT_NO = #{objectNo}
        AND A.PLAN_NO = #{planNo}
    </select>

    <select id="selectRoofModuleList" parameterType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRequest"
            resultType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRoofResponse">
        /* sqlid : com.interplug.qcast.api.pwrGnrSimulation.selectRoofModuleList (견적서 지붕재/모듈 정보 조회) */
        SELECT
            A.ROOF_NO
             , A.ROOF_SURFACE
             , A.SLOPE
             , A.AZIMUTH
             , A.ANGLE
             , B.ITEM_ID
             , B.AMOUNT
             , C.ITEM_NO
             , ((B.AMOUNT * C.PNOW_W) / 1000) AS SPECIFICATION /* 용량 */
        FROM  T_ROOF_ESTIMATE A
        INNER JOIN T_ROOF_ITEM_ESTIMATE B
            ON A.OBJECT_NO = B.OBJECT_NO
            AND A.PLAN_NO = B.PLAN_NO
            AND A.ROOF_NO = B.ROOF_NO
        INNER JOIN M_ITEM C
            ON B.ITEM_ID = C.ITEM_ID
        WHERE A.OBJECT_NO = #{objectNo}
          AND A.PLAN_NO = #{planNo}
    </select>

    <select id="selectRoofPcsList" parameterType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRequest"
            resultType="com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRoofResponse">
        /* sqlid : com.interplug.qcast.api.pwrGnrSimulation.selectRoofPcsList (견적서 지붕재/모듈 정보 조회) */
        SELECT
            A.AMOUNT  /* 매수X */
            , A.ITEM_ID
            , A.ITEM_NO
        FROM T_PART_ESTIMATE A
        INNER JOIN M_ITEM B
            ON A.ITEM_ID = B.ITEM_ID
        WHERE ITEM_GROUP  ='PC_'
          AND A.OBJECT_NO = #{objectNo}
          AND A.PLAN_NO = #{planNo}
    </select>

</mapper>