20260729231854

This commit is contained in:
oneao committed 2026-07-29 23:18:54 +08:00
1 parent 1c839b707a
commit 84673b3d3d
39 files changed
+4683 -281

No files matched your search

@@ -127,7 +127,6 @@ BEGIN TRANSACTION;
CREATE TABLE dbo.b_othercompany_bmfl (
b_id bigint NOT NULL,
b_parent_id bigint NULL,
b_code varchar(50) NOT NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT DF_b_othercompany_bmfl_level DEFAULT (1),
b_path varchar(1000) NOT NULL,
@@ -138,7 +137,6 @@ BEGIN TRANSACTION;
b_updateuser_id bigint NULL,
b_updatedatetime datetime NULL,
CONSTRAINT PK_b_othercompany_bmfl PRIMARY KEY (b_id),
CONSTRAINT UQ_b_othercompany_bmfl_code UNIQUE (b_code),
CONSTRAINT CK_b_othercompany_bmfl_level CHECK (b_level >= 1),
CONSTRAINT CK_b_othercompany_bmfl_parent CHECK (
b_parent_id IS NULL OR b_parent_id <> b_id
@@ -0,0 +1,20 @@
-- 删除 b_othercompany_bmfl 的 b_code 字段(无业务含义,b_id 已唯一标识)
BEGIN TRANSACTION;
IF EXISTS (
SELECT 1 FROM sys.columns
WHERE object_id = OBJECT_ID(N'dbo.b_othercompany_bmfl') AND name = 'b_code'
)
BEGIN
IF EXISTS (
SELECT 1 FROM sys.objects
WHERE object_id = OBJECT_ID(N'dbo.UQ_b_othercompany_bmfl_code') AND type = 'UQ'
)
BEGIN
ALTER TABLE dbo.b_othercompany_bmfl DROP CONSTRAINT UQ_b_othercompany_bmfl_code;
END
ALTER TABLE dbo.b_othercompany_bmfl DROP COLUMN b_code;
END
COMMIT TRANSACTION;
@@ -0,0 +1,125 @@
SET NOCOUNT ON;
SET XACT_ABORT ON;
BEGIN TRANSACTION;
-- 删除废弃的 b_contact_type 表
IF OBJECT_ID(N'dbo.b_contact_type', N'U') IS NOT NULL
DROP TABLE dbo.b_contact_type;
-- b_contact
DECLARE @ContactObjectId int = OBJECT_ID(N'dbo.b_contact', N'U');
DECLARE @RebuildContact bit = 0;
IF @ContactObjectId IS NULL
SET @RebuildContact = 1;
ELSE IF EXISTS (
SELECT 1 FROM sys.columns
WHERE object_id = @ContactObjectId
AND name = N'b_id'
AND system_type_id = 167 -- varchar → old structure
)
SET @RebuildContact = 1;
IF @RebuildContact = 1
BEGIN
-- 先删依赖视图
IF OBJECT_ID(N'dbo.v_b_contact', N'V') IS NOT NULL
DROP VIEW dbo.v_b_contact;
IF @ContactObjectId IS NOT NULL
DROP TABLE dbo.b_contact;
CREATE TABLE dbo.b_contact (
b_id bigint NOT NULL,
b_name_ch nvarchar(50) NULL,
b_name_en nvarchar(50) NULL,
b_sex nvarchar(50) NULL,
b_phone nvarchar(50) NULL,
b_mobilephone nvarchar(50) NULL,
b_fax nvarchar(50) NULL,
b_email nvarchar(50) NULL,
b_cate_id bigint NULL,
b_duty nvarchar(50) NULL,
b_homephone nvarchar(50) NULL,
b_homeaddr nvarchar(255) NULL,
b_bz nvarchar(max) NULL,
b_departmentname nvarchar(50) NULL,
b_picture varbinary(max) NULL,
b_customer_id bigint NULL,
b_owner_id bigint NULL,
b_isdefault int NULL,
b_showcolor int NULL,
b_birthday datetime NULL,
b_type1_id bigint NULL,
b_taste nvarchar(50) NULL,
b_habit nvarchar(50) NULL,
b_homesituation nvarchar(50) NULL,
b_htbegindate datetime NULL,
b_htenddate datetime NULL,
b_state nvarchar(50) NULL,
b_xh int NOT NULL CONSTRAINT DF_b_contact_xh DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT DF_b_contact_canuse DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime NULL,
b_updateuser_id bigint NULL,
b_updatedatetime datetime NULL,
CONSTRAINT PK_b_contact PRIMARY KEY (b_id)
);
CREATE INDEX IX_b_contact_customer
ON dbo.b_contact (b_customer_id, b_id);
CREATE INDEX IX_b_contact_owner
ON dbo.b_contact (b_owner_id, b_id);
CREATE INDEX IX_b_contact_cate
ON dbo.b_contact (b_cate_id, b_id);
END
-- v_b_contact 视图
IF OBJECT_ID(N'dbo.v_b_contact', N'V') IS NOT NULL
DROP VIEW dbo.v_b_contact;
EXEC sp_executesql N'
CREATE VIEW dbo.v_b_contact AS
SELECT
b_contact.b_id,
b_contact.b_name_ch,
b_contact.b_name_en,
b_contact.b_sex,
b_contact.b_phone,
b_contact.b_mobilephone,
b_contact.b_fax,
b_contact.b_email,
b_contact.b_cate_id,
b_contact.b_duty,
b_contact.b_homephone,
b_contact.b_homeaddr,
b_contact.b_bz,
b_contact.b_departmentname,
b_contact.b_picture,
b_contact.b_customer_id,
b_contact.b_owner_id,
b_contact.b_isdefault,
b_contact.b_showcolor,
b_contact.b_birthday,
b_contact.b_type1_id,
b_contact.b_taste,
b_contact.b_habit,
b_contact.b_homesituation,
b_contact.b_htbegindate,
b_contact.b_htenddate,
b_contact.b_state,
b_contact.b_xh,
b_contact.b_canuse,
b_contact.b_inputuser_id,
b_contact.b_inputdatetime,
b_contact.b_updateuser_id,
b_contact.b_updatedatetime,
ISNULL(b_user.b_name, b_user.b_account) AS v_ownername,
b_user.b_department AS v_ownerdepartment,
b_othercompany.b_name AS v_customer_name
FROM dbo.b_contact
LEFT JOIN dbo.b_user ON b_user.b_id = b_contact.b_owner_id
LEFT JOIN dbo.b_othercompany ON b_othercompany.b_id = b_contact.b_customer_id;
';
COMMIT TRANSACTION;
@@ -0,0 +1,244 @@
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51500, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
DECLARE @RebuildCore bit = 0;
IF OBJECT_ID(N'dbo.b_othercompany', N'U') IS NULL
OR COL_LENGTH(N'dbo.b_othercompany', N'b_code') IS NULL
OR EXISTS (
SELECT 1 FROM sys.columns
WHERE object_id = OBJECT_ID(N'dbo.b_othercompany')
AND name = N'b_id' AND system_type_id <> TYPE_ID(N'bigint')
)
OR OBJECT_ID(N'dbo.b_contact', N'U') IS NULL
OR EXISTS (
SELECT 1 FROM sys.columns
WHERE object_id = OBJECT_ID(N'dbo.b_contact')
AND name = N'b_customer_id' AND system_type_id <> TYPE_ID(N'bigint')
)
SET @RebuildCore = 1;
IF @RebuildCore = 1
BEGIN
IF OBJECT_ID(N'dbo.v_b_contact', N'V') IS NOT NULL
DROP VIEW dbo.v_b_contact;
IF OBJECT_ID(N'dbo.b_contact', N'U') IS NOT NULL
DROP TABLE dbo.b_contact;
IF OBJECT_ID(N'dbo.b_othercompany', N'U') IS NOT NULL
DROP TABLE dbo.b_othercompany;
CREATE TABLE dbo.b_othercompany (
b_id bigint NOT NULL,
b_code varchar(50) NOT NULL,
b_pycode varchar(50) NULL,
b_type nvarchar(200) NULL,
b_name nvarchar(500) NOT NULL,
b_shortname nvarchar(100) NULL,
b_linkman nvarchar(200) NULL,
b_phone nvarchar(500) NULL,
b_addr nvarchar(500) NULL,
b_firstlinkdate date NULL,
b_htno varchar(50) NULL,
b_htdate date NULL,
b_htexpiredate date NULL,
b_black int NOT NULL CONSTRAINT DF_b_othercompany_black DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT DF_b_othercompany_canuse DEFAULT (1),
b_zl int NOT NULL CONSTRAINT DF_b_othercompany_xh DEFAULT (0),
b_tel nvarchar(50) NULL,
b_fax nvarchar(500) NULL,
b_www varchar(200) NULL,
b_email varchar(200) NULL,
b_bankacount nvarchar(500) NULL,
b_invaccount nvarchar(500) NULL,
b_cate_id bigint NULL,
b_bz1 nvarchar(500) NULL,
b_bz2 nvarchar(500) NULL,
b_bz3 nvarchar(500) NULL,
b_bz4 nvarchar(500) NULL,
b_province nvarchar(50) NULL,
b_city nvarchar(50) NULL,
b_area nvarchar(50) NULL,
b_country nvarchar(50) NULL,
b_edicode varchar(50) NULL,
b_showcolor int NULL,
b_type_id bigint NULL,
b_from_id bigint NULL,
b_type1_id bigint NULL,
b_type2_id bigint NULL,
b_type3_id bigint NULL,
b_type4_id bigint NULL,
b_type5_id bigint NULL,
b_owner_id bigint NULL,
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT DF_b_othercompany_inputdatetime DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
b_password varchar(200) NULL,
b_state nvarchar(50) NULL,
b_bankacount_e nvarchar(500) NULL,
b_addr_e nvarchar(500) NULL,
b_name_e nvarchar(500) NULL,
CONSTRAINT PK_b_othercompany PRIMARY KEY (b_id),
CONSTRAINT UQ_b_othercompany_code UNIQUE (b_code),
CONSTRAINT FK_b_othercompany_category FOREIGN KEY (b_cate_id)
REFERENCES dbo.b_othercompany_bmfl (b_id),
CONSTRAINT FK_b_othercompany_owner FOREIGN KEY (b_owner_id)
REFERENCES dbo.b_user (b_id)
);
CREATE INDEX IX_b_othercompany_name ON dbo.b_othercompany (b_name, b_id);
CREATE INDEX IX_b_othercompany_pycode ON dbo.b_othercompany (b_pycode, b_id);
CREATE INDEX IX_b_othercompany_category ON dbo.b_othercompany (b_cate_id, b_id);
CREATE INDEX IX_b_othercompany_owner ON dbo.b_othercompany (b_owner_id, b_id);
CREATE TABLE dbo.b_contact (
b_id bigint NOT NULL,
b_name_ch nvarchar(50) NULL,
b_name_en nvarchar(50) NULL,
b_sex nvarchar(50) NULL,
b_phone nvarchar(50) NULL,
b_mobilephone nvarchar(50) NULL,
b_fax nvarchar(50) NULL,
b_email varchar(200) NULL,
b_cate_id bigint NULL,
b_duty nvarchar(50) NULL,
b_homephone nvarchar(50) NULL,
b_homeaddr nvarchar(255) NULL,
b_bz nvarchar(max) NULL,
b_departmentname nvarchar(100) NULL,
b_picture varbinary(max) NULL,
b_customer_id bigint NULL,
b_owner_id bigint NULL,
b_isdefault int NOT NULL CONSTRAINT DF_b_contact_isdefault DEFAULT (0),
b_showcolor int NULL,
b_birthday date NULL,
b_type1_id bigint NULL,
b_taste nvarchar(100) NULL,
b_habit nvarchar(100) NULL,
b_homesituation nvarchar(100) NULL,
b_htbegindate date NULL,
b_htenddate date NULL,
b_state nvarchar(50) NULL,
b_xh int NOT NULL CONSTRAINT DF_b_contact_xh DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT DF_b_contact_canuse DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT DF_b_contact_inputdatetime DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
CONSTRAINT PK_b_contact PRIMARY KEY (b_id),
CONSTRAINT FK_b_contact_customer FOREIGN KEY (b_customer_id)
REFERENCES dbo.b_othercompany (b_id),
CONSTRAINT FK_b_contact_owner FOREIGN KEY (b_owner_id)
REFERENCES dbo.b_user (b_id)
);
CREATE INDEX IX_b_contact_customer ON dbo.b_contact (b_customer_id, b_id);
CREATE INDEX IX_b_contact_owner ON dbo.b_contact (b_owner_id, b_id);
CREATE INDEX IX_b_contact_cate ON dbo.b_contact (b_cate_id, b_id);
END;
DECLARE @OtherCompanyModuleId bigint = (
SELECT TOP (1) b_id FROM dbo.s_module WHERE b_code = N'b_othercompany'
);
IF @OtherCompanyModuleId IS NOT NULL
BEGIN
IF EXISTS (
SELECT 1 FROM dbo.s_module_field
WHERE b_id = 920000000000002050 AND b_module_id <> @OtherCompanyModuleId
)
THROW 51502, N'合作伙伴业务编号字段预留 ID 已被占用。', 1;
IF NOT EXISTS (
SELECT 1 FROM dbo.s_module_field
WHERE b_module_id = @OtherCompanyModuleId AND b_field = N'b_code'
)
INSERT INTO dbo.s_module_field (
b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse
) VALUES (
920000000000002050, @OtherCompanyModuleId, N'b_code', N'合作伙伴编号',
N'field.b_othercompany.b_code', N'input', 1
);
DECLARE @BusinessCodeFieldId bigint = (
SELECT TOP (1) b_id FROM dbo.s_module_field
WHERE b_module_id = @OtherCompanyModuleId AND b_field = N'b_code'
);
UPDATE dbo.s_module_field_list
SET b_field_id = @BusinessCodeFieldId, b_width = 150
WHERE b_id = 920000000000003001
AND NOT EXISTS (
SELECT 1 FROM dbo.s_module_field_list AS existing
WHERE existing.b_module_id = @OtherCompanyModuleId
AND existing.b_field_id = @BusinessCodeFieldId
AND existing.b_id <> 920000000000003001
);
IF NOT EXISTS (
SELECT 1 FROM dbo.s_module_field_query
WHERE b_module_id = @OtherCompanyModuleId AND b_field_id = @BusinessCodeFieldId
)
INSERT INTO dbo.s_module_field_query (
b_id, b_module_id, b_field_id, b_component, b_operator,
b_default_value, b_xh, b_canuse
) VALUES (
920000000000004006, @OtherCompanyModuleId, @BusinessCodeFieldId,
N'input', N'like', NULL, 5, 1
);
END;
COMMIT TRANSACTION;
IF OBJECT_ID(N'dbo.v_b_contact', N'V') IS NOT NULL
DROP VIEW dbo.v_b_contact;
EXEC sys.sp_executesql N'
CREATE VIEW dbo.v_b_contact AS
SELECT
contact.b_id,
contact.b_name_ch,
contact.b_name_en,
contact.b_sex,
contact.b_phone,
contact.b_mobilephone,
contact.b_fax,
contact.b_email,
contact.b_cate_id,
contact.b_duty,
contact.b_homephone,
contact.b_homeaddr,
contact.b_bz,
contact.b_departmentname,
contact.b_picture,
contact.b_customer_id,
contact.b_owner_id,
contact.b_isdefault,
contact.b_showcolor,
contact.b_birthday,
contact.b_type1_id,
contact.b_taste,
contact.b_habit,
contact.b_homesituation,
contact.b_htbegindate,
contact.b_htenddate,
contact.b_state,
contact.b_xh,
contact.b_canuse,
contact.b_inputuser_id,
contact.b_inputdatetime,
contact.b_updateuser_id,
contact.b_updatedatetime,
ISNULL(owner_user.b_name, owner_user.b_account) AS v_ownername,
owner_user.b_department AS v_ownerdepartment,
customer.b_name AS v_customer_name
FROM dbo.b_contact AS contact
LEFT JOIN dbo.b_user AS owner_user ON owner_user.b_id = contact.b_owner_id
LEFT JOIN dbo.b_othercompany AS customer ON customer.b_id = contact.b_customer_id;
';
@@ -0,0 +1,759 @@
/* Generated schema-only migration: 基础资料. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.b_bgtype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_bgtype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_bgtype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_bgtype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_billtype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_billtype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_billtype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_billtype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_blstate', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_blstate] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_blstate] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_blstate_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_city', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_city] (
[b_id] bigint NOT NULL,
[b_name_c] nvarchar(50) NULL,
[b_name_e] nvarchar(50) NULL,
[b_country_name_e] nvarchar(50) NULL,
[b_country_name_c] nvarchar(50) NULL,
[b_bz] nvarchar(500) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_city] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_city_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_con_type', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_con_type] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_type] varchar(50) NULL,
[b_linkcon] varchar(50) NULL,
[b_default] int NOT NULL CONSTRAINT [DF_b_con_type_b_default] DEFAULT (0),
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_con_type] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_con_type_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_cztype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_cztype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_cztype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_cztype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_dailyfeetype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_dailyfeetype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_dailyfeetype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_dailyfeetype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_dailytype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_dailytype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_dailytype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_dailytype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_feetype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_feetype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_name_e] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_default] int NOT NULL CONSTRAINT [DF_b_feetype_b_default] DEFAULT (0),
[b_amount] decimal(18,2) NULL,
[b_tax] decimal(18,4) NULL,
[b_money_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_feetype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_feetype_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_b_feetype_b_money_id] ON dbo.[b_feetype] ([b_money_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.b_freightpayment', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_freightpayment] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_freightpayment] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_freightpayment_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_from', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_from] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_from] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_from_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_goodssource', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_goodssource] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_goodssource] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_goodssource_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_grade', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_grade] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_grade] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_grade_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_hl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_hl] (
[b_id] bigint NOT NULL,
[b_money_id] bigint NULL,
[b_bz] nvarchar(50) NULL,
[b_type] varchar(50) NULL,
[b_hl] decimal(18,4) NULL,
[b_month] varchar(50) NULL,
[b_qsdate] datetime2(0) NULL,
[b_zzdate] datetime2(0) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_b_hl] PRIMARY KEY ([b_id])
);
CREATE INDEX [IX_b_hl_b_money_id] ON dbo.[b_hl] ([b_money_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.b_httype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_httype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_httype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_httype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_ivtype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_ivtype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_ivtype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_ivtype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_jsfs', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_jsfs] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_jsfs] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_jsfs_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_money', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_money] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_hl] decimal(18,4) NULL,
[b_canuse] int NOT NULL CONSTRAINT [DF_b_money_b_canuse] DEFAULT (1),
[b_xh] int NULL,
[b_symbol] nvarchar(50) NULL,
[b_isconvert] varchar(1) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_money] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_money_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_oceanline', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_oceanline] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_oceanline] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_oceanline_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_operator', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_operator] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_operator] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_operator_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_other', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_other] (
[b_cateid] varchar(50) NULL,
[b_id] bigint NOT NULL,
[b_name_c] nvarchar(50) NULL,
[b_1] numeric(18,0) NULL,
[b_2] varchar(50) NULL,
[b_desc] nvarchar(255) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_other] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_other_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_other_bmfl] (
b_id bigint NOT NULL,
b_parent_id bigint NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT [DF_b_other_bmfl_level] DEFAULT (1),
b_path varchar(1000) NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_b_other_bmfl_xh] DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT [DF_b_other_bmfl_canuse] DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT [DF_b_other_bmfl_inputdatetime] DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
CONSTRAINT [PK_b_other_bmfl] PRIMARY KEY (b_id),
CONSTRAINT [CK_b_other_bmfl_parent] CHECK (b_parent_id IS NULL OR b_parent_id <> b_id),
CONSTRAINT [FK_b_other_bmfl_parent] FOREIGN KEY (b_parent_id) REFERENCES dbo.[b_other_bmfl] (b_id)
);
CREATE INDEX [IX_b_other_bmfl_parent] ON dbo.[b_other_bmfl] (b_parent_id, b_xh, b_id);
CREATE INDEX [IX_b_other_bmfl_path] ON dbo.[b_other_bmfl] (b_path, b_xh, b_id);
END;
IF OBJECT_ID(N'dbo.b_othercompany_accountbank', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_othercompany_accountbank] (
[subid] bigint NOT NULL,
[mx_xh] int NULL,
[father] bigint NULL,
[mx_bank] nvarchar(800) NULL,
[mx_bz1] nvarchar(200) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_inputuser_id] bigint NULL,
CONSTRAINT [PK_b_othercompany_accountbank] PRIMARY KEY ([subid]),
CONSTRAINT [FK_b_othercompany_accountbank_father] FOREIGN KEY ([father]) REFERENCES dbo.[b_othercompany] (b_id)
);
CREATE INDEX [IX_b_othercompany_accountbank_father] ON dbo.[b_othercompany_accountbank] ([father], [subid]);
END;
IF OBJECT_ID(N'dbo.b_othercompany_partner_type', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_othercompany_partner_type] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_othercompany_partner_type] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_othercompany_partner_type_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_package', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_package] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(100) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_package] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_package_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_port', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_port] (
[b_id] bigint NOT NULL,
[b_name_c] nvarchar(50) NULL,
[b_name_e] nvarchar(50) NULL,
[b_country] varchar(50) NULL,
[b_oceanline] varchar(50) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_tz] varchar(1) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_port] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_port_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_progress', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_progress] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(500) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_progress] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_progress_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_bgstate', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_bgstate] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_bgstate] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_bgstate_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_companytype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_companytype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_companytype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_companytype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_copies', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_copies] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_copies] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_copies_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_cystate', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_cystate] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_cystate] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_cystate_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_edittype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_edittype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_edittype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_edittype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_feesf', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_feesf] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_feesf] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_feesf_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_fielddefault', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_fielddefault] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_fielddefault] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_fielddefault_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_level', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_level] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_level] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_level_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_operator', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_operator] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_operator] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_operator_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_pricelisttype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_pricelisttype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_dw_id] bigint NULL,
[b_dw_name] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_pricelisttype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_pricelisttype_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_b_sys_pricelisttype_b_dw_id] ON dbo.[b_sys_pricelisttype] ([b_dw_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.b_sys_sex', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_sex] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_sex] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_sex_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_state', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_state] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_state] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_state_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_sys_yesno', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_sys_yesno] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_sys_yesno] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_sys_yesno_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_transway', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_transway] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(100) NULL,
[b_edicode] varchar(50) NULL,
[b_bz] nvarchar(100) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_transway] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_transway_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_user_feetype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_user_feetype] (
[b_id] bigint NOT NULL,
[b_user_id] bigint NULL,
[b_feetype_id] bigint NULL,
[b_bz] nvarchar(500) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_b_user_feetype] PRIMARY KEY ([b_id])
);
CREATE INDEX [IX_b_user_feetype_b_user_id] ON dbo.[b_user_feetype] ([b_user_id], [b_id]);
CREATE INDEX [IX_b_user_feetype_b_feetype_id] ON dbo.[b_user_feetype] ([b_feetype_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.b_user_worktime', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_user_worktime] (
[b_id] bigint NOT NULL,
[b_user_id] bigint NULL,
[b_day] varchar(10) NULL,
[b_timefrom] varchar(20) NULL,
[b_timeto] varchar(20) NULL,
[b_used] int NOT NULL CONSTRAINT [DF_b_user_worktime_b_used] DEFAULT (1),
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_b_user_worktime] PRIMARY KEY ([b_id])
);
CREATE INDEX [IX_b_user_worktime_b_user_id] ON dbo.[b_user_worktime] ([b_user_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.b_vessel', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_vessel] (
[b_id] bigint NOT NULL,
[b_vessel_name] nvarchar(100) NULL,
[b_edicode] varchar(50) NULL,
[b_voy] varchar(100) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_vessel] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_vessel_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_ysfs', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_ysfs] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_ysfs] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_ysfs_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_ystype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_ystype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_ystype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_ystype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_ywtype', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_ywtype] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_ywtype] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_ywtype_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.b_zxstate', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[b_zxstate] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(200) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_b_zxstate] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_b_zxstate_b_code] UNIQUE ([b_code])
);
END;
COMMIT TRANSACTION;
@@ -0,0 +1,214 @@
/* Generated schema-only migration: 合同和文件资料. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.bc_khht', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bc_khht] (
[b_id] bigint NOT NULL,
[b_customer_id] bigint NULL,
[b_htno] varchar(50) NOT NULL,
[b_begindate] date NULL,
[b_enddate] date NULL,
[b_httype] varchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_state] varchar(50) NULL,
[b_owner_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_mycompany_id] bigint NULL,
[b_zl] decimal(18,0) NULL,
[b_bz1] nvarchar(50) NULL,
[b_sales_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
CONSTRAINT [PK_bc_khht] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bc_khht_b_htno] UNIQUE ([b_htno])
);
CREATE INDEX [IX_bc_khht_b_customer_id] ON dbo.[bc_khht] ([b_customer_id], [b_id]);
CREATE INDEX [IX_bc_khht_b_owner_id] ON dbo.[bc_khht] ([b_owner_id], [b_id]);
CREATE INDEX [IX_bc_khht_b_mycompany_id] ON dbo.[bc_khht] ([b_mycompany_id], [b_id]);
CREATE INDEX [IX_bc_khht_b_sales_id] ON dbo.[bc_khht] ([b_sales_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.bc_pricelist', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bc_pricelist] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_dw_id] bigint NULL,
[b_type] varchar(50) NULL,
[b_canuse] int NOT NULL CONSTRAINT [DF_bc_pricelist_b_canuse] DEFAULT (1),
[b_begindate] date NULL,
[b_enddate] date NULL,
[b_loadport] varchar(50) NULL,
[b_aimport] varchar(50) NULL,
[b_cate_id] bigint NULL,
[b_owner_id] bigint NULL,
[b_state] varchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_bc_pricelist] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bc_pricelist_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_bc_pricelist_b_dw_id] ON dbo.[bc_pricelist] ([b_dw_id], [b_id]);
CREATE INDEX [IX_bc_pricelist_b_cate_id] ON dbo.[bc_pricelist] ([b_cate_id], [b_id]);
CREATE INDEX [IX_bc_pricelist_b_owner_id] ON dbo.[bc_pricelist] ([b_owner_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.bc_pricelist_bmfl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bc_pricelist_bmfl] (
b_id bigint NOT NULL,
b_parent_id bigint NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT [DF_bc_pricelist_bmfl_level] DEFAULT (1),
b_path varchar(1000) NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_bc_pricelist_bmfl_xh] DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT [DF_bc_pricelist_bmfl_canuse] DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT [DF_bc_pricelist_bmfl_inputdatetime] DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
CONSTRAINT [PK_bc_pricelist_bmfl] PRIMARY KEY (b_id),
CONSTRAINT [CK_bc_pricelist_bmfl_parent] CHECK (b_parent_id IS NULL OR b_parent_id <> b_id),
CONSTRAINT [FK_bc_pricelist_bmfl_parent] FOREIGN KEY (b_parent_id) REFERENCES dbo.[bc_pricelist_bmfl] (b_id)
);
CREATE INDEX [IX_bc_pricelist_bmfl_parent] ON dbo.[bc_pricelist_bmfl] (b_parent_id, b_xh, b_id);
CREATE INDEX [IX_bc_pricelist_bmfl_path] ON dbo.[bc_pricelist_bmfl] (b_path, b_xh, b_id);
END;
IF OBJECT_ID(N'dbo.bc_pricelist_sub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bc_pricelist_sub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_dw_id] bigint NULL,
[mx_dw_field] varchar(50) NULL,
[mx_type_id] bigint NULL,
[mx_feetype_id] bigint NULL,
[mx_moneytype_id] bigint NULL,
[mx_exrate] decimal(18,4) NULL,
[mx_price] decimal(18,2) NULL,
[mx_qty] decimal(18,3) NULL,
[mx_amount_root] decimal(18,3) NULL,
[mx_amount] decimal(18,3) NULL,
[mx_tax] decimal(18,4) NULL,
[mx_level] int NULL,
[mx_hstype_id] bigint NULL,
[mx_varchar_1] varchar(50) NULL,
[mx_varchar_2] varchar(50) NULL,
[mx_varchar_3] varchar(50) NULL,
[mx_varchar_4] varchar(50) NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_inputuser_id] bigint NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_bc_pricelist_sub] PRIMARY KEY ([subid]),
CONSTRAINT [FK_bc_pricelist_sub_father] FOREIGN KEY ([father]) REFERENCES dbo.[bc_pricelist] (b_id)
);
CREATE INDEX [IX_bc_pricelist_sub_father] ON dbo.[bc_pricelist_sub] ([father], [subid]);
CREATE INDEX [IX_bc_pricelist_sub_mx_dw_id] ON dbo.[bc_pricelist_sub] ([mx_dw_id], [subid]);
CREATE INDEX [IX_bc_pricelist_sub_mx_type_id] ON dbo.[bc_pricelist_sub] ([mx_type_id], [subid]);
CREATE INDEX [IX_bc_pricelist_sub_mx_feetype_id] ON dbo.[bc_pricelist_sub] ([mx_feetype_id], [subid]);
CREATE INDEX [IX_bc_pricelist_sub_mx_moneytype_id] ON dbo.[bc_pricelist_sub] ([mx_moneytype_id], [subid]);
CREATE INDEX [IX_bc_pricelist_sub_mx_hstype_id] ON dbo.[bc_pricelist_sub] ([mx_hstype_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bc_priceList_type', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bc_priceList_type] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_bc_priceList_type] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bc_priceList_type_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.bf_files', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bf_files] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_filename] nvarchar(500) NULL,
[mx_filesize] varchar(50) NULL,
[mx_fileext] varchar(50) NULL,
[mx_mapfilename] nvarchar(500) NULL,
[mx_moduleid] bigint NULL,
[mx_cutfilename] nvarchar(500) NULL,
[mx_cutfilesize] varchar(50) NULL,
[mx_cate_id] bigint NULL,
[mx_bz] nvarchar(500) NULL,
[mx_orderid] varchar(50) NULL,
[mx_sh] int NOT NULL CONSTRAINT [DF_bf_files_mx_sh] DEFAULT (0),
[mx_shdatetime] datetime2(0) NULL,
[mx_shuser_id] bigint NULL,
[mx_inputuser_id] bigint NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_bf_files] PRIMARY KEY ([subid])
);
CREATE INDEX [IX_bf_files_father] ON dbo.[bf_files] ([father], [subid]);
CREATE INDEX [IX_bf_files_mx_cate_id] ON dbo.[bf_files] ([mx_cate_id], [subid]);
CREATE INDEX [IX_bf_files_mx_shuser_id] ON dbo.[bf_files] ([mx_shuser_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bf_files_cateid', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bf_files_cateid] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_xh] int NULL,
[b_bz] nvarchar(50) NULL,
[b_canuse] int NOT NULL CONSTRAINT [DF_bf_files_cateid_b_canuse] DEFAULT (1),
[b_files_type] varchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_bf_files_cateid] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bf_files_cateid_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.bf_files_type', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bf_files_type] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_module_id] bigint NULL,
[b_module_name] nvarchar(50) NULL,
[b_xh] int NULL,
[b_bz] nvarchar(50) NULL,
[b_image_num] decimal(18,0) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_bf_files_type] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bf_files_type_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_bf_files_type_b_module_id] ON dbo.[bf_files_type] ([b_module_id], [b_id]);
END;
COMMIT TRANSACTION;
@@ -0,0 +1,396 @@
/* Generated schema-only migration: 业务单据. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.bs_business', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business] (
[b_id] bigint NOT NULL,
[b_ywno] varchar(50) NOT NULL,
[b_drno] varchar(50) NULL,
[b_ywtype] varchar(50) NULL,
[b_cargo_source] varchar(50) NULL,
[b_orderdate] datetime2(0) NULL,
[b_transterm] varchar(50) NULL,
[b_customer_id] bigint NULL,
[b_mycompany_id] bigint NULL,
[b_loadport] varchar(50) NULL,
[b_disport] varchar(50) NULL,
[b_aimport] varchar(50) NULL,
[b_transport] varchar(50) NULL,
[b_freightpayment] varchar(50) NULL,
[b_state] varchar(50) NULL,
[b_ysfs] varchar(50) NULL,
[b_ac_ctns] int NULL,
[b_ac_vol] decimal(18,3) NULL,
[b_ac_gw] decimal(18,3) NULL,
[b_ctns] int NULL,
[b_ctns_unit] varchar(50) NULL,
[b_namegoods] nvarchar(4000) NULL,
[b_vol] decimal(18,3) NULL,
[b_gw] decimal(18,3) NULL,
[b_voy] varchar(50) NULL,
[b_vessel] varchar(50) NULL,
[b_etd] datetime2(0) NULL,
[b_eta] datetime2(0) NULL,
[b_shipingdate] datetime2(0) NULL,
[b_arrivedate] datetime2(0) NULL,
[b_jgdate] datetime2(0) NULL,
[b_jddate] datetime2(0) NULL,
[b_progress] varchar(50) NULL,
[b_desc_con] nvarchar(100) NULL,
[b_desc_noandseal] nvarchar(150) NULL,
[b_sales_id] bigint NULL,
[b_doc_id] bigint NULL,
[b_sw_id] bigint NULL,
[b_operater_id] bigint NULL,
[b_owner_id] bigint NULL,
[b_shipcompany_id] bigint NULL,
[b_warehouse_id] bigint NULL,
[b_oceanline] varchar(50) NULL,
[b_bgcompany_id] bigint NULL,
[b_truck_id] bigint NULL,
[b_loaddate] datetime2(0) NULL,
[b_dcdw_id] bigint NULL,
[b_dcdwlinkman] varchar(50) NULL,
[b_dcno] varchar(50) NULL,
[b_dcdate] datetime2(0) NULL,
[b_fcdate] datetime2(0) NULL,
[b_jgbegindate] date NULL,
[b_jgenddate] date NULL,
[b_pcyqmemo] nvarchar(1000) NULL,
[b_enterstoreno] varchar(50) NULL,
[b_showcolor] varchar(50) NULL,
[b_blno] varchar(50) NULL,
[b_bl_copy] varchar(50) NULL,
[b_bl_state] varchar(50) NULL,
[b_bl_date] datetime2(0) NULL,
[b_bl_qsdate] datetime2(0) NULL,
[b_bl_jcdate] datetime2(0) NULL,
[b_bgdate] datetime2(0) NULL,
[b_bgno] varchar(50) NULL,
[b_bgtype] varchar(50) NULL,
[b_bgstate] varchar(50) NULL,
[b_cystate] varchar(50) NULL,
[b_bz1] nvarchar(1000) NULL,
[b_bz2] nvarchar(1000) NULL,
[b_bz3] nvarchar(1000) NULL,
[b_bz4] nvarchar(1000) NULL,
[b_shippermemo] nvarchar(2000) NULL,
[b_consigneememo] nvarchar(2000) NULL,
[b_notifymemo] nvarchar(2000) NULL,
[b_shipmark] nvarchar(2000) NULL,
[b_agentcompanyMemo] nvarchar(2000) NULL,
[b_con20] int NULL,
[b_con40] int NULL,
[b_con40h] int NULL,
[b_con45] int NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_yslocked] varchar(1) NULL,
[b_yslocked_date] datetime2(0) NULL,
[b_yslocked_userid] bigint NULL,
[b_yflocked] varchar(1) NULL,
[b_yflocked_date] datetime2(0) NULL,
[b_yflocked_userid] bigint NULL,
[b_cwlocked] varchar(1) NULL,
[b_cwlocked_date] datetime2(0) NULL,
[b_cwlocked_userid] bigint NULL,
CONSTRAINT [PK_bs_business] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_bs_business_b_ywno] UNIQUE ([b_ywno])
);
CREATE INDEX [IX_bs_business_b_customer_id] ON dbo.[bs_business] ([b_customer_id], [b_id]);
CREATE INDEX [IX_bs_business_b_mycompany_id] ON dbo.[bs_business] ([b_mycompany_id], [b_id]);
CREATE INDEX [IX_bs_business_b_sales_id] ON dbo.[bs_business] ([b_sales_id], [b_id]);
CREATE INDEX [IX_bs_business_b_doc_id] ON dbo.[bs_business] ([b_doc_id], [b_id]);
CREATE INDEX [IX_bs_business_b_sw_id] ON dbo.[bs_business] ([b_sw_id], [b_id]);
CREATE INDEX [IX_bs_business_b_operater_id] ON dbo.[bs_business] ([b_operater_id], [b_id]);
CREATE INDEX [IX_bs_business_b_owner_id] ON dbo.[bs_business] ([b_owner_id], [b_id]);
CREATE INDEX [IX_bs_business_b_shipcompany_id] ON dbo.[bs_business] ([b_shipcompany_id], [b_id]);
CREATE INDEX [IX_bs_business_b_warehouse_id] ON dbo.[bs_business] ([b_warehouse_id], [b_id]);
CREATE INDEX [IX_bs_business_b_bgcompany_id] ON dbo.[bs_business] ([b_bgcompany_id], [b_id]);
CREATE INDEX [IX_bs_business_b_truck_id] ON dbo.[bs_business] ([b_truck_id], [b_id]);
CREATE INDEX [IX_bs_business_b_dcdw_id] ON dbo.[bs_business] ([b_dcdw_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.bs_business_container', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business_container] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_hstype_id] bigint NULL,
[mx_xh] int NULL,
[mx_con_no] varchar(50) NULL,
[mx_sealno] varchar(50) NULL,
[mx_con_type] varchar(50) NULL,
[mx_con_size] varchar(50) NULL,
[mx_con_gw] decimal(18,6) NULL,
[mx_con_nw] decimal(18,6) NULL,
[mx_con_cartons] int NULL,
[mx_con_vol] decimal(18,6) NULL,
[mx_truck_id] bigint NULL,
[mx_truck_name] nvarchar(50) NULL,
[mx_truckno] varchar(50) NULL,
[mx_drive] varchar(50) NULL,
[mx_drivephone] varchar(50) NULL,
[mx_txplace] nvarchar(50) NULL,
[mx_txmemo] nvarchar(500) NULL,
[mx_txdate] datetime2(0) NULL,
[mx_zxdate] datetime2(0) NULL,
[mx_zxplace] nvarchar(50) NULL,
[mx_zxmemo] nvarchar(500) NULL,
[mx_date1] datetime2(0) NULL,
[mx_date2] datetime2(0) NULL,
[mx_date3] datetime2(0) NULL,
[mx_date4] datetime2(0) NULL,
[mx_date5] datetime2(0) NULL,
[mx_date6] datetime2(0) NULL,
[mx_bz1] nvarchar(500) NULL,
[mx_bz2] nvarchar(100) NULL,
[mx_bz3] nvarchar(100) NULL,
[mx_bz4] nvarchar(100) NULL,
[mx_bz5] nvarchar(100) NULL,
[mx_bz6] nvarchar(100) NULL,
[mx_bz7] nvarchar(100) NULL,
[mx_bz8] nvarchar(100) NULL,
[mx_memo8] nvarchar(10) NULL,
[mx_vgm] decimal(18,6) NULL,
[mx_vgm_cztype] varchar(100) NULL,
[mx_vgm_czdate] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_inputuser_id] bigint NULL,
CONSTRAINT [PK_bs_business_container] PRIMARY KEY ([subid]),
CONSTRAINT [FK_bs_business_container_father] FOREIGN KEY ([father]) REFERENCES dbo.[bs_business] (b_id)
);
CREATE INDEX [IX_bs_business_container_father] ON dbo.[bs_business_container] ([father], [subid]);
CREATE INDEX [IX_bs_business_container_mx_hstype_id] ON dbo.[bs_business_container] ([mx_hstype_id], [subid]);
CREATE INDEX [IX_bs_business_container_mx_truck_id] ON dbo.[bs_business_container] ([mx_truck_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bs_business_cw', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business_cw] (
[subid] bigint NOT NULL,
[subxh] int NOT NULL,
[father] bigint NULL,
[mx_bid] varchar(50) NULL,
[mx_level] int NOT NULL,
[mx_xh] int NULL,
[mx_dw_id] bigint NULL,
[mx_dw_name] nvarchar(50) NULL,
[mx_direction] varchar(20) NULL,
[mx_feetype_id] bigint NULL,
[mx_feetype_name] nvarchar(50) NULL,
[mx_moneytype_id] bigint NULL,
[mx_hstype_id] bigint NULL,
[mx_price] decimal(18,2) NULL,
[mx_qty] decimal(18,3) NULL,
[mx_amount] decimal(18,3) NULL,
[mx_amount_rmb] decimal(18,3) NULL,
[mx_exrate] decimal(18,4) NULL,
[mx_log_flag] varchar(50) NULL,
[mx_tax] decimal(18,4) NULL,
[mx_invoicenotax] decimal(18,3) NULL,
[mx_invoicetax] decimal(18,3) NULL,
[mx_sh_check] varchar(1) NULL,
[mx_sh_datetime] datetime2(0) NULL,
[mx_shman_id] bigint NULL,
[mx_cwgz_check] varchar(50) NULL,
[mx_cwgz_datetime] datetime2(0) NULL,
[mx_cwgzman_id] bigint NULL,
[mx_bill_id] bigint NULL,
[mx_bill_ywno] varchar(50) NULL,
[mx_bill_updatedatetime] datetime2(0) NULL,
[mx_bill_updateuser_id] bigint NULL,
[mx_bill_state] varchar(1) NULL,
[mx_bill_totalamount] decimal(18,3) NULL,
[mx_bill_totalamount_not] decimal(18,3) NULL,
[mx_invoice_id] bigint NULL,
[mx_invoice_ywno] varchar(50) NULL,
[mx_invoice_updatedatetime] datetime2(0) NULL,
[mx_invoice_updateuser_id] bigint NULL,
[mx_invoice_state] varchar(1) NULL,
[mx_invoice_totalamount] decimal(18,3) NULL,
[mx_invoice_totalamount_not] decimal(18,3) NULL,
[mx_sfd_id] bigint NULL,
[mx_sfd_ywno] varchar(50) NULL,
[mx_sfd_updatedatetime] datetime2(0) NULL,
[mx_sfd_updateuser_id] bigint NULL,
[mx_sfd_state] varchar(1) NULL,
[mx_sfd_totalamount] decimal(18,3) NULL,
[mx_sfd_totalamount_not] decimal(18,3) NULL,
[mx_mycompany_id] bigint NULL,
[mx_inputuser_id] bigint NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
[mx_memo1] nvarchar(1000) NULL,
[mx_memo2] nvarchar(1000) NULL,
[mx_memo3] nvarchar(1000) NULL,
[mx_memo4] nvarchar(1000) NULL,
[mx_memo5] nvarchar(1000) NULL,
[mx_varchar_1] varchar(50) NULL,
[mx_varchar_2] varchar(50) NULL,
[mx_varchar_3] varchar(50) NULL,
[mx_varchar_4] varchar(50) NULL,
[mx_varchar_5] varchar(50) NULL,
[mx_con_no] varchar(50) NULL,
[mx_qty_type] varchar(50) NULL,
CONSTRAINT [PK_bs_business_cw] PRIMARY KEY ([subid]),
CONSTRAINT [FK_bs_business_cw_father] FOREIGN KEY ([father]) REFERENCES dbo.[bs_business] (b_id)
);
CREATE INDEX [IX_bs_business_cw_father] ON dbo.[bs_business_cw] ([father], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_dw_id] ON dbo.[bs_business_cw] ([mx_dw_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_feetype_id] ON dbo.[bs_business_cw] ([mx_feetype_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_moneytype_id] ON dbo.[bs_business_cw] ([mx_moneytype_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_hstype_id] ON dbo.[bs_business_cw] ([mx_hstype_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_shman_id] ON dbo.[bs_business_cw] ([mx_shman_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_cwgzman_id] ON dbo.[bs_business_cw] ([mx_cwgzman_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_bill_id] ON dbo.[bs_business_cw] ([mx_bill_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_bill_updateuser_id] ON dbo.[bs_business_cw] ([mx_bill_updateuser_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_invoice_id] ON dbo.[bs_business_cw] ([mx_invoice_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_invoice_updateuser_id] ON dbo.[bs_business_cw] ([mx_invoice_updateuser_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_sfd_id] ON dbo.[bs_business_cw] ([mx_sfd_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_sfd_updateuser_id] ON dbo.[bs_business_cw] ([mx_sfd_updateuser_id], [subid]);
CREATE INDEX [IX_bs_business_cw_mx_mycompany_id] ON dbo.[bs_business_cw] ([mx_mycompany_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bs_business_hdbl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business_hdbl] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_blno] varchar(50) NULL,
[mx_shippermemo] nvarchar(2000) NULL,
[mx_consigneememo] nvarchar(2000) NULL,
[mx_notifymemo] nvarchar(2000) NULL,
[mx_agentcompanyMemo] nvarchar(2000) NULL,
[mx_freightpayment] varchar(50) NULL,
[mx_namegoods] nvarchar(4000) NULL,
[mx_ctns] int NULL,
[mx_ctns_unit_id] bigint NULL,
[mx_gw] decimal(18,3) NULL,
[mx_vol] decimal(18,3) NULL,
[mx_bz1] nvarchar(3000) NULL,
[mx_bz2] nvarchar(100) NULL,
[mx_bz3] nvarchar(100) NULL,
[mx_bz4] nvarchar(100) NULL,
[mx_bz5] nvarchar(100) NULL,
[mx_transterm] varchar(50) NULL,
[mx_drno] varchar(50) NULL,
[mx_aimport_id] bigint NULL,
[mx_shipmark] nvarchar(2000) NULL,
[mx_loadport_id] bigint NULL,
[mx_transport_id] bigint NULL,
[mx_inputuser_id] bigint NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_bs_business_hdbl] PRIMARY KEY ([subid]),
CONSTRAINT [FK_bs_business_hdbl_father] FOREIGN KEY ([father]) REFERENCES dbo.[bs_business] (b_id)
);
CREATE INDEX [IX_bs_business_hdbl_father] ON dbo.[bs_business_hdbl] ([father], [subid]);
CREATE INDEX [IX_bs_business_hdbl_mx_ctns_unit_id] ON dbo.[bs_business_hdbl] ([mx_ctns_unit_id], [subid]);
CREATE INDEX [IX_bs_business_hdbl_mx_aimport_id] ON dbo.[bs_business_hdbl] ([mx_aimport_id], [subid]);
CREATE INDEX [IX_bs_business_hdbl_mx_loadport_id] ON dbo.[bs_business_hdbl] ([mx_loadport_id], [subid]);
CREATE INDEX [IX_bs_business_hdbl_mx_transport_id] ON dbo.[bs_business_hdbl] ([mx_transport_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bs_business_hdbl_sub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business_hdbl_sub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_con_no] varchar(50) NULL,
[mx_blno] varchar(50) NULL,
[mx_con_cartons] int NULL,
[mx_con_gw] decimal(18,6) NULL,
[mx_con_nw] decimal(18,6) NULL,
[mx_con_vol] decimal(18,6) NULL,
[mx_bz1] nvarchar(3000) NULL,
[mx_bz2] nvarchar(100) NULL,
[mx_bz3] nvarchar(100) NULL,
[mx_bz4] nvarchar(100) NULL,
[mx_bz5] nvarchar(100) NULL,
[mx_linkfd_id] bigint NULL,
[mx_inputuser_id] bigint NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_bs_business_hdbl_sub] PRIMARY KEY ([subid])
);
CREATE INDEX [IX_bs_business_hdbl_sub_father] ON dbo.[bs_business_hdbl_sub] ([father], [subid]);
CREATE INDEX [IX_bs_business_hdbl_sub_mx_linkfd_id] ON dbo.[bs_business_hdbl_sub] ([mx_linkfd_id], [subid]);
END;
IF OBJECT_ID(N'dbo.bs_business_transport', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[bs_business_transport] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_source_type] varchar(50) NULL,
[mx_keyid] varchar(50) NULL,
[mx_processtype] varchar(50) NULL,
[mx_transtype] varchar(50) NULL,
[mx_loadport] varchar(50) NULL,
[mx_aimport] varchar(50) NULL,
[mx_ETD] datetime2(0) NULL,
[mx_ETA] datetime2(0) NULL,
[mx_truck_id] bigint NULL,
[mx_truckno] varchar(50) NULL,
[mx_pno] varchar(50) NULL,
[mx_bz] nvarchar(200) NULL,
[mx_startdate] datetime2(0) NULL,
[mx_finish] int NOT NULL CONSTRAINT [DF_bs_business_transport_mx_finish] DEFAULT (0),
[mx_finishdate] datetime2(0) NULL,
[mx_finish_userid] bigint NULL,
[mx_manage_id] bigint NULL,
[mx_user_id] bigint NULL,
[mx_varcahr1] varchar(50) NULL,
[mx_varcahr2] varchar(50) NULL,
[mx_varcahr3] varchar(50) NULL,
[mx_bz1] nvarchar(300) NULL,
[mx_bz2] nvarchar(300) NULL,
[mx_bz3] nvarchar(300) NULL,
[mx_jhdatetime] datetime2(0) NULL,
[mx_level] varchar(50) NULL,
[mx_state] varchar(50) NULL,
[mx_vessel_voy] varchar(150) NULL,
[mx_lastupdate_datatime] datetime2(0) NULL,
[mx_attach_bz1] nvarchar(300) NULL,
[mx_attach_bz2] nvarchar(300) NULL,
[mx_attach_bz3] nvarchar(300) NULL,
[mx_packdate] datetime2(0) NULL,
[mx_packplace] nvarchar(300) NULL,
[mx_txdate] datetime2(0) NULL,
[mx_txplace] nvarchar(300) NULL,
[mx_hxdate] datetime2(0) NULL,
[mx_hxplace] nvarchar(300) NULL,
[mx_conno] varchar(3000) NULL,
[mx_inputuser_id] bigint NULL,
[mx_inputdatetime] datetime2(0) NULL,
[mx_updateuser_id] bigint NULL,
[mx_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_bs_business_transport] PRIMARY KEY ([subid]),
CONSTRAINT [FK_bs_business_transport_father] FOREIGN KEY ([father]) REFERENCES dbo.[bs_business] (b_id)
);
CREATE INDEX [IX_bs_business_transport_father] ON dbo.[bs_business_transport] ([father], [subid]);
CREATE INDEX [IX_bs_business_transport_mx_truck_id] ON dbo.[bs_business_transport] ([mx_truck_id], [subid]);
CREATE INDEX [IX_bs_business_transport_mx_manage_id] ON dbo.[bs_business_transport] ([mx_manage_id], [subid]);
CREATE INDEX [IX_bs_business_transport_mx_user_id] ON dbo.[bs_business_transport] ([mx_user_id], [subid]);
END;
COMMIT TRANSACTION;
@@ -0,0 +1,362 @@
/* Generated schema-only migration: 财务. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.cw_account', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_account] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(500) NULL,
[b_type] varchar(200) NULL,
[b_bank] nvarchar(200) NULL,
[b_account] varchar(200) NOT NULL,
[b_date] datetime2(0) NULL,
[b_amount_start] decimal(18,2) NULL,
[b_amount] decimal(18,2) NULL,
[b_bz] nvarchar(500) NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_state] varchar(50) NULL,
[b_owner_id] bigint NULL,
[b_mycompany_id] bigint NULL,
[b_truckno] varchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
CONSTRAINT [PK_cw_account] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_account_b_account] UNIQUE ([b_account])
);
CREATE INDEX [IX_cw_account_b_owner_id] ON dbo.[cw_account] ([b_owner_id], [b_id]);
CREATE INDEX [IX_cw_account_b_mycompany_id] ON dbo.[cw_account] ([b_mycompany_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.cw_account_type', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_account_type] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(50) NULL,
[b_bz] nvarchar(50) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_cw_account_type] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_account_type_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.cw_bill', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_bill] (
[b_id] bigint NOT NULL,
[b_ywno] varchar(50) NOT NULL,
[b_date] datetime2(0) NULL,
[b_direction] varchar(20) NULL,
[b_document_type] varchar(50) NULL,
[b_dw_id] bigint NULL,
[b_mycompany_id] bigint NULL,
[b_amount] decimal(18,2) NULL,
[b_amount_desc] nvarchar(500) NULL,
[b_money_id] bigint NULL,
[b_account_id] bigint NULL,
[b_bankname] nvarchar(100) NULL,
[b_bankaccount] nvarchar(500) NULL,
[b_zl] decimal(18,0) NULL,
[b_plandate] datetime2(0) NULL,
[b_state] varchar(50) NULL,
[b_bz] nvarchar(500) NULL,
[b_owner_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_writeoff] varchar(50) NULL,
[b_writeoff_id] bigint NULL,
[b_writeoffdatetime] datetime2(0) NULL,
[b_dw_bankacount] nvarchar(500) NULL,
[b_dw_invaccount] varchar(500) NULL,
[b_my_bankacount] nvarchar(500) NULL,
[b_my_invaccount] varchar(500) NULL,
CONSTRAINT [PK_cw_bill] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_bill_b_ywno] UNIQUE ([b_ywno])
);
CREATE INDEX [IX_cw_bill_b_dw_id] ON dbo.[cw_bill] ([b_dw_id], [b_id]);
CREATE INDEX [IX_cw_bill_b_mycompany_id] ON dbo.[cw_bill] ([b_mycompany_id], [b_id]);
CREATE INDEX [IX_cw_bill_b_money_id] ON dbo.[cw_bill] ([b_money_id], [b_id]);
CREATE INDEX [IX_cw_bill_b_account_id] ON dbo.[cw_bill] ([b_account_id], [b_id]);
CREATE INDEX [IX_cw_bill_b_owner_id] ON dbo.[cw_bill] ([b_owner_id], [b_id]);
CREATE INDEX [IX_cw_bill_b_writeoff_id] ON dbo.[cw_bill] ([b_writeoff_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.cw_billsub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_billsub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_fee_id] bigint NULL,
[mx_fee_money_id] bigint NULL,
[mx_fee_amount] decimal(18,2) NULL,
[mx_bill_amount] decimal(18,2) NULL,
[mx_bz] nvarchar(200) NULL,
CONSTRAINT [PK_cw_billsub] PRIMARY KEY ([subid]),
CONSTRAINT [FK_cw_billsub_father] FOREIGN KEY ([father]) REFERENCES dbo.[cw_bill] (b_id)
);
CREATE INDEX [IX_cw_billsub_father] ON dbo.[cw_billsub] ([father], [subid]);
CREATE INDEX [IX_cw_billsub_mx_fee_id] ON dbo.[cw_billsub] ([mx_fee_id], [subid]);
CREATE INDEX [IX_cw_billsub_mx_fee_money_id] ON dbo.[cw_billsub] ([mx_fee_money_id], [subid]);
END;
IF OBJECT_ID(N'dbo.cw_daily', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_daily] (
[b_id] bigint NOT NULL,
[b_date] datetime2(0) NULL,
[b_bill] int NOT NULL CONSTRAINT [DF_cw_daily_b_bill] DEFAULT (0),
[b_feetype] varchar(50) NULL,
[b_amount] decimal(18,2) NULL,
[b_bz1] nvarchar(500) NULL,
[b_owner_id] bigint NULL,
[b_payee_id] bigint NULL,
[b_state] varchar(50) NULL,
[b_desc] nvarchar(500) NULL,
[b_type] varchar(50) NULL,
[b_account_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_zx] int NOT NULL CONSTRAINT [DF_cw_daily_b_zx] DEFAULT (0),
[b_zxuser_id] bigint NULL,
[b_zxdatetime] datetime2(0) NULL,
[b_dw_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_cw_daily] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_daily_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_cw_daily_b_owner_id] ON dbo.[cw_daily] ([b_owner_id], [b_id]);
CREATE INDEX [IX_cw_daily_b_payee_id] ON dbo.[cw_daily] ([b_payee_id], [b_id]);
CREATE INDEX [IX_cw_daily_b_account_id] ON dbo.[cw_daily] ([b_account_id], [b_id]);
CREATE INDEX [IX_cw_daily_b_zxuser_id] ON dbo.[cw_daily] ([b_zxuser_id], [b_id]);
CREATE INDEX [IX_cw_daily_b_dw_id] ON dbo.[cw_daily] ([b_dw_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.cw_invoice', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_invoice] (
[b_id] bigint NOT NULL,
[b_ywno] varchar(50) NOT NULL,
[b_date] datetime2(0) NULL,
[b_direction] varchar(20) NULL,
[b_document_type] varchar(50) NULL,
[b_dw_id] bigint NULL,
[b_mycompany_id] bigint NULL,
[b_amount] decimal(18,2) NULL,
[b_money_id] bigint NULL,
[b_account_id] bigint NULL,
[b_bankname] nvarchar(100) NULL,
[b_bankaccount] nvarchar(500) NULL,
[b_tax] varchar(50) NULL,
[b_state] varchar(50) NULL,
[b_bz] nvarchar(500) NULL,
[b_bz1] nvarchar(500) NULL,
[b_owner_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_writeoff] varchar(50) NULL,
[b_writeoff_id] bigint NULL,
[b_writeoffdatetime] datetime2(0) NULL,
[b_dw_bankacount] nvarchar(500) NULL,
[b_dw_invaccount] varchar(500) NULL,
[b_my_bankacount] nvarchar(500) NULL,
[b_my_invaccount] varchar(500) NULL,
CONSTRAINT [PK_cw_invoice] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_invoice_b_ywno] UNIQUE ([b_ywno])
);
CREATE INDEX [IX_cw_invoice_b_dw_id] ON dbo.[cw_invoice] ([b_dw_id], [b_id]);
CREATE INDEX [IX_cw_invoice_b_mycompany_id] ON dbo.[cw_invoice] ([b_mycompany_id], [b_id]);
CREATE INDEX [IX_cw_invoice_b_money_id] ON dbo.[cw_invoice] ([b_money_id], [b_id]);
CREATE INDEX [IX_cw_invoice_b_account_id] ON dbo.[cw_invoice] ([b_account_id], [b_id]);
CREATE INDEX [IX_cw_invoice_b_owner_id] ON dbo.[cw_invoice] ([b_owner_id], [b_id]);
CREATE INDEX [IX_cw_invoice_b_writeoff_id] ON dbo.[cw_invoice] ([b_writeoff_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.cw_invoicesub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_invoicesub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_fee_id] bigint NULL,
[mx_fee_money_id] bigint NULL,
[mx_fee_amount] decimal(18,2) NULL,
[mx_invoice_amount] decimal(18,2) NULL,
[mx_bz] nvarchar(50) NULL,
CONSTRAINT [PK_cw_invoicesub] PRIMARY KEY ([subid]),
CONSTRAINT [FK_cw_invoicesub_father] FOREIGN KEY ([father]) REFERENCES dbo.[cw_invoice] (b_id)
);
CREATE INDEX [IX_cw_invoicesub_father] ON dbo.[cw_invoicesub] ([father], [subid]);
CREATE INDEX [IX_cw_invoicesub_mx_fee_id] ON dbo.[cw_invoicesub] ([mx_fee_id], [subid]);
CREATE INDEX [IX_cw_invoicesub_mx_fee_money_id] ON dbo.[cw_invoicesub] ([mx_fee_money_id], [subid]);
END;
IF OBJECT_ID(N'dbo.cw_sfd', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_sfd] (
[b_id] bigint NOT NULL,
[b_ywno] varchar(50) NOT NULL,
[b_direction] varchar(20) NULL,
[b_document_type] varchar(50) NULL,
[b_date] datetime2(0) NULL,
[b_dw_id] bigint NULL,
[b_mycompany_id] bigint NULL,
[b_amount] decimal(18,3) NULL,
[b_amount_other] decimal(18,3) NULL,
[b_amount_sj] decimal(18,3) NULL,
[b_money_id] bigint NULL,
[b_exrate] decimal(18,4) NULL,
[b_amount_hx] decimal(18,3) NULL,
[b_amount_nothx] decimal(18,3) NULL,
[b_account_id] bigint NULL,
[b_bankname] nvarchar(100) NULL,
[b_bankaccount] nvarchar(500) NULL,
[b_state] varchar(50) NULL,
[b_bz] nvarchar(500) NULL,
[b_owner_id] bigint NULL,
[b_sh] int NOT NULL CONSTRAINT [DF_cw_sfd_b_sh] DEFAULT (0),
[b_sh_id] bigint NULL,
[b_shdatetime] datetime2(0) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_writeoff] varchar(50) NULL,
[b_writeoff_id] bigint NULL,
[b_writeoffdatetime] datetime2(0) NULL,
CONSTRAINT [PK_cw_sfd] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_cw_sfd_b_ywno] UNIQUE ([b_ywno])
);
CREATE INDEX [IX_cw_sfd_b_dw_id] ON dbo.[cw_sfd] ([b_dw_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_mycompany_id] ON dbo.[cw_sfd] ([b_mycompany_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_money_id] ON dbo.[cw_sfd] ([b_money_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_account_id] ON dbo.[cw_sfd] ([b_account_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_owner_id] ON dbo.[cw_sfd] ([b_owner_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_sh_id] ON dbo.[cw_sfd] ([b_sh_id], [b_id]);
CREATE INDEX [IX_cw_sfd_b_writeoff_id] ON dbo.[cw_sfd] ([b_writeoff_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.cw_sfdsub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_sfdsub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] int NULL,
[mx_fee_id] bigint NULL,
[mx_fee_money_id] bigint NULL,
[mx_fee_amount] decimal(18,2) NULL,
[mx_sf_money_id] bigint NULL,
[mx_sf_amount] decimal(18,2) NULL,
[mx_exrate] decimal(18,4) NULL,
[mx_bz] nvarchar(50) NULL,
CONSTRAINT [PK_cw_sfdsub] PRIMARY KEY ([subid]),
CONSTRAINT [FK_cw_sfdsub_father] FOREIGN KEY ([father]) REFERENCES dbo.[cw_sfd] (b_id)
);
CREATE INDEX [IX_cw_sfdsub_father] ON dbo.[cw_sfdsub] ([father], [subid]);
CREATE INDEX [IX_cw_sfdsub_mx_fee_id] ON dbo.[cw_sfdsub] ([mx_fee_id], [subid]);
CREATE INDEX [IX_cw_sfdsub_mx_fee_money_id] ON dbo.[cw_sfdsub] ([mx_fee_money_id], [subid]);
CREATE INDEX [IX_cw_sfdsub_mx_sf_money_id] ON dbo.[cw_sfdsub] ([mx_sf_money_id], [subid]);
END;
IF OBJECT_ID(N'dbo.cw_bill_business', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_bill_business] (
subid bigint NOT NULL,
[b_bill_id] bigint NOT NULL,
[b_business_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_bill_business_xh] DEFAULT (0),
CONSTRAINT [PK_cw_bill_business] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_bill_business] UNIQUE ([b_bill_id], [b_business_id]),
CONSTRAINT [FK_cw_bill_business_left] FOREIGN KEY ([b_bill_id]) REFERENCES dbo.[cw_bill] (b_id),
CONSTRAINT [FK_cw_bill_business_right] FOREIGN KEY ([b_business_id]) REFERENCES dbo.[bs_business] (b_id)
);
END;
IF OBJECT_ID(N'dbo.cw_invoice_bill', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_invoice_bill] (
subid bigint NOT NULL,
[b_invoice_id] bigint NOT NULL,
[b_bill_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_invoice_bill_xh] DEFAULT (0),
CONSTRAINT [PK_cw_invoice_bill] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_invoice_bill] UNIQUE ([b_invoice_id], [b_bill_id]),
CONSTRAINT [FK_cw_invoice_bill_left] FOREIGN KEY ([b_invoice_id]) REFERENCES dbo.[cw_invoice] (b_id),
CONSTRAINT [FK_cw_invoice_bill_right] FOREIGN KEY ([b_bill_id]) REFERENCES dbo.[cw_bill] (b_id)
);
END;
IF OBJECT_ID(N'dbo.cw_invoice_business', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_invoice_business] (
subid bigint NOT NULL,
[b_invoice_id] bigint NOT NULL,
[b_business_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_invoice_business_xh] DEFAULT (0),
CONSTRAINT [PK_cw_invoice_business] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_invoice_business] UNIQUE ([b_invoice_id], [b_business_id]),
CONSTRAINT [FK_cw_invoice_business_left] FOREIGN KEY ([b_invoice_id]) REFERENCES dbo.[cw_invoice] (b_id),
CONSTRAINT [FK_cw_invoice_business_right] FOREIGN KEY ([b_business_id]) REFERENCES dbo.[bs_business] (b_id)
);
END;
IF OBJECT_ID(N'dbo.cw_sfd_business', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_sfd_business] (
subid bigint NOT NULL,
[b_sfd_id] bigint NOT NULL,
[b_business_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_sfd_business_xh] DEFAULT (0),
CONSTRAINT [PK_cw_sfd_business] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_sfd_business] UNIQUE ([b_sfd_id], [b_business_id]),
CONSTRAINT [FK_cw_sfd_business_left] FOREIGN KEY ([b_sfd_id]) REFERENCES dbo.[cw_sfd] (b_id),
CONSTRAINT [FK_cw_sfd_business_right] FOREIGN KEY ([b_business_id]) REFERENCES dbo.[bs_business] (b_id)
);
END;
IF OBJECT_ID(N'dbo.cw_sfd_invoice', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_sfd_invoice] (
subid bigint NOT NULL,
[b_sfd_id] bigint NOT NULL,
[b_invoice_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_sfd_invoice_xh] DEFAULT (0),
CONSTRAINT [PK_cw_sfd_invoice] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_sfd_invoice] UNIQUE ([b_sfd_id], [b_invoice_id]),
CONSTRAINT [FK_cw_sfd_invoice_left] FOREIGN KEY ([b_sfd_id]) REFERENCES dbo.[cw_sfd] (b_id),
CONSTRAINT [FK_cw_sfd_invoice_right] FOREIGN KEY ([b_invoice_id]) REFERENCES dbo.[cw_invoice] (b_id)
);
END;
IF OBJECT_ID(N'dbo.cw_sfd_bill', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[cw_sfd_bill] (
subid bigint NOT NULL,
[b_sfd_id] bigint NOT NULL,
[b_bill_id] bigint NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_cw_sfd_bill_xh] DEFAULT (0),
CONSTRAINT [PK_cw_sfd_bill] PRIMARY KEY (subid),
CONSTRAINT [UQ_cw_sfd_bill] UNIQUE ([b_sfd_id], [b_bill_id]),
CONSTRAINT [FK_cw_sfd_bill_left] FOREIGN KEY ([b_sfd_id]) REFERENCES dbo.[cw_sfd] (b_id),
CONSTRAINT [FK_cw_sfd_bill_right] FOREIGN KEY ([b_bill_id]) REFERENCES dbo.[cw_bill] (b_id)
);
END;
COMMIT TRANSACTION;
@@ -0,0 +1,179 @@
/* Generated schema-only migration: OA. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.oa_notices', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_notices] (
[b_id] bigint NOT NULL,
[b_subject] nvarchar(250) NULL,
[b_info] nvarchar(max) NULL,
[b_inputdate] datetime2(0) NULL,
[b_inputuser_id] bigint NULL,
[b_toall] int NOT NULL CONSTRAINT [DF_oa_notices_b_toall] DEFAULT (0),
[b_order] int NULL,
[b_visible] int NOT NULL CONSTRAINT [DF_oa_notices_b_visible] DEFAULT (1),
[b_body] varbinary(max) NULL,
[b_owner_id] bigint NULL,
[b_state] varchar(50) NULL,
[b_dl_id] bigint NULL,
[b_xl_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_oa_notices] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_oa_notices_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_oa_notices_b_owner_id] ON dbo.[oa_notices] ([b_owner_id], [b_id]);
CREATE INDEX [IX_oa_notices_b_dl_id] ON dbo.[oa_notices] ([b_dl_id], [b_id]);
CREATE INDEX [IX_oa_notices_b_xl_id] ON dbo.[oa_notices] ([b_xl_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.oa_notices_attach', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_notices_attach] (
[SubID] bigint NOT NULL,
[father] bigint NULL,
[mx_attachname] nvarchar(500) NULL,
[mx_attachfile] varbinary(max) NULL,
[mx_contentid] nvarchar(500) NULL,
[mx_attachsize] varchar(50) NULL,
[mx_ifattachfile] varchar(500) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_oa_notices_attach] PRIMARY KEY ([SubID]),
CONSTRAINT [FK_oa_notices_attach_father] FOREIGN KEY ([father]) REFERENCES dbo.[oa_notices] (b_id)
);
CREATE INDEX [IX_oa_notices_attach_father] ON dbo.[oa_notices_attach] ([father], [SubID]);
END;
IF OBJECT_ID(N'dbo.oa_notices_dl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_notices_dl] (
[b_id] bigint NOT NULL,
[b_name] nvarchar(100) NULL,
[b_bz] nvarchar(100) NULL,
[b_xh] int NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_oa_notices_dl] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_oa_notices_dl_b_code] UNIQUE ([b_code])
);
END;
IF OBJECT_ID(N'dbo.oa_notices_xl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_notices_xl] (
[b_id] bigint NOT NULL,
[b_xh] int NULL,
[b_code] varchar(50) NOT NULL,
[b_name] nvarchar(100) NULL,
[b_father_id] bigint NULL,
[b_bz] nvarchar(100) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_oa_notices_xl] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_oa_notices_xl_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_oa_notices_xl_b_father_id] ON dbo.[oa_notices_xl] ([b_father_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.oa_noticesSub', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_noticesSub] (
[subid] bigint NOT NULL,
[father] bigint NULL,
[mx_xh] varchar(50) NULL,
[mx_user_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
CONSTRAINT [PK_oa_noticesSub] PRIMARY KEY ([subid]),
CONSTRAINT [FK_oa_noticesSub_father] FOREIGN KEY ([father]) REFERENCES dbo.[oa_notices] (b_id)
);
CREATE INDEX [IX_oa_noticesSub_father] ON dbo.[oa_noticesSub] ([father], [subid]);
CREATE INDEX [IX_oa_noticesSub_mx_user_id] ON dbo.[oa_noticesSub] ([mx_user_id], [subid]);
END;
IF OBJECT_ID(N'dbo.oa_reminder', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_reminder] (
[b_id] bigint NOT NULL,
[b_subject] nvarchar(250) NULL,
[b_content] nvarchar(max) NULL,
[b_datebegin] datetime2(0) NULL,
[b_reminder] int NOT NULL CONSTRAINT [DF_oa_reminder_b_reminder] DEFAULT (0),
[b_reminderday] int NULL,
[b_customer_id] bigint NULL,
[b_owner_id] bigint NULL,
[b_inputuser_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_oa_reminder] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_oa_reminder_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_oa_reminder_b_customer_id] ON dbo.[oa_reminder] ([b_customer_id], [b_id]);
CREATE INDEX [IX_oa_reminder_b_owner_id] ON dbo.[oa_reminder] ([b_owner_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.oa_title', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_title] (
[b_id] bigint NOT NULL,
[b_subject] nvarchar(250) NULL,
[b_inputuser_id] bigint NULL,
[b_inputdate] datetime2(0) NULL,
[b_inputtime] time(0) NULL,
[b_order] int NOT NULL,
[b_content] nvarchar(max) NULL,
[b_cate_id] bigint NULL,
[b_inputdatetime] datetime2(0) NULL,
[b_updateuser_id] bigint NULL,
[b_updatedatetime] datetime2(0) NULL,
[b_code] varchar(50) NOT NULL,
CONSTRAINT [PK_oa_title] PRIMARY KEY ([b_id]),
CONSTRAINT [UQ_oa_title_b_code] UNIQUE ([b_code])
);
CREATE INDEX [IX_oa_title_b_cate_id] ON dbo.[oa_title] ([b_cate_id], [b_id]);
END;
IF OBJECT_ID(N'dbo.oa_title_bmfl', N'U') IS NULL
BEGIN
CREATE TABLE dbo.[oa_title_bmfl] (
b_id bigint NOT NULL,
b_parent_id bigint NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT [DF_oa_title_bmfl_level] DEFAULT (1),
b_path varchar(1000) NOT NULL,
b_xh int NOT NULL CONSTRAINT [DF_oa_title_bmfl_xh] DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT [DF_oa_title_bmfl_canuse] DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT [DF_oa_title_bmfl_inputdatetime] DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
CONSTRAINT [PK_oa_title_bmfl] PRIMARY KEY (b_id),
CONSTRAINT [CK_oa_title_bmfl_parent] CHECK (b_parent_id IS NULL OR b_parent_id <> b_id),
CONSTRAINT [FK_oa_title_bmfl_parent] FOREIGN KEY (b_parent_id) REFERENCES dbo.[oa_title_bmfl] (b_id)
);
CREATE INDEX [IX_oa_title_bmfl_parent] ON dbo.[oa_title_bmfl] (b_parent_id, b_xh, b_id);
CREATE INDEX [IX_oa_title_bmfl_path] ON dbo.[oa_title_bmfl] (b_path, b_xh, b_id);
END;
COMMIT TRANSACTION;
@@ -0,0 +1,539 @@
/* Generated schema-only migration: 业务视图. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
IF OBJECT_ID(N'dbo.v_b_feetype', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_feetype];
EXEC sys.sp_executesql N'CREATE VIEW dbo.v_b_feetype AS SELECT fee.b_id, fee.b_name, fee.b_name_e, fee.b_bz, fee.b_default, fee.b_amount, fee.b_tax, fee.b_money_id, fee.b_inputuser_id, fee.b_inputdatetime, fee.b_updateuser_id, fee.b_updatedatetime, money.b_hl FROM dbo.b_feetype AS fee LEFT JOIN dbo.b_money AS money ON money.b_id = fee.b_money_id';
IF OBJECT_ID(N'dbo.v_b_hl', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_hl];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_hl] AS SELECT dbo.b_hl.b_id, dbo.b_hl.b_money_id,
dbo.b_hl.b_bz, dbo.b_hl.b_hl, dbo.b_hl.b_month, dbo.b_hl.b_qsdate,
dbo.b_hl.b_zzdate, CONVERT(varchar(4), dbo.b_hl.b_qsdate, 120) AS v_year,
dbo.b_hl.b_type
FROM dbo.b_hl';
IF OBJECT_ID(N'dbo.v_b_othercompany', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_name, dbo.b_othercompany.b_shortname, dbo.b_othercompany.b_linkman, dbo.b_othercompany.b_phone,
dbo.b_othercompany.b_addr, dbo.b_othercompany.b_firstlinkdate, dbo.b_othercompany.b_htno, dbo.b_othercompany.b_black, dbo.b_othercompany.b_canuse, dbo.b_othercompany.b_zl,
dbo.b_othercompany.b_tel, dbo.b_othercompany.b_fax, dbo.b_othercompany.b_www, dbo.b_othercompany.b_email, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_cate_id,
dbo.b_othercompany.b_bz1, dbo.b_othercompany.b_bz2, dbo.b_othercompany.b_bz3, dbo.b_othercompany.b_bz4, dbo.b_othercompany.b_province, dbo.b_othercompany.b_city,
dbo.b_othercompany.b_area, dbo.b_othercompany.b_country, dbo.b_othercompany.b_showcolor, dbo.b_othercompany.b_type_id, dbo.b_othercompany.b_from_id, dbo.b_othercompany.b_edicode,
dbo.b_othercompany.b_type1_id, dbo.b_othercompany.b_type2_id, dbo.b_othercompany.b_type3_id, dbo.b_othercompany.b_type4_id, dbo.b_othercompany.b_type5_id,
dbo.b_othercompany.b_owner_id, dbo.b_othercompany.b_inputuser_id, dbo.b_othercompany.b_inputdatetime, dbo.b_othercompany.b_updateuser_id, dbo.b_othercompany.b_updatedatetime,
dbo.b_othercompany.b_password, dbo.b_othercompany.b_state, dbo.b_othercompany.b_bankacount_e, dbo.b_othercompany.b_addr_e, dbo.b_othercompany.b_name_e,
dbo.b_othercompany.b_type, dbo.b_user.b_name AS v_ownername, dbo.b_othercompany.b_htdate, dbo.b_othercompany.b_htexpiredate, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_bg', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_bg];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_bg] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%bg%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_bmfl', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_bmfl];
EXEC sys.sp_executesql N'CREATE VIEW dbo.v_b_othercompany_bmfl AS SELECT b_id, b_name FROM dbo.b_othercompany_bmfl';
IF OBJECT_ID(N'dbo.v_b_othercompany_customer', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_customer];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_customer] AS SELECT dbo.b_othercompany.b_name, dbo.b_othercompany.b_id, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_type, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount, dbo.b_othercompany.b_zl
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%customer%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_cy', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_cy];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_cy] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%cy%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_dc', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_dc];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_dc] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%dc%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_my', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_my];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_my] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_type, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%my%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_other', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_other];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_other] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%other%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_ship', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_ship];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_ship] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%ship%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_truck', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_truck];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_truck] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, ISNULL(dbo.b_othercompany.b_shortname, '''') + ISNULL(dbo.b_othercompany.b_phone, '''') AS b_truckphone,
dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount,
dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%truck%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_othercompany_warehouse', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_othercompany_warehouse];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_othercompany_warehouse] AS SELECT dbo.b_othercompany.b_id, dbo.b_othercompany.b_name, dbo.b_user.b_name AS v_ownername, dbo.b_user.b_department AS v_ownerdepartment, dbo.b_othercompany.b_owner_id,
dbo.b_othercompany.b_type, dbo.b_othercompany.b_pycode, dbo.b_othercompany.b_bankacount, dbo.b_othercompany.b_invaccount
FROM dbo.b_othercompany LEFT OUTER JOIN
dbo.b_user ON dbo.b_othercompany.b_owner_id = dbo.b_user.b_id
WHERE (dbo.b_othercompany.b_type LIKE ''%warehouse%'') AND (ISNULL(dbo.b_othercompany.b_black, ''0'') <> ''1'')';
IF OBJECT_ID(N'dbo.v_b_port', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_port];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_port] AS SELECT b_id, b_name_e AS b_name, b_country
FROM dbo.b_port';
IF OBJECT_ID(N'dbo.v_b_user', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_user];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_user] AS SELECT b_name, b_department, b_id, b_machineid, b_bz, b_password, b_canuse, b_othermachinelogin, b_salesman, b_docman, b_dealman, b_receivelevel, b_paylevel, b_visible_customer,
b_visible_supply, b_levelvisible
FROM dbo.b_user';
IF OBJECT_ID(N'dbo.v_b_user_feetype', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_user_feetype];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_user_feetype] AS SELECT dbo.b_user_feetype.b_id, dbo.b_user_feetype.b_user_id,
dbo.b_user_feetype.b_feetype_id, dbo.b_feetype.b_name,
dbo.b_feetype.b_name AS v_b_feetype_name, dbo.b_user_feetype.b_bz
FROM dbo.b_user_feetype LEFT OUTER JOIN
dbo.b_feetype ON dbo.b_user_feetype.b_feetype_id = dbo.b_feetype.b_id';
IF OBJECT_ID(N'dbo.v_b_user_id', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_user_id];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_user_id] AS SELECT b_id, b_id AS b_name
FROM dbo.b_user';
IF OBJECT_ID(N'dbo.v_b_userandcontact', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_userandcontact];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_userandcontact] AS SELECT b_id, b_name
FROM dbo.b_user
union
select b_id,b_name_ch as b_name
from dbo.b_contact';
IF OBJECT_ID(N'dbo.v_b_vessel', N'V') IS NOT NULL
DROP VIEW dbo.[v_b_vessel];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_b_vessel] AS SELECT b_id, b_vessel_name AS b_name, b_voy
FROM dbo.b_vessel';
IF OBJECT_ID(N'dbo.v_bc_khht', N'V') IS NOT NULL
DROP VIEW dbo.[v_bc_khht];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bc_khht] AS SELECT dbo.bc_khht.b_id, dbo.bc_khht.b_customer_id, dbo.bc_khht.b_htno, dbo.bc_khht.b_begindate, dbo.bc_khht.b_enddate, dbo.bc_khht.b_httype, dbo.bc_khht.b_bz,
dbo.b_othercompany.b_name AS v_customer_name, dbo.bc_khht.b_state, dbo.bc_khht.b_owner_id, dbo.bc_khht.b_inputuser_id, dbo.bc_khht.b_inputdatetime, dbo.bc_khht.b_mycompany_id,
dbo.bc_khht.b_zl, dbo.bc_khht.b_bz1, b_othercompany_1.b_name AS v_mycompany_name, dbo.bc_khht.b_sales_id, dbo.b_user.b_name AS v_sales_name, dbo.bc_khht.b_updatedatetime,
dbo.bc_khht.b_updateuser_id
FROM dbo.bc_khht LEFT OUTER JOIN
dbo.b_user ON dbo.bc_khht.b_sales_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.bc_khht.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bc_khht.b_customer_id = dbo.b_othercompany.b_id';
IF OBJECT_ID(N'dbo.v_bc_pricelist', N'V') IS NOT NULL
DROP VIEW dbo.[v_bc_pricelist];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bc_pricelist] AS SELECT dbo.bc_priceList.b_id, dbo.bc_priceList.b_dw_id, dbo.bc_priceList.b_type, dbo.bc_priceList.b_canuse, dbo.bc_priceList.b_begindate, dbo.bc_priceList.b_enddate, dbo.bc_priceList.b_loadport,
dbo.bc_priceList.b_aimport, dbo.bc_priceList.b_cate_id, dbo.b_othercompany.b_name AS v_dw_name, dbo.bc_priceList.b_name, dbo.bc_priceList.b_owner_id, dbo.bc_priceList.b_state,
dbo.bc_priceList.b_inputuser_id, dbo.bc_priceList.b_inputdatetime, dbo.bc_priceList.b_updatedatetime, dbo.bc_priceList.b_updateuser_id
FROM dbo.bc_priceList LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bc_priceList.b_dw_id = dbo.b_othercompany.b_id';
IF OBJECT_ID(N'dbo.v_bc_pricelist_sub', N'V') IS NOT NULL
DROP VIEW dbo.[v_bc_pricelist_sub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bc_pricelist_sub] AS SELECT dbo.bc_pricelist_sub.subid, dbo.bc_pricelist_sub.father, dbo.bc_pricelist_sub.mx_xh, dbo.bc_pricelist_sub.mx_dw_id, dbo.bc_pricelist_sub.mx_type_id, dbo.bc_pricelist_sub.mx_feetype_id,
dbo.bc_pricelist_sub.mx_moneytype_id, dbo.bc_pricelist_sub.mx_exrate, dbo.bc_pricelist_sub.mx_price, dbo.bc_pricelist_sub.mx_qty, dbo.bc_pricelist_sub.mx_amount_root,
dbo.bc_pricelist_sub.mx_amount, dbo.bc_pricelist_sub.mx_tax, dbo.bc_pricelist_sub.mx_level, dbo.bc_pricelist_sub.mx_hstype_id, dbo.bc_pricelist_sub.mx_varchar_1,
dbo.bc_pricelist_sub.mx_varchar_2, dbo.bc_pricelist_sub.mx_varchar_3, dbo.bc_pricelist_sub.mx_varchar_4, dbo.bc_pricelist_sub.mx_inputdatetime, dbo.bc_pricelist_sub.mx_inputuser_id,
dbo.bc_pricelist_sub.mx_updateuser_id, dbo.bc_pricelist_sub.mx_updatedatetime, dbo.b_othercompany.b_name AS v_mx_dw_name, dbo.b_feetype.b_name AS v_mx_feetype_name,
dbo.bc_pricelist_sub.mx_dw_field, dbo.b_sys_pricelisttype.b_name AS v_dw_field, dbo.b_sys_pricelisttype.b_dw_id AS v_dw_id, dbo.b_sys_pricelisttype.b_dw_name AS v_dw_name
FROM dbo.bc_pricelist_sub LEFT OUTER JOIN
dbo.b_feetype ON dbo.bc_pricelist_sub.mx_feetype_id = dbo.b_feetype.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bc_pricelist_sub.mx_dw_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_sys_pricelisttype ON dbo.bc_pricelist_sub.mx_dw_field = dbo.b_sys_pricelisttype.b_id';
IF OBJECT_ID(N'dbo.v_bs_business', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business] AS SELECT dbo.bs_business.b_id, dbo.bs_business.b_ywno, dbo.bs_business.b_ywtype, dbo.bs_business.b_cargo_source, dbo.bs_business.b_orderdate, dbo.bs_business.b_transterm,
dbo.bs_business.b_customer_id, dbo.bs_business.b_mycompany_id, dbo.bs_business.b_loadport, dbo.bs_business.b_disport, dbo.bs_business.b_aimport, dbo.bs_business.b_transport,
dbo.bs_business.b_freightpayment, dbo.bs_business.b_state, dbo.bs_business.b_ysfs, dbo.bs_business.b_ctns, dbo.bs_business.b_ctns_unit, dbo.bs_business.b_namegoods,
dbo.bs_business.b_vol, dbo.bs_business.b_gw, dbo.bs_business.b_voy, dbo.bs_business.b_vessel, dbo.bs_business.b_etd, dbo.bs_business.b_eta, dbo.bs_business.b_shipingdate,
dbo.bs_business.b_arrivedate, dbo.bs_business.b_progress, dbo.bs_business.b_desc_con, dbo.bs_business.b_desc_noandseal, dbo.bs_business.b_sales_id, dbo.bs_business.b_sw_id,
dbo.bs_business.b_operater_id, dbo.bs_business.b_owner_id, dbo.bs_business.b_shipcompany_id, dbo.bs_business.b_warehouse_id, dbo.bs_business.b_dcdw_id,
dbo.bs_business.b_bgcompany_id, dbo.bs_business.b_truck_id, dbo.bs_business.b_dcdwlinkman, dbo.bs_business.b_dcno, dbo.bs_business.b_dcdate, dbo.bs_business.b_pcyqmemo,
dbo.bs_business.b_enterstoreno, dbo.bs_business.b_showcolor, dbo.bs_business.b_blno, dbo.bs_business.b_bl_copy, dbo.bs_business.b_bl_state, dbo.bs_business.b_bl_date,
dbo.bs_business.b_bl_qsdate, dbo.bs_business.b_bl_jcdate, dbo.bs_business.b_bgdate, dbo.bs_business.b_bgno, dbo.bs_business.b_bz1, dbo.bs_business.b_bz2, dbo.bs_business.b_bz3,
dbo.bs_business.b_bz4, dbo.bs_business.b_shippermemo, dbo.bs_business.b_consigneememo, dbo.bs_business.b_notifymemo, dbo.bs_business.b_shipmark,
dbo.bs_business.b_agentcompanyMemo, dbo.bs_business.b_con20, dbo.bs_business.b_inputuser_id, dbo.bs_business.b_inputdatetime, dbo.bs_business.b_updateuser_id,
dbo.bs_business.b_updatedatetime, dbo.bs_business.b_yslocked, dbo.bs_business.b_yslocked_date, dbo.bs_business.b_yslocked_userid, dbo.bs_business.b_yflocked,
dbo.bs_business.b_yflocked_date, dbo.bs_business.b_yflocked_userid, dbo.bs_business.b_cwlocked, dbo.bs_business.b_cwlocked_date, dbo.bs_business.b_cwlocked_userid,
b_othercompany_1.b_name AS v_my_company, b_othercompany_3.b_name AS v_customer_company, b_othercompany_2.b_name AS v_ship_company,
b_othercompany_4.b_name AS v_bg_company, b_othercompany_5.b_name AS v_dc_company, b_othercompany_6.b_name AS v_warehouse_company,
dbo.b_othercompany.b_name AS v_truck_company, b_user_2.b_name AS v_sw_name, b_user_1.b_name AS v_operater_name, dbo.b_user.b_name AS v_sales_name, dbo.bs_business.b_bgstate,
dbo.bs_business.b_drno, dbo.bs_business.b_loaddate, dbo.bs_business.b_fcdate, dbo.bs_business.b_jgbegindate, dbo.bs_business.b_jgenddate, dbo.bs_business.b_bgtype,
dbo.bs_business.b_cystate, dbo.bs_business.b_jgdate, dbo.bs_business.b_jddate, dbo.bs_business.b_oceanline, dbo.bs_business.b_doc_id, b_user_3.b_name AS v_doc_name,
dbo.bs_business.b_con40, dbo.bs_business.b_con40h, dbo.bs_business.b_con45, dbo.bs_business.b_ac_ctns, dbo.bs_business.b_ac_vol, dbo.bs_business.b_ac_gw
FROM dbo.bs_business LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.bs_business.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_2 ON dbo.bs_business.b_sw_id = b_user_2.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_3 ON dbo.bs_business.b_doc_id = b_user_3.b_id LEFT OUTER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bs_business.b_truck_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_6 ON dbo.bs_business.b_warehouse_id = b_othercompany_6.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_5 ON dbo.bs_business.b_dcdw_id = b_othercompany_5.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_4 ON dbo.bs_business.b_bgcompany_id = b_othercompany_4.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_2 ON dbo.bs_business.b_shipcompany_id = b_othercompany_2.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_3 ON dbo.bs_business.b_customer_id = b_othercompany_3.b_id';
IF OBJECT_ID(N'dbo.v_bs_business_container', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_container];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_container] AS SELECT dbo.bs_business_container.subid, dbo.bs_business_container.father, dbo.bs_business_container.mx_xh, dbo.bs_business_container.mx_con_no, dbo.bs_business_container.mx_hstype_id,
dbo.bs_business_container.mx_sealno, dbo.bs_business_container.mx_con_size, dbo.bs_business_container.mx_con_gw, dbo.bs_business_container.mx_con_nw,
dbo.bs_business_container.mx_con_cartons, dbo.bs_business_container.mx_con_vol, dbo.bs_business_container.mx_truck_id, dbo.bs_business_container.mx_truckno,
dbo.bs_business_container.mx_drive, dbo.bs_business_container.mx_drivephone, dbo.bs_business_container.mx_txplace, dbo.bs_business_container.mx_txmemo,
dbo.bs_business_container.mx_txdate, dbo.bs_business_container.mx_zxdate, dbo.bs_business_container.mx_zxplace, dbo.bs_business_container.mx_zxmemo,
dbo.bs_business_container.mx_date1, dbo.bs_business_container.mx_date2, dbo.bs_business_container.mx_date3, dbo.bs_business_container.mx_date4, dbo.bs_business_container.mx_date5,
dbo.bs_business_container.mx_date6, dbo.bs_business_container.mx_bz1, dbo.bs_business_container.mx_bz2, dbo.bs_business_container.mx_bz3, dbo.bs_business_container.mx_bz4,
dbo.bs_business_container.mx_bz5, dbo.bs_business_container.mx_bz6, dbo.bs_business_container.mx_bz7, dbo.bs_business_container.mx_bz8, dbo.bs_business_container.mx_vgm,
dbo.bs_business_container.mx_updateuser_id, dbo.bs_business_container.mx_updatedatetime, dbo.bs_business_container.mx_inputdatetime, dbo.bs_business_container.mx_inputuser_id,
dbo.bs_business_container.mx_con_type, dbo.bs_business_container.mx_vgm_cztype, dbo.bs_business_container.mx_vgm_czdate, dbo.bs_business_container.mx_truck_name,
dbo.bs_business_container.mx_memo8, dbo.bs_business.b_ywno, dbo.bs_business.b_drno, dbo.bs_business.b_shipingdate, dbo.bs_business.b_customer_id,
dbo.b_othercompany.b_name AS v_customer_company, dbo.bs_business.b_namegoods, dbo.bs_business.b_vessel, dbo.bs_business.b_voy, dbo.bs_business.b_blno,
dbo.bs_business.b_sales_id, dbo.b_user.b_name AS v_sales_name
FROM dbo.bs_business_container LEFT OUTER JOIN
dbo.bs_business ON dbo.bs_business_container.father = dbo.bs_business.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bs_business.b_customer_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id';
IF OBJECT_ID(N'dbo.v_bs_business_container_notpx', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_container_notpx];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_container_notpx] AS SELECT dbo.bs_business_container.father, dbo.bs_business_container.mx_con_no, dbo.bs_business_container.mx_sealno, dbo.bs_business_container.mx_con_gw,
dbo.bs_business_container.mx_con_cartons, dbo.bs_business_container.mx_con_vol, a.mx_con_gw AS v_px_gw, a.mx_con_cartons AS v_px_cartons, a.mx_con_vol AS v_px_vol,
ISNULL(dbo.bs_business_container.mx_con_gw, 0) - ISNULL(a.mx_con_gw, 0) AS v_notpx_gw, ISNULL(dbo.bs_business_container.mx_con_cartons, 0) - ISNULL(a.mx_con_cartons, 0)
AS v_notpx_cartons, ISNULL(dbo.bs_business_container.mx_con_vol, 0) - ISNULL(a.mx_con_vol, 0) AS v_notpx_vol, dbo.bs_business_container.subid, dbo.bs_business.b_namegoods,
dbo.bs_business_container.mx_con_type
FROM dbo.bs_business_container LEFT OUTER JOIN
dbo.bs_business ON dbo.bs_business_container.father = dbo.bs_business.b_id LEFT OUTER JOIN
(SELECT father, mx_con_no, SUM(mx_con_gw) AS mx_con_gw, SUM(mx_con_cartons) AS mx_con_cartons, SUM(mx_con_vol) AS mx_con_vol
FROM dbo.bs_business_hdbl_sub
GROUP BY father, mx_con_no) AS a ON dbo.bs_business_container.mx_con_no = a.mx_con_no AND dbo.bs_business_container.father = a.father';
IF OBJECT_ID(N'dbo.v_bs_business_cw', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_cw];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_cw] AS SELECT subid, subxh, father, mx_bid, mx_level, mx_xh, mx_dw_id, mx_dw_name, mx_direction, mx_feetype_id, mx_feetype_name, mx_moneytype_id, mx_hstype_id, mx_price, mx_qty, mx_amount,
mx_amount_rmb, mx_exrate, mx_log_flag, mx_tax, mx_invoicenotax, mx_invoicetax, mx_sh_check, mx_sh_datetime, mx_shman_id, mx_cwgz_check, mx_cwgz_datetime, mx_cwgzman_id,
mx_bill_id, mx_bill_ywno, mx_bill_updatedatetime, mx_bill_updateuser_id, mx_bill_state, mx_bill_totalamount, mx_bill_totalamount_not, mx_invoice_id, mx_invoice_ywno,
mx_invoice_updatedatetime, mx_invoice_updateuser_id, mx_invoice_state, mx_invoice_totalamount, mx_invoice_totalamount_not, mx_sfd_id, mx_sfd_ywno, mx_sfd_updatedatetime,
mx_sfd_updateuser_id, mx_sfd_state, mx_sfd_totalamount, mx_sfd_totalamount_not, mx_mycompany_id, mx_inputuser_id, mx_inputdatetime, mx_updateuser_id, mx_updatedatetime,
mx_memo1, mx_memo2, mx_memo3, mx_memo4, mx_memo5, mx_varchar_1, mx_varchar_2, mx_varchar_3, mx_varchar_4, mx_varchar_5, mx_con_no, mx_qty_type
FROM dbo.bs_business_cw';
IF OBJECT_ID(N'dbo.v_bs_business_cw_yf', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_cw_yf];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_cw_yf] AS SELECT subid, father, mx_xh, mx_dw_id, mx_direction, mx_feetype_id, ISNULL(mx_amount, 0) AS mx_amount, mx_price, mx_qty, mx_level, mx_moneytype_id, mx_hstype_id, mx_varchar_5, mx_exrate,
mx_tax, mx_inputdatetime, mx_inputuser_id, ISNULL(mx_amount_rmb, 0) AS mx_amount_rmb, mx_log_flag, mx_sh_check, mx_sh_datetime, mx_cwgz_check, mx_cwgz_datetime, mx_bill_id,
mx_bill_ywno, mx_bill_updatedatetime, mx_bill_updateuser_id, mx_bill_state, mx_bill_totalamount, mx_bill_totalamount_not, mx_invoice_id, mx_invoice_ywno, mx_invoice_updatedatetime,
mx_invoice_updateuser_id, mx_invoice_state, mx_invoice_totalamount, mx_invoice_totalamount_not, mx_sfd_id, mx_sfd_ywno, mx_sfd_updatedatetime, mx_sfd_updateuser_id, mx_sfd_state,
ISNULL(mx_sfd_totalamount, 0) AS mx_sfd_totalamount, mx_mycompany_id, ISNULL(mx_sfd_totalamount_not, 0) AS mx_sfd_totalamount_not, mx_updateuser_id, mx_updatedatetime,
mx_cwgzman_id, subxh, mx_shman_id, mx_con_no, mx_qty_type, mx_bid, mx_dw_name, mx_feetype_name, mx_invoicenotax, mx_invoicetax, mx_memo1
FROM dbo.bs_business_cw
WHERE (mx_direction = ''应付'')';
IF OBJECT_ID(N'dbo.v_bs_business_cw_ys', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_cw_ys];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_cw_ys] AS SELECT subid, father, mx_xh, mx_dw_id, mx_direction, mx_feetype_id, ISNULL(mx_amount, 0) AS mx_amount, mx_price, mx_qty, mx_level, mx_moneytype_id, mx_hstype_id, mx_exrate, mx_tax,
mx_inputdatetime, mx_inputuser_id, ISNULL(mx_amount_rmb, 0) AS mx_amount_rmb, mx_log_flag, mx_sh_check, mx_sh_datetime, mx_cwgz_check, mx_cwgz_datetime, mx_bill_id,
mx_bill_updatedatetime, mx_bill_updateuser_id, mx_bill_state, mx_bill_totalamount, mx_bill_totalamount_not, mx_invoice_id, mx_invoice_ywno, mx_invoice_updatedatetime,
mx_invoice_updateuser_id, mx_invoice_state, mx_invoice_totalamount, mx_invoice_totalamount_not, mx_sfd_id, mx_sfd_ywno, mx_sfd_updatedatetime, mx_sfd_updateuser_id, mx_sfd_state,
ISNULL(mx_sfd_totalamount, 0) AS mx_sfd_totalamount, mx_mycompany_id, ISNULL(mx_sfd_totalamount_not, 0) AS mx_sfd_totalamount_not, mx_updateuser_id, mx_updatedatetime,
mx_cwgzman_id, subxh, mx_shman_id, mx_con_no, mx_qty_type, mx_bid, mx_dw_name, mx_feetype_name, mx_bill_ywno, mx_invoicenotax, mx_invoicetax, mx_memo1
FROM dbo.bs_business_cw
WHERE (mx_direction = ''应收'')';
IF OBJECT_ID(N'dbo.v_bs_business_hdblno', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_hdblno];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_hdblno] AS SELECT subid, father, mx_xh, mx_blno, mx_shippermemo, mx_consigneememo, mx_notifymemo, mx_agentcompanyMemo, mx_freightpayment, mx_namegoods, mx_ctns, mx_ctns_unit_id, mx_gw,
mx_vol, mx_bz1, mx_bz2, mx_bz3, mx_bz4, mx_bz5, mx_transterm, mx_drno, mx_aimport_id, mx_shipmark, mx_loadport_id, mx_transport_id, mx_inputuser_id, mx_inputdatetime,
mx_updateuser_id, mx_updatedatetime
FROM dbo.bs_business_hdbl';
IF OBJECT_ID(N'dbo.v_bs_business_hdblno_sub', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_hdblno_sub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_hdblno_sub] AS SELECT subid, father, mx_xh, mx_con_no, mx_blno, mx_con_cartons, mx_con_gw, mx_con_nw, mx_con_vol, mx_bz1, mx_bz2, mx_bz3, mx_bz4, mx_bz5, mx_linkfd_id, mx_inputuser_id,
mx_inputdatetime, mx_updateuser_id, mx_updatedatetime
FROM dbo.bs_business_hdbl_sub';
IF OBJECT_ID(N'dbo.v_bs_business_transport', N'V') IS NOT NULL
DROP VIEW dbo.[v_bs_business_transport];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_bs_business_transport] AS SELECT dbo.bs_business_transport.subid, dbo.bs_business_transport.father, dbo.bs_business_transport.mx_xh, dbo.bs_business_transport.mx_processtype, dbo.bs_business_transport.mx_transtype,
dbo.bs_business_transport.mx_loadport, dbo.bs_business_transport.mx_aimport, dbo.bs_business_transport.mx_ETD, dbo.bs_business_transport.mx_ETA,
dbo.bs_business_transport.mx_truck_id, dbo.bs_business_transport.mx_truckno, dbo.bs_business_transport.mx_pno, dbo.bs_business_transport.mx_bz, dbo.bs_business_transport.mx_finish,
dbo.bs_business_transport.mx_finishdate, dbo.b_othercompany.b_name AS v_truck_name, dbo.bs_business_transport.mx_keyid, dbo.bs_business_transport.mx_user_id,
dbo.b_user.b_name AS v_user_name, dbo.bs_business_transport.mx_startdate, dbo.bs_business_transport.mx_source_type, dbo.bs_business_transport.mx_bz1,
dbo.bs_business_transport.mx_bz2, dbo.bs_business_transport.mx_bz3, dbo.bs_business_transport.mx_attach_bz1, dbo.bs_business_transport.mx_attach_bz2,
dbo.bs_business_transport.mx_attach_bz3, dbo.bs_business_transport.mx_packdate, dbo.bs_business_transport.mx_packplace, dbo.bs_business_transport.mx_txdate,
dbo.bs_business_transport.mx_txplace, dbo.bs_business_transport.mx_hxdate, dbo.bs_business_transport.mx_hxplace, dbo.bs_business_transport.mx_conno, '''' AS mx_attach
FROM dbo.bs_business_transport LEFT OUTER JOIN
dbo.b_user ON dbo.bs_business_transport.mx_user_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bs_business_transport.mx_truck_id = dbo.b_othercompany.b_id
WHERE (dbo.bs_business_transport.mx_source_type = ''bs_business'')';
IF OBJECT_ID(N'dbo.v_cw_account', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_account];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_account] AS SELECT dbo.cw_account.b_id, dbo.cw_account.b_name, dbo.cw_account.b_type, dbo.cw_account.b_bank, dbo.cw_account.b_account, dbo.cw_account.b_amount_start, dbo.cw_account.b_bz,
dbo.cw_account.b_date, ISNULL(dbo.cw_account.b_amount_start, 0) + ISNULL(a.sk, 0) - ISNULL(a.fk, 0) AS v_yuamount, ISNULL(dbo.cw_account.b_amount_start, 0) + ISNULL(a.sk, 0) - ISNULL(a.fk,
0) AS b_amount, CASE WHEN ISNULL(cw_account.b_bank, '''') = '''' THEN '''' ELSE ''银行名称:'' + ISNULL(cw_account.b_bank, '''') + '' '' END + CASE WHEN ISNULL(cw_account.b_account, '''')
= '''' THEN '''' ELSE ''银行账号:'' + ISNULL(cw_account.b_account, '''') END AS v_bankaccount, dbo.b_user.b_name AS v_ownername, dbo.cw_account.b_inputdatetime, dbo.cw_account.b_state,
dbo.cw_account.b_owner_id, dbo.cw_account.b_mycompany_id, dbo.b_othercompany.b_name AS v_company_name, dbo.cw_account.b_truckno, dbo.cw_account.b_inputuser_id,
dbo.cw_account.b_updatedatetime, dbo.cw_account.b_updateuser_id
FROM dbo.cw_account LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_account.b_mycompany_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_user ON dbo.cw_account.b_owner_id = dbo.b_user.b_id LEFT OUTER JOIN
(SELECT b_account_id, SUM(b_sk) AS sk, SUM(b_fk) AS fk
FROM (SELECT b_id, b_account_id, CASE b_type WHEN ''收入'' THEN b_amount ELSE 0 END AS b_sk, CASE b_type WHEN ''支出'' THEN b_amount ELSE 0 END AS b_fk
FROM dbo.cw_daily
UNION
SELECT b_id, b_account_id, CASE WHEN b_direction = ''实收'' THEN b_amount ELSE 0 END AS b_sk, CASE WHEN b_direction = ''实付'' THEN b_amount ELSE 0 END AS b_fk
FROM dbo.cw_sfd) AS a_1
GROUP BY b_account_id) AS a ON a.b_account_id = dbo.cw_account.b_id';
IF OBJECT_ID(N'dbo.v_cw_daily', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_daily];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_daily] AS SELECT dbo.cw_daily.b_date, dbo.cw_daily.b_desc, dbo.cw_daily.b_feetype, dbo.cw_daily.b_bill, dbo.cw_daily.b_owner_id, dbo.cw_daily.b_state, dbo.cw_daily.b_id, dbo.cw_daily.b_amount,
dbo.cw_daily.b_bz1, dbo.cw_daily.b_type, dbo.cw_daily.b_payee_id, b_user_1.b_name AS v_ownername, dbo.cw_daily.b_account_id, dbo.cw_daily.b_inputdatetime,
dbo.cw_account.b_name AS v_account_name, dbo.cw_daily.b_zx, dbo.cw_daily.b_zxuser_id, dbo.cw_daily.b_zxdatetime, dbo.cw_daily.b_dw_id, dbo.b_othercompany.b_name AS v_dw_name,
dbo.cw_account.b_bank AS v_accountbank, dbo.cw_account.b_account AS v_b_account, dbo.cw_daily.b_updatedatetime, dbo.cw_daily.b_updateuser_id, dbo.cw_daily.b_inputuser_id
FROM dbo.cw_daily LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_daily.b_dw_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.cw_account ON dbo.cw_daily.b_account_id = dbo.cw_account.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.cw_daily.b_owner_id = b_user_1.b_id';
IF OBJECT_ID(N'dbo.v_cw_fee_f', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_fee_f];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_fee_f] AS SELECT dbo.bs_business.b_ywno, dbo.bs_business_cw.subid, dbo.bs_business_cw.subxh, dbo.bs_business_cw.father, dbo.bs_business_cw.mx_xh, dbo.bs_business_cw.mx_dw_id,
dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_direction, dbo.bs_business_cw.mx_feetype_id, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business_cw.mx_moneytype_id,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime,
dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno, dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_invoice_updatedatetime,
dbo.bs_business_cw.mx_invoice_updateuser_id, dbo.bs_business_cw.mx_sfd_id, dbo.bs_business_cw.mx_sfd_ywno, dbo.bs_business_cw.mx_sfd_updatedatetime,
dbo.bs_business_cw.mx_sfd_updateuser_id, ISNULL(dbo.bs_business_cw.mx_sfd_totalamount, 0) AS mx_sfd_totalamount, ISNULL(dbo.bs_business_cw.mx_sfd_totalamount_not, 0)
AS mx_sfd_totalamount_not, dbo.bs_business_cw.mx_mycompany_id, dbo.bs_business.b_vessel, dbo.bs_business.b_voy, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate,
dbo.bs_business_cw.mx_exrate, dbo.bs_business.b_drno, dbo.bs_business.b_blno, dbo.b_othercompany.b_name AS v_customer_company, dbo.bs_business.b_desc_noandseal,
dbo.bs_business.b_orderdate, dbo.bs_business_cw.mx_bill_updatedatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_sw_id, dbo.bs_business.b_operater_id,
dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.bs_business_cw.mx_amount_rmb,
dbo.bs_business_cw.mx_bill_id, dbo.bs_business_cw.mx_invoice_id, dbo.bs_business_cw.mx_sfd_state, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime,
dbo.bs_business_cw.mx_memo1
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bs_business.b_customer_id = dbo.b_othercompany.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father';
IF OBJECT_ID(N'dbo.v_cw_fee_s', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_fee_s];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_fee_s] AS SELECT dbo.bs_business.b_ywno, dbo.bs_business_cw.subid, dbo.bs_business_cw.subxh, dbo.bs_business_cw.father, dbo.bs_business_cw.mx_xh, dbo.bs_business_cw.mx_dw_id,
dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_direction, dbo.bs_business_cw.mx_feetype_id, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business_cw.mx_moneytype_id,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime,
dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno, dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_invoice_updatedatetime,
dbo.bs_business_cw.mx_invoice_updateuser_id, dbo.bs_business_cw.mx_sfd_id, dbo.bs_business_cw.mx_sfd_ywno, dbo.bs_business_cw.mx_sfd_updatedatetime,
dbo.bs_business_cw.mx_sfd_updateuser_id, ISNULL(dbo.bs_business_cw.mx_sfd_totalamount, 0) AS mx_sfd_totalamount, ISNULL(dbo.bs_business_cw.mx_sfd_totalamount_not, 0)
AS mx_sfd_totalamount_not, dbo.bs_business_cw.mx_mycompany_id, dbo.bs_business.b_vessel, dbo.bs_business.b_voy, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate,
dbo.bs_business_cw.mx_exrate, dbo.bs_business.b_drno, dbo.bs_business.b_blno, dbo.b_othercompany.b_name AS v_customer_company, dbo.bs_business.b_desc_noandseal,
dbo.bs_business.b_orderdate, dbo.bs_business_cw.mx_bill_updatedatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_sw_id, dbo.bs_business.b_operater_id,
dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.bs_business_cw.mx_amount_rmb,
dbo.bs_business_cw.mx_bill_id, dbo.bs_business_cw.mx_invoice_id, dbo.bs_business_cw.mx_sfd_state, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime,
dbo.bs_business_cw.mx_memo1
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.bs_business.b_customer_id = dbo.b_othercompany.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father';
IF OBJECT_ID(N'dbo.v_cw_fkd', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_fkd];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_fkd] AS SELECT dbo.cw_sfd.b_id, dbo.cw_sfd.b_date, dbo.cw_sfd.b_money_id, dbo.cw_sfd.b_exrate, dbo.b_othercompany.b_name AS v_dw_name, dbo.cw_sfd.b_state, dbo.cw_sfd.b_owner_id, dbo.cw_sfd.b_bz,
dbo.cw_sfd.b_inputuser_id, dbo.cw_sfd.b_bankname, dbo.cw_sfd.b_bankaccount, dbo.cw_sfd.b_mycompany_id, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_sfd.b_amount_other,
dbo.cw_sfd.b_inputdatetime, dbo.cw_sfd.b_amount, dbo.cw_sfd.b_amount_hx, dbo.cw_sfd.b_amount_nothx, dbo.cw_sfd.b_sh, dbo.cw_sfd.b_updateuser_id, dbo.cw_sfd.b_updatedatetime,
dbo.cw_sfd.b_amount_sj, dbo.cw_sfd.b_dw_id, dbo.cw_sfd.b_direction, dbo.cw_sfd.b_writeoff, dbo.cw_sfd.b_writeoff_id, dbo.cw_sfd.b_writeoffdatetime, dbo.cw_sfd.b_shdatetime, dbo.cw_sfd.b_sh_id, dbo.cw_sfd.b_ywno, dbo.cw_sfd.b_document_type, dbo.b_user.b_name AS v_ownername,
dbo.cw_sfd.b_account_id
FROM dbo.cw_sfd INNER JOIN
dbo.b_user ON dbo.cw_sfd.b_owner_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_sfd.b_dw_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_sfd.b_mycompany_id = b_othercompany_1.b_id
WHERE (dbo.cw_sfd.b_direction = ''实付'')';
IF OBJECT_ID(N'dbo.v_cw_fkdsub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_fkdsub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_fkdsub] AS SELECT dbo.cw_sfdsub.subid, dbo.cw_sfdsub.father, dbo.cw_sfdsub.mx_xh, dbo.cw_sfdsub.mx_fee_id, dbo.cw_sfdsub.mx_fee_money_id, dbo.cw_sfdsub.mx_fee_amount, dbo.cw_sfdsub.mx_sf_money_id,
dbo.cw_sfdsub.mx_sf_amount, dbo.cw_sfdsub.mx_exrate, dbo.cw_sfdsub.mx_bz, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_direction, dbo.bs_business_cw.mx_feetype_name,
dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business.b_blno, dbo.bs_business.b_loaddate, dbo.bs_business.b_shipingdate, dbo.bs_business.b_id,
dbo.bs_business_cw.mx_invoice_updatedatetime, dbo.bs_business.b_ywno, dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_bill_ywno
FROM dbo.cw_sfdsub LEFT OUTER JOIN
dbo.bs_business_cw ON dbo.cw_sfdsub.mx_fee_id = dbo.bs_business_cw.subid LEFT OUTER JOIN
dbo.bs_business ON dbo.bs_business_cw.father = dbo.bs_business.b_id';
IF OBJECT_ID(N'dbo.v_cw_skd', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_skd];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_skd] AS SELECT dbo.cw_sfd.b_id, dbo.cw_sfd.b_date, dbo.cw_sfd.b_money_id, dbo.cw_sfd.b_exrate, dbo.b_othercompany.b_name AS v_dw_name, dbo.cw_sfd.b_state, dbo.cw_sfd.b_owner_id, dbo.cw_sfd.b_bz,
dbo.cw_sfd.b_inputuser_id, dbo.cw_sfd.b_bankname, dbo.cw_sfd.b_bankaccount, dbo.cw_sfd.b_mycompany_id, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_sfd.b_amount_other,
dbo.cw_sfd.b_inputdatetime, dbo.cw_sfd.b_amount, dbo.cw_sfd.b_amount_hx, dbo.cw_sfd.b_amount_nothx, dbo.cw_sfd.b_sh, dbo.cw_sfd.b_updateuser_id, dbo.cw_sfd.b_updatedatetime,
dbo.cw_sfd.b_amount_sj, dbo.cw_sfd.b_dw_id, dbo.cw_sfd.b_direction, dbo.cw_sfd.b_writeoff, dbo.cw_sfd.b_writeoff_id, dbo.cw_sfd.b_writeoffdatetime, dbo.cw_sfd.b_shdatetime, dbo.cw_sfd.b_sh_id, dbo.cw_sfd.b_ywno, dbo.cw_sfd.b_document_type, dbo.b_user.b_name AS v_ownername,
dbo.cw_sfd.b_account_id
FROM dbo.cw_sfd INNER JOIN
dbo.b_user ON dbo.cw_sfd.b_owner_id = dbo.b_user.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_sfd.b_dw_id = dbo.b_othercompany.b_id LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_sfd.b_mycompany_id = b_othercompany_1.b_id
WHERE (dbo.cw_sfd.b_direction = ''实收'')';
IF OBJECT_ID(N'dbo.v_cw_skdsub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_skdsub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_skdsub] AS SELECT dbo.cw_sfdsub.subid, dbo.cw_sfdsub.father, dbo.cw_sfdsub.mx_xh, dbo.cw_sfdsub.mx_fee_id, dbo.cw_sfdsub.mx_fee_money_id, dbo.cw_sfdsub.mx_fee_amount, dbo.cw_sfdsub.mx_sf_money_id,
dbo.cw_sfdsub.mx_sf_amount, dbo.cw_sfdsub.mx_exrate, dbo.cw_sfdsub.mx_bz, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_direction, dbo.bs_business_cw.mx_feetype_name,
dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business.b_blno, dbo.bs_business.b_loaddate, dbo.bs_business.b_shipingdate, dbo.bs_business.b_id,
dbo.bs_business_cw.mx_invoice_updatedatetime, dbo.bs_business.b_ywno, dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_bill_ywno
FROM dbo.cw_sfdsub LEFT OUTER JOIN
dbo.bs_business_cw ON dbo.cw_sfdsub.mx_fee_id = dbo.bs_business_cw.subid LEFT OUTER JOIN
dbo.bs_business ON dbo.bs_business_cw.father = dbo.bs_business.b_id';
IF OBJECT_ID(N'dbo.v_cw_yfbill', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_yfbill];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_yfbill] AS SELECT dbo.cw_bill.b_id, dbo.cw_bill.b_ywno, dbo.cw_bill.b_direction, dbo.cw_bill.b_dw_id, dbo.cw_bill.b_mycompany_id, dbo.cw_bill.b_amount, dbo.cw_bill.b_money_id, dbo.cw_bill.b_account_id,
dbo.cw_bill.b_bankname, dbo.cw_bill.b_bankaccount, dbo.cw_bill.b_zl, dbo.cw_bill.b_plandate, dbo.cw_bill.b_state, dbo.cw_bill.b_bz, dbo.cw_bill.b_owner_id, dbo.cw_bill.b_inputuser_id,
dbo.cw_bill.b_inputdatetime, dbo.cw_bill.b_updateuser_id, dbo.cw_bill.b_updatedatetime, dbo.cw_bill.b_writeoff, dbo.cw_bill.b_writeoff_id, dbo.cw_bill.b_writeoffdatetime, dbo.b_othercompany.b_name AS v_dw_name, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_bill.b_date, dbo.cw_bill.b_document_type, dbo.cw_bill.b_dw_bankacount,
dbo.cw_bill.b_dw_invaccount, dbo.cw_bill.b_my_bankacount, dbo.cw_bill.b_my_invaccount
FROM dbo.cw_bill LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_bill.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_bill.b_dw_id = dbo.b_othercompany.b_id
WHERE (dbo.cw_bill.b_direction = ''应付'')';
IF OBJECT_ID(N'dbo.v_cw_yfbillsub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_yfbillsub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_yfbillsub] AS SELECT dbo.cw_billsub.subid, dbo.cw_billsub.father, dbo.cw_billsub.mx_xh, dbo.cw_billsub.mx_fee_id, dbo.cw_billsub.mx_bz, dbo.cw_billsub.mx_fee_money_id, dbo.cw_billsub.mx_fee_amount,
dbo.cw_billsub.mx_bill_amount, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business.b_ywno, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate, dbo.bs_business.b_drno,
dbo.bs_business.b_blno, dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_moneytype_id, dbo.bs_business_cw.mx_exrate,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_amount_rmb, dbo.bs_business_cw.mx_sfd_totalamount,
dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime, dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno,
dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_operater_id,
dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.bs_business_cw.mx_direction
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id RIGHT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father RIGHT OUTER JOIN
dbo.cw_billsub ON dbo.bs_business_cw.subid = dbo.cw_billsub.mx_fee_id';
IF OBJECT_ID(N'dbo.v_cw_yfinvoice', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_yfinvoice];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_yfinvoice] AS SELECT dbo.cw_invoice.b_id, dbo.cw_invoice.b_direction, dbo.cw_invoice.b_dw_id, dbo.cw_invoice.b_mycompany_id, dbo.cw_invoice.b_amount, dbo.cw_invoice.b_money_id,
dbo.cw_invoice.b_account_id, dbo.cw_invoice.b_bankname, dbo.b_othercompany.b_name AS v_dw_name, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_invoice.b_bankaccount,
dbo.cw_invoice.b_owner_id, dbo.cw_invoice.b_state, dbo.cw_invoice.b_tax, dbo.cw_invoice.b_bz, dbo.cw_invoice.b_inputuser_id, dbo.cw_invoice.b_inputdatetime, dbo.cw_invoice.b_ywno,
dbo.cw_invoice.b_updateuser_id, dbo.cw_invoice.b_updatedatetime, dbo.cw_invoice.b_writeoff, dbo.cw_invoice.b_writeoff_id, dbo.cw_invoice.b_writeoffdatetime, dbo.cw_invoice.b_document_type, dbo.cw_invoice.b_date, dbo.cw_invoice.b_dw_bankacount, dbo.cw_invoice.b_dw_invaccount, dbo.cw_invoice.b_my_bankacount,
dbo.cw_invoice.b_my_invaccount, dbo.cw_invoice.b_bz1
FROM dbo.cw_invoice LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_invoice.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_invoice.b_dw_id = dbo.b_othercompany.b_id
WHERE (dbo.cw_invoice.b_direction = ''应付'')';
IF OBJECT_ID(N'dbo.v_cw_yfinvoicesub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_yfinvoicesub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_yfinvoicesub] AS SELECT dbo.cw_invoicesub.subid, dbo.cw_invoicesub.father, dbo.cw_invoicesub.mx_xh, dbo.cw_invoicesub.mx_fee_id, dbo.cw_invoicesub.mx_bz, dbo.cw_invoicesub.mx_fee_money_id,
dbo.cw_invoicesub.mx_fee_amount, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business.b_ywno, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate, dbo.bs_business.b_drno,
dbo.bs_business.b_blno, dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_moneytype_id, dbo.bs_business_cw.mx_exrate,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_amount_rmb, dbo.bs_business_cw.mx_sfd_totalamount,
dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime, dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno,
dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_operater_id,
dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.cw_invoicesub.mx_invoice_amount
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id RIGHT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father RIGHT OUTER JOIN
dbo.cw_invoicesub ON dbo.bs_business_cw.subid = dbo.cw_invoicesub.mx_fee_id';
IF OBJECT_ID(N'dbo.v_cw_ysbill', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_ysbill];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_ysbill] AS SELECT dbo.cw_bill.b_id, dbo.cw_bill.b_ywno, dbo.cw_bill.b_direction, dbo.cw_bill.b_dw_id, dbo.cw_bill.b_mycompany_id, dbo.cw_bill.b_amount, dbo.cw_bill.b_money_id, dbo.cw_bill.b_account_id,
dbo.cw_bill.b_bankname, dbo.cw_bill.b_bankaccount, dbo.cw_bill.b_zl, dbo.cw_bill.b_plandate, dbo.cw_bill.b_state, dbo.cw_bill.b_bz, dbo.cw_bill.b_owner_id, dbo.cw_bill.b_inputuser_id,
dbo.cw_bill.b_inputdatetime, dbo.cw_bill.b_updateuser_id, dbo.cw_bill.b_updatedatetime, dbo.cw_bill.b_writeoff, dbo.cw_bill.b_writeoff_id, dbo.cw_bill.b_writeoffdatetime, dbo.b_othercompany.b_name AS v_dw_name, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_bill.b_date, dbo.cw_bill.b_document_type, dbo.cw_bill.b_dw_bankacount,
dbo.cw_bill.b_dw_invaccount, dbo.cw_bill.b_my_bankacount, dbo.cw_bill.b_my_invaccount
FROM dbo.cw_bill LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_bill.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_bill.b_dw_id = dbo.b_othercompany.b_id
WHERE (dbo.cw_bill.b_direction = ''应收'')';
IF OBJECT_ID(N'dbo.v_cw_ysbillsub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_ysbillsub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_ysbillsub] AS SELECT dbo.cw_billsub.subid, dbo.cw_billsub.father, dbo.cw_billsub.mx_xh, dbo.cw_billsub.mx_fee_id, dbo.cw_billsub.mx_bz, dbo.cw_billsub.mx_fee_money_id, dbo.cw_billsub.mx_fee_amount,
dbo.cw_billsub.mx_bill_amount, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business.b_ywno, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate, dbo.bs_business.b_drno,
dbo.bs_business.b_blno, dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_moneytype_id, dbo.bs_business_cw.mx_exrate,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_amount_rmb, dbo.bs_business_cw.mx_sfd_totalamount,
dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime, dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno,
dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_operater_id,
dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.bs_business_cw.mx_direction
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id RIGHT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father RIGHT OUTER JOIN
dbo.cw_billsub ON dbo.bs_business_cw.subid = dbo.cw_billsub.mx_fee_id';
IF OBJECT_ID(N'dbo.v_cw_ysinvoice', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_ysinvoice];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_ysinvoice] AS SELECT dbo.cw_invoice.b_id, dbo.cw_invoice.b_direction, dbo.cw_invoice.b_dw_id, dbo.cw_invoice.b_mycompany_id, dbo.cw_invoice.b_amount, dbo.cw_invoice.b_money_id,
dbo.cw_invoice.b_account_id, dbo.cw_invoice.b_bankname, dbo.b_othercompany.b_name AS v_dw_name, b_othercompany_1.b_name AS v_mycompanyname, dbo.cw_invoice.b_bankaccount,
dbo.cw_invoice.b_owner_id, dbo.cw_invoice.b_state, dbo.cw_invoice.b_tax, dbo.cw_invoice.b_bz, dbo.cw_invoice.b_inputuser_id, dbo.cw_invoice.b_inputdatetime, dbo.cw_invoice.b_ywno,
dbo.cw_invoice.b_updateuser_id, dbo.cw_invoice.b_updatedatetime, dbo.cw_invoice.b_writeoff, dbo.cw_invoice.b_writeoff_id, dbo.cw_invoice.b_writeoffdatetime, dbo.cw_invoice.b_document_type, dbo.cw_invoice.b_date, dbo.cw_invoice.b_dw_bankacount, dbo.cw_invoice.b_dw_invaccount, dbo.cw_invoice.b_my_bankacount,
dbo.cw_invoice.b_my_invaccount, dbo.cw_invoice.b_bz1
FROM dbo.cw_invoice LEFT OUTER JOIN
dbo.b_othercompany AS b_othercompany_1 ON dbo.cw_invoice.b_mycompany_id = b_othercompany_1.b_id LEFT OUTER JOIN
dbo.b_othercompany ON dbo.cw_invoice.b_dw_id = dbo.b_othercompany.b_id
WHERE (dbo.cw_invoice.b_direction = ''应收'')';
IF OBJECT_ID(N'dbo.v_cw_ysinvoicesub', N'V') IS NOT NULL
DROP VIEW dbo.[v_cw_ysinvoicesub];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_cw_ysinvoicesub] AS SELECT dbo.cw_invoicesub.subid, dbo.cw_invoicesub.father, dbo.cw_invoicesub.mx_xh, dbo.cw_invoicesub.mx_fee_id, dbo.cw_invoicesub.mx_bz, dbo.cw_invoicesub.mx_fee_money_id,
dbo.cw_invoicesub.mx_fee_amount, dbo.bs_business_cw.mx_feetype_name, dbo.bs_business.b_ywno, dbo.bs_business.b_shipingdate, dbo.bs_business.b_loaddate, dbo.bs_business.b_drno,
dbo.bs_business.b_blno, dbo.bs_business.b_loadport, dbo.bs_business.b_aimport, dbo.bs_business_cw.mx_dw_name, dbo.bs_business_cw.mx_moneytype_id, dbo.bs_business_cw.mx_exrate,
dbo.bs_business_cw.mx_price, dbo.bs_business_cw.mx_qty, dbo.bs_business_cw.mx_amount, dbo.bs_business_cw.mx_amount_rmb, dbo.bs_business_cw.mx_sfd_totalamount,
dbo.bs_business_cw.mx_sfd_totalamount_not, dbo.bs_business_cw.mx_sh_check, dbo.bs_business_cw.mx_sh_datetime, dbo.bs_business_cw.mx_shman_id, dbo.bs_business_cw.mx_bill_ywno,
dbo.bs_business_cw.mx_invoice_ywno, dbo.bs_business_cw.mx_inputuser_id, dbo.bs_business_cw.mx_inputdatetime, dbo.bs_business.b_sales_id, dbo.bs_business.b_operater_id,
dbo.b_user.b_name AS v_sales_name, b_user_1.b_name AS v_operater_name, dbo.cw_invoicesub.mx_invoice_amount
FROM dbo.bs_business INNER JOIN
dbo.b_user ON dbo.bs_business.b_sales_id = dbo.b_user.b_id RIGHT OUTER JOIN
dbo.b_user AS b_user_1 ON dbo.bs_business.b_operater_id = b_user_1.b_id RIGHT OUTER JOIN
dbo.bs_business_cw ON dbo.bs_business.b_id = dbo.bs_business_cw.father RIGHT OUTER JOIN
dbo.cw_invoicesub ON dbo.bs_business_cw.subid = dbo.cw_invoicesub.mx_fee_id';
IF OBJECT_ID(N'dbo.v_feetype', N'V') IS NOT NULL
DROP VIEW dbo.[v_feetype];
EXEC sys.sp_executesql N'CREATE VIEW [dbo].[v_feetype] AS SELECT dbo.b_money.b_hl, dbo.b_feetype.b_id, dbo.b_feetype.b_name, dbo.b_feetype.b_name_e, dbo.b_feetype.b_bz, dbo.b_feetype.b_default, dbo.b_feetype.b_amount, dbo.b_feetype.b_tax,
dbo.b_feetype.b_money_id, dbo.b_feetype.b_inputuser_id, dbo.b_feetype.b_inputdatetime, dbo.b_feetype.b_updateuser_id, dbo.b_feetype.b_updatedatetime
FROM dbo.b_feetype LEFT OUTER JOIN
dbo.b_money ON dbo.b_feetype.b_money_id = dbo.b_money.b_name';
COMMIT TRANSACTION;
@@ -0,0 +1,633 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Reads the legacy SQL Server catalog and emits reviewed, schema-only FMS migrations.
* The generated SQL never connects back to the legacy database and never contains data.
*/
public final class GenerateBusinessMigrations {
private static final Set<String> EXCLUDED_TABLES = lowerSet(
"b_contact", "b_contact_type", "b_othercompany", "b_othercompany_bmfl",
"b_user", "b_user_power", "b_user_qx", "b_user_record",
"dtproperties", "log_datas"
);
private static final Set<String> TREE_TABLES = lowerSet(
"b_other_bmfl", "bc_pricelist_bmfl", "oa_title_bmfl"
);
private static final Set<String> EXCLUDED_VIEWS = lowerSet(
"v_autoidrule", "v_b_contact", "v_b_employee", "v_b_user_record"
);
private static final Set<String> BOOLEAN_COLUMNS = lowerSet(
"b_black", "b_canuse", "b_visible", "b_used", "b_default", "b_isdefault",
"b_finish", "b_sh", "b_bill", "b_zx", "b_toall", "b_reminder",
"b_othermachinelogin", "b_salesman", "b_docman", "b_dealman",
"b_visible_customer", "b_visible_supply", "b_levelvisible", "b_fromcustomer",
"b_logintime", "b_checkxy", "b_loginfee", "mx_finish", "mx_sh"
);
private static final Set<String> TRUE_DEFAULT_COLUMNS = lowerSet(
"b_canuse", "b_visible", "b_used"
);
private static final Set<String> UNICODE_HINTS = lowerSet(
"name", "memo", "bz", "addr", "address", "subject", "content", "info",
"desc", "caption", "department", "duty", "bank", "goods", "mark",
"remark", "taste", "habit", "situation", "place", "body"
);
private static final Map<String, String> BUSINESS_CODE_FIELDS = Map.ofEntries(
Map.entry("bc_khht", "b_htno"),
Map.entry("bs_business", "b_ywno"),
Map.entry("cw_account", "b_account"),
Map.entry("cw_bill", "b_ywno"),
Map.entry("cw_invoice", "b_ywno"),
Map.entry("cw_sfd", "b_ywno")
);
private static final Map<String, String> CHILD_PARENTS = Map.ofEntries(
Map.entry("b_othercompany_accountbank", "b_othercompany"),
Map.entry("bc_pricelist_sub", "bc_pricelist"),
Map.entry("bs_business_container", "bs_business"),
Map.entry("bs_business_cw", "bs_business"),
Map.entry("bs_business_hdbl", "bs_business"),
Map.entry("bs_business_transport", "bs_business"),
Map.entry("cw_billsub", "cw_bill"),
Map.entry("cw_invoicesub", "cw_invoice"),
Map.entry("cw_sfdsub", "cw_sfd"),
Map.entry("oa_notices_attach", "oa_notices"),
Map.entry("oa_noticessub", "oa_notices")
);
private static final Map<String, String> RENAMED_COLUMNS = Map.ofEntries(
Map.entry("bs_business_cw.mx_type_id", "mx_direction"),
Map.entry("bs_business_transport.mx_hstype_id", "mx_source_type"),
Map.entry("cw_bill.b_module_id", "b_direction"),
Map.entry("cw_bill.b_type_id", "b_document_type"),
Map.entry("cw_invoice.b_module_id", "b_direction"),
Map.entry("cw_invoice.b_type_id", "b_document_type"),
Map.entry("cw_sfd.b_module_id", "b_direction"),
Map.entry("cw_sfd.b_type_id", "b_document_type")
);
private record Column(
String name,
String type,
int maxLength,
int precision,
int scale,
boolean nullable,
int ordinal
) {}
private record Table(String name, List<Column> columns) {}
public static void main(String[] args) throws Exception {
Path apiRoot = Path.of("").toAbsolutePath().normalize();
Path sourceConfig = apiRoot.resolve("config/dbconfigs/G3HY2025.properties");
Path migrations = apiRoot.resolve("config/migrations");
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(sourceConfig)) {
properties.load(input);
}
try (Connection connection = DriverManager.getConnection(
properties.getProperty("url"),
properties.getProperty("username"),
properties.getProperty("password")
)) {
Map<String, Table> tables = loadTables(connection);
writeDomain(migrations.resolve("016_create_base_tables.sql"), "基础资料", tables, "base");
writeDomain(
migrations.resolve("017_create_contract_file_tables.sql"),
"合同和文件资料",
tables,
"contract-file"
);
writeDomain(migrations.resolve("018_create_business_tables.sql"), "业务单据", tables, "business");
writeDomain(migrations.resolve("019_create_finance_tables.sql"), "财务", tables, "finance");
writeDomain(migrations.resolve("020_create_oa_tables.sql"), "OA", tables, "oa");
writeViews(migrations.resolve("021_create_business_views.sql"), connection);
writeVerification(migrations.resolve("verify_business_schema.sql"), tables, connection);
}
}
private static Map<String, Table> loadTables(Connection connection) throws Exception {
String sql = """
SELECT t.name AS table_name, c.name AS column_name, ty.name AS type_name,
c.max_length, c.precision, c.scale, c.is_nullable, c.column_id
FROM sys.tables AS t
INNER JOIN sys.schemas AS s ON s.schema_id = t.schema_id
INNER JOIN sys.columns AS c ON c.object_id = t.object_id
INNER JOIN sys.types AS ty ON ty.user_type_id = c.user_type_id
WHERE s.name = N'dbo' AND t.is_ms_shipped = 0
ORDER BY t.name, c.column_id
""";
Map<String, List<Column>> columnsByTable = new LinkedHashMap<>();
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(sql)) {
while (rows.next()) {
String tableName = rows.getString("table_name");
columnsByTable.computeIfAbsent(tableName, ignored -> new ArrayList<>()).add(new Column(
rows.getString("column_name"),
rows.getString("type_name"),
rows.getInt("max_length"),
rows.getInt("precision"),
rows.getInt("scale"),
rows.getBoolean("is_nullable"),
rows.getInt("column_id")
));
}
}
Map<String, Table> result = new LinkedHashMap<>();
for (Map.Entry<String, List<Column>> entry : columnsByTable.entrySet()) {
if (!includeTable(entry.getKey())) continue;
result.put(entry.getKey().toLowerCase(Locale.ROOT), new Table(entry.getKey(), entry.getValue()));
}
return result;
}
private static boolean includeTable(String tableName) {
String name = tableName.toLowerCase(Locale.ROOT);
if (EXCLUDED_TABLES.contains(name)) return false;
return name.startsWith("b_")
|| name.startsWith("bc_")
|| name.startsWith("bf_")
|| name.startsWith("bs_")
|| name.startsWith("cw_")
|| name.startsWith("oa_");
}
private static String domainOf(String tableName) {
String name = tableName.toLowerCase(Locale.ROOT);
if (name.startsWith("bc_") || name.startsWith("bf_")) return "contract-file";
if (name.startsWith("bs_")) return "business";
if (name.startsWith("cw_")) return "finance";
if (name.startsWith("oa_")) return "oa";
return "base";
}
private static void writeDomain(
Path target,
String title,
Map<String, Table> tables,
String domain
) throws Exception {
StringBuilder sql = new StringBuilder(header(title));
tables.values().stream()
.filter(table -> domainOf(table.name()).equals(domain))
.sorted(Comparator.comparing(Table::name, String.CASE_INSENSITIVE_ORDER))
.forEach(table -> sql.append(createTable(table)));
if (domain.equals("finance")) appendFinanceRelations(sql);
sql.append("\nCOMMIT TRANSACTION;\n");
Files.writeString(target, sql.toString(), StandardCharsets.UTF_8);
}
private static String header(String title) {
return """
/* Generated schema-only migration: %s. No legacy data is copied. */
SET NOCOUNT ON;
SET XACT_ABORT ON;
IF DB_NAME() <> N'FMS'
THROW 51501, N'本迁移只能在 FMS 目标数据库执行。', 1;
BEGIN TRANSACTION;
""".formatted(title);
}
private static String createTable(Table table) {
String lowerName = table.name().toLowerCase(Locale.ROOT);
if (TREE_TABLES.contains(lowerName)) return createTreeTable(table.name());
boolean child = hasColumn(table, "subid");
String primaryKey = child ? originalColumnName(table, "subid") : "b_id";
boolean sourceHasStringId = !child && table.columns().stream().anyMatch(column ->
column.name().equalsIgnoreCase("b_id") && isTextType(column.type())
);
String businessCode = businessCodeField(table, sourceHasStringId);
List<String> definitions = new ArrayList<>();
if (!child && !hasColumn(table, "b_id")) {
definitions.add(" b_id bigint NOT NULL");
}
for (Column column : table.columns()) {
if (isPluralIdColumn(column.name())) continue;
String targetName = targetColumnName(table, column.name());
String definition = " " + quote(targetName) + " " + targetType(table, column);
boolean requiredCode = businessCode != null && column.name().equalsIgnoreCase(businessCode);
boolean requiredKey = column.name().equalsIgnoreCase(primaryKey)
|| (!child && column.name().equalsIgnoreCase("b_id"));
if (BOOLEAN_COLUMNS.contains(column.name().toLowerCase(Locale.ROOT))) {
int defaultValue = TRUE_DEFAULT_COLUMNS.contains(column.name().toLowerCase(Locale.ROOT)) ? 1 : 0;
definition += " NOT NULL CONSTRAINT "
+ quote("DF_" + safeName(table.name()) + "_" + safeName(column.name()))
+ " DEFAULT (" + defaultValue + ")";
} else {
definition += requiredCode || requiredKey ? " NOT NULL" : column.nullable() ? " NULL" : " NOT NULL";
}
definitions.add(definition);
}
if (sourceHasStringId && businessCode != null && !hasColumn(table, businessCode)) {
definitions.add(" " + quote(businessCode) + " varchar(50) NOT NULL");
}
definitions.add(" CONSTRAINT " + quote("PK_" + safeName(table.name()))
+ " PRIMARY KEY (" + quote(primaryKey) + ")");
if (businessCode != null) {
definitions.add(" CONSTRAINT " + quote("UQ_" + safeName(table.name()) + "_" + businessCode)
+ " UNIQUE (" + quote(businessCode) + ")");
}
String parentTable = CHILD_PARENTS.get(lowerName);
if (child && parentTable != null && hasColumn(table, "father")) {
definitions.add(" CONSTRAINT " + quote("FK_" + safeName(table.name()) + "_father")
+ " FOREIGN KEY (" + quote(originalColumnName(table, "father")) + ") REFERENCES dbo."
+ quote(parentTable) + " (b_id)");
}
StringBuilder result = new StringBuilder();
result.append(" IF OBJECT_ID(N'dbo.").append(escape(table.name())).append("', N'U') IS NULL\n");
result.append(" BEGIN\n");
result.append(" CREATE TABLE dbo.").append(quote(table.name())).append(" (\n");
result.append(String.join(",\n", definitions)).append("\n );\n");
appendIndexes(result, table, primaryKey, businessCode);
result.append(" END;\n\n");
return result.toString();
}
private static String createTreeTable(String tableName) {
String safe = safeName(tableName);
return """
IF OBJECT_ID(N'dbo.%s', N'U') IS NULL
BEGIN
CREATE TABLE dbo.%s (
b_id bigint NOT NULL,
b_parent_id bigint NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT %s DEFAULT (1),
b_path varchar(1000) NOT NULL,
b_xh int NOT NULL CONSTRAINT %s DEFAULT (0),
b_canuse int NOT NULL CONSTRAINT %s DEFAULT (1),
b_inputuser_id bigint NULL,
b_inputdatetime datetime2(0) NOT NULL CONSTRAINT %s DEFAULT (SYSDATETIME()),
b_updateuser_id bigint NULL,
b_updatedatetime datetime2(0) NULL,
CONSTRAINT %s PRIMARY KEY (b_id),
CONSTRAINT %s CHECK (b_parent_id IS NULL OR b_parent_id <> b_id),
CONSTRAINT %s FOREIGN KEY (b_parent_id) REFERENCES dbo.%s (b_id)
);
CREATE INDEX %s ON dbo.%s (b_parent_id, b_xh, b_id);
CREATE INDEX %s ON dbo.%s (b_path, b_xh, b_id);
END;
""".formatted(
escape(tableName), quote(tableName),
quote("DF_" + safe + "_level"), quote("DF_" + safe + "_xh"),
quote("DF_" + safe + "_canuse"), quote("DF_" + safe + "_inputdatetime"),
quote("PK_" + safe), quote("CK_" + safe + "_parent"), quote("FK_" + safe + "_parent"),
quote(tableName), quote("IX_" + safe + "_parent"), quote(tableName),
quote("IX_" + safe + "_path"), quote(tableName)
);
}
private static void appendIndexes(
StringBuilder sql,
Table table,
String primaryKey,
String businessCode
) {
Set<String> indexed = new LinkedHashSet<>();
for (Column column : table.columns()) {
String targetName = targetColumnName(table, column.name());
String lower = targetName.toLowerCase(Locale.ROOT);
if (lower.equals(primaryKey.toLowerCase(Locale.ROOT))) continue;
if (businessCode != null && lower.equals(businessCode.toLowerCase(Locale.ROOT))) continue;
if (lower.equals("father") || (lower.endsWith("_id") && !isAuditUserColumn(lower))) {
if (!indexed.add(lower)) continue;
String indexName = "IX_" + safeName(table.name()) + "_" + safeName(column.name());
sql.append(" CREATE INDEX ").append(quote(indexName)).append(" ON dbo.")
.append(quote(table.name())).append(" (").append(quote(targetName))
.append(", ").append(quote(primaryKey)).append(");\n");
}
}
}
private static String businessCodeField(Table table, boolean sourceHasStringId) {
String lowerName = table.name().toLowerCase(Locale.ROOT);
String configured = BUSINESS_CODE_FIELDS.get(lowerName);
if (configured != null) return configured;
if (hasColumn(table, "b_code")) return originalColumnName(table, "b_code");
return sourceHasStringId ? "b_code" : null;
}
private static String targetType(Table table, Column column) {
String name = column.name().toLowerCase(Locale.ROOT);
String sourceType = column.type().toLowerCase(Locale.ROOT);
String renameKey = table.name().toLowerCase(Locale.ROOT) + "." + name;
if (renameKey.equals("bs_business_cw.mx_type_id")
|| renameKey.equals("cw_bill.b_module_id")
|| renameKey.equals("cw_invoice.b_module_id")
|| renameKey.equals("cw_sfd.b_module_id")) {
return "varchar(20)";
}
if (renameKey.equals("bs_business_transport.mx_hstype_id")
|| renameKey.endsWith(".b_type_id")) {
return "varchar(50)";
}
if (name.equals("b_id") || name.equals("subid") || name.equals("father") || isReferenceId(name)) {
return "bigint";
}
if (BOOLEAN_COLUMNS.contains(name) || sourceType.equals("bit")) return "int";
if (name.endsWith("datetime") || name.endsWith("_datetime") || name.equals("b_inputdate")) {
return "datetime2(0)";
}
if (name.equals("b_inputtime")) return "time(0)";
if (name.equals("b_birthday") || name.endsWith("begindate") || name.endsWith("enddate")
|| name.endsWith("expiredate")) {
return "date";
}
if (sourceType.equals("text") || sourceType.equals("ntext")) return "nvarchar(max)";
if (sourceType.equals("image")) return "varbinary(max)";
if (sourceType.equals("datetime") || sourceType.equals("smalldatetime")) return "datetime2(0)";
if (sourceType.equals("float") || sourceType.equals("real")) return "decimal(18,6)";
if (sourceType.equals("money") || sourceType.equals("smallmoney")) return "decimal(19,4)";
if (sourceType.equals("decimal") || sourceType.equals("numeric")) {
return sourceType + "(" + column.precision() + "," + column.scale() + ")";
}
if (sourceType.equals("varchar") || sourceType.equals("char")
|| sourceType.equals("nvarchar") || sourceType.equals("nchar")) {
boolean unicode = sourceType.startsWith("n") || hasUnicodeHint(name);
String base = unicode ? "nvarchar" : "varchar";
int bytesPerChar = sourceType.startsWith("n") ? 2 : 1;
String length = column.maxLength() < 0 ? "max" : String.valueOf(column.maxLength() / bytesPerChar);
return base + "(" + length + ")";
}
if (sourceType.equals("binary") || sourceType.equals("varbinary")) {
String length = column.maxLength() < 0 ? "max" : String.valueOf(column.maxLength());
return sourceType + "(" + length + ")";
}
if (sourceType.equals("timestamp") || sourceType.equals("rowversion")) return "binary(8)";
if (sourceType.equals("uniqueidentifier")) return "bigint";
return sourceType;
}
private static boolean isReferenceId(String name) {
return name.endsWith("_id")
|| name.equals("userid")
|| name.equals("moduleid")
|| name.endsWith("userid")
|| name.endsWith("moduleid");
}
private static boolean isAuditUserColumn(String name) {
return name.equals("b_inputuser_id")
|| name.equals("b_updateuser_id")
|| name.equals("mx_inputuser_id")
|| name.equals("mx_updateuser_id");
}
private static boolean isPluralIdColumn(String name) {
String lower = name.toLowerCase(Locale.ROOT);
return lower.endsWith("_ids") || lower.equals("b_yw_ids") || lower.equals("b_bill_ids")
|| lower.equals("b_inv_ids");
}
private static boolean hasUnicodeHint(String name) {
for (String hint : UNICODE_HINTS) {
if (name.contains(hint)) return true;
}
return false;
}
private static boolean isTextType(String type) {
String lower = type.toLowerCase(Locale.ROOT);
return lower.equals("varchar") || lower.equals("nvarchar") || lower.equals("char")
|| lower.equals("nchar") || lower.equals("text") || lower.equals("ntext");
}
private static boolean hasColumn(Table table, String name) {
return table.columns().stream().anyMatch(column -> column.name().equalsIgnoreCase(name));
}
private static String originalColumnName(Table table, String name) {
return table.columns().stream()
.filter(column -> column.name().equalsIgnoreCase(name))
.findFirst()
.map(Column::name)
.orElse(name);
}
private static void appendFinanceRelations(StringBuilder sql) {
appendRelation(sql, "cw_bill_business", "b_bill_id", "cw_bill", "b_business_id", "bs_business");
appendRelation(sql, "cw_invoice_bill", "b_invoice_id", "cw_invoice", "b_bill_id", "cw_bill");
appendRelation(sql, "cw_invoice_business", "b_invoice_id", "cw_invoice", "b_business_id", "bs_business");
appendRelation(sql, "cw_sfd_business", "b_sfd_id", "cw_sfd", "b_business_id", "bs_business");
appendRelation(sql, "cw_sfd_invoice", "b_sfd_id", "cw_sfd", "b_invoice_id", "cw_invoice");
appendRelation(sql, "cw_sfd_bill", "b_sfd_id", "cw_sfd", "b_bill_id", "cw_bill");
}
private static void appendRelation(
StringBuilder sql,
String table,
String leftColumn,
String leftTable,
String rightColumn,
String rightTable
) {
String safe = safeName(table);
sql.append(" IF OBJECT_ID(N'dbo.").append(table).append("', N'U') IS NULL\n")
.append(" BEGIN\n")
.append(" CREATE TABLE dbo.").append(quote(table)).append(" (\n")
.append(" subid bigint NOT NULL,\n")
.append(" ").append(quote(leftColumn)).append(" bigint NOT NULL,\n")
.append(" ").append(quote(rightColumn)).append(" bigint NOT NULL,\n")
.append(" b_xh int NOT NULL CONSTRAINT ").append(quote("DF_" + safe + "_xh"))
.append(" DEFAULT (0),\n")
.append(" CONSTRAINT ").append(quote("PK_" + safe)).append(" PRIMARY KEY (subid),\n")
.append(" CONSTRAINT ").append(quote("UQ_" + safe)).append(" UNIQUE (")
.append(quote(leftColumn)).append(", ").append(quote(rightColumn)).append("),\n")
.append(" CONSTRAINT ").append(quote("FK_" + safe + "_left")).append(" FOREIGN KEY (")
.append(quote(leftColumn)).append(") REFERENCES dbo.").append(quote(leftTable)).append(" (b_id),\n")
.append(" CONSTRAINT ").append(quote("FK_" + safe + "_right")).append(" FOREIGN KEY (")
.append(quote(rightColumn)).append(") REFERENCES dbo.").append(quote(rightTable)).append(" (b_id)\n")
.append(" );\n")
.append(" END;\n\n");
}
private static void writeViews(Path target, Connection connection) throws Exception {
String query = """
SELECT v.name, sm.definition
FROM sys.views AS v
INNER JOIN sys.schemas AS s ON s.schema_id = v.schema_id
INNER JOIN sys.sql_modules AS sm ON sm.object_id = v.object_id
WHERE s.name = N'dbo'
ORDER BY v.name
""";
StringBuilder sql = new StringBuilder(header("业务视图"));
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(query)) {
while (rows.next()) {
String name = rows.getString("name");
if (!includeView(name)) continue;
String definition = rows.getString("definition");
if (name.equalsIgnoreCase("v_b_othercompany_bmfl")) {
definition = "CREATE VIEW dbo.v_b_othercompany_bmfl AS "
+ "SELECT b_id, b_name FROM dbo.b_othercompany_bmfl";
} else if (name.equalsIgnoreCase("v_b_feetype")) {
definition = "CREATE VIEW dbo.v_b_feetype AS SELECT "
+ "fee.b_id, fee.b_name, fee.b_name_e, fee.b_bz, fee.b_default, "
+ "fee.b_amount, fee.b_tax, fee.b_money_id, fee.b_inputuser_id, "
+ "fee.b_inputdatetime, fee.b_updateuser_id, fee.b_updatedatetime, money.b_hl "
+ "FROM dbo.b_feetype AS fee "
+ "LEFT JOIN dbo.b_money AS money ON money.b_id = fee.b_money_id";
}
definition = removeLegacyPluralIds(definition);
definition = renameLegacySemanticIds(name, definition);
sql.append(" IF OBJECT_ID(N'dbo.").append(escape(name)).append("', N'V') IS NOT NULL\n")
.append(" DROP VIEW dbo.").append(quote(name)).append(";\n")
.append(" EXEC sys.sp_executesql N'")
.append(escape(definition))
.append("';\n\n");
}
}
sql.append("COMMIT TRANSACTION;\n");
Files.writeString(target, sql.toString(), StandardCharsets.UTF_8);
}
private static boolean includeView(String viewName) {
String name = viewName.toLowerCase(Locale.ROOT);
if (EXCLUDED_VIEWS.contains(name)) return false;
return name.startsWith("v_b_") || name.startsWith("v_bc_")
|| name.startsWith("v_bs_") || name.startsWith("v_cw_")
|| name.equals("v_feetype");
}
private static String removeLegacyPluralIds(String definition) {
String result = definition;
for (String field : List.of("b_yw_ids", "b_bill_ids", "b_inv_ids")) {
result = result.replaceAll(
"(?i)(?:dbo\\.)?[A-Za-z0-9_]+\\." + field + "\\s*,\\s*",
""
);
result = result.replaceAll(
"(?i),\\s*(?:dbo\\.)?[A-Za-z0-9_]+\\." + field + "(?=\\s+FROM)",
""
);
}
return result;
}
private static String renameLegacySemanticIds(String viewName, String definition) {
String result = definition;
result = replaceIgnoreCase(result, "dbo.bs_business_cw.mx_type_id", "dbo.bs_business_cw.mx_direction");
result = replaceIgnoreCase(result, "dbo.bs_business_transport.mx_hstype_id", "dbo.bs_business_transport.mx_source_type");
result = replaceIgnoreCase(result, "dbo.cw_bill.b_module_id", "dbo.cw_bill.b_direction");
result = replaceIgnoreCase(result, "dbo.cw_bill.b_type_id", "dbo.cw_bill.b_document_type");
result = replaceIgnoreCase(result, "dbo.cw_invoice.b_module_id", "dbo.cw_invoice.b_direction");
result = replaceIgnoreCase(result, "dbo.cw_invoice.b_type_id", "dbo.cw_invoice.b_document_type");
result = replaceIgnoreCase(result, "dbo.cw_sfd.b_module_id", "dbo.cw_sfd.b_direction");
result = replaceIgnoreCase(result, "dbo.cw_sfd.b_type_id", "dbo.cw_sfd.b_document_type");
if (viewName.equalsIgnoreCase("v_bs_business_cw")
|| viewName.equalsIgnoreCase("v_bs_business_cw_yf")
|| viewName.equalsIgnoreCase("v_bs_business_cw_ys")) {
result = replaceIgnoreCase(result, "mx_type_id", "mx_direction");
}
if (viewName.equalsIgnoreCase("v_cw_account")) {
result = replaceIgnoreCase(result, "b_type_id", "b_direction");
result = replaceIgnoreCase(
result,
"a.b_account_id = dbo.cw_account.b_account",
"a.b_account_id = dbo.cw_account.b_id"
);
}
return result;
}
private static String replaceIgnoreCase(String value, String source, String replacement) {
return value.replaceAll("(?i)" + java.util.regex.Pattern.quote(source), replacement);
}
private static String targetColumnName(Table table, String sourceName) {
String key = table.name().toLowerCase(Locale.ROOT) + "." + sourceName.toLowerCase(Locale.ROOT);
return RENAMED_COLUMNS.getOrDefault(key, sourceName);
}
private static void writeVerification(
Path target,
Map<String, Table> tables,
Connection connection
) throws Exception {
int expectedTables = tables.size() + 6 + 5;
int expectedViews = 0;
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(
"SELECT name FROM sys.views WHERE is_ms_shipped = 0"
)) {
while (rows.next()) if (includeView(rows.getString(1))) expectedViews++;
}
String sql = """
SET NOCOUNT ON;
IF DB_NAME() <> N'FMS'
THROW 51510, N'验证脚本只能在 FMS 目标数据库执行。', 1;
SELECT
(SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0) AS table_count,
(SELECT COUNT(*) FROM sys.views WHERE is_ms_shipped = 0) AS view_count,
%d AS generated_business_table_minimum,
%d AS generated_business_view_count;
SELECT OBJECT_SCHEMA_NAME(c.object_id) AS schema_name,
OBJECT_NAME(c.object_id) AS object_name,
c.name AS column_name,
TYPE_NAME(c.user_type_id) AS type_name
FROM sys.columns AS c
INNER JOIN sys.tables AS t ON t.object_id = c.object_id
WHERE t.is_ms_shipped = 0
AND (c.name = N'b_id' OR c.name = N'subid' OR c.name = N'father' OR c.name LIKE N'%%[_]id')
AND TYPE_NAME(c.user_type_id) <> N'bigint'
ORDER BY schema_name, object_name, c.column_id;
SELECT s.name AS schema_name, v.name AS view_name
FROM sys.views AS v
INNER JOIN sys.schemas AS s ON s.schema_id = v.schema_id
WHERE v.is_ms_shipped = 0 AND OBJECTPROPERTY(v.object_id, 'IsSchemaBound') IN (0, 1)
AND EXISTS (
SELECT 1 FROM sys.sql_expression_dependencies AS d
WHERE d.referencing_id = v.object_id AND d.referenced_id IS NULL
AND d.referenced_entity_name IS NOT NULL
)
ORDER BY s.name, v.name;
""".formatted(expectedTables, expectedViews);
Files.writeString(target, sql, StandardCharsets.UTF_8);
}
private static String quote(String identifier) {
return "[" + identifier.replace("]", "]]" ) + "]";
}
private static String escape(String value) {
return value.replace("'", "''");
}
private static String safeName(String value) {
return value.replaceAll("[^A-Za-z0-9_]", "_");
}
private static Set<String> lowerSet(String... values) {
Set<String> result = new HashSet<>();
for (String value : values) result.add(value.toLowerCase(Locale.ROOT));
return result;
}
}
@@ -0,0 +1,58 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;
/** Executes only the reviewed schema-only business migrations against the FMS database. */
public final class RunBusinessMigrations {
private static final List<String> MIGRATIONS = List.of(
"015_normalize_existing_business_tables.sql",
"016_create_base_tables.sql",
"017_create_contract_file_tables.sql",
"018_create_business_tables.sql",
"019_create_finance_tables.sql",
"020_create_oa_tables.sql",
"021_create_business_views.sql"
);
public static void main(String[] args) throws Exception {
Path apiRoot = Path.of("").toAbsolutePath().normalize();
Path configPath = apiRoot.resolve("config/dbconfigs/G3HD.properties");
Path migrationDirectory = apiRoot.resolve("config/migrations");
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(configPath)) {
properties.load(input);
}
try (Connection connection = DriverManager.getConnection(
properties.getProperty("url"),
properties.getProperty("username"),
properties.getProperty("password")
)) {
if (!"FMS".equalsIgnoreCase(connection.getCatalog())) {
throw new IllegalStateException("Refusing to migrate database: " + connection.getCatalog());
}
for (String migration : MIGRATIONS) {
String sql = Files.readString(migrationDirectory.resolve(migration), StandardCharsets.UTF_8);
try (Statement statement = connection.createStatement()) {
statement.execute(sql);
}
System.out.println("APPLIED|" + migration);
}
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(
"SELECT (SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0), "
+ "(SELECT COUNT(*) FROM sys.views WHERE is_ms_shipped = 0)"
)) {
rows.next();
System.out.println("CATALOG|tables=" + rows.getInt(1) + "|views=" + rows.getInt(2));
}
}
}
}
@@ -0,0 +1,238 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** Performs read-only checks after the business schema migrations have run. */
public final class VerifyBusinessMigration {
private static final List<String> TABLE_MIGRATIONS = List.of(
"016_create_base_tables.sql",
"017_create_contract_file_tables.sql",
"018_create_business_tables.sql",
"019_create_finance_tables.sql",
"020_create_oa_tables.sql"
);
private static final Pattern CREATE_TABLE = Pattern.compile(
"(?i)CREATE\\s+TABLE\\s+dbo\\.(?:\\[([^]]+)]|([A-Za-z0-9_]+))"
);
public static void main(String[] args) throws Exception {
Path apiRoot = Path.of("").toAbsolutePath().normalize();
Path migrationDirectory = apiRoot.resolve("config/migrations");
Set<String> generatedTables = loadGeneratedTables(migrationDirectory);
Properties properties = new Properties();
try (InputStream input = Files.newInputStream(apiRoot.resolve("config/dbconfigs/G3HD.properties"))) {
properties.load(input);
}
try (Connection connection = DriverManager.getConnection(
properties.getProperty("url"),
properties.getProperty("username"),
properties.getProperty("password")
)) {
if (!"FMS".equalsIgnoreCase(connection.getCatalog())) {
throw new IllegalStateException("Refusing to verify database: " + connection.getCatalog());
}
verifyGeneratedTables(connection, generatedTables);
verifyCoreTables(connection);
verifyViews(connection);
printCatalogCounts(connection, generatedTables.size());
}
}
private static Set<String> loadGeneratedTables(Path migrationDirectory) throws Exception {
Set<String> result = new LinkedHashSet<>();
for (String migration : TABLE_MIGRATIONS) {
String sql = Files.readString(migrationDirectory.resolve(migration), StandardCharsets.UTF_8);
Matcher matcher = CREATE_TABLE.matcher(sql);
while (matcher.find()) {
result.add(matcher.group(1) != null ? matcher.group(1) : matcher.group(2));
}
}
return result;
}
private static void verifyGeneratedTables(Connection connection, Set<String> tables) throws Exception {
for (String table : tables) {
if (!tableExists(connection, table)) {
throw new IllegalStateException("Missing generated table: dbo." + table);
}
if (rowCount(connection, table) != 0) {
throw new IllegalStateException("Generated table is not empty: dbo." + table);
}
String primaryKey = columnExists(connection, table, "subid") ? "subid" : "b_id";
if (!primaryKeyMatches(connection, table, primaryKey)) {
throw new IllegalStateException("Unexpected primary key on dbo." + table + "; expected " + primaryKey);
}
verifyIdTypes(connection, table);
verifyNoLegacyTypes(connection, table);
verifyRemovedPluralIds(connection, table);
}
System.out.println("PASS|generated_tables=" + tables.size() + "|empty=true|keys=true|types=true");
}
private static void verifyCoreTables(Connection connection) throws Exception {
for (String table : List.of("b_othercompany", "b_contact", "b_othercompany_bmfl")) {
if (!tableExists(connection, table)) {
throw new IllegalStateException("Missing core business table: dbo." + table);
}
verifyIdTypes(connection, table);
}
long users = scalar(connection, "SELECT COUNT_BIG(*) FROM dbo.b_user");
long modules = scalar(connection, "SELECT COUNT_BIG(*) FROM dbo.s_module");
long fields = scalar(connection, "SELECT COUNT_BIG(*) FROM dbo.s_module_field");
long autoCodes = scalar(connection, "SELECT COUNT_BIG(*) FROM dbo.s_module_auto_code");
if (users == 0 || modules == 0 || fields == 0) {
throw new IllegalStateException("Existing user or module metadata is missing");
}
System.out.println("PASS|preserved|users=" + users + "|modules=" + modules
+ "|fields=" + fields + "|auto_codes=" + autoCodes);
}
private static void verifyViews(Connection connection) throws Exception {
List<String> viewNames = new ArrayList<>();
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(
"SELECT QUOTENAME(SCHEMA_NAME(schema_id)) + N'.' + QUOTENAME(name) "
+ "FROM sys.views WHERE is_ms_shipped = 0 ORDER BY name"
)) {
while (rows.next()) {
viewNames.add(rows.getString(1));
}
}
for (String viewName : viewNames) {
try (Statement refresh = connection.createStatement()) {
refresh.execute("EXEC sys.sp_refreshview N'" + viewName.replace("'", "''") + "'");
}
}
System.out.println("PASS|views_refreshed=" + viewNames.size());
}
private static void printCatalogCounts(Connection connection, int generatedTableCount) throws Exception {
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(
"SELECT (SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0), "
+ "(SELECT COUNT(*) FROM sys.views WHERE is_ms_shipped = 0)"
)) {
rows.next();
System.out.println("PASS|catalog|tables=" + rows.getInt(1) + "|views=" + rows.getInt(2)
+ "|generated_tables=" + generatedTableCount);
}
}
private static boolean tableExists(Connection connection, String table) throws Exception {
try (PreparedStatement statement = connection.prepareStatement(
"SELECT COUNT(*) FROM sys.tables WHERE schema_id = SCHEMA_ID(N'dbo') AND name = ?"
)) {
statement.setString(1, table);
try (ResultSet rows = statement.executeQuery()) {
rows.next();
return rows.getInt(1) == 1;
}
}
}
private static boolean columnExists(Connection connection, String table, String column) throws Exception {
try (PreparedStatement statement = connection.prepareStatement(
"SELECT COUNT(*) FROM sys.columns WHERE object_id = OBJECT_ID(?) AND name = ?"
)) {
statement.setString(1, "dbo." + table);
statement.setString(2, column);
try (ResultSet rows = statement.executeQuery()) {
rows.next();
return rows.getInt(1) == 1;
}
}
}
private static boolean primaryKeyMatches(Connection connection, String table, String expected) throws Exception {
String sql = """
SELECT c.name
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic
ON ic.object_id = i.object_id AND ic.index_id = i.index_id
INNER JOIN sys.columns AS c
ON c.object_id = ic.object_id AND c.column_id = ic.column_id
WHERE i.object_id = OBJECT_ID(?) AND i.is_primary_key = 1
ORDER BY ic.key_ordinal
""";
try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, "dbo." + table);
try (ResultSet rows = statement.executeQuery()) {
return rows.next()
&& rows.getString(1).equalsIgnoreCase(expected)
&& !rows.next();
}
}
}
private static void verifyIdTypes(Connection connection, String table) throws Exception {
String sql = """
SELECT c.name, TYPE_NAME(c.user_type_id)
FROM sys.columns AS c
WHERE c.object_id = OBJECT_ID(?)
AND (LOWER(c.name) IN (N'b_id', N'subid', N'father') OR LOWER(c.name) LIKE N'%[_]id')
AND TYPE_NAME(c.user_type_id) <> N'bigint'
""";
try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, "dbo." + table);
try (ResultSet rows = statement.executeQuery()) {
if (rows.next()) {
throw new IllegalStateException("Non-bigint ID column: dbo." + table + "."
+ rows.getString(1) + " (" + rows.getString(2).toLowerCase(Locale.ROOT) + ")");
}
}
}
}
private static void verifyNoLegacyTypes(Connection connection, String table) throws Exception {
String sql = """
SELECT c.name, TYPE_NAME(c.user_type_id)
FROM sys.columns AS c
WHERE c.object_id = OBJECT_ID(?)
AND TYPE_NAME(c.user_type_id) IN (N'text', N'ntext', N'image', N'float', N'real', N'uniqueidentifier')
""";
try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, "dbo." + table);
try (ResultSet rows = statement.executeQuery()) {
if (rows.next()) {
throw new IllegalStateException("Legacy type remains: dbo." + table + "." + rows.getString(1));
}
}
}
}
private static void verifyRemovedPluralIds(Connection connection, String table) throws Exception {
for (String column : List.of("b_yw_ids", "b_bill_ids", "b_inv_ids")) {
if (columnExists(connection, table, column)) {
throw new IllegalStateException("Legacy plural-ID column remains: dbo." + table + "." + column);
}
}
}
private static long rowCount(Connection connection, String table) throws Exception {
return scalar(connection, "SELECT COUNT_BIG(*) FROM dbo.[" + table.replace("]", "]]" ) + "]");
}
private static long scalar(Connection connection, String sql) throws Exception {
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(sql)) {
rows.next();
return rows.getLong(1);
}
}
}
@@ -0,0 +1,32 @@
SET NOCOUNT ON;
IF DB_NAME() <> N'FMS'
THROW 51510, N'验证脚本只能在 FMS 目标数据库执行。', 1;
SELECT
(SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0) AS table_count,
(SELECT COUNT(*) FROM sys.views WHERE is_ms_shipped = 0) AS view_count,
90 AS generated_business_table_minimum,
48 AS generated_business_view_count;
SELECT OBJECT_SCHEMA_NAME(c.object_id) AS schema_name,
OBJECT_NAME(c.object_id) AS object_name,
c.name AS column_name,
TYPE_NAME(c.user_type_id) AS type_name
FROM sys.columns AS c
INNER JOIN sys.tables AS t ON t.object_id = c.object_id
WHERE t.is_ms_shipped = 0
AND (c.name = N'b_id' OR c.name = N'subid' OR c.name = N'father' OR c.name LIKE N'%[_]id')
AND TYPE_NAME(c.user_type_id) <> N'bigint'
ORDER BY schema_name, object_name, c.column_id;
SELECT s.name AS schema_name, v.name AS view_name
FROM sys.views AS v
INNER JOIN sys.schemas AS s ON s.schema_id = v.schema_id
WHERE v.is_ms_shipped = 0 AND OBJECTPROPERTY(v.object_id, 'IsSchemaBound') IN (0, 1)
AND EXISTS (
SELECT 1 FROM sys.sql_expression_dependencies AS d
WHERE d.referencing_id = v.object_id AND d.referenced_id IS NULL
AND d.referenced_entity_name IS NOT NULL
)
ORDER BY s.name, v.name;