<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "对基础信息实绩操作">
	
	<query id = "ComBaseCountProcesscost.querypai" desc = "获取合同排产量信息">
	<![CDATA[
 SELECT F.*,
       CASE F.PROCESS_CODE 
         WHEN 'A' THEN ROUND((CASE F.HR_CAPCTY WHEN 0 THEN 1 ELSE F.HR_CAPCTY END)/60,3) 
         WHEN 'B' THEN ROUND((CASE F.HR_CAPCTY WHEN 0 THEN 1 ELSE F.HR_CAPCTY END)/60,3)
         ELSE  ROUND(60/(CASE F.HR_CAPCTY WHEN 0 THEN 1 ELSE F.HR_CAPCTY END),3) END XIAOSHI
FROM
(SELECT E.*,CASE E.PROCESS_CODE 
        WHEN 'A' THEN PA.HR_CAPCTY  WHEN 'B' THEN PB.HR_CAPCTY
        WHEN 'C' THEN PC.HR_CAPCTY  WHEN 'D' THEN PD.HR_CAPCTY
        WHEN 'E' THEN PE.HR_CAPCTY  WHEN 'F' THEN PF.HR_CAPCTY
        WHEN 'G' THEN PG.HR_CAPCTY  WHEN 'H' THEN PH.HR_CAPCTY ELSE NULL  END AS HR_CAPCTY
FROM
(SELECT PLINE.PROCESS_CODE,PLINE.PROCESS_DESC, D.*
FROM
(SELECT T.*,
       (SELECT C.WEIGTH_S * C.PRICE + C.MWIGHT
          FROM (SELECT B.*,
                       (SELECT NVL(MAX(A.COST_PRICE), 0)
                          FROM COST_BASE_PROCESSCOST_C A
                         WHERE A.VALIDFLAG = '1'
                           AND B.PLINE_CODE = A.PLINE_CODE
                           AND B.WEIGTH_S BETWEEN A.SCHEDULE_MIN AND
                               A.SCHEDULE_MAX) PRICE,
                       (SELECT NVL(MAX(#F#), 0)
                          FROM COST_BASE_PROCESSCOST CBPT
                         WHERE CBPT.PLINE_CODE = B.PLINE_CODE
                           AND CBPT.YEAR = {1}) MWIGHT
                  FROM (SELECT ZJ.PLINE_CODE,
                               NVL(SUM(ZJ.WEIGTH_S), 0) WEIGTH_S
                          FROM PLN_ORDER_ZG_S ZJ
                         WHERE ZJ.PRO_MONTH = {0}
                         GROUP BY ZJ.PLINE_CODE, ZJ.PRO_MONTH
                         ORDER BY PLINE_CODE) B) C
         WHERE C.PLINE_CODE = T.PLINE_CODE) PRICE
  FROM (SELECT ZG.PLINE_CODE,
               ZG.PLINE_NAME,
               ZG.INWL_ID,
               ZG.INWL_DESC,
               ZG.OUTWL_ID,
               ZG.OUTWL_DESC,
               ZG.PRO_MONTH,
               ZG.ORDER_NO || '/' || ZG.ORDER_SEQ AS ORDER_NO,
               ZG.WEIGTH_S
          FROM PLN_ORDER_ZG_S ZG
         WHERE ZG.PRO_MONTH = {0}) T
UNION ALL
SELECT T.*,
       (SELECT C.WEIGTH_S * C.PRICE + C.MWIGHT
          FROM (SELECT B.*,
                       (SELECT NVL(MAX(A.COST_PRICE), 0)
                          FROM COST_BASE_PROCESSCOST_C A
                         WHERE A.VALIDFLAG = '1'
                           AND B.PLINE_CODE = A.PLINE_CODE
                           AND B.WEIGTH_S BETWEEN A.SCHEDULE_MIN AND
                               A.SCHEDULE_MAX) PRICE,
                       (SELECT NVL(MAX(#F#), 0)
                          FROM COST_BASE_PROCESSCOST CBPT
                         WHERE CBPT.PLINE_CODE = B.PLINE_CODE
                           AND CBPT.YEAR = {1}) MWIGHT
                  FROM (SELECT ZJ.PLINE_CODE,
                               NVL(SUM(ZJ.WEIGTH_S), 0) WEIGTH_S
                          FROM PLN_ORDER_JGX_S ZJ
                         WHERE ZJ.PRO_MONTH = {0}
                         GROUP BY ZJ.PLINE_CODE, ZJ.PRO_MONTH
                         ORDER BY PLINE_CODE) B) C
         WHERE C.PLINE_CODE = T.PLINE_CODE) PRICE
  FROM (SELECT ZG.PLINE_CODE,
               ZG.PLINE_NAME,
               ZG.INWL_ID,
               ZG.INWL_DESC,
               ZG.OUTWL_ID,
               ZG.OUTWL_DESC,
               ZG.PRO_MONTH,
               ZG.ORDER_NO || '/' || ZG.ORDER_SEQ AS ORDER_NO,
               ZG.WEIGTH_S
          FROM PLN_ORDER_JGX_S ZG
         WHERE ZG.PRO_MONTH = {0}) T
UNION ALL
SELECT T.*,
       (SELECT C.WEIGTH_S * C.PRICE + C.MWIGHT
          FROM (SELECT B.*,
                       (SELECT NVL(MAX(A.COST_PRICE), 0)
                          FROM COST_BASE_PROCESSCOST_C A
                         WHERE A.VALIDFLAG = '1'
                           AND B.PLINE_CODE = A.PLINE_CODE
                           AND B.WEIGTH_S BETWEEN A.SCHEDULE_MIN AND
                               A.SCHEDULE_MAX) PRICE,
                       (SELECT NVL(MAX(#F#), 0)
                          FROM COST_BASE_PROCESSCOST CBPT
                         WHERE CBPT.PLINE_CODE = B.PLINE_CODE
                           AND CBPT.YEAR = {1}) MWIGHT
                  FROM (SELECT ZJ.PLINE_CODE,
                               NVL(SUM(ZJ.WEIGTH_S), 0) WEIGTH_S
                          FROM PLN_ORDER_RCL_S ZJ
                         WHERE ZJ.PRO_MONTH = {0}
                         GROUP BY ZJ.PLINE_CODE, ZJ.PRO_MONTH
                         ORDER BY PLINE_CODE) B) C
         WHERE C.PLINE_CODE = T.PLINE_CODE) PRICE
  FROM (SELECT ZG.PLINE_CODE,
               ZG.PLINE_NAME,
               ZG.INWL_ID,
               ZG.INWL_DESC,
               ZG.OUTWL_ID,
               ZG.OUTWL_DESC,
               ZG.PRO_MONTH,
               ZG.ORDER_NO || '/' || ZG.ORDER_SEQ AS ORDER_NO,
               ZG.WEIGTH_S
          FROM PLN_ORDER_RCL_S ZG
         WHERE ZG.PRO_MONTH = {0}) T
UNION ALL
SELECT T.*,
       (SELECT C.WEIGTH_S * C.PRICE + C.MWIGHT
          FROM (SELECT B.*,
                       (SELECT NVL(MAX(A.COST_PRICE), 0)
                          FROM COST_BASE_PROCESSCOST_C A
                         WHERE A.VALIDFLAG = '1'
                           AND B.PLINE_CODE = A.PLINE_CODE
                           AND B.WEIGTH_S BETWEEN A.SCHEDULE_MIN AND
                               A.SCHEDULE_MAX) PRICE,
                       (SELECT NVL(MAX(#F#), 0)
                          FROM COST_BASE_PROCESSCOST CBPT
                         WHERE CBPT.PLINE_CODE = B.PLINE_CODE
                           AND CBPT.YEAR = {1}) MWIGHT
                  FROM (SELECT ZJ.PLINE_CODE,
                               NVL(SUM(ZJ.WEIGTH_S), 0) WEIGTH_S
                          FROM PLN_ORDER_DBK_S ZJ
                         WHERE ZJ.PRO_MONTH = {0}
                         GROUP BY ZJ.PLINE_CODE, ZJ.PRO_MONTH
                         ORDER BY PLINE_CODE) B) C
         WHERE C.PLINE_CODE = T.PLINE_CODE) PRICE
  FROM (SELECT ZG.PLINE_CODE,
               ZG.PLINE_NAME,
               ZG.INWL_ID,
               ZG.INWL_DESC,
               ZG.OUTWL_ID,
               ZG.OUTWL_DESC,
               ZG.PRO_MONTH,
               ZG.ORDER_NO || '/' || ZG.ORDER_SEQ AS ORDER_NO,
               ZG.WEIGTH_S
          FROM PLN_ORDER_DBK_S ZG
         WHERE ZG.PRO_MONTH = {0}) T ) D
LEFT JOIN COM_BASE_PLINE PLINE ON D.PLINE_CODE =PLINE.PLINE_CODE AND PLINE.VALIDFLAG='1'   ) E 
     LEFT JOIN SLM_BASE_MATERIAL_A_PL PA ON E.PLINE_CODE =PA.PLINE_CODE AND E.INWL_ID = PA.IN_MATERIAL_NO AND E.OUTWL_ID=PA.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_B_PL PB ON E.PLINE_CODE =PB.PLINE_CODE AND E.INWL_ID = PB.IN_MATERIAL_NO AND E.OUTWL_ID=PB.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_C_PL PC ON E.PLINE_CODE =PC.PLINE_CODE AND E.INWL_ID = PC.IN_MATERIAL_NO AND E.OUTWL_ID=PC.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_D_PL PD ON E.PLINE_CODE =PD.PLINE_CODE AND E.INWL_ID = PD.IN_MATERIAL_NO AND E.OUTWL_ID=PD.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_E_PL PE ON E.PLINE_CODE =PE.PLINE_CODE AND E.INWL_ID = PE.IN_MATERIAL_NO AND E.OUTWL_ID=PE.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_F_PL PF ON E.PLINE_CODE =PF.PLINE_CODE AND E.INWL_ID = PF.IN_MATERIAL_NO AND E.OUTWL_ID=PF.OUT_MATERIAL_NO
    LEFT JOIN SLM_BASE_MATERIAL_K_PL PG ON E.PLINE_CODE =PG.PLINE_CODE AND E.INWL_ID = PG.IN_MATERIAL_NO AND E.OUTWL_ID=PG.OUT_MATERIAL_NO 
    LEFT JOIN SLM_BASE_MATERIAL_H_PL PH ON E.PLINE_CODE =PH.PLINE_CODE AND E.INWL_ID = PH.IN_MATERIAL_NO AND E.OUTWL_ID=PH.OUT_MATERIAL_NO ) F

	]]>
	</query>
	<query id = "ComBaseCountProcesscost.queryMonthone" desc = "获取断面信息">
	<![CDATA[
SELECT *
FROM COST_BASE_PROCESSCOST T 
WHERE T.VALIDFLAG='1'
	]]>
	</query>
	
	<query id = "ComBaseCountProcesscost.queryzonge" desc = "获取断面信息">
	<![CDATA[
SELECT #F# 
FROM COST_BASE_PROCESSCOST T 
WHERE T.PLINE_CODE= {0} AND T.YEAR ={1}
	]]>
	</query>
	
</queryMap>