<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">
	<query id="CoreSpecificationsBasicsNew.QUERY" desc="权限功能">
		<![CDATA[
			SELECT  'False' CHK,
					SPEC_CODE,
				    SPEC_NAME,
				    DIMATER,
					HEIGHT,
					WEIGHT,
					MSC_STYLE,
					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','有效','无效') VALIDFLAGNAME,
					MEMO
				 
				FROM COM_BASE_SPEC
				   WHERE VALIDFLAG in ('1' , '#VALIDFLAG#')
				   AND lower(SPEC_NAME)||'&' LIKE '%' || lower('#SPEC_NAME#') || '%'
				   AND DECODE('#MSC_STYLE#', NULL, '1', MSC_STYLE) = DECODE('#MSC_STYLE#', NULL, '1', '#MSC_STYLE#')
				   ORDER BY SPEC_CODE
		]]>
	</query>
	<query id="CoreSpecificationsBasicsNew.QUERYSTYLE" desc="查询PSC类型">
		<![CDATA[ 
		SELECT   'FALSE' CB, PC.SPEC_CODE, PC.SPEC_NAME,ER.ORDER_SPEC_CODE,ER.ORDER_SPEC_DESC,PC.DIMATER, PC.HEIGHT, PC.WEIGHT, PC.MSC_STYLE,
                 PC.CREATE_NAME,
                 TO_CHAR (PC.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                 PC.UPDATE_NAME,
                 TO_CHAR (PC.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') UPDATE_TIME,
                 PC.DELETE_NAME,
                 TO_CHAR (PC.DELETE_TIME, 'YYYY-MM-DD HH24:MI:SS') DELETE_TIME,
                 PC.VALIDFLAG, DECODE (PC.VALIDFLAG, '1', '有效', '无效') VALIDFLAGNAME,
                 PC.MEMO
            FROM COM_BASE_SPEC PC INNER JOIN COM_BASE_SPEC_ORDER ER ON
             PC.VALIDFLAG IN ('1',?) 
             AND ER.VALIDFLAG IN ('1') 
             AND LOWER (PC.SPEC_NAME) || '&' LIKE '%' || LOWER ((SELECT SPEC_NAME FROM COM_BASE_SPEC_ORDER WHERE ORDER_SPEC_DESC = ?)) || '%'
             AND PC.MSC_STYLE IN (?)
             AND PC.SPEC_CODE = ER.SPEC_CODE
        ORDER BY PC.SPEC_CODE
		]]>
	</query>
	<query id="CoreSpecificationsBasicsNew.ADD" desc="新增">
		<![CDATA[
		  
		  INSERT INTO COM_BASE_SPEC
		    (SPEC_CODE,
		     SPEC_NAME,
		     DIMATER,
		     HEIGHT,
		     WEIGHT,
		     MSC_STYLE,
		     CREATE_NAME,
		     CREATE_TIME,
		     VALIDFLAG,
		     MEMO)
		  VALUES
		    (?,
		     ?,
		     ?,
		     ?,
		     ROUND(?,4),
		     ?,
		     ?,
		     SYSDATE,
		     1,
		     ?)
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.Save" desc="保存">
		<![CDATA[
			DECLARE
			  P_SPEC_CODE     COM_BASE_SPEC.SPEC_CODE%TYPE := ':SPEC_CODE';
			  P_SPEC_NAME     COM_BASE_SPEC.SPEC_NAME%TYPE := ':SPEC_NAME';
			  P_DIMATER       COM_BASE_SPEC.DIMATER%TYPE := ':DIMATER';
			  P_HEIGHT        COM_BASE_SPEC.HEIGHT%TYPE := ':HEIGHT';
			  P_WEIGHT        COM_BASE_SPEC.WEIGHT%TYPE := ':WEIGHT';
			  P_MSC_STYLE     COM_BASE_SPEC.MSC_STYLE%TYPE := ':MSC_STYLE';
			  P_NAME          COM_BASE_SPEC.CREATE_NAME%TYPE := ':CREATE_NAME';
			  P_MEMO          COM_BASE_SPEC.MEMO%TYPE := ':MEMO';
			  P_MAX_SPEC_CODE COM_BASE_SPEC.SPEC_CODE%TYPE;
			  P_COUNT         NUMBER(5);
			
			BEGIN
			  SELECT ('c' ||
		         LPAD((NVL((TO_NUMBER(SUBSTR(MAX(T.SPEC_CODE), 2, 6)) + 1), 1)),
		               6,
		               '0')) SPEC_CODE
			    INTO P_MAX_SPEC_CODE
			    FROM COM_BASE_SPEC T;
			    
			  SELECT COUNT(1)
			    INTO P_COUNT FROM COM_BASE_SPEC
			   WHERE SPEC_CODE = P_SPEC_CODE;
			  IF P_COUNT = 0 THEN
			    INSERT INTO COM_BASE_SPEC
				    (SPEC_CODE,
				     SPEC_NAME,
				     DIMATER,
				     HEIGHT,
				     WEIGHT,
				     MSC_STYLE,
				     CREATE_NAME,
				     CREATE_TIME,
				     VALIDFLAG,
				     MEMO)
				  VALUES
				    (P_MAX_SPEC_CODE,
				     P_SPEC_NAME,
				     P_DIMATER,
				     P_HEIGHT,
				     P_WEIGHT,
				     P_MSC_STYLE,
				     P_NAME,
				     SYSDATE,
				     1,
				     P_MEMO);
				     
			    INSERT INTO COM_BASE_SPEC_ORDER
							(ORDER_SPEC_CODE,
					        ORDER_SPEC_DESC,
					        SPEC_CODE,
					        SPEC_NAME,
					        CREATE_NAME,
					        CREATE_TIME,
					        VALIDFLAG,
					        MEMO)
							VALUES(
							(SELECT P_MAX_SPEC_CODE || 'DH' ||
							       LPAD((NVL((TO_NUMBER(SUBSTR(MAX(T.ORDER_SPEC_CODE), 10, 6)) + 1), 1)),
							             6,
							             '0') ORDER_SPEC_CODE
							  FROM com_base_spec_order T
							 WHERE T.SPEC_CODE = P_MAX_SPEC_CODE),
							P_SPEC_NAME,P_MAX_SPEC_CODE,P_SPEC_NAME,
							P_NAME,SYSDATE,
							1, '');
				
				IF P_MSC_STYLE NOT IN ('C', 'D') THEN
					INSERT INTO COM_BASE_SPEC_ORDER
								(ORDER_SPEC_CODE,
						        ORDER_SPEC_DESC,
						        SPEC_CODE,
						        SPEC_NAME,
						        CREATE_NAME,
						        CREATE_TIME,
						        VALIDFLAG,
						        MEMO)
								VALUES(
								(SELECT P_MAX_SPEC_CODE || 'DH' ||
								       LPAD((NVL((TO_NUMBER(SUBSTR(MAX(T.ORDER_SPEC_CODE), 10, 6)) + 1), 1)),
								             6,
								             '0') ORDER_SPEC_CODE
								  FROM com_base_spec_order T
								 WHERE T.SPEC_CODE = P_MAX_SPEC_CODE),
								DECODE(P_MSC_STYLE, 'A', P_DIMATER || 'mm x ' || P_HEIGHT || 'mm', P_DIMATER || 'mm'),P_MAX_SPEC_CODE,P_SPEC_NAME,
								P_NAME,SYSDATE,
								1, '');
				END IF;
			  ELSE
			     UPDATE COM_BASE_SPEC set
							SPEC_NAME= P_SPEC_NAME, 
							DIMATER= P_DIMATER, 
							HEIGHT= P_HEIGHT, 
							WEIGHT= P_WEIGHT,
							MSC_STYLE= P_MSC_STYLE,
							UPDATE_NAME= P_NAME, 
							UPDATE_TIME= SYSDATE,
							MEMO= P_MEMO
							WHERE SPEC_CODE= P_SPEC_CODE;
			  END IF;
			END;
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.MODIFY" desc="修改">
		<![CDATA[
			 UPDATE COM_BASE_SPEC set
							SPEC_NAME=?, 
							DIMATER=?, 
							HEIGHT=?, 
							WEIGHT=?,
							MSC_STYLE=?,
							UPDATE_NAME=?, 
							UPDATE_TIME=SYADATE,
							MEMO=?
							WHERE SPEC_CODE=?
		]]>
	</query>
	<query id="CoreSpecificationsBasicsNew.DELETE" desc="作废">
		<![CDATA[
			 UPDATE COM_BASE_SPEC T
			   SET T.DELETE_NAME = ?, T.DELETE_TIME = SYSDATE, T.VALIDFLAG = '0'
			 WHERE T.SPEC_CODE = ?
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.RESUME" desc="恢复">
		<![CDATA[
			UPDATE COM_BASE_SPEC T
               SET T.DELETE_NAME = '', T.DELETE_TIME = '', T.VALIDFLAG = '1'
             WHERE T.SPEC_CODE = ?
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.MAXID" desc="获取最大id">
		<![CDATA[
			SELECT MAX(SPEC_CODE) FROM COM_BASE_SPEC
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.GetMaxOrder_Spec_Code" desc="获取最大id">
		<![CDATA[
			SELECT MAX(T.ORDER_SPEC_CODE) FROM COM_BASE_SPEC_ORDER T
			WHERE T.SPEC_CODE = ?
		]]>
	</query>
	
	
	<query id="CoreSpecificationsBasicsNew.IsExistSpec" desc="是否存在产品规格代码">
		<![CDATA[
			SELECT COUNT(1) FROM COM_BASE_SPEC T WHERE T.SPEC_NAME = ?
			AND T.SPEC_CODE != ?
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.IsExistOrderSpec" desc="是否存在订货规格代码">
		<![CDATA[
			SELECT COUNT(1) FROM COM_BASE_SPEC_ORDER T WHERE T.ORDER_SPEC_DESC = ?
			AND T.ORDER_SPEC_CODE != ?
		]]>
	</query>
	
	<query id="CoreSpecificationsBasicsNew.getMeterWeight" desc="米单重公式4052">
		<![CDATA[
		   SELECT BASENAME, BASECODE
           FROM COM_BASE_INFO
           WHERE SORTCODE = '4052'
           AND VALIDFLAG = '1'
           AND MEMO = ?
			 
		]]>
	</query>
	
</queryMap>