<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="接箍料收料">
	<query id="ReciveMaterial.queryCollarData" desc="查询质保数据">
<![CDATA[
	SELECT T.ORDERNO,
       T.RCDID,
       T.FACTORY,
       T.KIND,
       T.LCODE,
       T.LOTNO,
       T.STEELLEVEL,
       T.STEELGRADE,   
       T.SPEC,
       T.THICKNESS,
       T.GG,
       T.TYPEOFTHREAD,
       '0' HGUNIT,
       T.HGM,
       '0' HGWEIGHT,
       T.ORDERNAME,
       T.LENG,
       T.TESTIDEA,
       CONVERT(VARCHAR(100), T.TESTDATE, 23) AS TESTDATE,
       T.DESTINATION, 
       CASE T.CXSTU WHEN 20 THEN '已收料' ELSE '未收料' END AS CXSTU ,
       CASE T.CXSTU WHEN 01 THEN 'OK' 
       WHEN 02 THEN 'NO'
       WHEN 20 THEN 'OK'
       END AS CXSTUPP ,
       T.CXKIND,
       T.CXSTEELLEVEL,
       T.CXSTEELGRADE,
       T.CXTYPEOFTHREAD,
       T.CXSTANDARD,
       T.CXGG,
       T.STDSTYLE,
       T.DEPARTM,
       CONVERT(VARCHAR(100),T.CXUPDATEDATE, 20) AS CXUPDATEDATE,
       T.HEATHGUNIT,
       T.HEATHGWEIGHT,
       T.HEATSCUNIT,
       T.HEATSCWEIGHT,
       T.heathgm,
       CASE T.IFHEATPD WHEN 1 THEN '已判定' ELSE '未判定' END AS IFHEATPD,
       t.cxfactory
  FROM TABCXZLJK_JGL T  WHERE 1 = 1  
  ]]>
	</query>
	<query id="ReciveMaterial.getUpdateZbMatch" desc="更改质保状态">
		<![CDATA[
	    update tabcxzljk_jgl set 
		cxstu=?,
		CXKIND=?,
		CXSTEELLEVEL=?,
		CXGG=?,
		CXTYPEOFTHREAD=?,
		CXSTEELGRADE=?,
		cxfactory=?,
		cxupdatedate=getdate()
		where RCDID=? AND LCODE=? AND LOTNO=? and ordername=?
		]]>
	</query>
	<query id="ReciveMaterial.GETPRODUCT" desc="查询品名">
		<![CDATA[
	    SELECT 
	    PRODUC_JX,PRODUCCODE
	    FROM COM_BASE_PRODUCT T
	    WHERE T.VALIDFLAG ='1'
	    ORDER BY PRODUCNAME
		]]>
	</query>

	<query id="ReciveMaterial.GETSPEC" desc="查询产品规格">
		<![CDATA[
	     SELECT SPEC_NAME,SPEC_CODE
	     FROM COM_BASE_SPEC T
	     WHERE T.VALIDFLAG ='1'
	     ORDER BY SPEC_NAME
		]]>
	</query>

	<query id="ReciveMaterial.GETSTEEL" desc="查询钢级">
		<![CDATA[
	     SELECT STEELNAME,STEELCODE
	     FROM COM_BASE_STEEL T
	     WHERE T.VALIDFLAG ='1'
	     ORDER BY STEELNAME
		]]>
	</query>
	<query id="ReciveMaterial.GETGRADE" desc="查询钢种">
		<![CDATA[
	     SELECT GRADENAME,GRADECODE
       FROM COM_BASE_GRADE T
	     WHERE T.VALIDFLAG ='1'
	     ORDER BY GRADENAME
		]]>
	</query>
	<query id="ReciveMaterial.getPline" desc="查询产线">
		<![CDATA[
	   SELECT PLINE_NAME,PLINE_CODE
	    FROM COM_BASE_PLINE T
	    WHERE T.VALIDFLAG ='1'
	    ORDER BY PLINE_NAME
		]]>
	</query>
	<query id="ReciveMaterial.GETMODEL" desc="查询扣型">
		<![CDATA[
	    SELECT MODEL_DESC,MODEL_CODE
	    FROM COM_BASE_MODEL T
	    WHERE T.VALIDFLAG ='1'
	    ORDER BY MODEL_DESC
		]]>
	</query>
	<query id="ReciveMaterial.doQueryInList" desc="查询收料记录">
	<![CDATA[
 SELECT 
       t.INSTOCK_DOC,
       t.JUDGE_STOVE_NO,
       t.BATCH_NO,
       t.PRODUCCODE,
       t.PRODUCNAME,
       t.STD_CODE,
       t.STD_NAME,
       t.STEELCODE,
       t.STEELNAME,
       t.STD_STYLE,
       t.STD_STYLE_DESC,
       t.SPEC_CODE,
       t.SPEC_NAME,
       t.MODEL_CODE,
       t.MODEL_DESC,
       t.ACT_DIMATER,
       t.ACT_HEIGHT,
       to_char(t.ACT_LEN_MIN,'FM999990.00') AS ACT_LEN_MIN,
       to_char(t.ACT_LEN_MAX,'FM999990.00') AS ACT_LEN_MAX,
       to_char(t.ACT_LEN_MIN,'FM999990.00')||'-'||to_char(t.ACT_LEN_MAX,'FM999990.00') as LEN,
       sum(t.ACT_COUNT) as ACT_COUNT,
       to_char(sum(t.ACT_WEIGHT),'FM999999990.000') as ACT_WEIGHT,
       sum(nvl(t.ACT_LEN,0)) as ACT_LEN,
       t.BELONG_CODE,
       t.BELONG_NAME,
       s.STORAGE_NAME STORAGE_NO, 
       t.MEMO,
       t.CREATE_NAME,
       max(to_char(t.INSTOCK_TIME,'YYYY-MM-DD HH24:MI:SS')) as INSTOCK_TIME,
       max(to_char(t.IN_TIME_F,'YYYY-MM-DD')) AS IN_TIME_F,
       to_char(to_date(t.BAL_YEAR_MONTH,'YYYY-MM'),'yyyy-MM') as BAL_YEAR_MONTH,
       --t.BAL_YEAR_MONTH,
       t.ORDER_NO,
     t.ORDER_SEQ,
     t.DELIVERY_NO,
     t.JUDGE_STD_CODE,
     t.JUDGE_STD_NAME,
     t.PLINE_CODE,
     t.PLINE_NAME,
     t.GRADECODE,
     t.GRADENAME,
     DECODE(t.PRODUCT_FLAG,'801401','在制品','801402','成品','801403','商品')PRODUCT_FLAG,
     t.ZB_RCDID,
     d.SALE_AREA_DESC,
       d.create_name AS ordercreatename,
       t.PIPMEMO,
       t.BATCH_GROUD_NO,
       m.basename as GROUPNAME,
       T.INSTOCK_TYPE_NAME
 FROM YDM_ZC_INLIST t
  left join  ydm_bs_storage s
  on t.STORAGE_NO = s.STORAGE_NO
  left join  SLM_ORDER_HEAD d on 
   t.ord_pk = d.ord_pk
   left join (select m.pline_code,g.basename
  from com_base_pline m, com_base_info g
 where m.group_pay = g.basecode) m on m.pline_code = t.pline_code
 where t.INSTOCK_TYPE_CODE ='800703'
   AND t.JUDGE_STOVE_NO || '&' LIKE ('%' || upper(?) || '%')
   AND t.ORDER_NO || '&' LIKE ('%' || upper(?) || '%')
   AND t.HAND_FLAG = '0'
   AND T.PRODUCT_FLAG = '801401'
	]]>
	</query>
	<query id="ReciveMaterial.getInListDoc" desc="查询入库单号">
	<![CDATA[
	select INSTOCK_SQE,INSTOCK_DOC from ydm_zc_inlist 
    where 
    CREATE_TIME LIKE '%'|| to_date(?,'YYYY/MM/DD')||'%' 
    AND INSTOCK_TYPE_CODE LIKE '%'|| ? ||'%'
    order by INSTOCK_SQE desc
    ]]>
	</query>
	<query id="ReciveMaterial.getInListDoc1" desc="查询入库流水">
	<![CDATA[
	select INSTOCK_SQE,INSTOCK_DOC from ydm_zc_inlist 
    where 
    CREATE_TIME LIKE '%'|| to_date(?,'YYYY/MM/DD')||'%' 
    AND INSTOCK_DOC LIKE '%'|| ? ||'%'
    order by INSTOCK_SQE desc
    ]]>
	</query>
	<query id="ReciveMaterial.QueryMatNoM" desc="自动生存材料号">
		<![CDATA[
	 SELECT T.MAT_NO FROM MAT_ZC_M T WHERE T.JUDGE_STOVE_NO=? AND T.BATCH_NO=? ORDER BY T.MAT_NO DESC
		]]>
	</query>
	<query id="ReciveMaterial.queryGroupNo" desc="查询同炉同批组号">
		SELECT
		T.BATCH_GROUD_NO FROM MAT_ZC_M T WHERE T.JUDGE_STOVE_NO = ? AND
		T.BATCH_NO = ? ORDER BY T.BATCH_GROUD_NO DESC
       </query>
	<query id="ReciveMaterial.insertMat" desc="插入材料表">
		INSERT INTO MAT_ZC_M
		(
		JUDGE_STOVE_NO,
		BATCH_NO,
		BATCH_GROUD_NO,
		PRODUCCODE,
		PRODUCNAME,
		STEELCODE,
		STEELNAME,
		SPEC_CODE,
		SPEC_NAME,
		MODEL_CODE,
		MODEL_DESC,
		STD_CODE,
		STD_NAME,
		BELONG_CODE,
		BELONG_NAME,
		STD_STYLE,
		STD_STYLE_DESC,
		ORDER_NO,
		ORDER_SEQ,
		ORDER_SEQ_NO,
		ORD_PK,
		ORD_LN_PK,
		ORD_LN_DLY_PK,
		ACT_DIMATER,
		ACT_HEIGHT,
		LEN_NO,
		LEN_DESC,
		LEN_UNIT,
		ACT_LEN_MIN,
		ACT_LEN_MAX,
		CREATE_NAME,

		ACT_COUNT,
		ACT_WEIGHT,
		CREATE_TIME,
		INSTOCK_TIME,
		MAT_NO,
		MEMO,
		JUGDE_APPLY_FLAG,
		INSTOCK_FLAG,
		PRODUCT_FLAG,
		MAT_STATUS,
		ACT_LEN,
		JUDGE_STD_NAME,
		BAL_YEAR_MONTH,
		PLINE_CODE,
		PLINE_NAME,
		GRADECODE,
		GRADENAME,
		PIPMEMO,
		OLD_ORDER_NO,
		JUDGE_RESULT_TIME,
		MAT_ORIGIN_CODE,
		MAT_ORIGIN_NAME,
		SOURE_CODE,
		SOURE_NAME,
		MATERIAL_NO,
		MATERIAL_NAME,
		PACK_NO
		) VALUES
		(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,
		?,?,?,?,?,?,?,?,?,?,?,?,
		TO_NUMBER(?),ROUND(TO_NUMBER(?),4),TO_DATE(?,'YYYY-MM-DD
		HH24:MI:SS'),TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
		?,?,'1','1','801401','80150102',TO_NUMBER(?),?,?,?,?,?,?,?,?,TO_DATE(?,'YYYY-MM-DD'),?,?,?,?,?,?,?)
	</query>
	<query id="ReciveMaterial.insertButress" desc="插入位置表">
       <![CDATA[
       INSERT INTO YDM_ZC_BUTTRESS
    (
     JUDGE_STOVE_NO,
     BATCH_NO,
     BATCH_GROUD_NO,
     STORAGE_NO,
     LOCATION_NO,
     STORAGE_TYPE_NO,
     STORAGE_TYPE_NAME,
     
     CREATE_NAME,
     MAT_NO,
     CREATE_TIME,
     MANAGEMENT_NO,
     MANAGEMENT_NAME,
     DEPARTMENT_CODE,
     DEPARTMENT_DESC,
     STORAGE_ATTR,
     STORAGE_ATTR_NAME
     )
    VALUES ( ?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?)
		]]>
	</query>
	<query id="ReciveMaterial.insertInList" desc="插入入库表">
		INSERT INTO
		YDM_ZC_INLIST
		(MANAGEMENT_NO,
		MANAGEMENT_NAME,
		INSTOCK_SQE,
		INSTOCK_DOC,
		INSTOCK_TYPE_CODE,
		INSTOCK_TYPE_NAME,
		MAT_NO,
		LOT_NO,
		STOVE_NO,
		JUDGE_STOVE_NO,
		BATCH_NO,
		BATCH_GROUD_NO,

		PRODUCCODE,
		PRODUCNAME,
		STD_CODE,
		STD_NAME,

		STEELCODE,
		STEELNAME,
		STD_STYLE,
		STD_STYLE_DESC,
		SPEC_CODE,
		SPEC_NAME,
		MODEL_CODE,
		MODEL_DESC,
		ACT_DIMATER,
		ACT_HEIGHT,
		ACT_LEN_MIN,
		ACT_LEN_MAX,
		ACT_COUNT,
		ACT_WEIGHT,
		ACT_THEORY_WEIGHT,
		BELONG_CODE,
		BELONG_NAME,
		STORAGE_NO,

		MEMO,
		VALIDFLAG,
		CREATE_NAME,
		CREATE_TIME,
		ORDER_NO,
		ORDER_SEQ,
		DELIVERY_NO,
		ORD_PK,
		ORD_LN_PK,
		ORD_LN_DLY_PK,
		PRODUCT_FLAG,
		MAT_STATUS,
		INSTOCK_TIME,ZB_RCDID,ACT_LEN,DEPARTMENT_CODE,DEPARTMENT_DESC,JUDGE_STD_NAME,PLINE_CODE,PLINE_NAME,GRADECODE,GRADENAME,BAL_YEAR_MONTH,IN_TIME_F,PIPMEMO,MAT_ORIGIN_CODE,MAT_ORIGIN_NAME,SOURE_CODE,SOURE_NAME,MATERIAL_NO,MATERIAL_NAME,
		LOCATION_NO,STORAGE_ATTR,STORAGE_ATTR_NAME,STORAGE_TYPE_NO,STORAGE_TYPE_NAME)
		VALUES
		(?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		?,
		to_date(?,'YYYY-MM-DD
		HH24:MI:SS'),?,?,?,?,?,?,'801401','80150102',to_date(?,'YYYY-MM-DD
		HH24:MI:SS'),
		?,?,?,?,?,?,?,?,?,?,to_date(?,'YYYY-MM-DD
		HH24:MI:SS'),?,?,?,?,?,?,?,?,'800302','投料库','800202','钢管')
       </query>
	<query id="ReciveMaterial.updateSql" desc="更新数据收料状态">
		<![CDATA[
	    UPDATE tabcxzljk_jgl
	    SET cxstu='20'
	    where lcode=? AND lotno=? and RCDID=?
		]]>
	</query>
	<query id="ReciveMaterial.updateSqlHz" desc="更新数据核准状态">
		<![CDATA[
	    UPDATE tabcxzljk_jgl
	    SET cxstu='30'
	    where lcode=? AND lotno=? and RCDID=?
		]]>
	</query>
	<query id="ReciveMaterial.cancelReciveMat" desc="撤销收料">
<![CDATA[
DECLARE
BEGIN
  FOR MYROW IN (SELECT T.*
                  FROM YDM_ZC_INLIST T
                 WHERE T.INSTOCK_DOC = ?
                 AND T.ZB_RCDID = ?
                 ORDER BY T.MAT_NO DESC) LOOP
    DELETE YDM_ZC_BUTTRESS W WHERE W.MAT_NO = MYROW.MAT_NO;
    DELETE MAT_ZC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE MAT_ZC_M_XS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE YDM_ZC_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE YDM_ZC_INLIST_XS T WHERE T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
END;
]]>
	</query>
	<query id="ReciveMaterial.updateZB" desc="修改质保数据标志位">
<![CDATA[
	    UPDATE tabcxzljk_jgl
	    SET cxstu='00'
	    where lcode=? AND  lotno=?  and rcdid = ?
	     
		]]>
	</query>
	<query id="ReciveMaterial.selectMatStus" desc="查询是否满足撤销条件">
		SELECT COUNT(1)
		ACOUNT
		FROM MAT_ZC_M T
		WHERE T.JUDGE_STOVE_NO = ?
		AND T.BATCH_NO = ?
		AND
		T.BATCH_GROUD_NO = ?
		AND T.MAT_STATUS = '80150102'
		AND
		T.PRODUCT_FLAG='801401'
</query>
	<query id="ReciveMaterial.deletetMat" desc="删除材料表，位置表，入库表">
<![CDATA[
	DECLARE
BEGIN
  FOR MYROW IN (SELECT *
                  FROM (SELECT T.MAT_NO
                          FROM MAT_ZC_M T
                         WHERE T.PRODUCT_FLAG = '801401'
                           AND T.MAT_STATUS = '80150102'
                           AND T.JUDGE_STOVE_NO = ?
                           AND T.BATCH_NO = ?
                         ORDER BY T.MAT_NO DESC)
                 WHERE ROWNUM < ?) LOOP
    DELETE YDM_ZC_BUTTRESS W WHERE W.MAT_NO = MYROW.MAT_NO;
    DELETE MAT_ZC_M T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE MAT_ZC_M_XS T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE YDM_ZC_INLIST T WHERE T.MAT_NO = MYROW.MAT_NO;
    DELETE YDM_ZC_INLIST_XS T WHERE T.MAT_NO = MYROW.MAT_NO;
    
  END LOOP;
END;
		]]>
	</query>
	<query id="ReciveMaterial.updateMat" desc="修改材料表，入库表吨">
<![CDATA[
	DECLARE
BEGIN
  UPDATE MAT_ZC_M T SET T.ACT_WEIGHT = TO_NUMBER(?) WHERE T.MAT_NO = ?;
  UPDATE YDM_ZC_INLIST T
     SET T.ACT_WEIGHT = TO_NUMBER(?)
   WHERE T.MAT_NO = ?;
END;
	
		]]>
	</query>
	<query id="ReciveMaterial.QueryMatNoHz" desc="查询材料号">
<![CDATA[
SELECT T.MAT_NO
  FROM MAT_ZC_M T
 WHERE T.PRODUCT_FLAG = '801401'
   AND T.JUDGE_STOVE_NO = ?
   AND T.BATCH_NO = ?
 ORDER BY T.MAT_NO ASC
    ]]>
	</query>
</queryMap>