<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍工单">
	<query id="FrmPlnZyJgWorkBill.geQueryPlnJg" desc="查询炉计划">
        <![CDATA[    
SELECT T3.*, TO_NUMBER(T3.PLAN_BL_NUM) - TO_NUMBER(T3.BENN_NUM) PLN_KEB_NUM
  FROM (SELECT T.ZY_PLAN_ID,
               T.PRO_PLAN_ID,
               T.JG_GROUP_ID,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,
               T.PLINE_NAME,
               T.CODE_JG_BL,
               T.BL_WL_DESC,
               T.STEELNAME,
               T.GRADENAME,
               T.MIN_D,
               T.MIN_H,
               NVL(T.AIMLENGTH_BL,0) AIMLENGTH_BL,
               NVL(T.AIM_CUT_LEN,0) AIM_CUT_LEN,
               T.LENGTH_MIN,
               T.LENGTH_MAX,
               T.TAPER,
               T.CODE_JG,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.OUTDIAMETER,
               T.WALLTHICK,
               T.SPEC_JG_DESC,
               T.STYLE_JG,
               T.DIAMETER,
               T.CHECK_J_VAL,
               NVL(T.AIMLENGTH, 0) AIMLENGTH,
               NVL(T.SINGLEWEIGHT, 0) SINGLEWEIGHT,
               T.COAT_TYPE,
               NVL(T.PLAN_JG_NUM, 0) PLAN_JG_NUM,
               NVL(T.PLAN_BL_NUM, 0) PLAN_BL_NUM,
               NVL(T.PLAN_BL_WT, 0) PLAN_BL_WT,
               NVL(T.USE_BL_NUM, 0) USE_BL_NUM,
               NVL(T.USE_BL_WT, 0) USE_BL_WT,
               DECODE(T.ZY_PLAN_STATUS,
                      '0',
                      '编辑',
                      '1',
                      '下发',
                      '2',
                      '生产中',
                      '3',
                      '生产完成',
                      '生产关闭') ZY_PLAN_STATUS,
               T.MEMO,
               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,
               NVL((SELECT SUM(T1.PLAN_BL_NUM)
                     FROM PLN_ZY_JG_WORKBILL T1
                    WHERE T1.ZY_PLAN_ID = T.ZY_PLAN_ID),
                   0) BENN_NUM, 
               '10' AVERAGE_LEN,
               NVl(T.PLAN_JG_NUM,0) PLAN_JG_NUM1
          FROM PLN_ZY_JG T
         WHERE T.ZY_PLAN_ID LIKE '%' || ? || '%'
           AND T.ZY_PLAN_STATUS LIKE '%' || ? || '%'
           AND T.PLINE_CODE LIKE '%' || ? || '%') T3
 ORDER BY T3.CREATE_TIME ASC
        ]]>
	</query>

	<query id="FrmPlnZyJgWorkBill.geQueryPlnJgBill" desc="查询工单信息">
        <![CDATA[  
        SELECT T.WO_ID,
       T.ZY_PLAN_ID,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.PLINE_NAME,
       NVL(T.PLAN_JG_NUM,0) PLAN_JG_NUM,
       NVL(T.CS_JG_NUM,0) CS_JG_NUM,
       NVL(T.XQ_JG_NUM,0) XQ_JG_NUM,
       T.CUT_MACH_GRP_NM,
       NVL(T.INSTORE_NUM,0) INSTORE_NUM, 
       DECODE(T.ZY_BILL_STATUS,'0','编辑','1','下发','2','生产中','3','生产完成','4','生产关闭') ZY_BILL_STATUS,
       T.DEMAND_COPPER,
       T.DEMAND_DETECTION,
       T.DEMAND_BLAST,
       T.DEMAND_BONDERIZING,
       T.MEMO,
       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,
       DECODE(T.ZY_BILL_BC, '1', '早', '2', '中', '3', '夜') ZY_BILL_BC,
       DECODE(T.ZY_BILL_BZ, '1', '甲', '2', '乙', '3', '丙', '4', '丁') ZY_BILL_BZ,
       TO_CHAR(T.ZY_START_TIME, 'YYYY-MM-DD HH24:MI:SS') ZY_START_TIME,
       TO_CHAR(T.ZY_END_TIME, 'YYYY-MM-DD HH24:MI:SS') ZY_END_TIME,
       TO_CHAR(T.CLOSE_TIME, 'YYYY-MM-DD HH24:MI:SS') CLOSE_TIME,
       DECODE(T.IF_ALL_OUT_WORK, '0', '否', '1', '是') IF_ALL_OUT_WORK,
       NVL(T.PLAN_BL_NUM, 0) PLAN_BL_NUM,
       NVL(T.PLAN_BL_WT, 0) PLAN_BL_WT,
       NVL((SELECT SUM(T1.LOAD_PIECES)
             FROM COUPLING_LOADING_RESULT T1
            WHERE T1.WO_ID = T.WO_ID
              AND T1.ZY_PLAN_ID = T.ZY_PLAN_ID),
           0) LOAD_PIECES,
       NVL((SELECT SUM(T1.LOAD_WEIGHT)
             FROM COUPLING_LOADING_RESULT T1
            WHERE T1.WO_ID = T.WO_ID
              AND T1.ZY_PLAN_ID = T.ZY_PLAN_ID),
           0) LOAD_WEIGHT
  FROM PLN_ZY_JG_WORKBILL T
 WHERE T.ZY_PLAN_ID =?
 ORDER BY T.CREATE_TIME DESC
           ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.AddPlnBillResult" desc="新增工单信息">
        <![CDATA[  
         INSERT INTO PLN_ZY_JG_WORKBILL( WO_ID, ZY_PLAN_ID, JUDGE_STOVE_NO, BATCH_NO, 
 BATCH_GROUD_NO, PLINE_CODE, PLINE_NAME, IF_NEED_CJG, IF_IMPRESS, 
 IF_BLAST, IF_PLATE_CU, IF_PHOSPHATING, COAT_TYPE, PLAN_JG_NUM, CS_JG_NUM, XQ_JG_NUM, 
 CUT_MACH_GRP_NO, CUT_MACH_GRP_NM, DEMAND_COPPER, LATHE_GRP_NO, LATHE_GRP_NM,
 DEMAND_DETECTION, DEMAND_BLAST, DEMAND_BONDERIZING, MEMO, CREATE_NAME, 
 CREATE_TIME, ZY_BILL_BC, ZY_BILL_BZ, PLAN_BL_NUM, PLAN_BL_WT,CUT_PLN_NUMB,CJG_PLN_NUM,
 IMPRESS_PLN_NUM,LATHE_PLN_NUM,THREAD_PLN_NUM,DETECT_PLN_NUM,BLAST_PLN_NUM,PLT_PLN_NUM,
 PHOS_PLN_NUM,COPPER_PLN_NUM
 ) VALUES 
 (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
 TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,?,?,?,?,?,?,?)
          ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.updatePln" desc="修改工单表状态">
        <![CDATA[  
        UPDATE PLN_ZY_JG T SET T.ZY_PLAN_STATUS = ? WHERE T.ZY_PLAN_ID = ?
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryMatWeghit" desc="查询库存重量">
        <![CDATA[
        SELECT NVL(SUM(ACT_WEIGHT), 0) ACT_WEIGHT
  FROM (SELECT M.ACT_WEIGHT
          FROM MAT_ZC_M M, YDM_ZC_BUTTRESS T
         WHERE M.MAT_NO = T.MAT_NO
           AND M.PRODUCT_FLAG = '801401'
           AND M.MAT_STATUS = '80150102'
           AND M.JUDGE_STOVE_NO = ?
           AND M.BATCH_NO = ?
         ORDER BY M.MAT_NO)
 WHERE ROWNUM <?       
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryMatBill" desc="查询最大工单号">
        <![CDATA[
        SELECT ? || LPAD(SUBSTR(NVL(MAX(T.WO_ID), '00'), -2, 2) + 1, 2, '0') AS WO_ID
  FROM PLN_ZY_JG_WORKBILL T
 WHERE T.ZY_PLAN_ID = ?      
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.DeletePlnBillResult" desc="删除工单">
        <![CDATA[
 DELETE PLN_ZY_JG_WORKBILL
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.UpdatePlnBillStrat" desc="修改工单下发状态">
        <![CDATA[
UPDATE PLN_ZY_JG_WORKBILL
   SET ZY_BILL_STATUS = ?,
   UPDATE_NAME=?,
   UPDATE_TIME=TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.UpdateClosePlnBillStrat" desc="修改工单关闭状态">
        <![CDATA[
UPDATE PLN_ZY_JG_WORKBILL
   SET ZY_BILL_STATUS = ?,
       PLAN_BL_NUM    = TO_NUMBER(?),
       PLAN_BL_WT     = TO_NUMBER(?)
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.UpdateOffPlnBillStrat" desc="修改工单离线状态">
        <![CDATA[
UPDATE PLN_ZY_JG_WORKBILL
   SET IF_ALL_OUT_WORK = ?
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
         ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryPlnBillCount" desc="根据炉次计划号查询工单表是否还有数据">
        <![CDATA[
          SELECT COUNT(1) COUNT FROM PLN_ZY_JG_WORKBILL WHERE ZY_PLAN_ID = ?
          ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryPlnBillCount1" desc="根据炉次计划号查询工单表是否还有数据">
        <![CDATA[
          SELECT COUNT(1) COUNT FROM PLN_ZY_JG_WORKBILL WHERE ZY_PLAN_ID = ? AND ZY_BILL_STATUS <'4'
          ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryPlnBillCount2" desc="撤销关闭查询工单表是否还有数据">
        <![CDATA[
          SELECT COUNT(1) COUNT FROM PLN_ZY_JG_WORKBILL WHERE ZY_PLAN_ID = ? AND ZY_BILL_STATUS ='4'
          ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryPlnBillStrat" desc="查询工单状态">
        <![CDATA[
          SELECT ZY_BILL_STATUS,IF_ALL_OUT_WORK FROM PLN_ZY_JG_WORKBILL WHERE ZY_PLAN_ID = ? AND WO_ID=?
          ]]>
	</query>
	<query id="FrmPlnZyJgWorkBill.QueryEntrustedStrat" desc="查询是否存在委托单">
        <![CDATA[
          SELECT COUNT(*) COUNT
  FROM COUPLING_ENTRUSTED_RESULT T
 WHERE T.ZY_PLAN_ID = ?
   AND T.WO_ID = ?

          ]]>
	</query>
</queryMap>