<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="热处理废品原因维护">
	<query id="HttReason.doQuery" desc="废品原因查询">
	 <![CDATA[ 
SELECT T.ORDER_NO || '/' || T.ORDER_SEQ || '/' || T.DELIVERY_NO ORDER_NO_SEQ,
               T.HEAT_PLAN_NO,
               T.PLINE_NAME,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,       
               T.ORDER_NO,
               T.CREATE_NAME,
               TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
               T.UPDATE_NAME,
               TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
               DECODE(T.PLANSTATUS,
                      '00',
                      '计划',
                      '10',
                      '下发',
                      '20',
                      '生产中',
                      '30',
                      '生产完成',
                      '40',
                      '关闭') PLANSTATUS,
 
               (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_loading_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) LPRO_NUM,--上料
                 (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_loading_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) LFAIL_NUM,
                (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_hheat_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) UPRO_NUM,--高温炉
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_hheat_result T1      
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) UFAIL_NUM,
               (SELECT NVL(SUM(T1.PASS_NUM), 0)
                  FROM htt_quenching_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) PASS_NUM,--淬火
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_lheat_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CPRO_NUM,--低温炉
                 (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_lheat_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CFAIL_NUM,
                  (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_sizing_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TPRO_NUM,--定径
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_sizing_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_hlstraighten_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) HPRO_NUM,--热矫
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_hlstraighten_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) HFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM htt_clstraighten_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TWPRO_NUM,--冷矫
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM htt_clstraighten_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TWFAIL_NUM,
                     (SELECT NVL(SUM(T1.CHECKPIECES), 0)
                  FROM htt_appearancecheck_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) PPRO_NUM,--尺寸外观
                  (SELECT NVL(SUM(T1.WAST_NUM), 0)
                  FROM htt_appearancecheck_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) PFAIL_NUM,
                 (SELECT NVL(SUM(T1.TESTING_NUM), 0)
                  FROM htt_crack_detection_et T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) WPRO_NUM,--探伤
                 (SELECT NVL(SUM(T1.EWASTE_NUM), 0)
                  FROM htt_crack_detection_et T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) WFAIL_NUM,              
                   DECODE(T.BESIDE_STATUS,
                     '00',
                      '上料结炉',
                      '10',
                      '高温结炉',
                      '20',
                      '淬火结炉',
                      '30',
                      '低温结炉',
                      '40',
                      '定径结炉',
                      '50',
                      '热矫结炉',
                      '60',
                      '冷矫结炉',
                      '70',
                      '检验结炉',
                      '80',
                      '探伤结炉',
                      '90',
                      '交库结炉') BESIDE_STATUS,
               DECODE(T.PER_STATUS,
                       '00',
                      '上料开始',
                      '10',
                      '高温开始',
                      '20',
                      '淬火开始',
                      '30',
                      '低温开始',
                      '40',
                      '定径开始',
                      '50',
                      '热矫开始',
                      '60',
                      '冷矫开始',
                      '70',
                      '检验开始',
                      '80',
                      '探伤开始',
                      '90',
                      '交库开始') PER_STATUS        
          FROM pln_zy_rcl_m T where 1=1
	  ]]>
	</query>
	<query id="FrmReason.addOfficeD" desc="废品原因新增">
	 <![CDATA[ 
INSERT INTO MCH_FAIL_REASON
  (HEAT_PLAN_NO,ZY_BATCH_ID,PLINE_NAME,OP_PROCESS,FAIL_REASON)
VALUES
  (?, ?, ?,?,?)
	  ]]>
	</query>
	
	<query id="HttReason.queryfail" desc="查询废品原因">
	 <![CDATA[ 
select m.STATION_DESC,
t.DEF_FILL_NAME,
t.DEF_FILL_NUM from HTT_WASTE_RESULT t,Htt_COM_INFO m
where t.result_no=m.result_no and t.DEF_FILL_NO='2'
	  ]]>
	</query>
	
		<query id="HttReason.updatePerson" desc="修改人员">
	 <![CDATA[ 
 UPDATE MCH_PERSON T
   SET T.MAN_NAME = ?,T.PLINE_CODE = ?,T.PRO_BZ = ?
 WHERE T.MAN_NAME = ?
	  ]]>
	</query>
	
		<query id="FrmReason.delete" desc="删除废品原因">
	 <![CDATA[ 
 DELETE FROM MCH_FAIL_REASON T WHERE T.FAIL_REASON= ?
	  ]]>
	</query>
	

</queryMap>