-- T_EB_WARNNINGSCHEME 预警方案表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGSCHEME')
CREATE TABLE T_EB_WARNNINGSCHEME (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FNUMBER             NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FNAME               NVARCHAR(200)         NOT NULL DEFAULT ' ',
	FMODEL				BIGINT               NOT NULL DEFAULT 0,
	FBUSINESSMODEL		BIGINT               NOT NULL DEFAULT 0,
	FREMARK             NVARCHAR(500)         NOT NULL DEFAULT ' ',
	FWARNNINGRULE		BIGINT				 NOT NULL DEFAULT 0,
	FWARNNINGMSG		NVARCHAR(2000)		 NOT NULL DEFAULT ' ',
	FSTATUS				CHAR(1)				 NOT NULL DEFAULT '1',
	FMODIFIER      	    BIGINT               NULL,
	FMODIFYDATE      	DATETIME             NULL
);

EXEC P_ALTERPK 'PK_T_EB_WARNNINGSCHEME', 'T_EB_WARNNINGSCHEME', 'FID', '1';

-- T_EB_WARNNINGSCHEME_L 预警方案多语言表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGSCHEME_L')
CREATE TABLE T_EB_WARNNINGSCHEME_L (
	FPKID             	NVARCHAR(20)         NOT NULL DEFAULT ' ',
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FLOCALEID           NVARCHAR(20)         NOT NULL DEFAULT ' ',
	FNAME               NVARCHAR(200)        NOT NULL DEFAULT ' ',
	FREMARK             NVARCHAR(500)        NOT NULL DEFAULT ' '
);
EXEC P_ALTERPK 'PK_IDX_T_EB_WARNNINGSCHEME_L', 'T_EB_WARNNINGSCHEME_L', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_WARNNINGSCHEME_L') 
 CREATE INDEX IDX_T_EB_WARNNINGSCHEME_L ON T_EB_WARNNINGSCHEME_L ( FID ,FLOCALEID );


-- T_EB_WARNNINGENTITY 预警组织表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGENTITY')
CREATE TABLE T_EB_WARNNINGENTITY (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FSEQ                INT                  NOT NULL DEFAULT 0,	
	FENTITY             BIGINT               NOT NULL DEFAULT 0,	
	FRANGE              NVARCHAR(50)         NOT NULL DEFAULT ' '
);
EXEC P_ALTERPK 'PK_T_EB_WARNNINGENTITY', 'T_EB_WARNNINGENTITY', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_WARNNINGENTITY') 
 CREATE INDEX IDX_T_EB_WARNNINGENTITY ON T_EB_WARNNINGENTITY (FID);

-- T_EB_WARNNINGRECEIVER 预警方案接收人映射表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGRECEIVER')
CREATE TABLE T_EB_WARNNINGRECEIVER (
	FPKID             	BIGINT         		 NOT NULL DEFAULT 0,
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID         BIGINT               NOT NULL DEFAULT 0
);
EXEC P_ALTERPK 'PK_T_EB_WARNNINGRECEIVER', 'T_EB_WARNNINGRECEIVER', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_WARNNINGRECEIVER') 
 CREATE INDEX IDX_T_EB_WARNNINGRECEIVER ON T_EB_WARNNINGRECEIVER (FID);
 
-- T_EB_WARNNINGTARGET 预警指标表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGTARGET')
CREATE TABLE T_EB_WARNNINGTARGET (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FSEQ                INT                  NOT NULL DEFAULT 0
);
EXEC P_ALTERPK 'PK_T_EB_WARNNINGTARGET', 'T_EB_WARNNINGTARGET', 'FENTRYID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_WARNNINGTARGET') 
 CREATE INDEX IDX_T_EB_WARNNINGTARGET ON T_EB_WARNNINGTARGET (FID);
 
-- T_EB_WARNNINGTARGETENTITY 预警指标子表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_WARNNINGTARGETENTITY')
CREATE TABLE T_EB_WARNNINGTARGETENTITY (
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FDETAILID           BIGINT               NOT NULL DEFAULT 0,
	FSEQ                INT                  NOT NULL DEFAULT 0,	
	FMEMBER             BIGINT               NOT NULL DEFAULT 0,	
	FDIMENSIONTREEMODEL NVARCHAR(50)		 NOT NULL DEFAULT ' ',
	FDIMENSION          BIGINT               NOT NULL DEFAULT 0,	
	FISLEAF				CHAR(1)				 NOT NULL DEFAULT '1',
	FSCOPE              NVARCHAR(50)         NOT NULL DEFAULT ' '
);
EXEC P_ALTERPK 'PK_T_EB_WARNNINGTARGETENTITY', 'T_EB_WARNNINGTARGETENTITY', 'FDETAILID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_T_EB_WARNNINGTARGETENTITY') 
 CREATE INDEX IDX_T_EB_WARNNINGTARGETENTITY ON T_EB_WARNNINGTARGETENTITY (FENTRYID);
 
 