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

Create Table T_EQP_DATAILS(
RecordId		VARCHAR(50)		NOT NULL,
EqpId		VARCHAR(20)		NOT NULL,
OperType		VARCHAR(60)		NOT NULL,
HealthLevel		DECIMAL(5),
Operator		VARCHAR(50),
DateOper		TIMESTAMP,
Content		VARCHAR(1000),
FileAddr		VARCHAR(1000),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_EQP_DATAILS PRIMARY KEY (RecordId, EqpId, OperType)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_EQP_DATAILS IS '设备履历'@

COMMENT ON T_EQP_DATAILS (RecordId IS '履历编号')@
COMMENT ON T_EQP_DATAILS (EqpId IS '设备编号')@
COMMENT ON T_EQP_DATAILS (OperType IS '操作类型')@
COMMENT ON T_EQP_DATAILS (HealthLevel IS '健康状况（0~100）[严重报警，经用户确认健康度减1]')@
COMMENT ON T_EQP_DATAILS (Operator IS '操作人')@
COMMENT ON T_EQP_DATAILS (DateOper IS '操作时间')@
COMMENT ON T_EQP_DATAILS (Content IS '操作内容')@
COMMENT ON T_EQP_DATAILS (FileAddr IS '文件索引')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_EQP_DATAILS
*****************************************************************************/
DROP TRIGGER ins_b_T_EQP_DATAILS@

CREATE OR REPLACE TRIGGER ins_b_T_EQP_DATAILS
BEFORE INSERT ON T_EQP_DATAILS 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_EQP_DATAILS
*****************************************************************************/
DROP TRIGGER upd_b_T_EQP_DATAILS@

CREATE OR REPLACE TRIGGER upd_b_T_EQP_DATAILS
BEFORE UPDATE ON T_EQP_DATAILS 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
@
