-- T_EB_CONTROLWARNINGRULE 预警规则表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLWARNINGRULE')
CREATE TABLE T_EB_CONTROLWARNINGRULE (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FNUMBER             NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FNAME               NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FDESCRIPTION        NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FCREATER      	    BIGINT               NULL,
	FCREATEDATE      	DATETIME             NULL,
	FMODIFIER      	    BIGINT               NULL,
	FMODIFYDATE      	DATETIME             NULL,
	FWARNINGSENDTYPE    NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FCONDITION          NVARCHAR(2000)       NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_EB_CONTROLWARNINGRULE', 'T_EB_CONTROLWARNINGRULE', 'FID', '1';



-- T_EB_CONTROLWARNINGRULE_L 预警规则多语言表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_CONTROLWARNINGRULE_L')
CREATE TABLE T_EB_CONTROLWARNINGRULE_L (
	FPKID             	NVARCHAR(36)         NOT NULL DEFAULT ' ',
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FLOCALEID           NVARCHAR(10)         NOT NULL DEFAULT ' ',
	FNAME               NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FDESCRIPTION        NVARCHAR(50)         NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_EB_CONTROLWARNINGRULE_L', 'T_EB_CONTROLWARNINGRULE_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_CONTROLWARNINGRULE_L')
CREATE INDEX IDX_EB_CONTROLWARNINGRULE_L ON T_EB_CONTROLWARNINGRULE_L (FID,FLOCALEID);



-- T_EB_WARNINGRULECONDITION 预警规则条件表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGRULECONDITION')
CREATE TABLE T_EB_WARNINGRULECONDITION (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FBALANCE            NVARCHAR(50)         NULL,
	FACTUAL             NVARCHAR(50)         NULL,
	FOCCUPATION         NVARCHAR(50)         NULL,
	FEXECUTE            NVARCHAR(50)         NULL,
	FRATE               BIGINT               NULL
);

EXEC P_ALTERPK 'PK_EB_WARNINGRULECONDITION', 'T_EB_WARNINGRULECONDITION', 'FID', '1';



 -- T_EB_WARNINGRULERATE 预警规则执行进度表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGRULERATE')
CREATE TABLE T_EB_WARNINGRULERATE (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FTIME_PLAN          NVARCHAR(50)         NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_EB_WARNINGRULERATE', 'T_EB_WARNINGRULERATE', 'FID', '1';



-- T_EB_WARNINGRULERATE_L 预警规则执行进度多语言表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNINGRULERATE_L')
CREATE TABLE T_EB_WARNINGRULERATE_L (
	FPKID             	NVARCHAR(36)         NOT NULL DEFAULT ' ',
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FLOCALEID           NVARCHAR(10)         NOT NULL DEFAULT ' ',
	FTIME_PLAN          NVARCHAR(50)         NOT NULL DEFAULT ' '
);

EXEC P_ALTERPK 'PK_EB_WARNINGRULERATE_L', 'T_EB_WARNINGRULERATE_L', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_WARNINGRULERATE_L')
CREATE INDEX IDX_EB_WARNINGRULERATE_L ON T_EB_WARNINGRULERATE_L (FID,FLOCALEID);