<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="加工抽检实绩">
	<query id="FrmFinalCheck.getQueryExpandResult" desc="">
        <![CDATA[
    SELECT *
  FROM MCH_FINAL_CHECK_RESULT T
 WHERE T.HEAT_PLAN_NO = ? AND BATCH_NO =? ORDER BY RESULT_NO DESC
        ]]>
	</query>

	<query id="frmEntrust.QuerTreatment" desc="">
		<![CDATA[
    SELECT T.*
  FROM MCH_FINAL_CHECK_TREATMENT T
 WHERE 1=1
        ]]>
	</query>

	<query id="FrmFinalCheck.getQueryDetail" desc="">
		<![CDATA[
    SELECT T.*, DECODE(IS_SIZE_CHECK,'1','√','') IS_SIZE_CHECK,DECODE(IS_APP_CHECK,'1','√','') IS_APP_CHECK
  FROM MCH_FINAL_CHECK_RESULT_D T
 WHERE RESULT_NO =?
 ORDER BY MEASURING_SEQ,MAT_NO,POSITION_CODE
        ]]>
	</query>

	<query id="FrmFinalCheck.getFailDetail" desc="">
		<![CDATA[

SELECT D.RESULT_NO TREATMENT_NO, M.MAT_NO, T.MEASURING_SEQ, D.FAIL_TYPE_NAME
  FROM MCH_BUG_D D, MCH_WASTE_MAT_NO M, PORT_MCH_BATCH_SAMPLE_RESULT T
 WHERE D.FAIL_BILL = M.FAIL_BILL
   AND D.FAIL_BILL_SQE = M.FAIL_BILL_SQE
   AND T.HEAT_PLAN_NO = D.HEAT_PLAN_NO
   AND T.MAT_NO = M.MAT_NO

        ]]>
	</query>


	<query id="FrmFinalCheck.getQueryDetail1" desc="">
		<![CDATA[
    SELECT T.*, DECODE(IS_SIZE_CHECK,'1','√','') IS_SIZE_CHECK,DECODE(IS_APP_CHECK,'1','√','') IS_APP_CHECK,DECODE(STATION,'1','0','3','0',STATION) REPLAY_STATION
  FROM MCH_FINAL_CHECK_RESULT_D T
 WHERE  STATION <> '0'

        ]]>
	</query>


	<query id="FrmFinalCheck.getQueryDetail2" desc="">
		<![CDATA[
    SELECT T.*, DECODE(IS_SIZE_CHECK,'1','√','') IS_SIZE_CHECK,DECODE(IS_APP_CHECK,'1','√','') IS_APP_CHECK
  FROM MCH_FINAL_CHECK_RESULT_D T
 WHERE  STATION <> '0'

        ]]>
	</query>

	<query id="FrmFinalCheck.getQueryUnPassDetail" desc="">
		<![CDATA[
 SELECT T.*,
        DECODE(IS_SIZE_CHECK, '1', '√', '') IS_SIZE_CHECK,
        DECODE(IS_APP_CHECK, '1', '√', '') IS_APP_CHECK,
        DECODE(STATION, '1', '0', '3', '0', STATION) REPLAY_STATION,
        DECODE(REPLAY_STATION,
               NULL,
               (SELECT MEASURING_SEQ
                  FROM MCH_FINAL_CHECK_RESULT       M,
                       PORT_MCH_BATCH_SAMPLE_RESULT P
                 WHERE T.MAT_NO = P.MAT_NO
                   AND M.HEAT_PLAN_NO = P.HEAT_PLAN_NO
                   AND M.RESULT_NO = T.RESULT_NO) ,
               REPLAY_MEASURING_SEQ) REPLAY_MEASURING_SEQ
   FROM MCH_FINAL_CHECK_RESULT_D T
  WHERE STATION <> '0'


        ]]>
	</query>

	getQueryUnPassDetail

	<query id="FrmFinalCheck.getQueryTreatment" desc="">
		<![CDATA[
    SELECT T.*
  FROM MCH_FINAL_CHECK_TREATMENT T WHERE 1=1

        ]]>
	</query>



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

	<query id="FrmFinalCheck.AddResult" desc="">
		<![CDATA[
	INSERT INTO MCH_FINAL_CHECK_RESULT
  (RESULT_NO,
   HEAT_PLAN_NO,
   BATCH_NO,
   PLINE_CODE,
   PLINE_NAME,
   PRO_USER,
   PRO_NUM,
   PRO_WT,
   FAIL_NUM,
   FAIL_WT,
   PRO_SHIFT,
   PRO_GROUP,
   PRO_TIME,
   JUDGE_STOVE_NO,
   MEMO,
   REPORT_PATH,
   QUALIFIED_NUM,
   QUALIFIED_WT,
   UNQUALIFIED_NUM,
   UNQUALIFIED_WT,
   CHECK_NUM,
   CHECK_WT,
   DEPARTID,
   DEPARTNAME)
VALUES
  ('#RESULT_NO#',
   '#HEAT_PLAN_NO#',
   '#BATCH_NO#',
   '#PLINE_CODE#',
   '#PLINE_NAME#',
   '#PRO_USER#',
   '#PRO_NUM#',
   '#PRO_WT#',
   '#FAIL_NUM#',
   '#FAIL_WT#',
   '#PRO_SHIFT#',
   '#PRO_GROUP#',
   TO_DATE('#PRO_TIME#', 'YYYY-MM-DD HH24:MI:SS'),
   '#JUDGE_STOVE_NO#',
   '#MEMO#',
   '#REPORT_PATH#',
   '#QUALIFIED_NUM#',
   '#QUALIFIED_WT#',
   '#UNQUALIFIED_NUM#',
   '#UNQUALIFIED_WT#',
   '#CHECK_NUM#',
   '#CHECK_WT#',
    '#DEPARTID#',
   '#DEPARTNAME#')
			]]>
	</query>

_
	<query id="FrmFinalCheck.SelectCheckMatNo" desc="">
		<![CDATA[
     SELECT T.*,  DECODE(T.STATION,'3','TRUE','FALSE') CHK
       FROM (SELECT RESULT_NO,
                    MAT_NO,
                    MEASURING_SEQ,
                    BAR_CODE,
                    ACT_LEN,
                    ACT_WEIGHT,
                    MAX(STATION) STATION,
                    MAX(TREATMENT_NO) TREATMENT_NO
               FROM (SELECT M.*, D.STATION, D.TREATMENT_NO
                       FROM MCH_FINAL_CHECK_RESULT_MAT_NO M
                       LEFT JOIN MCH_FINAL_CHECK_RESULT_D D
                         ON M.RESULT_NO = D.RESULT_NO
                        AND M.MAT_NO = D.MAT_NO
                        AND ROWNUM = 1
                      WHERE M.RESULT_NO = ?)
              GROUP BY RESULT_NO,
                       MAT_NO,
                       MEASURING_SEQ,
                       BAR_CODE,
                       ACT_LEN,
                       ACT_WEIGHT) T
      WHERE (TREATMENT_NO = ? OR TREATMENT_NO IS NULL)
      ORDER BY MEASURING_SEQ, MAT_NO

			]]>
	</query>

	<query id="FrmFinalCheck.AddMatNo" desc="">
		<![CDATA[
		INSERT INTO MCH_FINAL_CHECK_RESULT_MAT_NO
  (RESULT_NO, MAT_NO, MEASURING_SEQ, BAR_CODE, ACT_LEN, ACT_WEIGHT)
  VALUES (?, ?, ?, ?, ?, ?)


			]]>
	</query>

	<query id="FrmFinalCheck.UpdateMatNoStatus" desc="">
		<![CDATA[
		UPDATE  PORT_MCH_BATCH_SAMPLE_RESULT T SET IS_FINALCHECK = '1'  WHERE heat_PLAN_NO =? AND MAT_NO = ?
			]]>
	</query>

	<query id="FrmFinalCheck.UpdateMatNoStatus1" desc="">
		<![CDATA[UPDATE PORT_MCH_BATCH_SAMPLE_RESULT T
   SET IS_FINALCHECK = '0'
 WHERE HEAT_PLAN_NO = ?
   AND MAT_NO = ?
			]]>
	</query>

	<query id="FrmFinalCheck.AddResultD" desc="">
		<![CDATA[
		INSERT INTO MCH_FINAL_CHECK_RESULT_D
  (RESULT_NO,
   MAT_NO,
   MEASURING_SEQ,
   BAR_CODE,
   POSITION_CODE,
   UNPASS_CODE,
   UNPASS_NAME,
   UNPASS_MEMO,
   STATION,
   TREATMENT_CODE,
   TREATMENT_NAME,
   POSITION_NAME,
   RESPONSIBLE_CODE,
   RESPONSIBLE_NAME,
   TREATMENT_CODE1,
   TREATMENT_NAME1,IS_SIZE_CHECK,IS_APP_CHECK,REPLAY_STATION,REPLAY_MEASURING_SEQ)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?)
			]]>
	</query>


	<query id="FrmFinalCheck.UpdateResultD" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_RESULT_D
   SET REPLAY_STATION = ?, SCRAP_CODE = ?, SCRAP_NAME = ? , TREATMENT_NO =?, REPLAY_MEASURING_SEQ =?
 WHERE RESULT_NO = ?
   AND MAT_NO = ?
   AND NVL(MEASURING_SEQ, -1) = NVL(?, -1)
   AND NVL(POSITION_CODE, '/') = NVL(?, '/')
   AND NVL(TREATMENT_CODE, '/') = NVL(?, '/')
   AND NVL(RESPONSIBLE_CODE, '/') = NVL(?, '/')

			]]>
	</query>

	<query id="FrmFinalCheck.AddResultT" desc="">
		<![CDATA[
INSERT INTO MCH_FINAL_CHECK_TREATMENT
  (TREATMENT_NO,
   RESULT_NO,
   RESPONSIBLE_CODE,
   RESPONSIBLE_NAME,
   UNQUALIFIED_NUM,
   TREATMENT_CODE,
   TREATMENT_NAME,
   PRO_TIME,
   PRO_USER,
   PRO_SHIFT,
   PRO_GROUP,
   PLINE_CODE,
   PLINE_NAME,
   PRODUCCODE,
   PRODUCNAME,
   STEELCODE,
   STEELNAME,
   GRADECODE,
   GRADENAME,
   MODEL_CODE,
   MODEL_DESC,
   STD_CODE,
   STD_NAME,
   STD_STYLE,
   STD_STYLE_DESC,
   SPEC_CODE,
   SPEC_NAME,
   HEAT_PLAN_NO,
   JUDGE_STOVE_NO,
   BATCH_NO,
   ORDER_NO)
  SELECT (SELECT ? || TO_CHAR(SYSDATE, 'yyyyMM') ||
                 LPAD(NVL(MAX(TO_NUMBER(SUBSTR(TREATMENT_NO,
                                               LENGTH(TREATMENT_NO) - 2))),
                          0) + 1,
                      3,
                      '0') TREATMENT_NO
            FROM MCH_FINAL_CHECK_TREATMENT
           WHERE TREATMENT_NO LIKE ? || TO_CHAR(SYSDATE, 'yyyyMM') || '___'),
         ?,
         ?,
         ?,
         ?,
         ?,
         ?,
         R.PRO_TIME,
         R.PRO_USER,
         R.PRO_SHIFT,
         R.PRO_GROUP,
         R.PLINE_CODE,
         R.PLINE_NAME,
         T.PRODUCCODE,
         T.PRODUCNAME,
         T.STEELCODE,
         T.STEELNAME,
         T.GRADECODE,
         T.GRADENAME,
         T.MODEL_CODE,
         T.MODEL_DESC,
         T.STD_CODE,
         T.STD_NAME,
         T.STD_STYLE,
         T.STD_STYLE_DESC,
         T.SPEC_CODE,
         T.SPEC_NAME,
         R.HEAT_PLAN_NO,
         R.JUDGE_STOVE_NO,
         R.BATCH_NO,
         T.ORDER_NO || '/' || T.ORDER_SEQ
    FROM PLN_ZY_JGX_M T, MCH_FINAL_CHECK_RESULT R
   WHERE T.HEAT_PLAN_NO = R.HEAT_PLAN_NO
     AND R.RESULT_NO = ?
			]]>
	</query>


	<query id="FrmFinalCheck.UpdateTreatmentNo" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_RESULT_D T
   SET TREATMENT_NO =
       (SELECT TREATMENT_NO
          FROM MCH_FINAL_CHECK_TREATMENT
         WHERE RESULT_NO = T.RESULT_NO
           AND NVL(TREATMENT_CODE, '/') = NVL(T.TREATMENT_CODE, '/')
           AND NVL(RESPONSIBLE_CODE, '/') = NVL(T.RESPONSIBLE_CODE, '/')
           AND ROWNUM = 1)
 WHERE RESULT_NO = ?
   AND NVL(TREATMENT_CODE, '/') = NVL(?, '/')
   AND NVL(RESPONSIBLE_CODE, '/') = NVL(?, '/')
   AND STATION <> '0'

		]]>
	</query>


	<query id="FrmFinalCheck.DeleteResult" desc="">
		<![CDATA[
DELETE MCH_FINAL_CHECK_RESULT WHERE RESULT_NO = ?
		]]>
	</query>


	<query id="FrmFinalCheck.DetailMatNo" desc="">
		<![CDATA[
DELETE MCH_FINAL_CHECK_RESULT_MAT_NO WHERE RESULT_NO = ?
		]]>
	</query>

	<query id="FrmFinalCheck.DeleteDetailResult" desc="">
		<![CDATA[
DELETE MCH_FINAL_CHECK_RESULT_D WHERE RESULT_NO = ?
		]]>
	</query>


	<query id="FrmFinalCheck.DeleteTreatMent" desc="">
		<![CDATA[
DELETE MCH_FINAL_CHECK_TREATMENT WHERE RESULT_NO = ?
		]]>
	</query>

	<query id="FrmFinalCheck.getTreatMentStatus" desc="">
		<![CDATA[
SELECT MAX(APPROVAL_STATUS) APPROVAL_STATUS FROM  MCH_FINAL_CHECK_TREATMENT WHERE RESULT_NO = ?
		]]>
	</query>


	<query id="FrmFinalCheck.UpdateTreatmentStatus" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_TREATMENT
   SET TREATMENT_REPLY = ?, REPLY_NAME = ?, REPLY_TIME = SYSDATE, DEPARTID=?,DEPARTNAME=?,APPROVAL_STATUS='1',
     FAIL_NUM =?, FAIL_WT=?,REPLY_SHIFT =?,REPLY_GROUP= ?
 WHERE TREATMENT_NO = ?

		]]>
	</query>

	<query id="FrmFinalCheck.UpdateTreatmentStatus1" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_TREATMENT
   SET TREATMENT_REPLY = ?, REPLY_NAME = ?, REPLY_TIME = null, DEPARTID='',DEPARTNAME ='',APPROVAL_STATUS='0', FAIL_NUM =0, FAIL_WT=0,REPLY_SHIFT ='',REPLY_GROUP= ''
 WHERE TREATMENT_NO = ?

		]]>
	</query>

	<query id="FrmFinalCheck.UpdateTreatmentStatus2" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_TREATMENT
   SET APPROVAL_NOTE = ?, APPROVAL_NAME = ?, APPROVAL_TIME = SYSDATE,APPROVAL_STATUS='2'
 WHERE TREATMENT_NO = ?

		]]>
	</query>

	<query id="FrmFinalCheck.UpdateTreatmentStatus3" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_TREATMENT
   SET APPROVAL_NOTE = '', APPROVAL_NAME = '', APPROVAL_TIME = null,APPROVAL_STATUS='1'
 WHERE TREATMENT_NO = ?

		]]>
	</query>

	<query id="FrmFinalCheck.UpdateComInfo" desc="">
		<![CDATA[

UPDATE MCH_COM_INFO M
   SET (FAIL_NUM, FAIL_WT) =
       (SELECT SUM(FAIL_NUM), SUM(FAIL_WT)
          FROM MCH_FINAL_CHECK_TREATMENT
         WHERE RESULT_NO = M.RESULT_NO)
 WHERE RESULT_NO = ?
		]]>
	</query>

	<query id="FrmFinalCheck.UpdateDetail" desc="">
		<![CDATA[
UPDATE MCH_FINAL_CHECK_RESULT_D
   SET REPLAY_STATION = DECODE(STATION, '0', '0', '2', '2', '')
 WHERE RESULT_NO = ?
   AND TREATMENT_NO = ?
		]]>
	</query>

	<query id="FrmFinalCheck.CheckStatus" desc="">
		<![CDATA[
SELECT (SELECT COUNT(1)
          FROM PORT_MCH_BATCH_SAMPLE_RESULT
         WHERE HEAT_PLAN_NO = ?
           AND BATCH_NO = ?
           AND IS_FINALCHECK = '0') +
       (SELECT COUNT(1)
          FROM MCH_FINAL_CHECK_TREATMENT T
         WHERE RESULT_NO IN (SELECT RESULT_NO
                               FROM MCH_FINAL_CHECK_RESULT
                              WHERE HEAT_PLAN_NO = ?
                                AND BATCH_NO = ?)
           AND APPROVAL_STATUS <> '2') NUM
  FROM DUAL


		]]>
	</query>



	<query id="FrmFinalCheck.DeleteCheckMatNo" desc="">
		<![CDATA[
DELETE FROM MCH_FINAL_CHECK_RESULT_D
 WHERE STATION = '3'
   AND RESULT_NO = ?
   AND TREATMENT_NO = ?

		]]>
	</query>

	<query id="FrmFinalCheck.AddCheckMatNo" desc="">
		<![CDATA[
INSERT INTO MCH_FINAL_CHECK_RESULT_D
  (RESULT_NO,
   MAT_NO,
   MEASURING_SEQ,
   BAR_CODE,
   POSITION_CODE,
   UNPASS_CODE,
   UNPASS_NAME,
   UNPASS_MEMO,
   STATION,
   TREATMENT_CODE,
   TREATMENT_NAME,
   POSITION_NAME,
   RESPONSIBLE_CODE,
   RESPONSIBLE_NAME,
   TREATMENT_CODE1,
   TREATMENT_NAME1,
   IS_SIZE_CHECK,
   IS_APP_CHECK,
   REPLAY_STATION,
   SCRAP_CODE,
   SCRAP_NAME,
   TREATMENT_NO)
VALUES
  (?,
   ?,
   ?,
   ?,
   '',
   '',
   '',
   '',
   '3',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   '',
   ?)
		]]>
	</query>



	<query id="FrmFinalCheck.queryTreatmentNo" desc="查询拆分处置单的新处置单">
		<![CDATA[
		  SELECT ? || '-' || LPAD(NVL(MAX(TO_NUMBER(SUBSTR(TREATMENT_NO,
                                                   LENGTH(TREATMENT_NO) - 1))),
                              0) + 1,
                          2,
                          '0') TREATMENT_NO
    FROM MCH_FINAL_CHECK_TREATMENT
   WHERE TREATMENT_NO LIKE ? || '-' || '__'

			]]>
	</query>

	<query id="FrmFinalCheck.SplitTreatment" desc="新增拆分处置单">
		<![CDATA[
		INSERT INTO MCH_FINAL_CHECK_TREATMENT
  (TREATMENT_NO,
   RESULT_NO,
   RESPONSIBLE_CODE,
   RESPONSIBLE_NAME,
   UNQUALIFIED_NUM,
   UNQUALIFIED_WT,
   TREATMENT_REPLY,
   APPROVAL_NOTE,
   APPROVAL_STATUS,
   TREATMENT_NAME,
   TREATMENT_CODE,
   PRO_TIME,
   PRO_USER,
   PRO_SHIFT,
   PRO_GROUP,
   PLINE_CODE,
   PLINE_NAME,
   DEPARTID,
   DEPARTNAME,
   REPLY_NAME,
   REPLY_TIME,
   PRODUCCODE,
   PRODUCNAME,
   STEELCODE,
   STEELNAME,
   GRADECODE,
   GRADENAME,
   MODEL_CODE,
   MODEL_DESC,
   STD_CODE,
   STD_NAME,
   STD_STYLE,
   STD_STYLE_DESC,
   SPEC_CODE,
   SPEC_NAME,
   APPROVAL_NAME,
   APPROVAL_TIME,
   HEAT_PLAN_NO,
   JUDGE_STOVE_NO,
   BATCH_NO,
   ORDER_NO)
  SELECT ?,
         RESULT_NO,
         RESPONSIBLE_CODE,
         RESPONSIBLE_NAME,
         UNQUALIFIED_NUM,
         UNQUALIFIED_WT,
         TREATMENT_REPLY,
         APPROVAL_NOTE,
         APPROVAL_STATUS,
         TREATMENT_NAME,
         TREATMENT_CODE,
         PRO_TIME,
         PRO_USER,
         PRO_SHIFT,
         PRO_GROUP,
         PLINE_CODE,
         PLINE_NAME,
         DEPARTID,
         DEPARTNAME,
         REPLY_NAME,
         REPLY_TIME,
         PRODUCCODE,
         PRODUCNAME,
         STEELCODE,
         STEELNAME,
         GRADECODE,
         GRADENAME,
         MODEL_CODE,
         MODEL_DESC,
         STD_CODE,
         STD_NAME,
         STD_STYLE,
         STD_STYLE_DESC,
         SPEC_CODE,
         SPEC_NAME,
         APPROVAL_NAME,
         APPROVAL_TIME,
         HEAT_PLAN_NO,
         JUDGE_STOVE_NO,
         BATCH_NO,
         ORDER_NO
    FROM MCH_FINAL_CHECK_TREATMENT
    WHERE TREATMENT_NO =?
			]]>
	</query>

	<query id="FrmFinalCheck.UpdateTreatmentNoNum" desc="更新处置单不合支数">
		<![CDATA[
	UPDATE MCH_FINAL_CHECK_TREATMENT T
   SET (UNQUALIFIED_NUM, UNQUALIFIED_WT) =
       (SELECT COUNT(1), SUM(ACT_WEIGHT)
          FROM MCH_FINAL_CHECK_RESULT_D D, MCH_FINAL_CHECK_RESULT_MAT_NO M
         WHERE D.RESULT_NO = M.RESULT_NO
           AND D.MAT_NO = M.MAT_NO
           AND D.RESULT_NO = T.RESULT_NO
           AND D.TREATMENT_NO = T.TREATMENT_NO
           AND D.STATION = '1')
 WHERE T.TREATMENT_NO = ?

			]]>
	</query>


</queryMap>