<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="加工拧接实绩">
	<query id="FrmCoupMakeupResult.getQueryExpandResult" desc="查询拧接实绩">
        <![CDATA[
    SELECT *
  FROM MCH_TWISTINGLY_RESULT T
 WHERE T.HEAT_PLAN_NO = ? AND BATCH_NO =?
        ]]>
	</query>
		<query id="FrmCoupMakeupResult.getQueryExpandResultStuts" desc="查询相同炉计划ID下拧接实绩状态">
        <![CDATA[
   SELECT B.STATION_STATUS
  FROM MCH_TWISTINGLY_RESULT T INNER JOIN MCH_COM_INFO B ON T.RESULT_NO=B.RESULT_NO
 WHERE T.HEAT_PLAN_NO = ? AND T.PLINE_CODE = ?
        ]]>
	</query>
	
	<query id="FrmCoupMakeupResult.getQueryExpandResult1" desc="查询拧接实绩合格支数的和">
        <![CDATA[
   SELECT NVL(SUM(T.PRO_NUM), 0) PRO_NUM FROM MCH_TWISTINGLY_RESULT T
   WHERE T.HEAT_PLAN_NO = ?
        ]]>
	</query>
	<query id="FrmCoupMakeupResult.detelefailnum" desc="删除废品缺陷">
		<![CDATA[
DELETE MCH_BUG_D WHERE RESULT_NO = ? and HEAT_PLAN_NO = ? and PLINE_CODE = ?	
		]]>
	</query>
		<query id="FrmCoupMakeupResult.querymaxsqe" desc="查询最大的离线序号">
	 <![CDATA[ 
SELECT ? ||
       LPAD(SUBSTR(NVL(MAX(T.RESULT_SQE), '00'), -2, 2) + 1, 2, '0') AS RESULT_SQE
  FROM MCH_OFFLINE_RESULT_D T
 WHERE  T.HEAT_PLAN_NO = ? and t.PLINE_CODE =?
	  ]]>
	</query>

	<query id="FrmCoupMakeupResult.QueryCouplingMatDeal" desc="查询接箍领用记录">
		<![CDATA[
     SELECT * FROM COUPLING_MAT_DEAL WHERE DEAL_TYPE_CODE='800801' AND OUT_FLAG='2' and handle_flag = '0'
     and pline_code = 'C110' --AND (ORD_LN_DLY_PK=? or 1=1)
        ]]>
	</query>
	
	<query id="FrmCoupMakeupResult.queryGxPosition" desc="查询产线下工序的位置">
		<![CDATA[
SELECT LENGTH(SUBSTR(T.STATION_NAMES, 0, INSTR(STATION_NAMES, '拧接'))) -
       LENGTH(REPLACE(SUBSTR(T.STATION_NAMES,0,INSTR(STATION_NAMES, '拧接')), ';', '')) + 1  CNUM
  FROM MCH_COM_SETPLINE T
 WHERE T.PLINE_CODE = ?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.AddExpandResult" desc="新增拧接实绩">
		<![CDATA[
		INSERT INTO MCH_TWISTINGLY_RESULT (RESULT_NO, HEAT_PLAN_NO, ZY_BATCH_ID, 
PRO_PLAN_ID, GX_PLAN_NO, PLINE_CODE, PLINE_NAME,  
 PRO_NUM, PRO_WT, FAIL_NUM, FAIL_WT,FAIL_BILL, 
 OFFLINE_NUM, OFFLINE_WT, RE_NUM, RE_WT, MONITORDEMAND, 
IF_MONITOR_RCL, PRODUCER, PRDCR_NO, PRODUCER_TIME, RRO_TIME, PRO_SHIFT, 
PRO_GROUP, COL_MODE, CREATE_TIME,PIPE_END_MF,COUPLING_NUM,J_VALUE_MIN,J_VALUE_MAX,
TORQUES_SET_MIN,TORQUES_SET_MAX,TORQUES_MIN,TORQUES_OPT,TORQUES_MAX,TORQUES_CURVE,SPEED_CURVE,
SCREWOIL_TYPE,SCREWOIL_BACHNO,SCREWOIL_NUM,COUPLING_HEAT_NO,COUPLING_LOT_NO,CREATET_USER,OUTNUM_CUT,LENGTH_IN,LENGTHMAX_IN,LENGTHMIN_IN) 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="FrmCoupMakeupResult.AddComInfoResult1" desc="修改材料状态和工序编码">
		<![CDATA[
UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T SET T.MAT_STATUS=?,T.OP_PROCESS=?
WHERE T.HEAT_PLAN_NO=? AND T.MAT_NO=?
			]]>
	</query>

	<query id="FrmCoupMakeupResult.qureyGxComInfo" desc="查询工序是否是结炉状态">
		<![CDATA[
SELECT DISTINCT STATION_STATUS
  FROM MCH_COM_INFO
 WHERE HEAT_PLAN_NO = ?
   AND PLINE_CODE = ?
   AND STATION_CODE = ?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.UpdatePln1" desc="撤销修改计划表状态">
		<![CDATA[
 UPDATE PLN_ZY_JGX_M
    SET  PER_STATUS = ?
  WHERE HEAT_PLAN_NO = ?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.queryExpandMaxRESULT" desc="查询最大实绩编号">
		<![CDATA[
SELECT ? ||
       LPAD(SUBSTR(NVL(MAX(T.RESULT_NO), '000000'), -6, 6) + 1, 6, '0') AS RESULT_NO
  FROM MCH_TWISTINGLY_RESULT T
 WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') = ?
   AND T.PLINE_CODE = ?
		]]>
	</query>
	<query id="FrmCoupMakeupResult.queryExpandNUM" desc="查询管号队列里合格的材料号">
		<![CDATA[
	SELECT T1.MAT_NO
  FROM (SELECT T.MAT_NO
          FROM PORT_MCH_BATCH_SAMPLE_RESULT T
         WHERE T.MAT_STATUS = '00'
           AND T.IS_SAMPLE_PIPE='0'
           AND T.HEAT_PLAN_NO = ?
         ORDER BY T.MAT_NO ASC) T1
 WHERE ROWNUM<?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.deleteComInfoResult" desc="删除公共信息">
		<![CDATA[
		DELETE MCH_COM_INFO WHERE RESULT_NO = ?		
		]]>
	</query>
	<query id="FrmCoupMakeupResult.deleteVrpExpandResult" desc="删除拧接实绩">
		<![CDATA[
		DELETE MCH_TWISTINGLY_RESULT WHERE RESULT_NO = ?		
		]]>
	</query>

	<query id="FrmCoupMakeupResult.UpdatePln" desc="新增修改计划表状态">
		<![CDATA[
 UPDATE PLN_ZY_JGX_M
    SET  PER_STATUS = '50'
  WHERE HEAT_PLAN_NO = ?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.queryExpandFailNUM1" desc="查询工序废品数量">
		<![CDATA[
		SELECT NVL(SUM(T.FAIL_NUM),0) FAIL_NUM FROM MCH_TWISTINGLY_RESULT T
WHERE  T.HEAT_PLAN_NO=? 
			]]>
	</query>
	<query id="FrmCoupMakeupResult.queryExpandNUM2" desc="查询废品材料信息">
		<![CDATA[
	SELECT T1.MAT_NO
  FROM (SELECT T.MAT_NO
          FROM PORT_MCH_BATCH_SAMPLE_RESULT T
         WHERE T.MAT_STATUS = '10'
           AND T.HEAT_PLAN_NO = ?
             AND T.OP_PROCESS=?
         ORDER BY T.MAT_NO ASC) T1
 WHERE ROWNUM<?
			]]>
	</query>
		<query id="FrmCoupMakeupResult.queryExpandJfailNum" desc="查询废品材料信息">
		<![CDATA[
	SELECT T1.MAT_NO
  FROM (SELECT T.MAT_NO
          FROM PORT_MCH_BATCH_SAMPLE_RESULT T
         WHERE T.MAT_STATUS = '15'
           AND T.HEAT_PLAN_NO = ?
             AND T.OP_PROCESS=?
         ORDER BY T.MAT_NO ASC) T1
 WHERE ROWNUM<?
			]]>
	</query>
	<query id="FrmCoupMakeupResult.updateVrpExpandResult" desc="修改拧接实绩">
		<![CDATA[		
	UPDATE MCH_TWISTINGLY_RESULT
   SET PRO_NUM        = ?,
       PRO_WT         = ?,
       FAIL_NUM       = ?,
       FAIL_WT        = ?,
       FAIL_BILL    = ?,
      
       PIPE_END_MF   = ?,
       COUPLING_HEAT_NO = ?,
       COUPLING_LOT_NO  = ?,
       COUPLING_NUM   = ?,
       J_VALUE_MIN   = ?,
       J_VALUE_MAX   = ?,
       TORQUES_SET_MIN = ?,
       TORQUES_SET_MAX = ?,
       TORQUES_MIN   = ?,
       TORQUES_OPT   = ?,
       TORQUES_MAX   = ?,
       TORQUES_CURVE  = ?,
       SPEED_CURVE    = ?,
       SCREWOIL_TYPE   = ?,
       SCREWOIL_BACHNO = ?,
       SCREWOIL_NUM   = ?,
       
       PRODUCER       = ?,
       PRODUCER_TIME  = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       RRO_TIME      = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       PRO_SHIFT     = ?,
       PRO_GROUP     = ?,
       UPDATE_TIME    = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       UPDATE_NAME    = ?
 WHERE RESULT_NO = ?  
			]]>
	</query>
	<query id="FrmCoupMakeupResult.queryExpandFailNUM" desc="查询管号队列废品数量">
		<![CDATA[
		SELECT NVL(SUM(T.ACT_COUNT),0) ACT_COUNT
  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
 WHERE T.MAT_STATUS = '10'
   AND T.HEAT_PLAN_NO = ?
   AND T.OP_PROCESS = ?
		
			]]>
	</query>
	<query id="FrmCoupMakeupResult.updateComInfoResult" desc="修改公共信息">
		<![CDATA[
UPDATE MCH_COM_INFO
   SET PRODUCER      = ?,
       PRODUCER_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       PRO_NUM       = ?,
       PRO_WT        = ?,
       FAIL_NUM      = ?,
       FAIL_WT       = ?,
       RRO_TIME      = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
       PRO_SHIFT     = ?,
       PRO_GROUP     = ?
 WHERE RESULT_NO = ?
		]]>
	</query>
	<query id="FrmCoupMakeupResult.qureyGxLxCount" desc="查询是否离线">
		<![CDATA[
		SELECT COUNT(1) COUNT
  FROM PORT_MCH_BATCH_SAMPLE_RESULT T
 WHERE T.HEAT_PLAN_NO =?
   AND T.PLINE_CODE =?
   AND T.OP_PROCESS = ?
    AND T.MAT_STATUS='20'
   AND T.LEVE_LOG<>'00'
			]]>
	</query>


	<query id="FrmCoupMakeupResult.queryResultNo" 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  MCH_TWISTINGLY_RESULT
   WHERE RESULT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMMDD') || '______'
			]]>
	</query>

	<query id="FrmCoupMakeupResult.doUpdateCouplingNum" desc="修改接箍个数">
		<![CDATA[
		UPDATE MCH_TWISTINGLY_RESULT SET COUPLING_NUM = '#COUPLING_NUM#'
		WHERE RESULT_NO = '#RESULT_NO#' AND JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#' AND BATCH_NO = '#BATCH_NO#'
		]]>
	</query>
	<query id="FrmCoupMakeupResult.AddResult" desc="增加实绩">
		<![CDATA[

   INSERT INTO MCH_TWISTINGLY_RESULT
     (RESULT_NO,
      HEAT_PLAN_NO,
      BATCH_NO,
      PLINE_CODE,
      PLINE_NAME,
      IF_MONITOR_RCL,
      PRDCR_NO,
      PRODUCER,
      PRODUCER_TIME,
      OUTNUM_CUT,
      PRO_NUM,
      PRO_WT,
      FAIL_NUM,
      FAIL_WT,
      PRO_SHIFT,
      PRO_GROUP,
      PRO_USER,
      PRO_TIME,
      JUDGE_STOVE_NO,
       PIPE_END_MF,
   COUPLING_HEAT_NO,
   COUPLING_LOT_NO,
   COUPLING_NUM,
   COUPLING_WT,
   JVALUE_MIN,
   JVALUE_MAX,
   TORQUES_SET_MIN,
   TORQUES_SET_MAX,
   TORQUES_MIN,
   TORQUES_OPT,
   TORQUES_MAX,
   TORQUES_CURVE,
   SPEED_CURVE,
   SCREWOIL_TYPE,
   SCREWOIL_BACHNO,
   SCREWOIL_NUM,
    TOPQUALIFIED,
   TURNING_TORQUES_MAX,
   TURNING_TORQUES_MIN,
   QUALIFIED_NUM,
   QUALIFIED_WT,
   RE_PRO_NUM,
   RE_PRO_WT,
   MEMO,
   RESPONSIBLE,
   TORQUES_UNIT,
   FINAL_QUALIFIED_NUM,
   FINAL_QUALIFIED_WT,
   REPORT_PATH)
   VALUES
     ('#RESULT_NO#',
      '#HEAT_PLAN_NO#',
      '#BATCH_NO#',
      '#PLINE_CODE#',
      '#PLINE_NAME#',
      '#IF_MONITOR_RCL#',
      '#PRDCR_NO#',
      '#PRODUCER#',
      '#PRODUCER_TIME#',
      '#OUTNUM_CUT#',
      '#PRO_NUM#',
      '#PRO_WT#',
      '#FAIL_NUM#',
      '#FAIL_WT#',
      '#PRO_SHIFT#',
      '#PRO_GROUP#',
      '#PRO_USER#',
      TO_DATE('#PRO_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
      '#JUDGE_STOVE_NO#',
       '#PIPE_END_MF#',
   '#COUPLING_HEAT_NO#',
   '#COUPLING_LOT_NO#',
   '#COUPLING_NUM#',
   '#COUPLING_WT#',
   '#JVALUE_MIN#',
   '#JVALUE_MAX#',
   '#TORQUES_SET_MIN#',
   '#TORQUES_SET_MAX#',
   '#TORQUES_MIN#',
   '#TORQUES_OPT#',
   '#TORQUES_MAX#',
   '#TORQUES_CURVE#',
   '#SPEED_CURVE#',
   '#SCREWOIL_TYPE#',
   '#SCREWOIL_BACHNO#',
   '#SCREWOIL_NUM#',
    '#TOPQUALIFIED#',
    '#TURNING_TORQUES_MAX#',
    '#TURNING_TORQUES_MIN#',
    '#QUALIFIED_NUM#',
    '#QUALIFIED_WT#',
    '#RE_PRO_NUM#',
    '#RE_PRO_WT#',
    '#MEMO#',
    '#RESPONSIBLE#',
    '#TORQUES_UNIT#',
    '#FINAL_QUALIFIED_NUM#',
    '#FINAL_QUALIFIED_WT#',
    '#REPORT_PATH#')
			]]>
	</query>

	<query id="FrmCoupMakeupResult.AddDetailResult" desc="增加实绩">
		<![CDATA[
 INSERT INTO MCH_TWISTINGLY_RESULT_D(
        RESULT_NO,
        SEQ,
        COUPLING_STOVE_NO,
        LOT_NO,
        COUPLING_NUM,
        HEAT_PLAN_NO,
        PLINE_CODE,
        PLINE_NAME,
        BATCH_NO,
        JUDGE_STOVE_NO,
        COUPLING_WT,
        DEAL_ORDE,
        WO_ID,
        COUPLING_FAIL_NUM,
        COUPLING_FAIL_WT)
 VALUES(
        '#RESULT_NO#',
        ?,
        ?,
       ?,
       ?,
        '#HEAT_PLAN_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#BATCH_NO#',
        '#JUDGE_STOVE_NO#',
       ?,
       ?,
       ?,
       ?,
       ?)

			]]>
	</query>

	<query id="FrmCoupMakeupResult.AddDetailResult1" desc="增加实绩">
		<![CDATA[
 INSERT INTO MCH_TWISTINGLY_RESULT_D(
        RESULT_NO,
        SEQ,
        COUPLING_STOVE_NO,
        LOT_NO,
        COUPLING_NUM,
        HEAT_PLAN_NO,
        PLINE_CODE,
        PLINE_NAME,
        BATCH_NO,
        JUDGE_STOVE_NO,
        COUPLING_WT,
        DEAL_ORDE,
        WO_ID,
        COUPLING_FAIL_NUM,
        COUPLING_FAIL_WT)
 VALUES(
        '#RESULT_NO#',
        (SELECT nvl(MAX(SEQ),0) + 1 FROM MCH_TWISTINGLY_RESULT_D WHERE RESULT_NO = '#RESULT_NO#'),
        ?,
       ?,
       ?,
        '#HEAT_PLAN_NO#',
        '#PLINE_CODE#',
        '#PLINE_NAME#',
        '#BATCH_NO#',
        '#JUDGE_STOVE_NO#',
       ?,
       ?,
       ?,
       ?,
       ?)

			]]>
	</query>

	<query id="FrmCoupMakeupResult.DeleteResult" desc="删除实绩">
		<![CDATA[
DELETE FROM MCH_TWISTINGLY_RESULT WHERE RESULT_NO =?

			]]>
	</query>

	<query id="FrmCoupMakeupResult.DeleteDetailResult" desc="删除实绩">
		<![CDATA[
DELETE FROM MCH_TWISTINGLY_RESULT_D WHERE RESULT_NO =?

			]]>
	</query>

	<query id="FrmCoupMakeupResult.QueryDetail" desc="">
		<![CDATA[
SELECT * FROM MCH_TWISTINGLY_RESULT_D T WHERE 1=1
        ]]>
	</query>

	<query id="FrmCoupMakeupResult.UpdatePath" desc="更新报告路径">
		<![CDATA[
UPDATE MCH_TWISTINGLY_RESULT SET REPORT_PATH = ? WHERE RESULT_NO =?

			]]>
	</query>

	<query id="FrmCoupMakeupResult.UpdateCouplingDeal" desc="更新接箍领用出库">
		<![CDATA[
UPDATE COUPLING_MAT_DEAL T
   SET USED_NUM      = NVL(USED_NUM, 0) + ?,
       USED_WT       = NVL(USED_WT, 0) + ?,
       FAILL_NUM     = NVL(FAILL_NUM, 0) + ?,
       FAILL_WT      = NVL(FAILL_WT, 0) + ?,
       T.HANDLE_FLAG = CASE
                         WHEN NVL(T.DEAL_NUM, 0) - NVL(T.USED_NUM, 0) -
                              NVL(T.FAILL_NUM, 0) - NVL(T.BACK_NUM, 0) -
                              NVL(?, 0) - NVL(?, 0) = 0 THEN
                          '1'
                         ELSE
                          '0'
                       END
 WHERE DEAL_ORDE = ?
			]]>
	</query>


	<query id="FrmCoupMakeupResult.UpdateCouplingDeal1" desc="更新接箍领用出库">
		<![CDATA[
UPDATE COUPLING_MAT_DEAL T
   SET USED_NUM      = NVL(USED_NUM, 0) - ?,
       USED_WT       = NVL(USED_WT, 0) - ?,
       FAILL_NUM     = NVL(FAILL_NUM, 0) - ?,
       FAILL_WT      = NVL(FAILL_WT, 0) - ?,
       T.HANDLE_FLAG = CASE
                         WHEN NVL(T.DEAL_NUM, 0) - NVL(T.USED_NUM, 0) -
                              NVL(T.FAILL_NUM, 0) - NVL(T.BACK_NUM, 0) +
                              NVL(?, 0) + NVL(?, 0) = 0 THEN
                          '1'
                         ELSE
                          '0'
                       END
 WHERE DEAL_ORDE = ?
			]]>
	</query>

	<query id="FrmCoupMakeupResult.QueryRemainQty" desc="查询接箍领用出库剩余支">
		<![CDATA[
SELECT NVL(NVL(DEAL_NUM,0)- NVL(USED_NUM,0)-NVL(FAILL_NUM,0) -NVL(BACK_NUM,0),0) REMAIN  FROM COUPLING_MAT_DEAL WHERE  DEAL_ORDE = ?

			]]>
	</query>




</queryMap>