<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="钢种与规格维护">
	<query id="GrandeRSpec.queryGrade" desc="查询钢种">
		<![CDATA[
			SELECT MSC,
		       MSC_PLINE,
		       GRADECODE,
		       GRADENAME,
		       ASSORTMENT_CODE,
		       ASSORTMENT_NAME,
		       CREATE_NAME,
		       CREATE_TIME,
		       UPDATE_NAME,
		       UPDATE_TIME,
		       DELETE_NAME,
		       DELETE_TIME,
		       VALIDFLAG,
		       DECODE(VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
		       MEMO,
		       STD_CODE,
		       STD_NAME,
		       CIC,
		       MANAGE_CATEGORY,
		       PRIORITY
		  FROM COM_MSC_GRADE
		 WHERE MSC = '#MSC#'
		   AND MSC_PLINE = '#MSC_PLINE#'
		   AND DECODE('#GRADECODE#', NULL, '1', GRADECODE) = DECODE('#GRADECODE#', NULL, '1', '#GRADECODE#')
		   AND VALIDFLAG = '1'
		 ]]>
	</query>
	
	<query id="GrandeRSpec.querySpec" desc="查询规格范围">
		<![CDATA[
			SELECT 
		       MSC,
		       MSC_PLINE,
		       GRADECODE,
		       GRADENAME,
		       HEIGHT_MIN,
		       DIMATER_MIN,
		       DIMATER_MAX,
		       HEIGHT_MIAX,
		       HEIGHT_MIN HEIGHT_MIN_OLD,
		       DIMATER_MIN DIMATER_MIN_OLD,
		       DIMATER_MAX DIMATER_MAX_OLD,
		       HEIGHT_MIAX HEIGHT_MIAX_OLD,
		       CREATE_NAME,
		       TO_CHAR(CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
		       UPDATE_NAME,
		       TO_CHAR(UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
		       DELETE_NAME,
		       TO_CHAR(DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
		       VALIDFLAG,
		       DECODE(VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
		       MEMO,
		       MSC || MSC_PLINE || GRADECODE || HEIGHT_MIN || HEIGHT_MIAX || DIMATER_MIN || DIMATER_MAX PRIMARY_KEY
		 FROM COM_MSC_GRADE_R_SPEC t
		 WHERE
		 T.MSC = '#MSC#'
		 AND T.MSC_PLINE = '#MSC_PLINE#'
		 AND T.GRADECODE = '#GRADECODE#'
		 AND T.VALIDFLAG IN( '1', '#IS_DELETE#')
		 ]]>
	</query>
	
	<query id="GrandeRSpec.UpdateGrade" desc="修改管理分类">
		<![CDATA[
UPDATE COM_MSC_GRADE
   SET MANAGE_CATEGORY = '#MANAGE_CATEGORY#', PRIORITY = '#PRIORITY#'
 WHERE MSC = '#MSC#'
   AND MSC_PLINE = '#MSC_PLINE#'
   AND GRADECODE = '#GRADECODE#'
		 ]]>
	</query>
	
	<query id="GrandeRSpec.SaveSpec" desc="保存规格范围">
		<![CDATA[
			DECLARE
			P_MSC COM_MSC_GRADE_R_SPEC.MSC%TYPE := '#MSC#';
			P_MSC_PLINE COM_MSC_GRADE_R_SPEC.MSC_PLINE%TYPE := '#MSC_PLINE#';
			P_GRADECODE COM_MSC_GRADE_R_SPEC.GRADECODE%TYPE := '#GRADECODE#';
			P_GRADENAME COM_MSC_GRADE_R_SPEC.GRADENAME%TYPE := '#GRADENAME#';
			P_HEIGHT_MIN COM_MSC_GRADE_R_SPEC.HEIGHT_MIN%TYPE := '#HEIGHT_MIN#';
			P_DIMATER_MIN COM_MSC_GRADE_R_SPEC.DIMATER_MIN%TYPE := '#DIMATER_MIN#';
			P_DIMATER_MAX COM_MSC_GRADE_R_SPEC.DIMATER_MAX%TYPE := '#DIMATER_MAX#';
			P_HEIGHT_MIAX COM_MSC_GRADE_R_SPEC.HEIGHT_MIAX%TYPE := '#HEIGHT_MIAX#';
			P_HEIGHT_MIN_OLD COM_MSC_GRADE_R_SPEC.HEIGHT_MIN%TYPE := '#HEIGHT_MIN_OLD#';
			P_DIMATER_MIN_OLD COM_MSC_GRADE_R_SPEC.DIMATER_MIN%TYPE := '#DIMATER_MIN_OLD#';
			P_DIMATER_MAX_OLD COM_MSC_GRADE_R_SPEC.DIMATER_MAX%TYPE := '#DIMATER_MAX_OLD#';
			P_HEIGHT_MIAX_OLD COM_MSC_GRADE_R_SPEC.HEIGHT_MIAX%TYPE := '#HEIGHT_MIAX_OLD#';
			P_CREATE_NAME COM_MSC_GRADE_R_SPEC.CREATE_NAME%TYPE := '#CREATE_NAME#';
			P_UPDATE_NAME COM_MSC_GRADE_R_SPEC.UPDATE_NAME%TYPE := '#UPDATE_NAME#';
			P_DELETE_NAME COM_MSC_GRADE_R_SPEC.DELETE_NAME%TYPE := '#DELETE_NAME#';
			P_MEMO COM_MSC_GRADE_R_SPEC.MEMO%TYPE := '#MEMO#';
			P_COUNT NUMBER(3);
			BEGIN
			
			   SELECT COUNT(1)
			     INTO P_COUNT
			     FROM COM_MSC_GRADE_R_SPEC
			    WHERE MSC = P_MSC
			      AND MSC_PLINE = P_MSC_PLINE
			      AND GRADECODE = P_GRADECODE
			      AND HEIGHT_MIN = P_HEIGHT_MIN_OLD
			      AND DIMATER_MIN = P_DIMATER_MIN_OLD
			      AND DIMATER_MAX = P_DIMATER_MAX_OLD
			      AND HEIGHT_MIAX = P_HEIGHT_MIAX_OLD;
			   IF P_COUNT = 0 THEN
			     INSERT INTO COM_MSC_GRADE_R_SPEC
			       (MSC,
			        MSC_PLINE,
			        GRADECODE,
			        GRADENAME,
			        HEIGHT_MIN,
			        DIMATER_MIN,
			        DIMATER_MAX,
			        HEIGHT_MIAX,
			        CREATE_NAME,
			        CREATE_TIME,
			        VALIDFLAG,
			        MEMO)
			     VALUES
			       (P_MSC,
			        P_MSC_PLINE,
			        P_GRADECODE,
			        P_GRADENAME,
			        P_HEIGHT_MIN,
			        P_DIMATER_MIN,
			        P_DIMATER_MAX,
			        P_HEIGHT_MIAX,
			        P_CREATE_NAME,
			        SYSDATE,
			        '1',
			        P_MEMO);
			ELSE   
			    UPDATE COM_MSC_GRADE_R_SPEC
			       SET HEIGHT_MIN  = P_HEIGHT_MIN,
			           DIMATER_MIN = P_DIMATER_MIN,
			           DIMATER_MAX = P_DIMATER_MAX,
			           HEIGHT_MIAX = P_HEIGHT_MIAX,
			           UPDATE_NAME = P_UPDATE_NAME,
			           UPDATE_TIME = SYSDATE,
			           MEMO        = P_MEMO
			     WHERE MSC = P_MSC
			       AND MSC_PLINE = P_MSC_PLINE
			       AND GRADECODE = P_GRADECODE
			       AND HEIGHT_MIN = P_HEIGHT_MIN_OLD
			      AND DIMATER_MIN = P_DIMATER_MIN_OLD
			      AND DIMATER_MAX = P_DIMATER_MAX_OLD
			      AND HEIGHT_MIAX = P_HEIGHT_MIAX_OLD;
			END IF;
			END;
		 ]]>
	</query>

	<query id="GrandeRSpec.deleteOrResumeSpec" desc="作废或者恢复规格范围">
		<![CDATA[
			DECLARE
			P_MSC COM_MSC_GRADE_R_SPEC.MSC%TYPE := '#MSC#';
			P_MSC_PLINE COM_MSC_GRADE_R_SPEC.MSC_PLINE%TYPE := '#MSC_PLINE#';
			P_GRADECODE COM_MSC_GRADE_R_SPEC.GRADECODE%TYPE := '#GRADECODE#';
			P_HEIGHT_MIN COM_MSC_GRADE_R_SPEC.HEIGHT_MIN%TYPE := '#HEIGHT_MIN#';
			P_DIMATER_MIN COM_MSC_GRADE_R_SPEC.DIMATER_MIN%TYPE := '#DIMATER_MIN#';
			P_DIMATER_MAX COM_MSC_GRADE_R_SPEC.DIMATER_MAX%TYPE := '#DIMATER_MAX#';
			P_HEIGHT_MIAX COM_MSC_GRADE_R_SPEC.HEIGHT_MIAX%TYPE := '#HEIGHT_MIAX#';
			P_HEIGHT_MIN_OLD COM_MSC_GRADE_R_SPEC.HEIGHT_MIN%TYPE := '#HEIGHT_MIN_OLD#';
			P_DIMATER_MIN_OLD COM_MSC_GRADE_R_SPEC.DIMATER_MIN%TYPE := '#DIMATER_MIN_OLD#';
			P_DIMATER_MAX_OLD COM_MSC_GRADE_R_SPEC.DIMATER_MAX%TYPE := '#DIMATER_MAX_OLD#';
			P_HEIGHT_MIAX_OLD COM_MSC_GRADE_R_SPEC.HEIGHT_MIAX%TYPE := '#HEIGHT_MIAX_OLD#';
			P_UPDATE_NAME COM_MSC_GRADE_R_SPEC.UPDATE_NAME%TYPE := '#UPDATE_NAME#';
			P_DELETE_NAME COM_MSC_GRADE_R_SPEC.DELETE_NAME%TYPE := '#DELETE_NAME#';
			P_VALIDFLAG COM_MSC_GRADE_R_SPEC.VALIDFLAG%TYPE := '#VALIDFLAG#';
			BEGIN
			IF P_VALIDFLAG = '0' THEN
			    UPDATE COM_MSC_GRADE_R_SPEC T SET T.VALIDFLAG = P_VALIDFLAG,
			    T.DELETE_NAME = P_DELETE_NAME, T.DELETE_TIME = SYSDATE,
			    T.UPDATE_NAME = '', T.UPDATE_TIME = ''
			    WHERE T.MSC = P_MSC AND T.MSC_PLINE = P_MSC_PLINE AND T.GRADECODE = P_GRADECODE
			    AND HEIGHT_MIN = P_HEIGHT_MIN_OLD
			      AND DIMATER_MIN = P_DIMATER_MIN_OLD
			      AND DIMATER_MAX = P_DIMATER_MAX_OLD
			      AND HEIGHT_MIAX = P_HEIGHT_MIAX_OLD;
			ELSE   
			   UPDATE COM_MSC_GRADE_R_SPEC T SET T.VALIDFLAG = P_VALIDFLAG,
			    T.DELETE_NAME = '', T.DELETE_TIME = '',
			    T.UPDATE_NAME = P_UPDATE_NAME, T.UPDATE_TIME = SYSDATE
			    WHERE T.MSC = P_MSC AND T.MSC_PLINE = P_MSC_PLINE AND T.GRADECODE = P_GRADECODE
			    AND HEIGHT_MIN = P_HEIGHT_MIN_OLD
			      AND DIMATER_MIN = P_DIMATER_MIN_OLD
			      AND DIMATER_MAX = P_DIMATER_MAX_OLD
			      AND HEIGHT_MIAX = P_HEIGHT_MIAX_OLD;
			END IF;
			END;
		 ]]>
	</query>
	
	<query id="GrandeRSpec.isExistSpec" desc="是否存在该规格范围">
		<![CDATA[
		SELECT COUNT(1) FROM COM_MSC_GRADE_R_SPEC T WHERE
		T.MSC = '#MSC#' AND T.MSC_PLINE = '#MSC_PLINE#'
		 AND T.GRADECODE = '#GRADECODE#'
			    AND HEIGHT_MIN = '#HEIGHT_MIN#'
			      AND DIMATER_MIN = '#DIMATER_MIN#'
			      AND DIMATER_MAX = '#DIMATER_MAX#'
			      AND HEIGHT_MIAX = '#HEIGHT_MIAX#'
		 ]]>
	</query>
</queryMap>