-- T_EB_RECIPIENTMAPPING 接收人映射方案表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RECIPIENTMAPPING')
CREATE TABLE T_EB_RECIPIENTMAPPING (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FORGTYPE            NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FNUMBER             NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FNAME               NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FBGORGMULTIVIEW     CHAR(1)              NOT NULL DEFAULT '0',
	FDESCRIPTION        NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FCREATER      	    BIGINT               NULL,
	FCREATEDATE      	DATETIME             NULL,
	FMODIFIER      	    BIGINT               NULL,
	FMODIFYDATE      	DATETIME             NULL,
	FMODEL      	    BIGINT               NOT NULL DEFAULT 0,
	FISDEFAULT          CHAR(1)              NOT NULL DEFAULT '0'
);

EXEC P_ALTERPK 'PK_EB_RECIPIENTMAPPING', 'T_EB_RECIPIENTMAPPING', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_RECIPIENTMAPPING')
CREATE INDEX IDX_EB_RECIPIENTMAPPING ON T_EB_RECIPIENTMAPPING (FMODEL);



-- T_EB_RECIPIENTMAPPING_L 接收人映射方案多语言表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RECIPIENTMAPPING_L')
CREATE TABLE T_EB_RECIPIENTMAPPING_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_RECIPIENTMAPPING_L', 'T_EB_RECIPIENTMAPPING_L', 'FPKID', '1';

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



-- T_EB_RECIPIENTMAPENTRY 接收人映射方案明细表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RECIPIENTMAPENTRY')
CREATE TABLE T_EB_RECIPIENTMAPENTRY (
	FID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FSEQ                INT                  NOT NULL DEFAULT 0,
	FORGTYPEITEM        NVARCHAR(50)         NOT NULL DEFAULT ' ',
	FBGORGVIEW          BIGINT               NULL,
	FSTATUS             CHAR(1)              NOT NULL DEFAULT '0',
	FORG                BIGINT               NULL
);

EXEC P_ALTERPK 'PK_EB_RECIPIENTMAPENTRY', 'T_EB_RECIPIENTMAPENTRY', 'FENTRYID', '1';

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



 -- T_EB_RECIPIENTMAPPERSON 接收人映射方案人员多选成员表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_RECIPIENTMAPPERSON')
CREATE TABLE T_EB_RECIPIENTMAPPERSON (
	FPKID             	BIGINT               NOT NULL DEFAULT 0,
	FENTRYID            BIGINT               NOT NULL DEFAULT 0,
	FBASEDATAID    		BIGINT               NOT NULL DEFAULT 0
);

EXEC P_ALTERPK 'PK_EB_RECIPIENTMAPPERSON', 'T_EB_RECIPIENTMAPPERSON', 'FPKID', '1';

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