<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="管加工废品原因维护">
	<query id="FrmReason.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 MCH_LOADING_RESULT T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) LPRO_NUM,
                 (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM MCH_LOADING_RESULT T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) LFAIL_NUM,
                (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_ut_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) UPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_ut_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) UFAIL_NUM,
               (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_mt_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) MPRO_NUM,
                   (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_mt_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) MFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_cut_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CPRO_NUM,
                 (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_cut_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CFAIL_NUM,
                  (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_threader_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_threader_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_hread_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) HPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_hread_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) HFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_twistingly_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TWPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_twistingly_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) TWFAIL_NUM,
                     (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_path_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) PPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_path_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) PFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_watergage_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) WPRO_NUM,
                 (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_watergage_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) WFAIL_NUM,
                 (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_chamfering_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CHPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_chamfering_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) CHFAIL_NUM,
                   (SELECT NVL(SUM(T1.PRO_NUM), 0)
                  FROM mch_measure_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) MEPRO_NUM,
                  (SELECT NVL(SUM(T1.FAIL_NUM), 0)
                  FROM mch_measure_result T1
                 WHERE T1.HEAT_PLAN_NO = T.HEAT_PLAN_NO) MEFAIL_NUM,
                   DECODE(T.BESIDE_STATUS,
                      '00',
                      '上料结束',
                      '01',
                      '探伤结束',
                      '02',
                      '切管结束',
                      '03',
                      '车丝结束',
                      '04',
                      '螺纹检验结束',
                      '05',
                      '拧接结束',
                      '06',
                      '通径结束',
                      '07',
                      '水压结束',
                      '08',
                      '倒棱结束',
                      '09',
                      '测量点结束',
                      '10',
                      '交库结束') BESIDE_STATUS,
               DECODE(T.PER_STATUS,
                      '00',
                      '上料开始',
                      '01',
                      '探伤开始',
                      '02',
                      '切管开始',
                      '03',
                      '车丝开始',
                      '04',
                      '螺纹检验开始',
                      '05',
                      '拧接开始',
                      '06',
                      '通径开始',
                      '07',
                      '水压开始',
                      '08',
                      '倒棱开始',
                      '09',
                      '测量点开始',
                      '10',
                      '交库开始') PER_STATUS         
          FROM pln_zy_jgx_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="FrmReason.queryfail" desc="查询废品原因">
	 <![CDATA[ 
SELECT M.STATION_DESC,
T.FAIL_TYPE_NAME,
T.FAIL_NUM,
DECODE(T.FAIL_SORT,'00','可疑','10','废品','20','绝废') FAIL_SORT,
T.FAIL_DIRECT
FROM MCH_BUG_D T,MCH_COM_INFO M
WHERE T.RESULT_NO=M.RESULT_NO  #HEAT_PLAN_NO# 

	  ]]>
	</query>
	
		<query id="FrmReason.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>