<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍车丝作业实绩">
	<query id="CoupThreadingService.ProcessPlan.GetThreadingResult"
		desc="根据计划号查询车丝实绩">
        <![CDATA[
      SELECT 
       T.COL_OPERATOR1,
       T.COL_OPERATOR2,
       T.RESULT_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ZY_PLAN_ID,
       T.PRODUCED_PCS,
       T.QUALIRIED_PCS,
       T.REJECTED_PCS,
       T.REJECTED_REASON,
       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,
       T.MACHINE_NO,
       T.PRODUCER,
       TO_CHAR(T.PRODUCER_TIME, 'YYYY-MM-DD HH24:MI:SS') PRODUCER_TIME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.WO_ID,
       T.OFF_NUM,
       DECODE(T.IF_ALL_OUT_WORK,'0','/','1','是') IF_ALL_OUT_WORK,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.MEMO,
       T.CONFIRM    
 FROM COUPLING_THREADING_RESULT T
 WHERE T.WO_ID= ?
 ORDER BY T.CREATE_TIME DESC
        ]]>
	</query>
    
    <query id="CoupThreadingService.getConfirm" desc="确认车丝实绩">
	<![CDATA[
 UPDATE COUPLING_THREADING_RESULT T SET T.CONFIRM = '1',T.CONFIRM_NAME =?,T.CONFIRM_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
  WHERE T.RESULT_NO = ?
	]]>
	</query>
	
	<query id="CoupThreadingService.getCancelConfirm" desc="取消车丝喷砂实绩">
	<![CDATA[
 UPDATE COUPLING_THREADING_RESULT T SET T.CONFIRM = '0',T.CONFIRM_NAME =?,T.CONFIRM_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
  WHERE T.RESULT_NO = ?
	]]>
	</query>
    
    <query id="CoupThreadingService.getMachine" desc="查询机床编号">
	SELECT T.MACHINE_NAME,T.MACHINE_NO  FROM COUPLING_MACHINE_USER T WHERE 1=1 
	</query>
	<query id="CoupThreadingService.getThreadResult" desc="查询车丝支数总和">
        <![CDATA[
   SELECT NVL(SUM(T.PRODUCED_PCS), 0) PRO_NUM FROM COUPLING_THREADING_RESULT T
   WHERE T.WO_ID = ?
        ]]>
	</query>
	<query id="CoupThreadingService.getMachUser" desc="查询操作工">
		SELECT T.MACHINE_USER1,T.MACHINE_USER2	FROM COUPLING_OPERATION T WHERE 1=1 AND T.PROCESS_NO='700305'
	</query>
	<query id="CoupThreadingService.getMatProBz" desc="查询操作工班组">
		SELECT T.PRO_BZ, DECODE(T.PRO_BZ, '1', '甲', '2', '乙', '3', '丙', '4', '丁') PRO_BZ_NAME	FROM COUPLING_OPERATION T WHERE 1=1 AND  T.PROCESS_NO='700305'
	</query>
	<query id="CoupThreadingService.ProcessPlan.AddThreadingResult"
		desc="新增车丝实绩">
        <![CDATA[
       INSERT INTO COUPLING_THREADING_RESULT (RESULT_NO, MACHINE_NO, PRODUCED_PCS, 
QUALIRIED_PCS, REJECTED_PCS, REJECTED_REASON, PRODUCER, PRODUCER_TIME, 
COL_SHIFT, COL_GROUP, COL_USER, COL_TIME, PLINE_CODE, ZY_PLAN_ID, CREATE_TIME, 
COL_OPERATOR1,COL_OPERATOR2, COL_MODE,WO_ID,IF_ALL_OUT_WORK,PLINE_NAME,JUDGE_STOVE_NO,BATCH_NO,MEMO) VALUES (?, ?, ?, ?, ?, ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), 
?, ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), ?,?, ?,?,?,?,?,?,?)		    
        ]]>
	</query>
	<query id="CoupThreadingService.getQueryWoId" desc="根据条件查询车丝实绩信息">
		<![CDATA[
	SELECT T.RESULT_NO,
       T.PLINE_CODE,
       T.ZY_PLAN_ID,
       T.WO_ID,
       T.COL_MODE,
       T.COL_TIME,
       T.COL_SHIFT,
       T.COL_GROUP,
       T.OFF_NUM
  FROM COUPLING_THREADING_RESULT T
	WHERE  T.OFF_NUM=? AND T.WO_ID=?
	AND T.PLINE_CODE=? AND T.ZY_PLAN_ID=?
	AND T.COL_USER=? AND T.COL_SHIFT=?
	AND T.COL_GROUP=? AND T.COL_TIME=? 
		]]>
	</query>
	<query id="CoupThreadingService.ProcessPlan.lixianThreadingResult"
		desc="离线车丝实绩">
        <![CDATA[
UPDATE COUPLING_THREADING_RESULT T SET T.OFF_NUM=TO_NUMBER(NVL(T.OFF_NUM,0))+TO_NUMBER(?)  WHERE T.RESULT_NO=? 
    
        ]]>
	</query>
	
	<query id="CoupThreadingService.UpdatelixianThreadingResult"
		desc="修改工单工序点的离线状态">
        <![CDATA[
     UPDATE PLN_ZY_JG_WORKBILL SET IF_OUT_LATHE = '1' WHERE WO_ID = ?
       
        ]]>
	</query>
	<query id="CoupThreadingService.queryThreaingRESULT" desc="查询最大实绩编号">
	 SELECT ? || ? || TO_CHAR(SYSDATE, 'yyyyMMDD') ||
         LPAD(NVL(MAX(TO_NUMBER(SUBSTR(RESULT_NO, LENGTH(RESULT_NO) - 5))),
                  0) + 1,
              6,
              '0') RESULT_NO
    FROM  COUPLING_THREADING_RESULT
   WHERE RESULT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
	</query>
	<query id="CoupThreadingService.AddComInfoResult" desc="插入ComInfo表">
		DECLARE
		BEGIN
		FOR MYROW IN (SELECT T.* FROM PLN_ZY_JG T WHERE T.ZY_PLAN_ID = ?) LOOP
		INSERT INTO COUPLING_COM_INFO
		(STEELCODE,
		STEELNAME,
		MODEL_CODE,
		MODEL_DESC,
		OUTDIAMETER,
		WALLTHICK,
		SPEC_JG,
		SPEC_JG_DESC,
		STYLE_JG,
		DIAMETER,
		CHECK_J_VAL,
		AIMLENGTH,
		SINGLEWEIGHT,
		MONITORDEMAND,
		IF_MONITOR_JG,
		PRDCR_NO,
		PRODUCER,
		PRODUCER_TIME,
		MACH_NO,
		MACH_NM,
		PRO_NUM,
		PRO_WT,
		FAIL_NUM,
		FAIL_WT,
		OFFLINE_NUM,
		OFFLINE_WT,
		STATION_STATUS,
		RRO_TIME,
		RRO_TIME_NU,
		PRO_USER,
		PRO_SHIFT,
		PRO_GROUP,
		RESULT_NO,
		ZY_PLAN_ID,
		PRO_PLAN_ID,
		CODE_JG_BL,
		JG_GROUP_ID,
		IF_OUT_RPO,
		PLINE_CODE,
		PLINE_NAME,
		STATION_CODE,
		STATION_DESC,
		JUDGE_STOVE_NO,
		BATCH_NO,
		BL_WL_ID,
		BL_WL_DESC,
		MIN_D,
		MIN_H,
		AIMLENGTH_BL,
		AIM_CUT_LEN,
		LENGTH_MIN,
		LENGTH_MAX,
		TAPER,
		CODE_JG,
		GRADECODE,
		GRADENAME,CREATE_TIME,COL_OPERATOR,COL_OPERATOR2,WO_ID)
		VALUES
		(MYROW.STEELCODE,
		MYROW.STEELNAME,
		MYROW.MODEL_CODE,
		MYROW.MODEL_DESC,
		MYROW.OUTDIAMETER,
		MYROW.WALLTHICK,
		MYROW.SPEC_JG,
		MYROW.SPEC_JG_DESC,
		MYROW.STYLE_JG,
		MYROW.DIAMETER,
		MYROW.CHECK_J_VAL,
		MYROW.AIMLENGTH,
		MYROW.SINGLEWEIGHT,
		MYROW.MONITORDEMAND,
		MYROW.IF_MONITOR_JG,
		MYROW.PRDCR_NO,
		?,
		TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
		?,
		'',
		?,
		?,
		?,
		?,
		'',
		'',
		'1',
		TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
		'',
		?,
		?,
		?,
		?,
		MYROW.ZY_PLAN_ID,
		MYROW.PRO_PLAN_ID,
		MYROW.CODE_JG_BL,
		MYROW.JG_GROUP_ID,
		'1',
		MYROW.PLINE_CODE,
		MYROW.PLINE_NAME,
		?,
		'车丝',
		MYROW.JUDGE_STOVE_NO,
		MYROW.BATCH_NO,
		MYROW.BL_WL_ID,
		MYROW.BL_WL_DESC,
		MYROW.MIN_D,
		MYROW.MIN_H,
		MYROW.AIMLENGTH_BL,
		MYROW.AIM_CUT_LEN,
		MYROW.LENGTH_MIN,
		MYROW.LENGTH_MAX,
		MYROW.TAPER,
		MYROW.CODE_JG,
		MYROW.GRADECODE,
		MYROW.GRADENAME,TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),?,?,?);
		END LOOP;
		END;
	</query>
	
	<query
		id="CoupThreadingService.lixianofflineResult"
		desc="新增离线表">
        <![CDATA[      
       INSERT INTO COUPLING_OFFLINE_RESULT
    (RESULT_NO,
     PLINE_CODE,
     WO_ID,
     STATION_CODE,
     STATION_DESC,
     JUDGE_STOVE_NO,
     BATCH_NO,
     OFFLINE_NUM,
     OFFLINE_WT,
     IF_ALL_OUT_WORK,
     HARSH_TYPE,
     COATING_TYPE,
     COL_TIME,
     COL_USER,
     COL_SHIFT,
     COL_GROUP,
     CREATE_TIME,OFF_XH)
  VALUES
    (?,
     ?,
     ?,
     ?,
     '车丝',
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),(SELECT LPAD(SUBSTR(NVL(MAX(T.OFF_XH), '000'), -3, 3) + 1, 3, '0') AS OFF_XH
   FROM COUPLING_OFFLINE_RESULT T
  WHERE RESULT_NO = ?))
        ]]>
	</query>
	<query id="CoupThreadingService.lixianComInfoResult" desc="插入ComInfo表">
		DECLARE
		BEGIN
		FOR MYROW IN (SELECT T.* FROM PLN_ZY_JG T WHERE T.HEAT_PLAN_NO = ?) LOOP
		INSERT INTO COUPLING_COM_INFO
		(STEELCODE,
		STEELNAME,
		MODEL_CODE,
		MODEL_DESC,
		OUTDIAMETER,
		WALLTHICK,
		SPEC_JG,
		SPEC_JG_DESC,
		STYLE_JG,
		DIAMETER,
		CHECK_J_VAL,
		AIMLENGTH,
		SINGLEWEIGHT,
		MONITORDEMAND,
		IF_MONITOR_JG,
		PRDCR_NO,
		PRODUCER,
		PRODUCER_TIME,
		MACH_NO,
		MACH_NM,
		PRO_NUM,
		PRO_WT,
		FAIL_NUM,
		FAIL_WT,
		OFFLINE_NUM,
		OFFLINE_WT,
		STATION_STATUS,
		RRO_TIME,
		RRO_TIME_NU,
		PRO_USER,
		PRO_SHIFT,
		PRO_GROUP,
		RESULT_NO,
		PRO_PLAN_ID,
		CODE_JG_BL,
		JG_GROUP_ID,
		IF_OUT_RPO,
		PLINE_CODE,
		PLINE_NAME,
		STATION_CODE,
		STATION_DESC,
		JUDGE_STOVE_NO,
		BATCH_NO,
		BL_WL_ID,
		BL_WL_DESC,
		MIN_D,
		MIN_H,
		AIMLENGTH_BL,
		AIM_CUT_LEN,
		LENGTH_MIN,
		LENGTH_MAX,
		TAPER,
		CODE_JG,
		GRADECODE,
		GRADENAME,CREATE_TIME,COL_OPERATOR,WO_ID)
		VALUES
		(MYROW.STEELCODE,
		MYROW.STEELNAME,
		MYROW.MODEL_CODE,
		MYROW.MODEL_DESC,
		MYROW.OUTDIAMETER,
		MYROW.WALLTHICK,
		MYROW.SPEC_JG,
		MYROW.SPEC_JG_DESC,
		MYROW.STYLE_JG,
		MYROW.DIAMETER,
		MYROW.CHECK_J_VAL,
		MYROW.AIMLENGTH,
		MYROW.SINGLEWEIGHT,
		MYROW.MONITORDEMAND,
		MYROW.IF_MONITOR_JG,
		MYROW.PRDCR_NO,
		?,
		TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
		?,
		'',
		?,
		?,
		?,
		?,
		?,
		'',
		'1',
		TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
		'',
		?,
		?,
		?,
		?,
		MYROW.PRO_PLAN_ID,
		MYROW.CODE_JG_BL,
		MYROW.JG_GROUP_ID,
		?,
		MYROW.PLINE_CODE,
		MYROW.PLINE_NAME,
		?,
		'车丝',
		MYROW.JUDGE_STOVE_NO,
		MYROW.BATCH_NO,
		MYROW.BL_WL_ID,
		MYROW.BL_WL_DESC,
		MYROW.MIN_D,
		MYROW.MIN_H,
		MYROW.AIMLENGTH_BL,
		MYROW.AIM_CUT_LEN,
		MYROW.LENGTH_MIN,
		MYROW.LENGTH_MAX,
		MYROW.TAPER,
		MYROW.CODE_JG,
		MYROW.GRADECODE,
		MYROW.GRADENAME,TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),?,?);
		END LOOP;
		END;
	</query>
	
	<query id="CoupThreadingService.ProcessPlan.unlixianThreadingResult"
		desc="撤销离线车丝实绩">
        <![CDATA[
      DELETE coupling_threading_result WHERE RESULT_NO = ?
    
        ]]>
	</query>
	
	<query id="CoupThreadingService.unlixianComInfoResult" desc="撤销ComInfo表">
		DELETE COUPLING_COM_INFO WHERE RESULT_NO = ? AND WO_ID=? AND IF_OUT_RPO = '1'
	</query>
	
	<query
		id="CoupThreadingService.unlixianofflineResult"
		desc="撤销离线表">
        <![CDATA[
         DELETE COUPLING_OFFLINE_RESULT WHERE RESULT_NO = ? 
        ]]>
	</query>
	
	<query id="CoupThreadingService.unupdatelixianofflineResult"
		desc="修改工单工序的离线状态">
        <![CDATA[
      UPDATE PLN_ZY_JG_WORKBILL
   SET IF_OUT_LATHE = '0'
 WHERE WO_ID = ?
      
        ]]>
	</query>
	
	<query id="CoupThreadingService.unupdatelixianofflineResult2"
		desc="修改工单工序的离线状态">
        <![CDATA[
      UPDATE PLN_ZY_JG_WORKBILL
   SET IF_OUT_LATHE = '1'
 WHERE WO_ID = ?
      
        ]]>
	</query>
	
	<query id="CoupThreadingService.querylixian" desc="查询车丝实绩对应是否离线">
SELECT count(1) count
  FROM coupling_threading_result T
 WHERE T.WO_ID = ?
   and t.if_all_out_work='1'
	</query> 
	<query id="CoupThreadingService.doBeside" desc="结炉">
		DECLARE
BEGIN
  UPDATE COUPLING_COM_INFO T
     SET T.STATION_STATUS = '2'
   WHERE T.ZY_PLAN_ID = ?
     AND T.STATION_CODE = ?
     AND T.WO_ID = ?;
  UPDATE PLN_ZY_JG_WORKBILL T
     SET T.LATHE_STATUS = '2'
   WHERE T.ZY_PLAN_ID = ?
     AND T.WO_ID = ?;
END;
	</query>
	<query id="CoupThreadingService.selectComInfo" desc="查询是否已存在该单号的实绩">
SELECT T.PRO_NUM
  FROM COUPLING_COM_INFO T
 WHERE T.ZY_PLAN_ID = ?
   AND T.STATION_CODE = ?
   AND T.WO_ID = ?
	</query>
	<query id="CoupThreadingService.DeleteComInfoResult" desc="删除comInfo表">
DELETE COUPLING_COM_INFO
 WHERE RESULT_NO = ?
   AND STATION_CODE = ?
   AND WO_ID = ?
</query>
	<query id="CoupThreadingService.queryCutCou" desc="查询车丝实绩对应工单重支数">
 SELECT COUNT(1) COUNT,
       SUM(NVL(T.QUALIRIED_PCS, 0)) QUALIRIED_PCS,
       SUM(NVL(T.REJECTED_PCS, 0)) REJECTED_PCS
  FROM COUPLING_THREADING_RESULT T
 WHERE T.ZY_PLAN_ID = ?
 AND T.WO_ID = ?
	</query>
	<query id="CoupThreadingService.DeleteCutResult" desc="删除车丝实绩">
DELETE COUPLING_THREADING_RESULT WHERE RESULT_NO = ?
	</query>
	<query id="CoupThreadingService.UpdateCutResult" desc="修改车丝实绩">
UPDATE COUPLING_THREADING_RESULT
   SET PRODUCED_PCS    = ?,
       QUALIRIED_PCS   = ?,
       REJECTED_PCS    = ?,
       REJECTED_REASON = ?,
       COL_SHIFT       = ?,
       COL_GROUP       = ?,
       MACHINE_NO      = ?,
       PRODUCER        = ?,
       PRODUCER_TIME   = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       COL_OPERATOR1   = ?,
       COL_OPERATOR2   =?
 WHERE RESULT_NO = ?
	</query>
	<query id="CoupThreadingService.UpdateComInfoResult" desc="修改comInfo表">
UPDATE COUPLING_COM_INFO
   SET PRO_NUM       = ?,
       PRO_WT =?,
       FAIL_NUM      = ?,
       FAIL_WT=?,
       PRO_SHIFT     = ?,
       PRO_GROUP     = ?,
       COL_OPERATOR = ?,
       COL_OPERATOR2 =?,
       PRODUCER      = ?,
       PRODUCER_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
 WHERE RESULT_NO = ?
   AND STATION_CODE = ?
   AND WO_ID = ?

	</query>
	<query id="CoupThreadingService.unDoBeside" desc="撤销结炉">
DECLARE
BEGIN
  UPDATE COUPLING_COM_INFO T
     SET T.STATION_STATUS = '1'
   WHERE T.ZY_PLAN_ID = ?
     AND T.STATION_CODE = ?
     AND T.WO_ID = ?;
  UPDATE PLN_ZY_JG_WORKBILL T
     SET T.LATHE_STATUS = '1'
   WHERE T.ZY_PLAN_ID = ?
     AND T.WO_ID = ?;
END;
	</query>
</queryMap>