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

Create Table T_EQP_REPORT(
ReportId		VARCHAR(50)		NOT NULL,
Name		VARCHAR(50)		NOT NULL,
RuleId		VARCHAR(50),
EqpId		VARCHAR(20),
Type		DECIMAL(1)		NOT NULL,
Remark		VARCHAR(100),
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_EQP_REPORT PRIMARY KEY (ReportId)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@
Alter Table T_EQP_REPORT ALTER COLUMN RuleId SET WITH Default '-1'@
Alter Table T_EQP_REPORT ALTER COLUMN EqpId SET WITH Default '-1'@
Alter Table T_EQP_REPORT ALTER COLUMN Type SET WITH Default 0@

COMMENT ON Table T_EQP_REPORT IS '设备类运行报告'@

COMMENT ON T_EQP_REPORT (ReportId IS '报告ID')@
COMMENT ON T_EQP_REPORT (Name IS '报告名称')@
COMMENT ON T_EQP_REPORT (RuleId IS '规则id(只有故障报告需要)')@
COMMENT ON T_EQP_REPORT (EqpId IS '设备id(只有故障报告需要)')@
COMMENT ON T_EQP_REPORT (Type IS '报告类型(0: 检修 1: 故障)')@
COMMENT ON T_EQP_REPORT (Remark IS '备注')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_EQP_REPORT
*****************************************************************************/
DROP TRIGGER ins_b_T_EQP_REPORT@

CREATE OR REPLACE TRIGGER ins_b_T_EQP_REPORT
BEFORE INSERT ON T_EQP_REPORT 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_REPORT
*****************************************************************************/
DROP TRIGGER upd_b_T_EQP_REPORT@

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