CREATE TABLE "zfd_UNIT"  ( 
	"ID"            	VARCHAR(32) NOT NULL,
	"LIST"          	INTEGER NOT NULL,
	"NAME"          	VARCHAR(100) NOT NULL,
	"CODE"          	VARCHAR(20) NOT NULL,
	"PARENT_ID"         VARCHAR(32) NOT NULL,
	"UNIT_LEVEL"        INTEGER NOT NULL,
	CONSTRAINT "zfd_UNIT_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_CRON_EXCLUSIVE_TASK"  ( 
	"ID"         	VARCHAR(200) NOT NULL,
	"RUNNING"    	SMALLINT NOT NULL DEFAULT 0,
	"UPDATE_TIME"	TIMESTAMP NOT NULL,
	"NODE_TAG"   	VARCHAR(100) NOT NULL,
	"MD5"        	VARCHAR(50) NOT NULL,
	CONSTRAINT "zfd_CRON_TASK_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_RESOURCE"  ( 
	"ID"            	VARCHAR(32) NOT NULL,
	"LIST"          	INTEGER NOT NULL,
	"LOGO_PIC"      	VARCHAR(100),
	"MENU_ID"       	VARCHAR(32),
	"MENU_TYPE"     	VARCHAR(10) NOT NULL,
	"NAME"          	VARCHAR(200) NOT NULL,
	"REQUEST_METHOD"	VARCHAR(10) NOT NULL,
	"TYPE_CODE"     	VARCHAR(20) NOT NULL,
	"URL"           	VARCHAR(300) NOT NULL,
	CONSTRAINT "zfd_RESOURCE_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_ROLE"  ( 
	"ID"    	VARCHAR(32) NOT NULL,
	"INFO"  	VARCHAR(255),
	"LIST"  	INTEGER NOT NULL,
	"NAME"  	VARCHAR(30) NOT NULL,
	"SYSTEM"	SMALLINT NOT NULL,
	"UNIT_ID"   VARCHAR(32) NOT NULL,
	CONSTRAINT "zfd_ROLE_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_ROLE_RESOURCE"  ( 
	"ID"         	VARCHAR(32) NOT NULL,
	"RESOURCE_ID"	VARCHAR(32) NOT NULL,
	"ROLE_ID"    	VARCHAR(32) NOT NULL,
	CONSTRAINT "zfd_ROLE_RESOURCE_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_SCHEDULE_LOG"  ( 
	"ID"          	VARCHAR(32) NOT NULL,
	"BY_SYSTEM"   	SMALLINT NOT NULL,
	"CURRENT_CRON"	VARCHAR(50) NOT NULL,
	"END_TIME"    	TIMESTAMP NOT NULL,
	"EXEC_TIME"   	BIGINT NOT NULL,
	"START_TIME"  	TIMESTAMP NOT NULL,
	"TASK_NAME"   	VARCHAR(100) NOT NULL,
	CONSTRAINT "zfd_SCHEDULE_LOG_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_SYSTEM_INFO"  ( 
	"ID"         	VARCHAR(32) NOT NULL,
	"CONF_TYPE"  	VARCHAR(20) NOT NULL,
	"JSON_STR"   	VARCHAR(4000) NOT NULL,
	"UPDATE_TIME"	TIMESTAMP,
	"USER_ID"    	VARCHAR(32) NOT NULL,
	"ZIPED"      	SMALLINT NOT NULL,
	CONSTRAINT "zfd_SYS_INFO_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_SYSTEM_LOG"  ( 
	"ID"      	VARCHAR(32) NOT NULL,
	"INFO"    	VARCHAR(300) NOT NULL,
	"IP"      	VARCHAR(50) NOT NULL,
	"LOG_TYPE"	VARCHAR(10) NOT NULL,
	"OPTIME"  	TIMESTAMP NOT NULL,
	"USER_ID" 	VARCHAR(32) NOT NULL,
	CONSTRAINT "zfd_SYSTEM_LOG_PK" PRIMARY KEY("ID")
)
GO
CREATE TABLE "zfd_USER"  ( 
	"ID"        	VARCHAR(32) NOT NULL,
	"EMAIL"     	VARCHAR(100),
	"FAX"       	VARCHAR(50),
	"LOGIN_NAME"	VARCHAR(20) NOT NULL,
	"MALE"      	SMALLINT NOT NULL,
	"MOBILE"    	VARCHAR(50) NOT NULL,
	"NAME"      	VARCHAR(50) NOT NULL,
	"NAME_PY"   	VARCHAR(100) NOT NULL,
	"PASSWD"    	VARCHAR(512) NOT NULL,
	"STATUS"    	VARCHAR(10) NOT NULL,
	"TEL"       	VARCHAR(50),
	"ROLE_ID"   	VARCHAR(32),
	"UNIT_ID"   VARCHAR(32) NOT NULL,
	CONSTRAINT "zfd_USER_PK" PRIMARY KEY("ID")
)
GO
CREATE INDEX "zfd_CRON_TASK_PK"
	ON "zfd_CRON_EXCLUSIVE_TASK"("ID")
GO
CREATE INDEX "zfd_RESOURCE_PK"
	ON "zfd_RESOURCE"("ID")
GO
CREATE UNIQUE INDEX "zfd_RESOURCE_UK"
	ON "zfd_RESOURCE"("REQUEST_METHOD", "URL")
GO
CREATE INDEX "zfd_ROLE_PK"
	ON "zfd_ROLE"("ID")
GO
CREATE INDEX "zfd_ROLE_RESOURCE_PK"
	ON "zfd_ROLE_RESOURCE"("ID")
GO
CREATE UNIQUE INDEX "zfd_ROLE_UK"
	ON "zfd_ROLE"("NAME")
GO
CREATE INDEX "zfd_SCHEDULE_LOG_IX1"
	ON "zfd_SCHEDULE_LOG"("START_TIME")
GO
CREATE INDEX "zfd_SCHEDULE_LOG_PK"
	ON "zfd_SCHEDULE_LOG"("ID")
GO
CREATE INDEX "zfd_SYSTEM_LOG_IX1"
	ON "zfd_SYSTEM_LOG"("LOG_TYPE")
GO
CREATE INDEX "zfd_SYSTEM_LOG_IX2"
	ON "zfd_SYSTEM_LOG"("OPTIME" DESC)
GO
CREATE INDEX "zfd_SYSTEM_LOG_PK"
	ON "zfd_SYSTEM_LOG"("ID")
GO
CREATE INDEX "zfd_SYS_INFO_PK"
	ON "zfd_SYSTEM_INFO"("ID")
GO
CREATE UNIQUE INDEX "zfd_SYS_INFO_UK"
	ON "zfd_SYSTEM_INFO"("CONF_TYPE", "USER_ID")
GO
CREATE INDEX "zfd_USER_IX1"
	ON "zfd_USER"("NAME")
GO
CREATE INDEX "zfd_USER_IX2"
	ON "zfd_USER"("NAME_PY")
GO
CREATE INDEX "zfd_USER_PK"
	ON "zfd_USER"("ID")
GO
CREATE UNIQUE INDEX "zfd_USER_UK"
	ON "zfd_USER"("LOGIN_NAME")
GO

ALTER TABLE "zfd_RESOURCE"
	ADD CONSTRAINT "zfd_RESOURCE_UK"
	UNIQUE ("REQUEST_METHOD", "URL")
GO
ALTER TABLE "zfd_ROLE"
	ADD CONSTRAINT "zfd_ROLE_UK"
	UNIQUE ("NAME")
GO
ALTER TABLE "zfd_SYSTEM_INFO"
	ADD CONSTRAINT "zfd_SYS_INFO_UK"
	UNIQUE ("CONF_TYPE", "USER_ID")
GO
ALTER TABLE "zfd_USER"
	ADD CONSTRAINT "zfd_USER_UK"
	UNIQUE ("LOGIN_NAME")
GO
ALTER TABLE "zfd_ROLE_RESOURCE"
	ADD CONSTRAINT "zfd_ROLE_RES_ROLE_FK"
	FOREIGN KEY("ROLE_ID")
	REFERENCES "zfd_ROLE"("ID")
	ON DELETE RESTRICT
	ON UPDATE RESTRICT 
GO
ALTER TABLE "zfd_ROLE_RESOURCE"
	ADD CONSTRAINT "zfd_ROLE_RES_RESOURCE_FK"
	FOREIGN KEY("RESOURCE_ID")
	REFERENCES "zfd_RESOURCE"("ID")
	ON DELETE RESTRICT
	ON UPDATE RESTRICT 
GO
ALTER TABLE "zfd_SYSTEM_LOG"
	ADD CONSTRAINT "zfd_SYS_LOG_USER_FK"
	FOREIGN KEY("USER_ID")
	REFERENCES "zfd_USER"("ID")
	ON DELETE RESTRICT
	ON UPDATE RESTRICT 
GO
ALTER TABLE "zfd_USER"
	ADD CONSTRAINT "zfd_USER_ROLE_FK"
	FOREIGN KEY("ROLE_ID")
	REFERENCES "zfd_ROLE"("ID")
	ON DELETE RESTRICT
	ON UPDATE RESTRICT 
GO
