-- T_EB_WARNINGREPORT 预警详情表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGREPORT')
CREATE TABLE T_EB_WARNINGREPORT (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FWARNSCHEME			BIGINT               NOT NULL DEFAULT 0,
	FMODELID			BIGINT               NOT NULL DEFAULT 0,
	FBUSSMODEL			BIGINT               NOT NULL DEFAULT 0,
	FEARLYWARNID		BIGINT               NOT NULL DEFAULT 0,
	FTIME             	NVARCHAR(255)        NOT NULL DEFAULT ' ',
	FRECEIVERID			BIGINT               NOT NULL DEFAULT 0,
	FCREATEDATE      	DATETIME             NULL	
);

EXEC P_ALTERPK 'PK_EB_WARNINGREPORT', 'T_EB_WARNINGREPORT', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGREPORTS')
CREATE INDEX IDX_EB_WARNINGREPORTS ON T_EB_WARNINGREPORT (FWARNSCHEME);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGREPORTM')
CREATE INDEX IDX_EB_WARNINGREPORTM ON T_EB_WARNINGREPORT (FMODELID,FBUSSMODEL);


-- T_EB_WARNINGREPORTENTRY 预警详情分录表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGREPORTENTRY')
CREATE TABLE T_EB_WARNINGREPORTENTRY (	
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID           	BIGINT               NOT NULL DEFAULT 0,
	FSEQ             	INTEGER              NOT NULL DEFAULT 0,
	FORGUNITID          BIGINT               NOT NULL DEFAULT 0,
	FACCOUNTID          BIGINT               NOT NULL DEFAULT 0,
	FYEAR             	BIGINT               NOT NULL DEFAULT 0,
	FPERIODID           BIGINT               NOT NULL DEFAULT 0,
	FVERSIONID          BIGINT               NOT NULL DEFAULT 0,
	FCURRENCYID         BIGINT               NOT NULL DEFAULT 0,
	FAUDITTRAILID       BIGINT               NOT NULL DEFAULT 0,
	FICID             	BIGINT               NOT NULL DEFAULT 0,
	FCHANGETYPEID       BIGINT               NOT NULL DEFAULT 0,
	FDATATYPEID         BIGINT               NOT NULL DEFAULT 0,
	FMETRICID           BIGINT               NOT NULL DEFAULT 0	
);

EXEC P_ALTERPK 'PK_EB_WARNINGREPORTENTRY', 'T_EB_WARNINGREPORTENTRY', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGREPORTENTRY')
CREATE INDEX IDX_EB_WARNINGREPORTENTRY ON T_EB_WARNINGREPORTENTRY (FID);


-- T_EB_WARNINGSUBENTRY 预警详情值表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGSUBENTRY')
CREATE TABLE T_EB_WARNINGSUBENTRY (
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FDETAILID            BIGINT               NOT NULL DEFAULT 0,
	FSEQ             	INTEGER              NOT NULL DEFAULT 0,
	FTYPE            	NVARCHAR(50)        NOT NULL DEFAULT ' ',
	FVALUE             	DECIMAL(19,6)        NULL	
);

EXEC P_ALTERPK 'PK_EB_WARNINGSUBENTRY', 'T_EB_WARNINGSUBENTRY', 'FDETAILID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGSUBENTRY')
CREATE INDEX IDX_EB_WARNINGSUBENTRY ON T_EB_WARNINGSUBENTRY (FENTRYID);


 -- T_EB_WARNINGRPTUSERDEF 预警详情自定义维度成员表 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGUSERDEF')
CREATE TABLE T_EB_WARNINGUSERDEF (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FDETAILID			BIGINT               NOT NULL DEFAULT 0,
	FSEQ             	INTEGER              NOT NULL DEFAULT 0,
	FDIMENSIONID        BIGINT               NOT NULL DEFAULT 0,
	FMEMBERID           BIGINT               NOT NULL DEFAULT 0	
);

EXEC P_ALTERPK 'PK_EB_WARNINGUSERDEF', 'T_EB_WARNINGUSERDEF', 'FDETAILID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGUSERDEF')
CREATE INDEX IDX_EB_WARNINGUSERDEF ON T_EB_WARNINGUSERDEF (FID);

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGUSERDEFE')
CREATE INDEX IDX_EB_WARNINGUSERDEFE ON T_EB_WARNINGUSERDEF (FENTRYID);