/**Begin D:\PDM_UPGRADE\PDM1\SOEHRR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SOEHRR_COLLECTTASK' AND KSQL_COL_NAME ='FCYCTASKID')
ALTER TABLE T_SOEHRR_COLLECTTASK ADD (FCYCTASKID BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_CYCFILLUNITS')
CREATE TABLE T_SOEHRR_CYCFILLUNITS (
                                       FPKID BIGINT DEFAULT 0 NOT NULL,
                                       FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                       FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_AUTOCOLLRECORD')
CREATE TABLE T_SOEHRR_AUTOCOLLRECORD (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
                                         FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                         FSTATUS VARCHAR(2) DEFAULT ' ' NOT NULL,
                                         FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                         FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                         FENABLE VARCHAR(2) DEFAULT ' ' NOT NULL,
                                         FCREATETIME DATETIME,
                                         FMODIFYTIME DATETIME,
                                         FMASTERID BIGINT DEFAULT 0 NOT NULL,
                                         FDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FDISABLERID BIGINT DEFAULT 0 NOT NULL,
                                         FDISABLEDATE DATETIME,
                                         FGENSTATUS VARCHAR(10) DEFAULT ' ' NOT NULL,
                                         FCYCTASKID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_DISDATEENTRY')
CREATE TABLE T_SOEHRR_DISDATEENTRY (
                                       FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                       FSEQ INT DEFAULT 0 NOT NULL,
                                       FBELONGPERIOD BIGINT DEFAULT 0 NOT NULL,
                                       FDATASTARTTIME VARCHAR(50) DEFAULT ' ' NOT NULL,
                                       FDATAENDTIME VARCHAR(50) DEFAULT ' ' NOT NULL,
                                       FSTARTDATE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                       FENDDATE VARCHAR(50) DEFAULT ' ' NOT NULL,
                                       FDATASTARTTIMEVAL DATETIME,
                                       FDATAENDTIMEVAL DATETIME,
                                       FSTARTDATEVAL DATETIME,
                                       FENDDATEVAL DATETIME,
                                       FBELONGYEAR INT DEFAULT 0 NOT NULL,
                                       FID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_CYCCOLLECTTASK')
CREATE TABLE T_SOEHRR_CYCCOLLECTTASK (
                                         FID BIGINT DEFAULT 0 NOT NULL,
                                         FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
                                         FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                         FSTATUS VARCHAR(2) DEFAULT ' ' NOT NULL,
                                         FCREATORID BIGINT DEFAULT 0 NOT NULL,
                                         FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                                         FENABLE VARCHAR(2) DEFAULT ' ' NOT NULL,
                                         FCREATETIME DATETIME,
                                         FMODIFYTIME DATETIME,
                                         FMASTERID BIGINT DEFAULT 0 NOT NULL,
                                         FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                         FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FINDEX INT DEFAULT 0 NOT NULL,
                                         FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
                                         FDISABLERID BIGINT DEFAULT 0 NOT NULL,
                                         FDISABLEDATE DATETIME,
                                         FORGID BIGINT DEFAULT 0 NOT NULL,
                                         FDISORG BIGINT DEFAULT 0 NOT NULL,
                                         FREPORTCLASSIFY BIGINT DEFAULT 0 NOT NULL,
                                         FMSGCONTENT VARCHAR(255) DEFAULT ' ' NOT NULL,
                                         FMSGCONTENT_TAG NCLOB
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_AUTOCOLLRECORD_L')
CREATE TABLE T_SOEHRR_AUTOCOLLRECORD_L (
                                           FID BIGINT DEFAULT 0 NOT NULL,
                                           FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
                                           FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
                                           FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                           FDESC NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_CYCCOLLECTTASK_L')
CREATE TABLE T_SOEHRR_CYCCOLLECTTASK_L (
                                           FID BIGINT DEFAULT 0 NOT NULL,
                                           FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
                                           FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
                                           FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                           FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
                                           FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SOEHRR_TASKCONFENTRY')
CREATE TABLE T_SOEHRR_TASKCONFENTRY (
                                        FENTRYID BIGINT DEFAULT 0 NOT NULL,
                                        FSEQ INT DEFAULT 0 NOT NULL,
                                        FRPTTPL BIGINT DEFAULT 0 NOT NULL,
                                        FID BIGINT DEFAULT 0 NOT NULL
);


/** 优化索引 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_RPTTPLVAR_V') CREATE INDEX IDX_SOEHRR_RPTTPLVAR_V ON T_SOEHRR_RPTTPLVAR ( FREPENTRYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_RPTTPLAREA_V') CREATE INDEX IDX_SOEHRR_RPTTPLAREA_V ON T_SOEHRR_RPTTPLAREA ( FREPENTRYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_RPTTPLVERRULE_V') CREATE INDEX IDX_SOEHRR_RPTTPLVERRULE_V ON T_SOEHRR_RPTTPLVERRULE ( FREPENTRYID );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_RFILLTASK') CREATE INDEX IDX_SOEHRR_RFILLTASK ON T_SOEHRR_REPORT ( FFILLTASK );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_FILLSOLUTION') CREATE INDEX IDX_SOEHRR_FILLSOLUTION ON T_SOEHRR_FILLTASK ( FSOLUTION );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_FILLHATCHSOL') CREATE INDEX IDX_SOEHRR_FILLHATCHSOL ON T_SOEHRR_FILLTASK ( FHATCHSOLUTION );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_SOEHRR_FILLFEXEUNIT') CREATE INDEX IDX_SOEHRR_FILLFEXEUNIT ON T_SOEHRR_FILLTASK ( FEXEUNIT );

/**End D:\PDM_UPGRADE\PDM1\SOEHRR_table.sql **/
