-- 业务成组关系记录
-- 游发扬 2023.05.06

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGRECORD')
 CREATE TABLE T_IM_BGRECORD (
FID BIGINT DEFAULT 0 NOT NULL,
FBGSETTING BIGINT DEFAULT 0 NOT NULL,
FISCOMPLETED CHAR(1) DEFAULT '0' NOT NULL,
FCREATETIME DATETIME,
FUPDATETIME DATETIME,
FGROUPVALUE NVARCHAR(255) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGRECORDE')
 CREATE TABLE T_IM_BGRECORDE (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FTYPE CHAR(1) DEFAULT '0' NOT NULL,
FISLASTENTRY CHAR(1) DEFAULT '0' NOT NULL,
FBIZBILLID BIGINT DEFAULT 0 NOT NULL,
FBIZENTRYID BIGINT DEFAULT 0 NOT NULL,
FMATERIALID	BIGINT DEFAULT 0 NOT NULL,
FOWNERID BIGINT DEFAULT 0 NOT NULL,
FBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FBIZDATE DATETIME,
FBOOKDATE DATETIME,
FFORMID VARCHAR(36) DEFAULT ' ' NOT NULL,
FBILLNO NVARCHAR(100) DEFAULT ' ' NOT NULL,
FISDEL CHAR(1) DEFAULT '0' NOT NULL
);

-- 业务成组关系配置
-- 游发扬 2023.04.20
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGSET')
CREATE TABLE T_IM_BGSET (
	FID BIGINT DEFAULT 0 NOT NULL,
	FNUMBER VARCHAR(30) DEFAULT ' ' NOT NULL,
	FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FSTATUS CHAR(1) DEFAULT 'A' NOT NULL,
	FCREATORID BIGINT DEFAULT 0 NOT NULL,
	FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
	FENABLE CHAR(1) DEFAULT '1' NOT NULL,
	FCREATETIME DATETIME,
	FMODIFYTIME DATETIME,
	FMASTERID BIGINT DEFAULT 0 NOT NULL,
	FPRIORITY INT DEFAULT 0 NOT NULL,
	FISPRESET CHAR(1) DEFAULT '0' NOT NULL,
	FREMARK NVARCHAR(2000) DEFAULT ' ' NOT NULL,
	FGROUPTYPE CHAR(1) DEFAULT 'A' NOT NULL
	);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGSET_L')
CREATE TABLE T_IM_BGSET_L (
	FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
	FID BIGINT DEFAULT 0 NOT NULL,
	FLOCALEID VARCHAR(10) DEFAULT '' NOT NULL ,
	FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FREMARK NVARCHAR(2000) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGSETENTRY')
CREATE TABLE T_IM_BGSETENTRY (
	FID BIGINT DEFAULT 0 NOT NULL,
	FENTRYID BIGINT DEFAULT 0 NOT NULL,
	FSEQ INT DEFAULT 0 NOT NULL,
	FFORMID VARCHAR(36) DEFAULT ' ' NOT NULL,
	FCFILTER VARCHAR(512) DEFAULT ' ' NOT NULL,
	FTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
	FGROUPBILLNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FCFILTERJSON VARCHAR(512) DEFAULT ' ' NOT NULL,
	FCFILTERJSON_TAG NCLOB,
	FRELTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
	FEISPRESET CHAR(1) DEFAULT '0' NOT NULL,
	FFILTER VARCHAR(512) DEFAULT ' ' NOT NULL,
	FFILTERJSON VARCHAR(255) DEFAULT ' ' NOT NULL,
	FFILTERJSON_TAG NCLOB,
	FRELFIELD VARCHAR(2000) DEFAULT ' ' NOT NULL,
	FSELFIELD VARCHAR(2000) DEFAULT ' ' NOT NULL,
	FTEXT2LONG VARCHAR(2000) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGSETENTRY_L')
CREATE TABLE T_IM_BGSETENTRY_L (
	FPKID VARCHAR(36) DEFAULT ' ' NOT NULL,
	FENTRYID BIGINT DEFAULT 0 NOT NULL,
	FLOCALEID VARCHAR(10) DEFAULT '' NOT NULL,
	FGROUPBILLNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_BGSETRENTRY')
CREATE TABLE T_IM_BGSETRENTRY (
	FID BIGINT DEFAULT 0 NOT NULL,
	FENTRYID BIGINT DEFAULT 0 NOT NULL,
	FSEQ INT DEFAULT 0 NOT NULL,
	FFIELDNAME0 NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FFIELDKEY0 VARCHAR(50) DEFAULT ' ' NOT NULL,
	FFIELDNAME1 NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FFIELDKEY1 VARCHAR(50) DEFAULT ' ' NOT NULL,
	FFIELDNAME2 NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FFIELDKEY2 VARCHAR(50) DEFAULT ' ' NOT NULL,
	FFIELDNAME3 NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FFIELDKEY3 VARCHAR(50) DEFAULT ' ' NOT NULL,
	FFIELDNAME4 NVARCHAR(100) DEFAULT ' ' NOT NULL,
	FFIELDKEY4 VARCHAR(50) DEFAULT ' ' NOT NULL
);
