<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="消息">
	<query id="message.selectByKey" desc="消息查询">
		<![CDATA[
SELECT T.* FROM APP_MESSAGE T  WHERE REFER_KEY =? AND VALIDFLAG ='20' AND WINDOW_KEY =?
		]]>
	</query>

	<query  id="message.getMaxId" desc="消息查询最大ID">

		SELECT 'C' || TO_CHAR(SYSDATE,'YYYYMMDD' ) ||
		LPAD(NVL(MAX(TO_NUMBER(SUBSTR(MESSAGE_NO, LENGTH(MESSAGE_NO) - 4))),
		0) + 1,
		5,
		'0') MESSAGE_NO
		FROM APP_MESSAGE
		WHERE MESSAGE_NO LIKE   'C' ||  TO_CHAR(SYSDATE,'YYYYMMDD' )  ||  '_____'
	</query>

	<query id="message.insert">
		insert into APP_MESSAGE (MESSAGE_NO, MESSAGE_TITLE, MESSAGE_LEVEL_CODE,
		MESSAGE_LEVEL_DESC, MESSAGE_CLASS_CODE, MESSAGE_CLASS_DESC,
		MESSAGE_PATH, RELEASE_ORG_CODE, RELEASE_ORG_DESC,
		RELEASE_USERID, RELEASE_NAME, RELEASE_TIME,
		VALIDFLAG, MEMO, CREATE_USERID,
		CREATE_NAME, CREATE_TIME,REFER_KEY,
		APPROVAL_NODE, WINDOW_KEY, EVENT_KEY,
		NEED_GROUP, IS_PUSH, MESSAGE_CONTENT
		)
		values ( '#MESSAGE_NO#',
		'#MESSAGE_TITLE#',
		'#MESSAGE_LEVEL_CODE#',
		(SELECT BASENAME FROM COM_BASE_INFO t WHERE BASECODE='#MESSAGE_LEVEL_CODE#'),
		'#MESSAGE_CLASS_CODE#',
		(SELECT BASENAME FROM COM_BASE_INFO t WHERE BASECODE='#MESSAGE_CLASS_CODE#'),
		'#MESSAGE_PATH#',
		'#RELEASE_ORG_CODE#',
		'#RELEASE_ORG_DESC#',
		'#RELEASE_USERID#',
		'#RELEASE_NAME#',
		SYSDATE,
		'#VALIDFLAG#',
		'#MEMO#',
		'#CREATE_USERID#',
		'#CREATE_NAME#',
		SYSDATE,
		'#REFER_KEY#',
		'#APPROVAL_NODE#',
		'#WINDOW_KEY#',
		'#EVENT_KEY#',
		'#NEED_GROUP#',
		'0',
		'#MESSAGE_CONTENT#'
		)
	</query>

	<query id="message.insertUser">
		INSERT INTO APP_MESSAGE_USER
		(MESSAGE_NO,
		TARGET_USERID,
		TARGET_NAME,
		READ_TIME,
		VALIDFLAG,
		TARGET_LOGO,
		USER_NODE)
		SELECT ?, M.USER_ID, N.USERNAME, NULL, '00', NULL, STATUS_PREVIOUS
		FROM (SELECT DISTINCT ID, USER_ID, PROCESS.STATUS_PREVIOUS
		FROM (SELECT CASE
		WHEN C.KEY IN
		('MarkCompleted', 'CancleMarkCompleted') AND
		M.CUSTOMINFO = '1' THEN
		'5'
		WHEN C.KEY IN
		('MarkCompleted', 'CancleMarkCompleted') AND
		M.CUSTOMINFO = '3' THEN
		'6'
		ELSE
		M.CUSTOMINFO
		END ID,
		C.KEY,
		U.USER_ID,
		D.PLINE_CODE,
		D.PLINE_NAME
		FROM CORE_APP_FUNCTION   M,
		CORE_APP_FUNCTION   C,
		CORE_APP_ROLERELATE R,
		CORE_APP_USER_ROLE  U
		LEFT JOIN (SELECT D.ROLEID, P.PLINE_CODE, P.PLINE_NAME
		FROM CORE_APP_ROLEDATA D, COM_BASE_PLINE P
		WHERE D.DEPTID = P.DEPARTMENT_CODE) D
		ON D.ROLEID = U.ROLE_ID
		WHERE C.PARENT_ID = M.ID
		AND M.KEY =
		'Core.StlMes.Client.Mcp.Treatment.HeatTreatment.FrmEntrustDataApproval'
		AND C.KEY IN ('ApprovalOk', 'MarkCompleted')
		AND C.ID = R.FUNID
		AND R.ROLEID = U.ROLE_ID
		AND U.ROLE_ID NOT IN ('admin', '2439')) Q,
		HTT_ENTRUST_PROCESS_DEFAUL PROCESS,
		HTT_ENTRUST H
		WHERE Q.ID = PROCESS.APPROVAL_NO
		AND PROCESS.APPROVAL_TYPE = '0'
		AND PROCESS.BUTTON_KEY = Q.KEY
		AND PROCESS.SUBCONTRACT_TARGET = H.SUBCONTRACT_TARGET
		AND (PROCESS.SUBCONTRACT_TYPE = '/' OR
		PROCESS.SUBCONTRACT_TYPE = H.SUBCONTRACT_TYPE)
		AND H.PLINE_CODE = Q.PLINE_CODE
		AND H.SUBCONTRACT_NO = ?) M,
		CORE_APP_USER N
		WHERE M.USER_ID = N.USERID
	</query>

	<query id="message.update">
		UPDATE APP_MESSAGE SET APPROVAL_NODE =?, EVENT_KEY=?
		where MESSAGE_NO =?
	</query>
</queryMap>