-- 任务执行人表

-- 任务下达暂存表关联的执行人表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKORG_EXECUTORS') 
CREATE TABLE T_EB_TASKORG_EXECUTORS (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_EB_TASKORG_EXECUTORS', 'T_EB_TASKORG_EXECUTORS', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_TASKORG_EXECUTORS') 
CREATE INDEX IDX_EB_TASKORG_EXECUTORS ON T_EB_TASKORG_EXECUTORS (FID);

-- 任务下达分配表关联的执行人表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKSAVE_EXECUTORS') 
CREATE TABLE T_EB_TASKSAVE_EXECUTORS (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_EB_TASKSAVE_EXECUTORS', 'T_EB_TASKSAVE_EXECUTORS', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_TASKSAVE_EXECUTORS') 
CREATE INDEX IDX_EB_TASKSAVE_EXECUTORS ON T_EB_TASKSAVE_EXECUTORS (FID);


-- 任务实例表关联的执行人表
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_EB_TASKPROCES_EXECUTORS') 
CREATE TABLE T_EB_TASKPROCES_EXECUTORS (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_EB_TASKPROCES_EXECUTORS', 'T_EB_TASKPROCES_EXECUTORS', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_TASKPROCES_EXECUTORS') 
CREATE INDEX IDX_EB_TASKPROCES_EXECUTORS ON T_EB_TASKPROCES_EXECUTORS (FID);

-- 任务暂存表增加字段来源类型
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_TASKSAVE' AND KSQL_COL_NAME IN ('FSOURCETYPE')) 
ALTER TABLE T_EB_TASKSAVE ADD (FSOURCETYPE CHAR(1) DEFAULT '0' NOT NULL);