<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="复取样实绩操作">
	
	<query id="FrmMilReSample.getFrmMilReSample" desc="查询">
    <![CDATA[
      select REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '') JUDGE_STOVE_NO,
       T1.LOT_NO,
       T1.PLINE_CODE,
       (SELECT A.PLINE_NAME
          FROM COM_BASE_PLINE A
         WHERE A.PLINE_CODE = T1.PLINE_CODE) PLINE_CODE1,
       MAX(P.RE_GET_SAMPLE_STATUS) RE_GET_SAMPLE_STATUS,
       
       (SELECT SUM(B.ACT_COUNT)
          FROM PORT_MIL_BATCH_SAMPLE_RESULT B
         WHERE B.PLAN_ID = T1.ID
           AND B.INSTORE_FLAG = '1'
           AND B.STATUS = '0') ACT_COUNT,
       
       (SELECT CASE
                 WHEN SUM(C.ACT_COUNT) > 0 THEN
                  '正常送判'
               END
          FROM QCM_ZG_JUGDE_APPLY C
         WHERE C.JUDGE_STOVE_NO = REGEXP_REPLACE(T1.JUDGE_STOVE_NO, '-.*', '')
           AND C.IS_FLAG = 0) APPLY_FLAG,
       
       T1.CONTRACT_NO,
       T1.VARIETIES,
       T1.STEELNAME,
       T1.GRADENAME,
       REPLACE(T1.PIPE_SIZE, '*', 'x') PIPE_SIZE,
       T1.BUCKLE_TYPE,
       T1.LENGTH_RANGE,
       T1.ROLL_STANDRAD,
       T1.FEED_TIME,
       T1.PRO_PLAN_ID,
       T1.GX_PLAN_NO,
       CASE T1.NODE_STATUS
         WHEN '10' THEN
          '锯切完成'
         WHEN '20' THEN
          '出炉'
         WHEN '30' THEN
          '穿孔完成'
         WHEN '40' THEN
          '连轧完成'
         WHEN '50' THEN
          '出再加热炉'
         WHEN '60' THEN
          '出定径'
         WHEN '70' THEN
          '分切完成'
         WHEN '80' THEN
          '矫直完成'
         WHEN '90' THEN
          '探伤完成'
         WHEN '96' THEN
          '质检完成'
         WHEN '99' THEN
          '下线'
       END NODE_STATUS1
  from MIL_PLAN T1, PORT_MIL_BATCH_SAMPLE_RESULT P
 WHERE T1.ID = P.PLAN_ID
        ]]>
	</query>
	
	<query id="FrmMilReSample.getPortMilBatchSampleResult" desc="根据炉号、批号、产线查进程表数据">
    <![CDATA[
	select t.judge_stove_no,
       t.lot_no,
       t.group_no,
       t.BATCH_NO,
       t.pline_code,
       (SELECT A.PLINE_NAME
          FROM COM_BASE_PLINE A
         WHERE A.PLINE_CODE = T.PLINE_CODE) PLINE_NAME,
       T.SEQ,
       T.MAT_NO,
       T.M_MAT_NO,
       T.M_M_MAT_NO,
       T.REMARK,
       T.PRO_PLAN_ID,
       T.GX_PLAN_NO,
       DECODE(T.IS_SAMPLE_PIPE, 1, '样管', '非样管') IS_SAMPLE_PIPE,
       DECODE(t.op_process, '14', '复取样废', '正常') STATUS,
       T.RE_GET_SAMPLE_NAME,
       T.RE_GET_SAMPLE_TIME,
       T.RE_GET_SAMPLE_STATUS,
       '样管' sample1,
       '非样管' noSample,
       '复取样废' fei,
       '废管回退' noFei,
       t1.NODE_FUR_FLAG
  from PORT_MIL_BATCH_SAMPLE_RESULT t, mil_instore_result t1
 where 1 = 1
      --and t.instore_flag = '1'
   and t.judge_stove_no = t1.judge_stove_no(+)
   and t.is_valid = '1'
   and t.GROUP_NO is not null
   and t.status <> '1'
   and (t.status <> '2' or (t.status = '2' and t.op_process = '14'))
        ]]>
	</query>
	
	<query id="FrmMilReSample.updateProcess" desc="修改进程表复取样状态">
    <![CDATA[
	update PORT_MIL_BATCH_SAMPLE_RESULT t
   set t.re_get_sample_status = '1',
       t.re_get_sample_time   = sysdate,
       t.re_get_sample_name   = ?
 where t.lot_no = ?
   and REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = ?
   and t.pline_code = ?
   AND NVL(T.PRO_PLAN_ID, '/') = NVL(?, '/')
   AND NVL(T.GX_PLAN_NO, '/') = NVL(?, '/')
        ]]>
	</query>
	
	<query id="FrmMilReSample.cancelPipeIn" desc="撤销交库">
    <![CDATA[
		DECLARE
  V_JUDGE_STOVE_NO MAT_BC_M.JUDGE_STOVE_NO%TYPE := ?;
  V_LOT_NO         PORT_MIL_BATCH_SAMPLE_RESULT.LOT_NO%TYPE := ?;
  V_PLINE_CODE     PORT_MIL_BATCH_SAMPLE_RESULT.PLINE_CODE%TYPE := ?;
BEGIN

   FOR MYROW IN (SELECT M.MAT_NO,
                       T.JUDGE_STOVE_NO,
                       T.ACT_COUNT,
                       T.ACT_THEORY_WEIGHT
                  FROM PORT_MIL_BATCH_SAMPLE_RESULT T, MAT_BC_M M
                 WHERE T.MAT_NO = M.ZG_MAT_NO
                   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = M.JUDGE_STOVE_NO
                   AND T.PLINE_CODE = M.PLINE_CODE
                   AND T.LOT_NO = M.LOT_NO
                   AND T.STATUS = '2'
                   AND T.OP_PROCESS = '14'
                   AND REGEXP_REPLACE(T.JUDGE_STOVE_NO, '-.*', '') = V_JUDGE_STOVE_NO
                   AND T.LOT_NO = V_LOT_NO
                   AND T.PLINE_CODE = V_PLINE_CODE) LOOP
  
    UPDATE MAT_BC_M C SET C.QCM_STAUS = '22'
     WHERE C.JUDGE_STOVE_NO = V_JUDGE_STOVE_NO
       AND C.MAT_NO = MYROW.MAT_NO;

  END LOOP;
END;

        ]]>
	</query>
	
	<query id="FrmMilReSample.updateMatNO" desc="废材料表同批号的样管">
    <![CDATA[
	update MAT_BC_M t
   set t.sample_flag       = '1',
       t.qcm_staus         = '22',
       T.JUDGE_RESULT_CODE = '40740705',
       T.JUDGE_RESULT      = '废品',
       T.SCRAP_REASON      = '复取样',
       T.PRO_PLAN_ID_NEXT  = '',
       T.GX_PLAN_NO_NEXT   = ''
 where t. mat_no = (SELECT MAT_NO
                   FROM (SELECT T.MAT_NO, ROWNUM
                           FROM MAT_BC_M T
                          WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                            AND T.BATCH_NO = '#BATCH_NO#'
                            AND T.Sample_Flag = '1'
                            and t.qcm_staus = '00'
                          ORDER BY T.MAT_NO)
                  WHERE ROWNUM = 1)
        ]]>
	</query>
	
	<query id="FrmMilReSample.updateMatNOBack" desc="废材料表同批号的样管回退">
    <![CDATA[
	update MAT_BC_M t
   set  t.qcm_staus = '00',
   T.SCRAP_TYPE = ''
 where t. mat_no = (SELECT MAT_NO
                   FROM (SELECT T.MAT_NO, ROWNUM
                           FROM MAT_BC_M T
                          WHERE T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
                            AND T.BATCH_NO = '#BATCH_NO#'
                            AND T.Sample_Flag = '1'
                            AND t.qcm_staus = '22'
                          ORDER BY T.MAT_NO)
                  WHERE ROWNUM = 1)
        ]]>
	</query>
	
	<query id="FrmMilReSample.updateInlistBack" desc="废入库表同批号的样管回退">
    <![CDATA[
	update YDM_BC_INLIST t
   set t.QCM_STAUS = '00'
 where t.instock_type_code = '800701'
   and t.mat_no = (select MAT_NO
                     from (select m.mat_no, ROWNUM
                             from YDM_BC_INLIST m
                            where m.judge_stove_no = '#JUDGE_STOVE_NO#'
                              and m.QCM_STAUS = '22'
                              order by m.MAT_NO )
                    where ROWNUM = 1)
        ]]>
	</query>
	
	
</queryMap>