<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc=" 孔型计划">
	<query id="FrmPlnPassmodel.initPline" desc="初始化产线">
         <![CDATA[
         SELECT T.PLINE_CODE, T.PLINE_NAME
  FROM COM_BASE_PLINE T
 WHERE T.VALIDFLAG = '1'
 ORDER BY T.PROCESS_CODE, T.PLINE_NAME
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.initPassModel" desc="初始化孔型">
         <![CDATA[
  SELECT T.PASS_CODE, T.PASS_NAME
  FROM COM_MSC_PLINE_R_SPEC T
 WHERE T.PLINE_CODE = ?
   AND T.VALIDFLAG = '1'
 GROUP BY T.PASS_CODE, T.PASS_NAME
 ORDER BY TO_NUMBER(TO_NUMBER(SUBSTR(T.PASS_NAME, 0, 3)))
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.add" desc="新增">
         <![CDATA[
   INSERT INTO PLN_PASSMODEL
  (PASSM_PLAN_ID,
   PRO_MONTH,
   GX_PRO_SEQ,
   PLINE_CODE,
   PLINE_NAME,
   PASS_CODE,
   PASS_NAME,
   PLAN_NUM,
   BEGIN_TIME,
   END_TIME,
   CREATE_NAME,
   CREATE_TIME,
   UPDATE_NAME,
   UPDATE_TIME)
VALUES
  ('#PASSM_PLAN_ID#',
   '#PRO_MONTH#',
   '#GX_PRO_SEQ#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#PASS_CODE#',
   '#PASS_NAME#',
   '#PLAN_NUM#',
   TO_DATE('#BEGIN_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   TO_DATE('#END_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#CREATE_NAME#',
   SYSDATE,
   '#UPDATE_NAME#',
   NULL)
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.update" desc="修改">
         <![CDATA[
UPDATE PLN_PASSMODEL T
   SET T.PASSM_PLAN_ID = '#PASSM_PLAN_ID#',
       T.PRO_MONTH     = '#PRO_MONTH#',
       T.GX_PRO_SEQ    = TO_NUMBER('#GX_PRO_SEQ#'),
       T.PASS_CODE     = '#PASS_CODE#',
       T.PASS_NAME     = '#PASS_NAME#',
       T.PLAN_NUM      = '#PLAN_NUM#',
       T.BEGIN_TIME    =TO_DATE('#BEGIN_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       T.END_TIME      =TO_DATE('#END_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
       T.UPDATE_NAME   = '#UPDATE_NAME#',
       T.UPDATE_TIME   = SYSDATE
 WHERE T.PASSM_PLAN_ID = '#PASSM_PLAN_ID#'
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.delete" desc="删除">
         <![CDATA[
           DELETE FROM PLN_PASSMODEL T WHERE T.PASSM_PLAN_ID=?
                 ]]>
	</query>


	<query id="FrmPlnPassmodel.updateSeq" desc="修改序号">
         <![CDATA[
          UPDATE PLN_PASSMODEL T
   SET T.GX_PRO_SEQ = TO_NUMBER(T.GX_PRO_SEQ) + TO_NUMBER(?)
 WHERE T.PLINE_CODE = ?
   AND TO_NUMBER(T.GX_PRO_SEQ) > TO_NUMBER(?)
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.query" desc="查询">
         <![CDATA[
            SELECT 
       T.PASSM_PLAN_ID,
       T.PRO_MONTH,
       T.GX_PRO_SEQ,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.PASS_CODE,
       T.PASS_NAME,
       T.PLAN_NUM,
       TO_CHAR(T.BEGIN_TIME, 'YYYY-MM-DD HH24:MI:SS') BEGIN_TIME,
       TO_CHAR(T.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME
 FROM PLN_PASSMODEL T
 WHERE 1=1
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.getMaxGxProSeq" desc="查询最大序号">
         <![CDATA[
           SELECT NVL(MAX(TO_NUMBER(T.GX_PRO_SEQ)), 0) + 1 GX_PRO_SEQ
  FROM PLN_PASSMODEL T
 WHERE T.PLINE_CODE = ?
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.getMaxEndTime" desc="查询最大结束时间">
         <![CDATA[
         SELECT TO_CHAR(MAX(T.END_TIME), 'yyyy-mm-dd hh24:mi:ss') PLAN_TIME_E
  FROM PLN_PASSMODEL T
 WHERE T.PLINE_CODE = ? and PRO_MONTH = ?
                 ]]>
	</query>

	<query id="FrmPlnPassmodel.getTimeBySeq" desc="条件查询时间">
         <![CDATA[
        SELECT TO_CHAR(T.BEGIN_TIME, 'YYYY-MM-DD HH24:MI:SS') BEGIN_TIME,
       TO_CHAR(T.END_TIME, 'YYYY-MM-DD HH24:MI:SS') END_TIME
  from PLN_PASSMODEL T
 WHERE T.PLINE_CODE = ?
   AND T.GX_PRO_SEQ = TO_number(?)
                 ]]>
	</query>


	<query id="FrmPlnPassmodel.getMaxPassPlanId" desc="查询最大孔型计划编号">
         <![CDATA[
       SELECT ? || LPAD(TO_NUMBER(NVL(SUBSTR(MAX(T.PASSM_PLAN_ID), -3), '0')) + 1,
                 3,
                 '0') AS PASSM_PLAN_ID
  FROM PLN_PASSMODEL T
 WHERE INSTR(T.PASSM_PLAN_ID, ?) > 0
                 ]]>
	</query>

</queryMap>