<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="标准管理">
	<query id="CoreStandard.query" desc="标准基础  查询">
		<![CDATA[
			SELECT   
		           S.STD_CODE,
                   S.STD_NAME,
                   S.STD_CODE STD_CODE_OLD,
                   S.STD_NAME STD_NAME_OLD,
                   S.STDSTYLE,
                   S.STD_NOTE,
                   S.STD_STYLE,
                   S.STD_STYLE_NAME,
                   S.STD_VERSION,
                   S.PROCESS_CODE,
                   S.PROCESS_DESC,
                   S.DEPARTMENT_CODE,
                   S.DEPARTMENT_DESC,
                   S.UNIT_CODE,
                   S.UNIT_DESC,
                   S.CREATE_NAME,
                   TO_CHAR(S.CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss') CREATE_TIME,
                   S.UPDATE_NAME,
                   TO_CHAR(S.UPDATE_TIME, 'yyyy-mm-dd hh24:mi:ss') UPDATE_TIME,
                   S.DELETE_NAME,
                   TO_CHAR(S.DELETE_TIME, 'yyyy-mm-dd hh24:mi:ss') DELETE_TIME,
                   DECODE(S.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                   S.MEMO,
                   DECODE(S.ACCEPT_BID, '1', 'True', '0', 'False') ACCEPT_BID,
                   DECODE(S.PURCHASE_STD, '1', 'True', '0', 'False') PURCHASE_STD
              FROM COM_BASE_STD S
             WHERE LOWER(S.STD_NAME) || '&' LIKE '%' || LOWER(?) || '%'
               AND S.VALIDFLAG IN ('1', ?)
               AND S.STDSTYLE IN (DECODE(?, '2', 'N', '3', 'K', 'P'),
                   DECODE(?, '2', '', '3', '', 'S'))
               AND DECODE(?, NULL, 1, INSTR(S.PROCESS_CODE, ?)) > 0
          ORDER BY S.STD_CODE		
		]]>
	</query>
		
	 
	<query id="CoreStandard.add" desc="标准基础 新增">
		<![CDATA[
			INSERT INTO COM_BASE_STD
                        (STD_CODE,
                         STD_NAME,
                         STDSTYLE,
                         STD_NOTE,
                         STD_STYLE,
                         STD_STYLE_NAME,
                         STD_VERSION,
                         PROCESS_CODE,
                         PROCESS_DESC,
                         DEPARTMENT_CODE,
                         DEPARTMENT_DESC,
                         UNIT_CODE,
                         UNIT_DESC,
                         CREATE_NAME,
                         CREATE_TIME,
                         VALIDFLAG,
                         MEMO,
                         ACCEPT_BID,
                         PURCHASE_STD)
                 VALUES
                 ((SELECT 'STD' || LPAD(TO_CHAR(TO_NUMBER(SUBSTR(NVL(MAX(STD_CODE), 'STD0000000'), 4, 7)) + 1),7,'0') AS STD_CODE FROM COM_BASE_STD),
                  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE, DEFAULT, ?, ?, ?)
		]]>
	</query>
	
	<query id="CoreStandard.update" desc="标准基础 修改">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET STD_CODE        = ?,
                   STD_NAME        = ?,
                   STDSTYLE        = ?,
                   STD_NOTE        = ?,
                   STD_STYLE       = ?,
                   STD_STYLE_NAME  = ?,
                   STD_VERSION     = ?,
                   PROCESS_CODE    = ?,
                   PROCESS_DESC    = ?,
                   DEPARTMENT_CODE = ?,
                   DEPARTMENT_DESC = ?,
                   UNIT_CODE       = ?,
                   UNIT_DESC       = ?,
                   UPDATE_NAME     = ?,
                   UPDATE_TIME     = SYSDATE,
                   MEMO            = ?,
                   ACCEPT_BID = ?,
                   PURCHASE_STD = ?
            WHERE STD_CODE = ?			
		]]>
	</query>
	
	<query id="CoreStandard.delete" desc="标准基础 作废">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE STD_CODE = ?
		]]>
	</query>
	
	<query id="CoreStandard.resume" desc="标准基础 恢复">
		<![CDATA[
			UPDATE COM_BASE_STD
               SET DELETE_NAME = ?, DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE STD_CODE = ?
		]]>
    </query>
    
   <query id="CoreStandard.GETPSCUPDATE" desc="标准基础 恢复">
		<![CDATA[
			SELECT 1 FROM COM_PSC
			WHERE STD_CODE = ?
		]]>
    </query>
    
     <query id="CoreStandard.queryCust" desc="最终客户 查詢">
		<![CDATA[
			SELECT C.STD_CODE,
                   C.STD_NAME,
                   C.CUST_CODE,
                   C.CUST_NAME,
                   C.CREATE_NAME,
                   TO_CHAR(C.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                   C.UPDATE_NAME,
                   TO_CHAR(C.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                   C.DELETE_NAME,
                   TO_CHAR(C.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                   DECODE(C.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                   C.MEMO,
                   C.CUST_CODE AS OLD_CUST_CODE
              FROM COM_BASE_STD_R_CUST C
             WHERE C.STD_CODE = ?
               AND C.VALIDFLAG IN ('1', ?)
		]]>
	</query>
    
    <query id="CoreStandard.addCust" desc="最终客户 增加">
		<![CDATA[
			INSERT INTO COM_BASE_STD_R_CUST
                        (STD_CODE,
                         STD_NAME,
                         CUST_CODE,
                         CUST_NAME,
                         CREATE_NAME,
                         CREATE_TIME,
                         VALIDFLAG,
                         MEMO)
               VALUES(?,?,?, ?,?,SYSDATE,DEFAULT,?)
		]]>
	</query>
	
	<query id="CoreStandard.updateCust" desc="最终客户 修改">
		<![CDATA[
			UPDATE COM_BASE_STD_R_CUST
               SET STD_CODE    = ?,
                   STD_NAME    = ?,
                   CUST_CODE   = ?,
                   CUST_NAME   = ?,
                   UPDATE_NAME = ?,
                   UPDATE_TIME = SYSDATE,
                   MEMO        = ?
                WHERE STD_CODE = ?
                 AND CUST_CODE = ?
		]]>
	</query>
	
	<query id="CoreStandard.UpdatedeleteCust" desc="最终客户 修改">
		<![CDATA[
			DELETE COM_BASE_STD_R_CUST
               
                WHERE STD_CODE = ?
                 AND CUST_CODE = ?
		]]>
	</query>
	
	<query id="CoreStandard.DeleteCust1" desc="最终客户 修改">
		<![CDATA[
			DELETE COM_BASE_STD_R_CUST
 
            WHERE STD_CODE = ?
                 
		]]>
	</query>
	
	<query id="CoreStandard.deleteCust" desc="最终客户 作废">
		<![CDATA[
			UPDATE COM_BASE_STD_R_CUST
               SET DELETE_NAME = ?, DELETE_TIME = SYSDATE, VALIDFLAG = '0'
             WHERE STD_CODE = ?
               AND CUST_CODE = ? AND VALIDFLAG='1'
		]]>
	</query>
	
	<query id="CoreStandard.resumeCust" desc="最终客户 恢复">
		<![CDATA[
			UPDATE COM_BASE_STD_R_CUST
               SET DELETE_NAME = ?, DELETE_TIME = NULL, VALIDFLAG = '1'
             WHERE STD_CODE = ?
               AND CUST_CODE = ? AND VALIDFLAG='0'
		]]>
	</query>
	
	<query id="CoreStandard.checkCust" desc="最终客户 检查重复">
		<![CDATA[
			SELECT 1
              FROM COM_BASE_STD_R_CUST C
             WHERE C.STD_CODE = ?
               AND C.CUST_CODE = ?
		]]>
	</query>
	
	<query id="CoreStandard.checkStdName" desc="验证标准名称">
        <![CDATA[          
             SELECT SUM(CNT) FROM 
             (SELECT   COUNT(1) CNT
             FROM COM_MSC_STD_CIC
             WHERE STD_CODE_NK=?  AND VALIDFLAG='1'            
             UNION ALL
             SELECT   COUNT(1) CNT
             FROM COM_MSC_STD_PIC  
             WHERE  STD_CODE_NK=?  AND VALIDFLAG='1'
             UNION ALL
             SELECT   COUNT(1)
             FROM COM_MSC_STD_SPEC
             WHERE  STD_CODE=?  AND VALIDFLAG='1'
             UNION ALL
             SELECT   COUNT(1)
             FROM COM_MSC_STD_DETECTION
             WHERE  STD_CODE_NK=?  AND VALIDFLAG='1'
             UNION ALL
             SELECT   COUNT(1)
             FROM COM_MSC_STD_WATER
             WHERE  STD_CODE_NK=?  AND VALIDFLAG='1'
             UNION ALL
             SELECT COUNT(1)
             FROM COM_BASE_STD_R_CUST
             WHERE STD_CODE=? AND VALIDFLAG='1'
             ) T
	     ]]>
	  </query>
	  
	  <query id="CoreStandard.getStationType" desc="获取工序点类型">
        <![CDATA[          
SELECT T.STATION_TYPE
  FROM COM_MSC_STATION T
 WHERE T.PROCESS_CODE = '#PROCESS_CODE#'
   AND T.MSC = '#MSC#'
   AND T.MSC_PLINE = '#MSC_PLINE#'
	     ]]>
	  </query>
	
	<query id="CoreStandard.getProcessByStdCode" desc="通过标准代码获取工序集合">
        <![CDATA[          
SELECT T.PROCESS_CODE FROM COM_BASE_STD T WHERE T.STD_CODE = '#STD_CODE#'
	     ]]>
	  </query>
	  
	<query id="CoreStandard.getProcessDescByCode" desc="通过工序代码获取工序名称">
        <![CDATA[          
SELECT PROCESS_DESC FROM COM_BASE_PROCESS T WHERE T.PROCESS_CODE = '#PROCESS_CODE#'
	     ]]>
	  </query>
	  
	<query id="CoreStandard.getComBaseStdByPk" desc="通过主键查询标准">
        <![CDATA[          
SELECT * FROM COM_BASE_STD T WHERE T.STD_CODE = '#STD_CODE#'
	     ]]>
	</query>
	  
	<query id="CoreStandard.getPlnCicStatus" desc="获取成分索引计划状态">
        <![CDATA[          
SELECT T.EXE_STATUS
  FROM PLN_ORDER_ZG_S T
 WHERE INSTR(T.CIC_GROUP_GP, {0}) > 0
   AND T.EXE_STATUS IN ('0', '1')
	     ]]>
	</query>
	
	<query id="CoreStandard.getStdNkIndex" desc="内控索引查询界面SQL">
        <![CDATA[          
SELECT T.STD_NAME_NK,
       T.CIC,
       T.GRADENAME,
       T.PRODUCNAME_NK,
       T.STEELNAME_NK,
       T.MODEL_DESC,
       T.MEMO,
       T2.ORD_COUNT
  FROM COM_MSC_STD_CIC T
  LEFT JOIN (SELECT COUNT(1) ORD_COUNT, CIC
               FROM (SELECT T2.ORDER_NO, T4.CIC
                       FROM PLN_ORDER_ZG_S           T,
                            PLN_SALEORD              T2,
                            CRAFT_ORD_DESIGN         T3,
                            CRAFT_ORD_DESIGN_STD_CIC T4
                      WHERE T.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
                        AND T.CIC_GROUP_GP IS NOT NULL
                        AND T3.ORD_LN_PK = T2.ORD_LN_PK
                        AND T3.CRAFT_SEQ = T.CRAFT_SEQ
                        AND T4.DESGIN_KEY = T3.DESGIN_KEY
                        AND (T2.PORDERSTATUS IN ('1', '2', '3') OR
                            T2.PORDERSTATUS IN ('4', '5') AND
                            TO_DATE(T2.ROLL_MONTH, 'YYYY-MM') =
                            TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM'))
                        AND T4.SPECL_FL = '2'
                      GROUP BY T2.ORDER_NO, T4.CIC)
              GROUP BY CIC) T2
    ON T2.CIC = T.CIC
 WHERE T.STDSTYLE = 'N'
   AND T.VALIDFLAG = '1'
   AND ({0} IS NULL OR T.STD_NAME_NK LIKE '%' || {0} || '%')
   AND ({1} IS NULL OR T.GRADENAME LIKE '%' || {1} || '%')
   ORDER BY STD_NAME_NK, GRADENAME, CIC
	     ]]>
	</query>
</queryMap>