<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="终检实绩">
<query id="FrmZjResult.getQueryZjBaseInfo" desc="查询终检基础信息">
 
 SELECT T1.*, T2.LENGTH,T2.ZJID, T2.COATING, T2.PROTECTOR, T2.MARKING, T2.RESI_MAG
  FROM (SELECT DISTINCT MAX(T.JUDGE_STOVE_NO) JUDGE_STOVE_NO,
                        MAX(T.SPEC_NAME) SPEC_NAME,
                        MAX(T.GRADENAME) GRADENAME,
                        MAX(T.STEELNAME) STEELNAME,
                        MAX(T.ORDER_NO) || '/' || MAX(T.ORDER_SEQ)  ORDER_NO,
                        MAX(T.PRODUCNAME) PRODUCNAME,
                        MAX(T2.BATCH_NO) BATCH_NO,
                        MAX(T.STD_NAME) STD_NAME
          FROM PLN_ZY_JGX_M T ,PLN_ZY_JGX_C T2
         WHERE T.HEAT_PLAN_NO = T2.HEAT_PLAN_NO
         AND T2.PER_STATUS IS NOT NULL
         AND T.PLANSTATUS IN ('10', '20', '30', '40')
         AND NVL(T2.PLINE_CODE_W, T2.PLINE_CODE) IN
        ('C109', 'C108', 'C092', 'C102', 'C107', 'C104', 'C100')
         AND T.JUDGE_STOVE_NO = ?
         GROUP BY T.HEAT_PLAN_NO, T2.BATCH_NO) T1
  LEFT JOIN PLN_ZY_ZJ_M T2
    ON T1.JUDGE_STOVE_NO = T2.JUDGE_STOVE_NO
</query>

<query id = "FrmZjResult.getQueryZjDetial" desc = "查询详情">
SELECT T.*,
       D.*,
       S.LENGTHDISC,
       (SELECT SUM(PRO_NUM)
          FROM MCH_LOADING_RESULT
         WHERE HEAT_PLAN_NO = T.HEAT_PLAN_NO
           AND BATCH_NO = T.BATCH_NO) INCOMING_PCS
  FROM (SELECT T.HEAT_PLAN_NO HEAT_PLAN_NO,
               T2.BATCH_NO,
               MAX(T.GX_PLAN_NO) GX_PLAN_NO,
               MAX(T.PRO_PLAN_ID) PRO_PLAN_ID,
               MAX(T.JUDGE_STOVE_NO) JUDGE_STOVE_NO,
               MAX(S.GX_PRO_SEQ) GX_PRO_SEQ_ORDER,
               MAX(NVL(T2.PLINE_CODE_W, T2.PLINE_CODE)) PLINE_CODE,
               MAX(T.PLANSTATUS) PLANSTATUS
          FROM PLN_ZY_JGX_M T
          LEFT JOIN PLN_ORDER_JGX_S S
            ON T.PRO_PLAN_ID = S.PRO_PLAN_ID
           AND T.GX_PLAN_NO = S.GX_PLAN_NO, PLN_ZY_JGX_C T2
         WHERE T.HEAT_PLAN_NO = T2.HEAT_PLAN_NO
           AND T2.PER_STATUS IS NOT NULL
           AND T.JUDGE_STOVE_NO LIKE ? || '%'
           AND T.PLANSTATUS IN ('10', '20', '30', '40')
           AND NVL(T2.PLINE_CODE_W, T2.PLINE_CODE) IN
               ('C109', 'C108', 'C092', 'C102', 'C107', 'C104', 'C100')
         GROUP BY T.HEAT_PLAN_NO, T2.BATCH_NO) T
  LEFT JOIN PLN_ORDER_JGX_S S
    ON T.PRO_PLAN_ID = S.PRO_PLAN_ID 
   AND T.GX_PLAN_NO = S.GX_PLAN_NO
   LEFT JOIN (SELECT M.JUDGE_STOVE_NO, DT.*
               FROM PLN_ZY_ZJ_M_DETAIL DT, PLN_ZY_ZJ_M M
              WHERE DT.ZJID = M.ZJID) D
               ON T.JUDGE_STOVE_NO = D.JUDGE_STOVE_NO
 ORDER BY DECODE(T.PLANSTATUS, '40', 2, '30', 1, 0),
          T.PLINE_CODE,
          TO_NUMBER(T.GX_PRO_SEQ_ORDER),
          T.JUDGE_STOVE_NO,
          T.BATCH_NO ASC
</query>

<query id = "FrmZjResult.getQueryZjc" desc = "查询管号">
SELECT HEAT_PLAN_SQE,
       JUDGE_STOVE_NO,
       PIPE_END_OD1,
       PIPE_END_OD2,
       PIPE_END_OUT_OF_ROUNDNESS,
       PIPE_END_MM,
       PIPE_END_S1,
       PIPE_END_S2,
       PIPE_END_S3,
       PIPE_END_S4,
       PIPE_END_BEVEL,
       PIPE_END_ROOT_FACE,
       PIPE_END_OUT_OF_SQUARENESS,
       PIPE_END_RESI_MAG,
       PIPE_BODY_OD1,
       PIPE_BODY_OD2,
       PIPE_BODY_OUT_OF_ROUNDNESS,
       BACKUP1,
       BACKUP2,
       BACKUP3,
       BACKUP4,
       IS_DECIDE,
       PIPE_BODY_LENGS,
       PIPE_BODY_MM,
       MAT_NO,
       PIPE_END_OD1_B,
       PIPE_END_OD2_B,
       PIPE_END_OUT_OF_ROUNDNESS_B,
       PIPE_END_MM_B,
       PIPE_END_S1_B,
       PIPE_END_S2_B,
       PIPE_END_S3_B,
       PIPE_END_S4_B,
       PIPE_END_BEVEL_B,
       PIPE_END_ROOT_FACE_B,
       PIPE_END_OUT_OF_SQUARENESS_B,
       PIPE_END_RESI_MAG_B,
       PIPE_END_RESI_MAG_2,
       PIPE_END_RESI_MAG_3,
       PIPE_END_RESI_MAG_4,
       PIPE_END_RESI_MAG_2_B,
       PIPE_END_RESI_MAG_3_B,
       PIPE_END_RESI_MAG_4_B
  FROM PLN_ZY_ZJ_C T
  WHERE T.JUDGE_STOVE_NO = ?
  ORDER BY HEAT_PLAN_SQE ASC
</query>

<query id = "FrmZjResult.queryZjBaseInfoId">
SELECT ZJID FROM PLN_ZY_ZJ_M WHERE JUDGE_STOVE_NO = ?
</query>

<query id="FrmZjResult.AddPlaZyZjM" desc = "新增pln_zy_zj_m表">
insert into pln_zy_zj_m
  (judge_stove_no,
   batch_no,
   spec_name,
   gradename,
   steelname,
   order_no,
   producname,
   std_name,
   length,
   coating,
   protector,
   marking,
   resi_mag)
values
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
</query>

<query id = "FrmZjResult.UpdatePlaZyZjM" desc = "修改pln_zy_zj_m表">
UPDATE PLN_ZY_ZJ_M SET
       BATCH_NO = ?,
       SPEC_NAME = ?,
       GRADENAME = ?,
       STEELNAME = ?,
       ORDER_NO = ?,
       PRODUCNAME = ?,
       STD_NAME = ?,
       LENGTH = ?,
       COATING = ?,
       PROTECTOR = ?,
       MARKING = ?,
       RESI_MAG = ?
 WHERE ZJID = ?
</query>

<query id="FrmZjResult.AddPlaZyZjMd" desc = "新增pln_zy_zj_m_detail表">
insert into pln_zy_zj_m_detail
  (zjid,
   incoming_pcs,
   comprehensive_qualified_pcs,
   scratch_out,
   scratch_pcs,
   dent_out,
   dent_pcs,
   cracks_out,
   cracks_pcs,
   arc_burns_out,
   arc_burns_pcs,
   laminations_out,
   laminations_pcs,
   geometric_deviations_out,
   geometric_deviations_pcs,
   other_out,
   other_pcs)
values
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
</query>

<query id="FrmZjResult.UpdatePlaZyZjMd" desc = "修改pln_zy_zj_m_detail表">
UPDATE PLN_ZY_ZJ_M_DETAIL
   SET
       INCOMING_PCS = ?,
       COMPREHENSIVE_QUALIFIED_PCS = ?,
       SCRATCH_OUT = ?,
       SCRATCH_PCS = ?,
       DENT_OUT = ?,
       DENT_PCS = ?,
       CRACKS_OUT = ?,
       CRACKS_PCS = ?,
       ARC_BURNS_OUT = ?,
       ARC_BURNS_PCS = ?,
       LAMINATIONS_OUT = ?,
       LAMINATIONS_PCS = ?,
       GEOMETRIC_DEVIATIONS_OUT = ?,
       GEOMETRIC_DEVIATIONS_PCS = ?,
       OTHER_OUT = ?,
       OTHER_PCS = ?
 WHERE  ZJID = ?
</query>

<query id="FrmZjResult.AddPlaZyZjC" desc = "新增pln_zy_zj_c">
insert into pln_zy_zj_c
  (heat_plan_sqe,
   judge_stove_no,
   pipe_end_od1,
   pipe_end_od2,
   pipe_end_out_of_roundness,
   pipe_end_mm,
   pipe_end_s1,
   pipe_end_s2,
   pipe_end_s3,
   pipe_end_s4,
   pipe_end_bevel,
   pipe_end_root_face,
   pipe_end_out_of_squareness,
   pipe_end_resi_mag,
   pipe_body_od1,
   pipe_body_od2,
   pipe_body_out_of_roundness,
   is_decide,
   pipe_body_lengs)
values
  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
</query>

<query id="FrmZjResult.UpdatePlaZyZjC" desc = "修改pln_zy_zj_c" >
UPDATE PLN_ZY_ZJ_C
   SET 
       PIPE_END_OD1 = ?,
       PIPE_END_OD2 = ?,
       PIPE_END_OUT_OF_ROUNDNESS = ?,
       PIPE_END_MM = ?,
       PIPE_END_S1 = ?,
       PIPE_END_S2 = ?,
       PIPE_END_S3 = ?,
       PIPE_END_S4 = ?,
       PIPE_END_BEVEL = ?,
       PIPE_END_ROOT_FACE = ?,
       PIPE_END_OUT_OF_SQUARENESS = ?,
       PIPE_END_RESI_MAG = ?,
       PIPE_BODY_OD1 = ?,
       PIPE_BODY_OD2 = ?,
       PIPE_BODY_OUT_OF_ROUNDNESS = ?,
       IS_DECIDE = ?,
       PIPE_BODY_LENGS = ?,
       PIPE_BODY_MM = ?,
       PIPE_END_OD1_B = ?,
       PIPE_END_OD2_B = ?,
       PIPE_END_OUT_OF_ROUNDNESS_B = ?,
       PIPE_END_MM_B = ?,
       PIPE_END_S1_B = ?,
       PIPE_END_S2_B = ?,
       PIPE_END_S3_B = ?,
       PIPE_END_S4_B = ?,
       PIPE_END_BEVEL_B = ?,
       PIPE_END_ROOT_FACE_B = ?,
       PIPE_END_OUT_OF_SQUARENESS_B = ?,
       PIPE_END_RESI_MAG_B = ?,
       PIPE_END_RESI_MAG_2 = ?,
       PIPE_END_RESI_MAG_3 = ?,
       PIPE_END_RESI_MAG_4 = ?,
       PIPE_END_RESI_MAG_2_B = ?,
       PIPE_END_RESI_MAG_3_B = ?,
       PIPE_END_RESI_MAG_4_B = ?
 WHERE HEAT_PLAN_SQE = ? AND JUDGE_STOVE_NO = ?
</query>

<query id = "FrmZjResult.geRtdMeasurePosdataAll" desc = "查询测量点数据支数">
   SELECT T.*,
       DENSE_RANK() OVER(PARTITION BY JUDGE_STOVE_NO, BATCH_NO, TO_NUMBER(MAT_NO) ORDER BY MAT_NO_CX ASC, MSAUER_DATE DESC, KEY_ID DESC) RK
  FROM RTD_MEASURE_POSDATA T
 WHERE 1 = 1
</query>

<query id = "FrmZjResult.CheckZjC" desc = "管号确认">
  insert into pln_zy_zj_c (mat_no,heat_plan_sqe,judge_stove_no,pipe_body_lengs) values (?,?,?,?)
</query>

<query id = "FrmZjResult.DCheckZjC" desc = "管号取消">
  delete from pln_zy_zj_c where heat_plan_sqe = ? and judge_stove_no = ? and mat_no = ?
</query>

<query id ="FrmZjResult.DoDelete" desc = "删除">
  DECLARE
  V_JUDGESTONO VARCHAR2(20) := ?;
  V_ZJID       VARCHAR2(100) := '';
BEGIN
  SELECT ZJID
    INTO V_ZJID
    FROM PLN_ZY_ZJ_M T
   WHERE T.JUDGE_STOVE_NO = V_JUDGESTONO;
  IF V_ZJID IS NOT NULL THEN
    DELETE FROM PLN_ZY_ZJ_M T WHERE T.JUDGE_STOVE_NO = V_JUDGESTONO;
    DELETE FROM PLN_ZY_ZJ_M_DETAIL T WHERE T.ZJID = V_ZJID;
    DELETE FROM PLN_ZY_ZJ_C T WHERE T.JUDGE_STOVE_NO = V_JUDGESTONO;
  END IF;
END;
</query>
</queryMap>