/* 删除原来的表 */
IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_LOG') 
DROP TABLE T_PERM_LOG;

IF EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_LOG_ARCHIVE') 
DROP TABLE T_PERM_LOG_ARCHIVE;


/* 重建表 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_LOG') 
 CREATE TABLE T_PERM_LOG (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FBUSI_FROM VARCHAR(100) DEFAULT ' ' NOT NULL,
FBUSI_TYPE VARCHAR(100) DEFAULT ' ' NOT NULL,
FCLOUD_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FCLOUD_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAPP_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FAPP_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFORM_IDENTITY VARCHAR(50) DEFAULT ' ' NOT NULL,
FFORM_NAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FPERM_ITEM_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FPERM_ITEM_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOP NVARCHAR(100) DEFAULT ' ' NOT NULL,
FOPBTN NVARCHAR(100) DEFAULT ' ' NOT NULL,
FINTERFACE_METHOD VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_ID VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_NUMBER VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FPRE_DATA NCLOB,
FAFTER_DATA NCLOB,
FDIFF_CONTENT NCLOB,
FOPER_ID BIGINT DEFAULT 0 NOT NULL,
FOPER_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPER_NUMBER VARCHAR(36) DEFAULT ' ' NOT NULL,
FOPER_USERNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOPER_ORG_ID BIGINT DEFAULT 0 NOT NULL,
FOPER_ORG_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPER_TIME DATETIME,
FOP_DESC NCLOB,
FCLIENT_TYPE VARCHAR(300) DEFAULT ' ' NOT NULL,
FCLIENT_IP VARCHAR(300) DEFAULT ' ' NOT NULL,
FCLIENT_NAME VARCHAR(300) DEFAULT ' ' NOT NULL,
FCREATE_TIME DATETIME,
FMODIFY_TIME DATETIME,
FHAS_GENDIFF CHAR(1) DEFAULT '0' NOT NULL,
FGENDIFF_RESULT VARCHAR(300) DEFAULT ' ' NOT NULL,
FFILING_TIME DATETIME,
FFROM_BACKUP CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_LOG_ARCHIVE') 
 CREATE TABLE T_PERM_LOG_ARCHIVE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
FBUSI_FROM VARCHAR(100) DEFAULT ' ' NOT NULL,
FBUSI_TYPE VARCHAR(100) DEFAULT ' ' NOT NULL,
FCLOUD_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FCLOUD_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FAPP_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FAPP_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FFORM_IDENTITY VARCHAR(50) DEFAULT ' ' NOT NULL,
FFORM_NAME NVARCHAR(200) DEFAULT ' ' NOT NULL,
FPERM_ITEM_ID VARCHAR(36) DEFAULT ' ' NOT NULL,
FPERM_ITEM_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOP NVARCHAR(100) DEFAULT ' ' NOT NULL,
FOPBTN NVARCHAR(100) DEFAULT ' ' NOT NULL,
FINTERFACE_METHOD VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_ID VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_NUMBER VARCHAR(100) DEFAULT ' ' NOT NULL,
FOP_ITEM_NAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FPRE_DATA NCLOB,
FAFTER_DATA NCLOB,
FDIFF_CONTENT NCLOB,
FOPER_ID BIGINT DEFAULT 0 NOT NULL,
FOPER_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPER_NUMBER VARCHAR(36) DEFAULT ' ' NOT NULL,
FOPER_USERNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FOPER_ORG_ID BIGINT DEFAULT 0 NOT NULL,
FOPER_ORG_NAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPER_TIME DATETIME,
FOP_DESC NCLOB,
FCLIENT_TYPE VARCHAR(300) DEFAULT ' ' NOT NULL,
FCLIENT_IP VARCHAR(300) DEFAULT ' ' NOT NULL,
FCLIENT_NAME VARCHAR(300) DEFAULT ' ' NOT NULL,
FCREATE_TIME DATETIME,
FMODIFY_TIME DATETIME,
FHAS_GENDIFF CHAR(1) DEFAULT '0' NOT NULL,
FFILING_TIME DATETIME
);



 EXEC P_ALTERPK 'PK_PERM_LOG', 'T_PERM_LOG', 'FID,FNUMBER', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FOPER_TIME') CREATE INDEX IDX_FOPER_TIME ON T_PERM_LOG ( FOPER_TIME );
 
 
 EXEC P_ALTERPK 'PK_PERM_LOG_ARCHIVE', 'T_PERM_LOG_ARCHIVE', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PL_ARCH_OPTIME') CREATE INDEX IDX_PL_ARCH_OPTIME ON T_PERM_LOG_ARCHIVE ( FOPER_TIME );
 


