<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="查询合同号信息">

	<query id="CoreConReviewInfo.getProInfomation" desc="查询产品信息">
		<![CDATA[
				 SELECT A.ORDER_NO,
				 B.FINAL_USER_DESC,
       NVL(TRIM(B.ORDER_ADD_DESC), '无附加要求') AS ORDER_ADD_DESC,
       B.PSC_DESC,
       B.MSC,
       B.ORDER_QTY || B.ORDER_UNIT AS ORDERQTY,
       b.ORD_ENSU_TOTL_LEN,
       B.LEN_DESC,
       NVL(TRIM(B.ORDER_SPECIAL_DESC),'无技术特殊要求') AS ORDER_SPECIAL_DESC
  FROM SLM_ORDER_HEAD A, SLM_ORDER_LINE B
 WHERE A.ORD_PK = B.ORD_PK
   AND A.ORDER_NO = ?
   AND A.VALIDFLAG = '1'
   AND B.VALIDFLAG = '1'
				 
		]]>
	</query>

	<query id="CoreConReviewInfo.getReviewInfomation" desc="查询评审信息">
		<![CDATA[
			   
	SELECT T.LIST_PK_VAL,
       DECODE(T.LIST_TYP, 'H', '合同号', 'L', '合同行', '交货行') LIST_TYP,
       (CASE
         WHEN T.LIST_TYP = 'H' THEN
          (SELECT C.ORDER_NO
             FROM SLM_ORDER_HEAD C
            WHERE C.ORD_PK = T.LIST_PK_VAL)
         ELSE
          (SELECT C.ORDER_NO || '/' || D.ORDER_SEQ
             FROM SLM_ORDER_LINE D, SLM_ORDER_HEAD C
            WHERE D.ORD_PK = C.ORD_PK
              AND D.ORD_LN_PK = T.LIST_PK_VAL)
       END) AS ORDER_NO,
       DECODE(T.REVIEW_ITM,
              'T',
              '技术',
              'D',
              '交货期',
              'P',
              '价格',
              'F',
              '法务',
              'E',
              '生效') REVIEW_ITM,
       DECODE(T.REVIEW_STATUS,
              'L',
              '封锁',
              'W',
              '待审',
              'D',
              '评审中',
              'S',
              '评审通过',
              'F',
              '评审失败') REVIEW_STATUS,
       T.REVIEW_F_RS,
       T.REVIEW_DEPT,
       T.REVIEW_MAN,
       TO_CHAR(T.REVIEW_EDATE,'YYYY-MM-DD HH24:MI:SS') REVIEW_EDATE, 
       T.REVIEW_TIMES,
       DECODE(T.IS_CURT_REVIEW, '1', '是', '否') IS_CURT_REVIEW,
       T.RT_REVIEW_ITM
  FROM SLM_ORDER_REVIEW_ITEM_LIST T
 WHERE T.REVIEW_NO IN (SELECT B.REVIEW_NO
                         FROM SLM_ORDER_HEAD A, SLM_ORDER_REVIEW B
                        WHERE A.ORD_PK = B.ORD_PK
                          AND A.ORDER_NO = ?
                          AND A.VALIDFLAG = '1'
                          AND B.VALIDFLAG = '1')
 ORDER BY T.REVIEW_EDATE ASC,DECODE(T.REVIEW_ITM,'T','1','D','2','P','3','F','4','5') ASC,T.LIST_PK_VAL ASC
		]]>
	</query>

	<query id="CoreConReviewInfo.getOrdNoByTime" desc="查询合同号">
		<![CDATA[
				SELECT T.ORDER_NO
  FROM SLM_ORDER_HEAD T
 WHERE T.CREATE_TIME BETWEEN TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND T.VALIDFLAG = '1'				 
		]]>
	</query>

	<query id="CoreConReviewInfo.getReviewInfomationNext" desc="查询评审信息">
		<![CDATA[
				SELECT P.LIST_PK_VAL,
       P.LIST_TYP,
       P.ORDER_NO,
       P.REVIEW_STATUS,
       P.REVIEW_F_RS,
       P.REVIEW_DEPT,
       P.REVIEW_MAN,
       P.REVIEW_EDATE,
       P.REVIEW_TIMES,
       P.IS_CURT_REVIEW,
       P.RT_REVIEW_ITM,
       DECODE(P.REVIEW_ITM,
                      'T',
                      '技术',
                      'D',
                      '交货期',
                      'P',
                      '价格',
                      'F',
                      '法务',
                      'E',
                      '生效') REVIEW_ITM
  FROM (SELECT T.LIST_PK_VAL,
               DECODE(T.LIST_TYP, 'H', '合同号', 'L', '合同行', '交货行') LIST_TYP,
               (CASE
                 WHEN T.LIST_TYP = 'H' THEN
                  (SELECT C.ORDER_NO
                     FROM SLM_ORDER_HEAD C
                    WHERE C.ORD_PK = T.LIST_PK_VAL)
                 ELSE
                  (SELECT C.ORDER_NO || '/' || D.ORDER_SEQ
                     FROM SLM_ORDER_LINE D, SLM_ORDER_HEAD C
                    WHERE D.ORD_PK = C.ORD_PK
                      AND D.ORD_LN_PK = T.LIST_PK_VAL)
               END) AS ORDER_NO,
               T.REVIEW_ITM,
               DECODE(T.REVIEW_STATUS,
                      'L',
                      '封锁',
                      'W',
                      '待审',
                      'D',
                      '评审中',
                      'S',
                      '评审通过',
                      'F',
                      '评审失败') REVIEW_STATUS,
               T.REVIEW_F_RS,
               T.REVIEW_DEPT,
               T.REVIEW_MAN,
               TO_CHAR(T.REVIEW_EDATE, 'YYYY-MM-DD HH24:MI:SS') REVIEW_EDATE,
               T.REVIEW_TIMES,
               DECODE(T.IS_CURT_REVIEW, '1', '是', '否') IS_CURT_REVIEW,
               T.RT_REVIEW_ITM
          FROM SLM_ORDER_REVIEW_ITEM_LIST T
         WHERE T.REVIEW_NO IN (SELECT B.REVIEW_NO
                                 FROM SLM_ORDER_HEAD A, SLM_ORDER_REVIEW B
                                WHERE A.ORD_PK = B.ORD_PK
                                  AND A.ORDER_NO = ?
                                  AND A.VALIDFLAG = '1'
                                  AND B.VALIDFLAG = '1')) P
 WHERE P.LIST_TYP = '合同号'
    OR P.LIST_PK_VAL = ?
 ORDER BY P.REVIEW_EDATE ASC,
          DECODE(P.REVIEW_ITM, 'T', '1', 'D', '2', 'P', '3', 'F', '4', '5') ASC,
          P.LIST_PK_VAL ASC
		]]>
	</query>

	<query id="CoreConReviewInfo.getLastQualityDept" desc="查询技术评审最终评审部门">
		<![CDATA[
SELECT (SELECT B.DEPARTNAME
          FROM CORE.CORE_APP_DEPARTMENT B
         WHERE B.DEPARTID = (SELECT B.PID
                               FROM CORE.CORE_APP_DEPARTMENT B
                              WHERE B.DEPARTID = T.UNIT_CODE)) || '-' ||
       T.UNIT_DESC DEPTDESC
  FROM SLM_ORD_DESIGN_STS_TKLG_LST T
 WHERE TO_NUMBER(T.SEQ_INDEX) =
       (SELECT MIN(T.SEQ_INDEX)
          FROM SLM_ORD_DESIGN_STS_TKLG_LST T
         WHERE T.ORD_LN_PK = ?
           AND T.DESIGN_STS = 'F'
           AND T.VALIDFLAG = '1')
   AND T.ORD_LN_PK = ?
   AND T.VALIDFLAG = '1'
UNION ALL
SELECT '生产计划部-计划科'
  FROM DUAL
 WHERE NOT EXISTS (SELECT 1
          FROM SLM_ORD_DESIGN_STS_TKLG_LST T
         WHERE T.ORD_LN_PK = ?
           AND T.VALIDFLAG = '1'
           AND T.DESIGN_STS = 'F')
		]]>
	</query>
</queryMap>