<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc=" 螺纹检验实绩">
	<query id="ThreadInspectResultService.ProcessPlan.GetThreadingSelfcheck"
		desc="查询自检记录">
        <![CDATA[
	SELECT T.RESULT_NO,
       T.PLINE_CODE,
       T.ZY_PLAN_ID,
       T.COUPLING_NO,
       T.TAPER,
       T.LEADS,
       T.HEIGHT,
       T.PDIAMETER_OVALITY,
       T.BROKENTHREAD,
       T.AL,
       T.RUN_OUT,
       T.CHAMFER,
       T.RESULTS,
       T.THREADFORM,
       T.WO_ID
  FROM COUPLING_THINSPECT_SELFCHECK T
 WHERE T.RESULT_NO = ?
 AND WO_ID=?
 ORDER BY T.COUPLING_NO ASC    
        ]]>
        </query>
        <query id="ThreadInspectResultService.getthreadinspResult" desc="查询螺纹检验支数总和">
        <![CDATA[
   SELECT NVL(SUM(T.INSPECT_PIECES), 0) PRO_NUM FROM coupling_thinspect_result T
   WHERE T.WO_ID = ?
        ]]>
	</query>
	   <query id="ThreadInspectResultService.getConfirm" desc="确认螺纹检验实绩">
	<![CDATA[
 UPDATE COUPLING_THINSPECT_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="ThreadInspectResultService.getCancelConfirm" desc="取消螺纹检验喷砂实绩">
	<![CDATA[
 UPDATE COUPLING_THINSPECT_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="ThreadInspectResultService.getQueryComInfo" desc="查询螺纹检验废品原因">
        <![CDATA[
   SELECT T.BASENAME FAIL_TYPE_NAME
  FROM COM_BASE_INFO T
 WHERE T.SORTCODE = ?
   AND T.VALIDFLAG = '1'
        ]]>
	</query>
	<query id="ThreadInspectResultService.ProcessPlan.AddThreadingSelfcheck"
		desc="新增自检记录">
        <![CDATA[
 INSERT INTO COUPLING_THINSPECT_SELFCHECK T
  (T.TAPER,
   T.LEADS,
   T.HEIGHT,
   T.PDIAMETER_OVALITY,
   T.BROKENTHREAD,
   T.AL,
   T.RUN_OUT,
   T.CHAMFER,
   T.RESULTS,
   T.THREADFORM,
   T.RESULT_NO,
   T.PLINE_CODE,
   T.ZY_PLAN_ID,
   T.COUPLING_NO,
   T.WO_ID)
VALUES
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)  
        ]]>
	</query>


<query id="ThreadInspectResultService.ProcessPlan.lixianThreadingResult"
		desc="离线螺纹实绩">
        <![CDATA[
  UPDATE COUPLING_THINSPECT_RESULT T SET T.OFF_NUM=TO_NUMBER(NVL(T.OFF_NUM,0))+TO_NUMBER(?)  WHERE T.RESULT_NO=?  
        ]]>
	</query>
	
	<query id="ThreadInspectResultService.updatelixianofflineResult"
		desc="修改工单工序的离线状态">
        <![CDATA[
      UPDATE PLN_ZY_JG_WORKBILL
   SET IF_OUT_THREAD='1'
 WHERE WO_ID = ?
        ]]>
	</query>
	
	<query id="ThreadInspectResultService.DeleteFail"
		desc="删除螺纹检验废品">
        <![CDATA[
      DELETE FROM COUPLING_BUG T
 WHERE T.RESULT_NO = ?
   AND T.WO_ID = ?
        ]]>
	</query>
	
		<query id="ThreadInspectResultService.ProcessPlan.AddFailComInfo"
		desc="新增螺纹检验废品数据">
        <![CDATA[
    INSERT INTO COUPLING_BUG 
(RESULT_NO,
WO_ID,
FAIL_TYPE_CODE,
FAIL_TYPE_NAME,
FAIL_NUM,
FAIL_WT
) VALUES(
?,
?,
?,
?,
?,
?)
        ]]>
	</query>
	
	
	<query id="ThreadInspectResultService.ProcessPlan.unlixianThreadingResult"
		desc="撤销离线螺纹检验实绩">
        <![CDATA[
      DELETE COUPLING_THINSPECT_RESULT WHERE RESULT_NO = ?
    
        ]]>
	</query>
	
	
	<query id="ThreadInspectResultService.unlixianComInfoResult" desc="撤销ComInfo表">
		DELETE COUPLING_COM_INFO WHERE RESULT_NO = ? AND WO_ID=? AND IF_OUT_RPO = '1'
	</query>
	
	
	<query
		id="ThreadInspectResultService.unlixianofflineResult"
		desc="撤销离线表">
        <![CDATA[
         DELETE COUPLING_OFFLINE_RESULT WHERE RESULT_NO = ? 
        ]]>
	</query>
	
	
	<query id="ThreadInspectResultService.unupdatelixianofflineResult"
		desc="修改工单工序的离线状态">
        <![CDATA[
      UPDATE PLN_ZY_JG_WORKBILL
   SET IF_OUT_THREAD='0'
 WHERE WO_ID = ?
      
        ]]>
	</query>
	
	
	
	<query id="ThreadInspectResultService.unupdatelixianofflineResult2"
		desc="修改工单工序的离线状态">
        <![CDATA[
      UPDATE PLN_ZY_JG_WORKBILL
   SET IF_OUT_THREAD='1'
 WHERE WO_ID = ?
      
        ]]>
	</query>
	
	
	<query id="ThreadInspectResultService.querylixian" desc="查询螺纹检验实绩对应是否离线">
SELECT count(1) count
  FROM COUPLING_THINSPECT_RESULT T
 WHERE T.WO_ID = ?
   and t.if_all_out_work='1'
	</query>
	
	
	
	
	<query id="ThreadInspectResultService.lixianComInfoResult" desc="插入公共信息表">
		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="ThreadInspectResultService.lixianofflineResult"
		desc="新增离线表">
        <![CDATA[
         INSERT INTO COUPLING_OFFLINE_RESULT
    (RESULT_NO,
     PLINE_CODE,
     ZY_PLAN_ID,
     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)
  VALUES
    (?,
     ?,
     ?,
     ?,
     ?,
     '螺纹',
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
     ?,
     ?,
     ?,
     TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'))
        ]]>
	</query>
	<query
		id="ThreadInspectResultService.ProcessPlan.UpdateThreadingSelfcheck"
		desc="修改自检记录">
        <![CDATA[
         UPDATE COUPLING_THINSPECT_SELFCHECK T
   SET T.TAPER             = ?,
       T.LEADS           = ?,
       T.HEIGHT            = ?,
       T.PDIAMETER_OVALITY = ?,
       T.BROKENTHREAD      = ?,
       T.AL                = ?,
       T.RUN_OUT           = ?,
       T.CHAMFER           = ?,
       T.RESULTS            = ?,
       T.THREADFORM        = ?
 WHERE T.RESULT_NO = ?
   AND T.COUPLING_NO = ?
        ]]>
	</query>

	<query id="ThreadInspectResultService.ProcessPlan.GetThreadInspectResult"
		desc="根据计划号查询螺纹检验实绩">
        <![CDATA[
      SELECT (SELECT LISTAGG(T1.FAIL_TYPE_NAME || ';') WITHIN GROUP(ORDER BY FAIL_TYPE_NAME)
                  FROM (SELECT T2.FAIL_TYPE_NAME || '(' || T2.FAIL_NUM || ')' FAIL_TYPE_NAME,
                               T2.WO_ID,
                               T2.RESULT_NO
                          FROM COUPLING_BUG T2) T1
                 WHERE T1.WO_ID = T.WO_ID
                   AND T1.RESULT_NO = T.RESULT_NO) FAIL_NAME,
               T.*
          FROM COUPLING_THINSPECT_RESULT T WHERE T.WO_ID =?
        ]]>
	</query>

	<query
		id="ThreadInspectResultService.ProcessPlan.UpdateThreadInspectResult"
		desc="修改">
		<![CDATA[
 UPDATE COUPLING_THINSPECT_RESULT
   SET 
       QUALIRIED_PCS    = ?,
       REPAIRED_PCS     = ?,
       COL_SHIFT        = ?,
       COL_GROUP        = ?,
       INSPECT_PIECES   = ?,
       COL_TIME = ?,
       MEMO = ?
 WHERE RESULT_NO = ?
		]]>
	</query>

	<query id="ThreadInspectResultService.ProcessPlan.AddThreadInspectResult"
		desc="新增螺纹检验实绩">
        <![CDATA[
        INSERT INTO COUPLING_THINSPECT_RESULT (RESULT_NO, PLINE_CODE, 
QUALIRIED_PCS, REPAIRED_PCS, REPAIRED_REASON1, REPAIRED_PCS1, REPAIRED_REASON2, 
REPAIRED_PCS2, REPAIRED_REASON3, REPAIRED_PCS3, COL_MODE, COL_TIME, COL_USER, 
COL_SHIFT, COL_GROUP, INSPECT_PIECES, REPAIRED_REASON4, REPAIRED_PCS4, 
REJECTED_PCS, REJECTED_PCS1, REJECTED_REASON1, REJECTED_REASON2, REJECTED_PCS2, 
REJECTED_REASON3, REJECTED_PCS3, REJECTED_REASON4, REJECTED_PCS4, 
REJECTED_REASON5, REJECTED_PCS5, REJECTED_REASON6, REJECTED_PCS6, 
REJECTED_REASON7, REJECTED_PCS7, REJECTED_REASON8, REJECTED_PCS8,ZY_PLAN_ID,CREATE_TIME,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'),?,?,?,?,?,?)
	    
        ]]>
	</query>
	<query id="ThreadInspectResultService.queryPlanJg" desc="查询计划状态">
		<![CDATA[
		SELECT T.ZY_PLAN_STATUS,T.PLT_CU_STATUS,T.PHOS_STATUS,T.LATHE_STATUS,T.THREAD_CHK_STATUS FROM PLN_ZY_JG T WHERE T.ZY_PLAN_ID=?
		]]>
	</query>
	<query id="ThreadInspectResultService.queryLoadRESULT" desc="查询最大实绩编号 ">
	<![CDATA[
   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_THINSPECT_RESULT
   WHERE RESULT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
	]]>
	</query>
	<query id="ThreadInspectResultService.queryJcodeResult" desc="查询最大检测编号 ">
	<![CDATA[
 SELECT 'LW' ||
        LPAD(SUBSTR(NVL(MAX(T.COUPLING_NO), '0000'), -4, 4) + 1, 4, '0') AS COUPLING_NO
   FROM COUPLING_THINSPECT_SELFCHECK T
  WHERE T.RESULT_NO = ?
    AND T.WO_ID = ?
	]]>
	</query>
	
	<query id="ThreadInspectResultService.UpdatePlnInfo" desc="修改接箍公共信息 ">
	<![CDATA[
UPDATE COUPLING_COM_INFO
   SET PRO_NUM      = ?,
       PRO_WT =?,
       FAIL_NUM     = ?,
       FAIL_WT=?,
       PRO_SHIFT    = ?,
       PRO_GROUP    = ?,
       COL_OPERATOR = ?
 WHERE STATION_CODE = ? 
   AND RESULT_NO = ? 
   AND WO_ID = ?

	]]>
	</query>
	<query id="ThreadInspectResultService.queryThrePlanNumber" desc="查询螺纹检验总个数 ">
	<![CDATA[
	SELECT COUNT(1) COUNT, SUM(NVL(T.QUALIRIED_PCS, 0)) QUALIRIED_PCS,
       SUM(NVL(T.REJECTED_PCS, 0)) REJECTED_PCS
  FROM COUPLING_THINSPECT_RESULT T
 WHERE T.ZY_PLAN_ID = ?
 AND T.WO_ID=?
		]]>
	</query>
	<query id="ThreadInspectResultService.DeleteThreadingSelfcheck" desc="删除抽检记录 ">
	<![CDATA[
	DELETE COUPLING_THINSPECT_SELFCHECK  WHERE RESULT_NO = ?   AND PLINE_CODE = ?   AND ZY_PLAN_ID = ?   AND COUPLING_NO = ?
		]]>
	</query>
	<query id="ThreadInspectResultService.DeleteThreadingSelfcheck1" desc="删除螺纹实绩是删除抽检记录 ">
	<![CDATA[
	DELETE COUPLING_THINSPECT_SELFCHECK  WHERE RESULT_NO = ? 		]]>
	</query>
	<query id="ThreadInspectResultService.queryInsRestrs" desc="查询抽检记录 ">
	<![CDATA[
	SELECT COUNT(1) COUNT FROM COUPLING_THINSPECT_SELFCHECK T WHERE T.RESULT_NO=? AND T.WO_ID=?
		]]>
	</query>
	<query id="ThreadInspectResultService.queryThrRestrs" desc="查询螺纹检验记录 ">
	<![CDATA[
SELECT COUNT(1) COUNT FROM COUPLING_THINSPECT_RESULT T WHERE T.RESULT_NO=? 
		]]>
	</query>
	<query id="ThreadInspectResultService.DeleteThreadInspectResult" desc="删除螺纹检验 ">
	<![CDATA[
	 DELETE COUPLING_THINSPECT_RESULT WHERE RESULT_NO = ?
		]]>
	</query>
	<query id="ThreadInspectResultService.DeletePlnInfo" desc="删除接箍公共信息 ">
	<![CDATA[
	DELETE COUPLING_COM_INFO WHERE RESULT_NO = ?    AND STATION_CODE = ? AND WO_ID=?
		]]>
	</query>
	<query id="ThreadInspectResultService.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.THREAD_CHK_STATUS = '2' WHERE T.ZY_PLAN_ID = ? AND T.WO_ID=?;
END;
	</query>
	<query id="ThreadInspectResultService.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.THREAD_CHK_STATUS = '1' WHERE T.ZY_PLAN_ID = ? AND T.WO_ID=?;
END;
	</query>
</queryMap>