<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="标准号与适用规格关联表">
	<query id="BaseStdRSpec.query" desc="查询标准号与适用规格关联数据">
		<![CDATA[ 
		       SELECT 
		       STD_CODE,
		       STD_CODE STD_CODE_OLD,
		       STD_NAME,
		       MIN_H,
		       MIN_H MIN_H_OLD,
		       MAX_H,
		       MAX_H MAX_H_OLD,
		       MIN_D,
		       MIN_D MIN_D_OLD,
		       MAX_D,
		       MAX_D MAX_D_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', '有效', '无效', '未识别') VALIDFLAG_NAME,
		       MEMO,
		       MSC_STYLE,
		       MSC_STYLE MSC_STYLE_OLD,
		       SPEC_CODE,
		       SPEC_CODE SPEC_CODE_OLD,
		       SPEC_NAME
		 FROM COM_BASE_STD_R_SPEC T
		 WHERE T.STD_CODE = '#STD_CODE#'
		 AND T.VALIDFLAG IN ('1', '#VALIDFLAG#')
		 ORDER BY T.MSC_STYLE, TO_NUMBER(T.MIN_D)
		]]>
	</query>
	
	<query id="BaseStdRSpec.save" desc="保存标准与适用规格关联数据">
		<![CDATA[ 
		       DECLARE
				  P_COUNT NUMBER(5);
				BEGIN
				  IF '#VALIDFLAG#' IS NULL THEN
				    INSERT INTO COM_BASE_STD_R_SPEC
				      (STD_CODE,
				       STD_NAME,
				       MIN_H,
				       MAX_H,
				       MIN_D,
				       MAX_D,
				       CREATE_NAME,
				       CREATE_TIME,
				       VALIDFLAG,
				       MEMO,
				       MSC_STYLE,
				       SPEC_CODE,
				       SPEC_NAME)
				    VALUES
				      ('#STD_CODE#',
				       '#STD_NAME#',
				       '#MIN_H#',
				       '#MAX_H#',
				       '#MIN_D#',
				       '#MAX_D#',
				       '#CREATE_NAME#',
				       SYSDATE,
				       '1',
				       '#MEMO#',
				       '#MSC_STYLE#',
				       '#SPEC_CODE#',
				       '#SPEC_NAME#');
				  ELSE
				    UPDATE COM_BASE_STD_R_SPEC T
				       SET 
				           MIN_H       = '#MIN_H#',
				           MAX_H       = '#MAX_H#',
				           MIN_D       = '#MIN_D#',
				           MAX_D       = '#MAX_D#',
				           UPDATE_NAME = '#UPDATE_NAME#',
				           UPDATE_TIME = SYSDATE,
				           MEMO        = '#MEMO#',
				           MSC_STYLE = '#MSC_STYLE#',
				           SPEC_CODE = '#SPEC_CODE#',
				           SPEC_NAME = '#SPEC_NAME#'
				     WHERE T.STD_CODE = '#STD_CODE_OLD#'
				       AND NVL(TO_NUMBER(T.MIN_H), '0') = NVL(TO_NUMBER('#MIN_H_OLD#'), '0')
				       AND NVL(TO_NUMBER(T.MIN_D), '0') = NVL(TO_NUMBER('#MIN_D_OLD#'), '0')
				       AND NVL(TO_NUMBER(T.MAX_H), '0') = NVL(TO_NUMBER('#MAX_H_OLD#'), '0')
				       AND NVL(TO_NUMBER(T.MAX_D), '0') = NVL(TO_NUMBER('#MAX_D_OLD#'), '0')
				       AND NVL(T.SPEC_CODE, '0') = NVL('#SPEC_CODE_OLD#', '0');
				  END IF;
				END;
		]]>
	</query>
	
	<query id="BaseStdRSpec.updateState" desc="修改标准号与适用规格关联数据">
		<![CDATA[ 
		DECLARE
			BEGIN
			  IF '#VALIDFLAG#' = '0' THEN
			    UPDATE COM_BASE_STD_R_SPEC T
			       SET T.VALIDFLAG   = '0',
			           T.DELETE_NAME = '#DELETE_NAME#',
			           T.DELETE_TIME = SYSDATE
			     WHERE T.STD_CODE = '#STD_CODE_OLD#'
			       AND NVL(TO_NUMBER(T.MIN_H), '0') = NVL(TO_NUMBER('#MIN_H_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MIN_D), '0') = NVL(TO_NUMBER('#MIN_D_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MAX_H), '0') = NVL(TO_NUMBER('#MAX_H_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MAX_D), '0') = NVL(TO_NUMBER('#MAX_D_OLD#'), '0')
			       AND NVL(T.SPEC_CODE, '0') = NVL('#SPEC_CODE_OLD#', '0');
			  ELSE
			    UPDATE COM_BASE_STD_R_SPEC T
			       SET T.VALIDFLAG   = '1',
			           T.DELETE_NAME = '',
			           T.DELETE_TIME = '',
			           T.UPDATE_NAME = '#UPDATE_NAME#',
			           T.UPDATE_TIME = SYSDATE
			     WHERE T.STD_CODE = '#STD_CODE_OLD#'
			       AND NVL(TO_NUMBER(T.MIN_H), '0') = NVL(TO_NUMBER('#MIN_H_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MIN_D), '0') = NVL(TO_NUMBER('#MIN_D_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MAX_H), '0') = NVL(TO_NUMBER('#MAX_H_OLD#'), '0')
			       AND NVL(TO_NUMBER(T.MAX_D), '0') = NVL(TO_NUMBER('#MAX_D_OLD#'), '0')
			       AND NVL(T.SPEC_CODE, '0') = NVL('#SPEC_CODE_OLD#', '0');
			  END IF;
			END;
		]]>
	</query>
	
	<query id="BaseStdRSpec.isExistSpec" desc="是否存在规格范围">
		<![CDATA[ 
			SELECT COUNT(1)
			  FROM COM_BASE_STD_R_SPEC T
			 WHERE T.STD_CODE = '#STD_CODE#'
			   AND NVL(TO_NUMBER(T.MIN_H), '0') = NVL(TO_NUMBER('#MIN_H#'), '0')
		       AND NVL(TO_NUMBER(T.MIN_D), '0') = NVL(TO_NUMBER('#MIN_D#'), '0')
		       AND NVL(TO_NUMBER(T.MAX_H), '0') = NVL(TO_NUMBER('#MAX_H#'), '0')
		       AND NVL(TO_NUMBER(T.MAX_D), '0') = NVL(TO_NUMBER('#MAX_D#'), '0')
		       AND NVL(T.SPEC_CODE, '0') = NVL('#SPEC_CODE#', '0')
		]]>
	</query>
</queryMap>
