<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="检验项和标准关系表">
	<query id="ComBasePhyRStdMng.Query" desc="查询检验项和标准的关系">
		<![CDATA[
		 SELECT 
	       T.PHY_STD_ID,
	       T.STD_CODE,
	       NVL(A.STD_NAME, T.STD_NAME) STD_NAME,
	       T.STD_CODE_ALPHA,
	       NVL(B.STD_NAME, T.STD_NAME_ALPHA) STD_NAME_ALPHA,
	       T.PHY_CODE,
	       NVL(C.PHY_TYPE, T.PHY_TYPE) PHY_TYPE,
	       T.PHY_STD,
	       D.STD_NAME PHY_STD_NAME,
	       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,
	       T.DELETE_NAME,
	       TO_CHAR(T.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
	       T.VALIDFLAG,
	       DECODE(T.VALIDFLAG, '1', '有效', '0', '无效', '未识别') VALIDFLAG_NAME,
	       T.MEMO,
	       T.STD_FILE_PATH
	 FROM COM_BASE_PHY_R_STD T
	 LEFT JOIN COM_BASE_STD A ON A.STD_CODE = T.STD_CODE
	 LEFT JOIN COM_BASE_STD B ON B.STD_CODE = T.STD_CODE_ALPHA
	 LEFT JOIN COM_BASE_PHY_B C ON C.PHY_CODE = T.PHY_CODE
	 LEFT JOIN COM_BASE_STD D ON D.STD_CODE = T.PHY_STD
	 WHERE
	 T.VALIDFLAG IN ('1', ?)
	 AND DECODE(?, NULL, '1', T.PHY_CODE) LIKE DECODE(?, NULL, '1', '%' || ? || '%')
		]]>
	</query>
	
	<query id="ComBasePhyRStdMng.Insert" desc="新增检验项和标准的关系">
		<![CDATA[
		  INSERT INTO COM_BASE_PHY_R_STD(
	        PHY_STD_ID,
	        STD_CODE,
	        STD_NAME,
	        STD_CODE_ALPHA,
	        STD_NAME_ALPHA,
	        PHY_CODE,
	        PHY_TYPE,
	        PHY_STD,
	        CREATE_NAME,
	        CREATE_TIME,
	        VALIDFLAG,
	        MEMO,
	        STD_FILE_PATH)
	 VALUES( 
	        (':PHY_CODE' || ':STD_CODE' || ':STD_CODE_ALPHA' || ':PHY_STD'),
	        ':STD_CODE',
	        ':STD_NAME',
	        ':STD_CODE_ALPHA',
	        ':STD_NAME_ALPHA',
	        ':PHY_CODE',
	        ':PHY_TYPE',
	        ':PHY_STD',
	        ':CREATE_NAME',
	        SYSDATE,
	        '1',
	        ':MEMO',':STD_FILE_PATH')
		]]>
	</query>
	
	<query id="ComBasePhyRStdMng.Update" desc="修改检验项和标准的关系">
		<![CDATA[
		   UPDATE COM_BASE_PHY_R_STD
			   SET 
			        PHY_STD_ID = (':PHY_CODE' || ':STD_CODE' || ':STD_CODE_ALPHA' || ':PHY_STD'),
			        STD_CODE = ':STD_CODE',
			        STD_NAME = ':STD_NAME',
			        STD_CODE_ALPHA = ':STD_CODE_ALPHA',
			        STD_NAME_ALPHA = ':STD_NAME_ALPHA',
			        PHY_CODE = ':PHY_CODE',
			        PHY_TYPE = ':PHY_TYPE',
			        PHY_STD = ':PHY_STD',
			        UPDATE_NAME = ':UPDATE_NAME',
			        UPDATE_TIME = SYSDATE,
			        MEMO = ':MEMO',
			        STD_FILE_PATH = ':STD_FILE_PATH'
			 WHERE
			 PHY_STD_ID = ':PHY_STD_ID'
		]]>
	</query>
	
	<query id="ComBasePhyRStdMng.DeleteOrResume" desc="作废或者恢复检验项和标准的关系">
		<![CDATA[
		   DECLARE
			  P_PHY_STD_ID  COM_BASE_PHY_R_STD.PHY_STD_ID%TYPE := ?;
			  P_NAME      COM_BASE_PHY_R_STD.CREATE_NAME%TYPE := ?;
			  P_VALIDFLAG COM_BASE_PHY_R_STD.VALIDFLAG%TYPE := ?;
			BEGIN
			  IF P_VALIDFLAG = 1 THEN
			    UPDATE COM_BASE_PHY_R_STD T
			       SET T.UPDATE_NAME = P_NAME,
			           T.UPDATE_TIME = SYSDATE,
			           T.DELETE_NAME = '',
			           T.DELETE_TIME = '',
			           T.VALIDFLAG   = '1'
			     WHERE T.PHY_STD_ID = P_PHY_STD_ID;
			  ELSE
			    UPDATE COM_BASE_PHY_R_STD T
			       SET T.DELETE_NAME = P_NAME,
			           T.DELETE_TIME = SYSDATE,
			           T.VALIDFLAG   = '0'
			     WHERE T.PHY_STD_ID = P_PHY_STD_ID;
			  END IF;
			END;
		]]>
	</query>
	
	<query id="ComBasePhyRStdMng.isExistPhyStdId" desc="是否存在检验项和标准关系主键">
		<![CDATA[
		SELECT COUNT(1) FROM COM_BASE_PHY_R_STD WHERE PHY_STD_ID 
			= (':PHY_CODE' || ':STD_CODE' || ':STD_CODE_ALPHA' || ':PHY_STD')
		]]>
	</query>
	
	<query id="ComBasePhyRStdMng.getStdAlpha" desc="标准下的ALpha">
		<![CDATA[
		   SELECT 
		   ALPHA_CODE AS STD_CODE, 
		   ALPHA_NAME AS STD_NAME
  
         FROM COM_BASE_STD_ALPHA T
         WHERE VALIDFLAG = '1'
         AND T.STD_CODE = ?
         ORDER BY ALPHA_CODE
		 
		]]>
	</query>
</queryMap>