-- Version:		2025.7.31  14:52:27
Drop Table T_RULE_ALG@

Create Table T_RULE_ALG(
AlgId		DECIMAL(10)		NOT NULL,
AlgGroup		VARCHAR(50)		NOT NULL,
AlgName		VARCHAR(200),
AlgParam		VARCHAR(3000),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_RULE_ALG PRIMARY KEY (AlgId, AlgGroup)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_RULE_ALG IS '规则算法'@

COMMENT ON T_RULE_ALG (AlgId IS '算法id')@
COMMENT ON T_RULE_ALG (AlgGroup IS '算法分组')@
COMMENT ON T_RULE_ALG (AlgName IS '算法名称')@
COMMENT ON T_RULE_ALG (AlgParam IS '参数 {  "tags": ["张力"，"速度"]，  "limit_alarm": {   "name":"对那个数据判断的极限"，   "max": 11，   "min": 22  }，  "limit_error": {   "name":"对那个数据判断的极限"，   "max": 11，   "min": 22  }，  "probability_alarm": {   "name":"概率区间"，   "tag": ""，   "probability": 80  }，  "probabil')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_RULE_ALG
*****************************************************************************/
DROP TRIGGER ins_b_T_RULE_ALG@

CREATE OR REPLACE TRIGGER ins_b_T_RULE_ALG
BEFORE INSERT ON T_RULE_ALG REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.toc = (values sysdate);
	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
/****************************************************************************
						UPDATE TRIGGER FOR TABLE
							  T_RULE_ALG
*****************************************************************************/
DROP TRIGGER upd_b_T_RULE_ALG@

CREATE OR REPLACE TRIGGER upd_b_T_RULE_ALG
BEFORE UPDATE ON T_RULE_ALG REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
