/* 权限管理员 表结构 增加字段 fupdatetime、fupdatorid、fisupdate */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ADMIN' AND KSQL_COL_NAME ='FUPDATETIME') 
 ALTER TABLE T_PERM_ADMIN ADD (FUPDATETIME DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ADMIN' AND KSQL_COL_NAME ='FUPDATORID') 
 ALTER TABLE T_PERM_ADMIN ADD (FUPDATORID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PERM_ADMIN' AND KSQL_COL_NAME ='fisupdate') 
 ALTER TABLE T_PERM_ADMIN ADD (fisupdate CHAR(1) DEFAULT '0' NOT NULL );
 

/* 旧版管理员功能启用开关 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_OLDADMINENABLE') 
 CREATE TABLE T_PERM_OLDADMINENABLE (
FID BIGINT DEFAULT 0 NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FMODIFYTIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL
);


/* 管理员组类型 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SEC_USERGROUPTYPE') 
 CREATE TABLE T_SEC_USERGROUPTYPE (
FID BIGINT DEFAULT 0 NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FENABLE CHAR(1) DEFAULT '1' NOT NULL,
FSTATUS VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FISPRESET CHAR(1) DEFAULT '0' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


/* 管理员组类型(多语言) 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SEC_USERGROUPTYPE_L') 
 CREATE TABLE T_SEC_USERGROUPTYPE_L (
FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);

/* 管理员组 表 增加 FUSERGROUPTYPEID */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SEC_USERGROUP' AND KSQL_COL_NAME ='FUSERGROUPTYPEID') 
 ALTER TABLE T_SEC_USERGROUP ADD (FUSERGROUPTYPEID BIGINT DEFAULT 0 NOT NULL );
 
/* 管理员组扩展信息 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SEC_USERGROUP_P') 
 CREATE TABLE T_SEC_USERGROUP_P (
FID BIGINT DEFAULT 0 NOT NULL,
FADMINSCHEME BIGINT DEFAULT 0 NOT NULL,
FADMINTYPE BIGINT DEFAULT 0 NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SEC_USERGROUP_P' AND KSQL_COL_NAME ='FOLDADMINID') 
 ALTER TABLE T_SEC_USERGROUP_P ADD (FOLDADMINID VARCHAR(18) DEFAULT ' ' NOT NULL );
 
/* 管理员业务单元管辖范围 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ADMINGROUPBIZUNIT') 
 CREATE TABLE T_PERM_ADMINGROUPBIZUNIT (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERGROUPID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL
); 

/* 管理员行政组织管辖范围 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ADMINGROUPORG') 
 CREATE TABLE T_PERM_ADMINGROUPORG (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERGROUPID BIGINT DEFAULT 0 NOT NULL,
FORGID BIGINT DEFAULT 0 NOT NULL
);

/* 管理员应用管辖范围 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ADMINGROUPAPP') 
 CREATE TABLE T_PERM_ADMINGROUPAPP (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERGROUPID BIGINT DEFAULT 0 NOT NULL,
FAPPID VARCHAR(36) DEFAULT ' ' NOT NULL
);

/* 管理员行政组织管辖范围额外用户 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ADMINGROUPADDUSER') 
 CREATE TABLE T_PERM_ADMINGROUPADDUSER (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERID BIGINT DEFAULT 0 NOT NULL,
FUSERGROUPID BIGINT DEFAULT 0 NOT NULL
);

/* 管理员系统服务云管辖范围 表结构 */
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PERM_ADMINGROUPFUNPERM') 
 CREATE TABLE T_PERM_ADMINGROUPFUNPERM (
FID BIGINT DEFAULT 0 NOT NULL,
FUSERGROUPID BIGINT DEFAULT 0 NOT NULL,
FAPPID VARCHAR(18) DEFAULT ' ' NOT NULL,
FENTITYNUM VARCHAR(36) DEFAULT ' ' NOT NULL,
FPERMITEMID VARCHAR(18) DEFAULT ' ' NOT NULL
);
 
 