<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍委托单">
	<query id="FrmOutManagement.geQueryPlnJgBill" desc="查询工单信息">
        <![CDATA[  
    SELECT T.WO_ID,
       T.ZY_PLAN_ID,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       DECODE(T.COAT_TYPE,'0','镀铜','1','磷化','2','无') COAT_TYPE,
       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,
       NVL(T.INSTORE_NUM, 0) INSTORE_NUM,
       T.DEMAND_COPPER,
       T.DEMAND_DETECTION,
       T.DEMAND_BLAST,
       T.DEMAND_BONDERIZING,
       DECODE(T.IF_ALL_OUT_WORK, '0', 'FALSE', '1', 'TRUE') IF_ALL_OUT_WORK,
       NVL(T.PLAN_BL_NUM, 0) PLAN_BL_NUM,
       DECODE(T.IF_OUT_COPPER, '0', 'FALSE', '1', 'TRUE') IF_OUT_COPPER,
       DECODE(T.IF_OUT_CUT, '0', 'FALSE', '1', 'TRUE') IF_OUT_CUT,
       DECODE(T.IF_OUT_CJG, '0', 'FALSE', '1', 'TRUE') IF_OUT_CJG,
       DECODE(T.IF_OUT_IMPRESS, '0', 'FALSE', '1', 'TRUE') IF_OUT_IMPRESS,
       DECODE(T.IF_OUT_LATHE, '0', 'FALSE', '1', 'TRUE') IF_OUT_LATHE,
       DECODE(T.IF_OUT_DETECT, '0', 'FALSE', '1', 'TRUE') IF_OUT_DETECT,
       DECODE(T.IF_OUT_BLAST, '0', 'FALSE', '1', 'TRUE') IF_OUT_BLAST,
       DECODE(T.IF_OUT_COAT, '0', 'FALSE', '1', 'TRUE') IF_OUT_COAT,
       DECODE(T.IF_OUT_THREAD, '0', 'FALSE', '1', 'TRUE') IF_OUT_THREAD,
        NVL((SELECT T1.OFF_NUM FROM COUPLING_CUT_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) CUT_PLN_NUMB,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_CUT_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) CJG_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_CUT_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) IMPRESS_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_THREADING_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) LATHE_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_THINSPECT_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) THREAD_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_INSPECTION_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) DETECT_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_SANDBLAST_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) BLAST_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_PHOSPHATE_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) PLT_PLN_NUM,
       NVL((SELECT T1.OFF_NUM FROM COUPLING_PHOSPHATE_RESULT T1 WHERE T1.WO_ID=T.WO_ID AND T1.IF_ALL_OUT_WORK='1'), 0) PHOS_PLN_NUM,
       '0' COPPER_PLN_NUM
  FROM PLN_ZY_JG_WORKBILL T
 WHERE (T.IF_ALL_OUT_WORK = '1' OR T.IF_OUT_COPPER = '1' OR
       T.IF_OUT_CJG = '1' OR T.IF_OUT_IMPRESS = '1' OR
       T.IF_OUT_LATHE = '1' OR T.IF_OUT_DETECT = '1' OR
       T.IF_OUT_BLAST = '1' OR T.IF_OUT_COAT = '1' OR
       T.IF_OUT_THREAD = '1' OR T.IF_OUT_CUT = '1')
 AND T.ZY_PLAN_ID LIKE '%'|| ? ||'%'
 AND T.WO_ID  LIKE '%'|| ? ||'%'
 AND T.PLINE_CODE LIKE '%'|| ? ||'%'
 ORDER BY T.CREATE_TIME DESC 
           ]]>
	</query>
	<query id="FrmOutManagement.geQueryEntrusted" desc="查询委托单信息">
        <![CDATA[  
    SELECT 
       T.ENTRUSTED_NO,
       T.PLINE_CODE,
       (SELECT T1.PLINE_NAME FROM COM_BASE_PLINE T1 WHERE T1.VALIDFLAG='1' AND T1.PLINE_CODE=T.PLINE_CODE) PLINE_NAME,
       T.ZY_PLAN_ID,
       T.WO_ID,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       NVL(T.ENTRUSTED_NUM1,0) ENTRUSTED_NUM1,
       NVL(T.ENTRUSTED_WT1,0) ENTRUSTED_WT1,
       NVL(T.ENTRUSTED_NUM2,0) ENTRUSTED_NUM2,
       NVL(T.ENTRUSTED_WT2,0) ENTRUSTED_WT2,
       NVL(T.ENTRUSTED_NUM3,0) ENTRUSTED_NUM3,
       NVL(T.ENTRUSTED_WT3,0) ENTRUSTED_WT3,
       NVL(T.ENTRUSTED_NUM4,0) ENTRUSTED_NUM4,
       NVL(T.ENTRUSTED_WT4,0) ENTRUSTED_WT4,
       NVL(T.ENTRUSTED_NUM5,0) ENTRUSTED_NUM5,
       NVL(T.ENTRUSTED_WT5,0) ENTRUSTED_WT5,
       NVL(T.ENTRUSTED_NUM6,0) ENTRUSTED_NUM6,
       NVL(T.ENTRUSTED_WT6,0) ENTRUSTED_WT6,
       NVL(T.ENTRUSTED_NUM7,0) ENTRUSTED_NUM7,
       NVL(T.ENTRUSTED_WT7,0) ENTRUSTED_WT7,
       NVL(T.ENTRUSTED_NUM8,0) ENTRUSTED_NUM8,
       NVL(T.ENTRUSTED_WT8,0) ENTRUSTED_WT8,
       NVL(T.ENTRUSTED_NUM9,0) ENTRUSTED_NUM9,
       NVL(T.ENTRUSTED_WT9,0) ENTRUSTED_WT9,
       DECODE(T.ENTRUSTED_LOG,'1','编辑','2','委托申请','3','审批通过','4','审批不通过') ENTRUSTED_LOG,
       T.HARSH_TYPE,
       DECODE(T.COATING_TYPE,'0','镀铜','1','磷化','无') COATING_TYPE,
       T.COL_MODE,
       TO_CHAR(T.COL_TIME, 'YYYY-MM-DD HH24:MI:SS') COL_TIME,
       T.COL_USER,
       DECODE(T.COL_SHIFT, '1', '早', '2', '中', '3', '夜') COL_SHIFT,
       DECODE(T.COL_GROUP, '1', '甲', '2', '乙', '3', '丙', '4', '丁') COL_GROUP,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       NVL(T.ENTRUSTED_NUM10,0) ENTRUSTED_NUM10,
       NVL(T.ENTRUSTED_WT10,0) ENTRUSTED_WT10,
       NVL(T.ENTRUSTED_NUM11,0) ENTRUSTED_NUM11,
       NVL(T.ENTRUSTED_WT11,0) ENTRUSTED_WT11
 FROM COUPLING_ENTRUSTED_RESULT T
 WHERE T.ZY_PLAN_ID LIKE '%'|| ? ||'%'
 AND T.WO_ID  LIKE '%'|| ? ||'%'
 AND T.PLINE_CODE LIKE '%'|| ? ||'%'
 ORDER BY T.ENTRUSTED_NO DESC 
           ]]>
	</query>
	<query id="FrmOutManagement.AddPlnBillResult" desc="新增委托单信息">
        <![CDATA[  
INSERT INTO COUPLING_ENTRUSTED_RESULT (ENTRUSTED_NO, PLINE_CODE, ZY_PLAN_ID, 
WO_ID, JUDGE_STOVE_NO, BATCH_NO, ENTRUSTED_NUM1, ENTRUSTED_NUM2, ENTRUSTED_NUM3, 
ENTRUSTED_NUM4, ENTRUSTED_NUM5,  ENTRUSTED_NUM6,  ENTRUSTED_NUM7, 
ENTRUSTED_NUM8,  ENTRUSTED_NUM9, ENTRUSTED_NUM10,  ENTRUSTED_NUM11, 
ENTRUSTED_LOG, HARSH_TYPE, COATING_TYPE, COL_MODE, COL_TIME, COL_USER, 
COL_SHIFT, COL_GROUP, CREATE_TIME) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
?,?,?,?,?,?,TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
          ]]>
	</query>
	<query id="FrmOutManagement.QueryMatWeghit" desc="查询库存重量">
        <![CDATA[
        SELECT NVL(SUM(ACT_WEIGHT), 0) ACT_WEIGHT
  FROM (SELECT M.ACT_WEIGHT
          FROM MAT_BC_M M, YDM_BC_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="FrmOutManagement.QueryMaxEnt" desc="查询最大委托单号">
        <![CDATA[
       SELECT 'WA' || ? ||
       LPAD(SUBSTR(NVL(MAX(T.ENTRUSTED_NO), '000'), -3, 3) + 1, 3, '0') AS ENTRUSTED_NO
  FROM COUPLING_ENTRUSTED_RESULT T
 WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') = ?    
         ]]>
	</query>
	<query id="FrmOutManagement.DeletePlnBillResult" desc="删除委托单">
        <![CDATA[
 DELETE COUPLING_ENTRUSTED_RESULT
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
   AND ENTRUSTED_NO=?
         ]]>
	</query>
	<query id="FrmOutManagement.UpdatePlnBillStrat" desc="修改委托单申请状态">
        <![CDATA[
UPDATE COUPLING_ENTRUSTED_RESULT
   SET ENTRUSTED_LOG = ?
 WHERE ZY_PLAN_ID = ?
   AND WO_ID = ?
   AND ENTRUSTED_NO=?
         ]]>
	</query>
	<query id="FrmOutManagement.QueryPlnBillStrat" desc="查询委托单状态">
        <![CDATA[
          SELECT ENTRUSTED_LOG FROM COUPLING_ENTRUSTED_RESULT WHERE ZY_PLAN_ID = ? AND WO_ID=? AND ENTRUSTED_NO=?
          ]]>
	</query>
</queryMap>