diff --git a/code/fms/FMS新系统核心表结构设计.md b/code/fms/FMS新系统核心表结构设计.md index 6d5d41fa..dfe5002f 100644 --- a/code/fms/FMS新系统核心表结构设计.md +++ b/code/fms/FMS新系统核心表结构设计.md @@ -273,31 +273,29 @@ create index ix_s_menu_route ## 8. 权限 -> 权限直接授予用户,不引入角色继承。`s_power.b_id` 是内部主键,`s_power.b_code` 是稳定且全局唯一的业务键;字段授权使用独立的字段访问策略表。 +> 权限直接授予用户,不引入角色继承。`s_power.b_id` 是权限编码本身(业务键即主键),格式 `类型.对象[.能力]`,例如 `menu.cw_fee`、`module.cw_fee`、`action.cw_fee.audit`;完整规范见《字段权限与用户个性化设计.md》「权限编码规范」。字段授权使用独立的字段访问策略表。 ```sql create table dbo.s_power ( - b_id bigint not null, - b_code varchar(300) not null, + b_id varchar(100) not null, -- 权限编码即主键:menu.cw_fee / module.cw_fee / action.cw_fee.audit b_name nvarchar(200) not null, b_i18n varchar(150) null, - b_power_type varchar(20) not null, -- menu/page/report/module/action - b_resource_id varchar(128) not null, - b_owner_type varchar(20) null, -- action owner type - b_owner_id varchar(128) null, -- action owner id - b_capability varchar(30) not null, -- access/execute/read/create/update/delete/export + b_power_type varchar(20) not null, -- page/menu/module/action/report + b_owner_type varchar(20) not null, -- 归属对象类型:page/menu/module/report;action 时为所属模块或页面 + b_owner_id varchar(50) not null, -- 归属对象编码:菜单/模块/页面/报表编码 + b_capability varchar(30) null, -- action 的操作或动作编码:create/update/delete/export/audit...;入口类为 null + b_operation varchar(30) null, -- 兼容列:access/execute,由 b_power_type 派生 b_canuse tinyint not null default 1, b_xh int not null default 0, - primary key (b_id), - unique (b_code) + primary key (b_id) ); -create index ix_s_power_resource - on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_resource_id, b_canuse); +create index ix_s_power_owner + on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_capability, b_canuse); create table dbo.s_user_power ( b_user_id varchar(50) not null, - b_power_id bigint not null, + b_power_id varchar(100) not null, -- s_power.b_id,即权限编码 b_canuse tinyint not null default 1, b_updatedatetime datetime2 null, primary key (b_user_id, b_power_id) @@ -345,18 +343,17 @@ create index ix_s_user_data_scope_module 权限点约定: -- `menu/access`:菜单或页面入口访问权限; -- `module/read|create|update|delete|export`:模块级数据操作权限; -- `action/execute`:菜单或页面中的按钮、动作权限; +- `page.<页面编码>` / `menu.<菜单编码>` / `report.<报表编码>`:入口访问权限,报表列表中的每个报表可作为一个资源; +- `module.<模块编码>`:模块访问(≈ read,能否查看该模块数据); +- `action.<模块编码>.<操作或动作>`:数据操作(`create` / `update` / `delete` / `export`)与业务动作(`audit` / `settle` 等)统一为动作权限; - `s_user_field_permission`:字段 `hidden/view/edit` 访问级别,以及独立的查询/导出能力; -- `page/access`、`report/access`:独立页面或报表访问权限,报表列表中的每个报表可作为一个资源; -- `b_power_type` 和 `b_capability` 是可扩展编码,新增资源类型不新增权限表,但需要补充权限定义和前端/后端校验规则。 -- 动作业务键必须包含所属资源命名空间,例如 `action.module.cw_fee.audit.execute`,不得使用裸 `action.audit`。 +- `b_power_type` 和 `b_capability` 是可扩展编码,新增资源类型不新增权限表,但需要补充权限定义和前端/后端校验规则; +- 动作必须带所属模块命名空间,例如 `action.cw_fee.audit`,不得使用裸 `action.audit`;**动作归属模块而非菜单**,避免同一个动作在不同菜单下被重复配置。 权限计算约定: -- 入口权限默认拒绝:`menu/access`、`page/access`、`report/access` 和 `action/execute` 必须存在有效的 `s_user_power` 授权记录;停用的权限点或授权记录不生效; -- 模块操作权限默认放行:`module/read|create|update|delete|export` 没有用户授权记录时视为允许;`s_power` 权限点或用户授权记录存在 `b_canuse = 0` 时视为明确禁用; +- 入口权限默认拒绝:`page.*`、`menu.*`、`report.*` 与 `action.*` 必须存在有效的 `s_user_power` 授权记录;停用的权限点或授权记录不生效; +- 模块操作 `action.<模块编码>.<操作>` 在没有授权记录时**默认放行还是默认拒绝尚未最终确定**,见《字段权限与用户个性化设计.md》「待确认事项」第 1 条;`s_power` 权限点或用户授权记录存在 `b_canuse = 0` 时视为明确禁用; - 字段没有有效用户策略记录时不增加限制,按 `s_field`、`s_field_view`、`s_field_edit`、`s_field_query` 等模块默认配置执行;有效的 `s_user_field_permission` 只能收紧权限;`hidden` 表示不可见,`view` 表示可见只读,`edit` 表示可见可编辑; - `hidden` 字段不可查询、不可导出;`b_allow_query` / `b_allow_export` 不能突破字段访问级别; - 模块数据操作权限与数据范围同时生效:先判断操作权限,再按 `s_user_data_scope` 限制数据行;数据范围没有配置时视为 `all`; diff --git a/code/fms/demo.html b/code/fms/demo.html index bdb0151c..5c8ba71c 100644 --- a/code/fms/demo.html +++ b/code/fms/demo.html @@ -1,857 +1,129 @@ - - -FMS 权限中心 · 一屏授权 - - - + + + FMS 权限中心 · 功能实例授权 + + + - +
- - -
-
-
- F -
-
FMS 权限中心
-
一客户一库 · 权限点自动生成
-
-
-
- -
-
- IT -
-
系统管理员
-
客户库:DEMO-FWD
-
+
+
+
+ F +
FMS 权限中心
功能实例授权 · 一客户一库
+ +
系统管理员
DEMO-FWD
IT
- -
+
+
+
授权对象
+ +
未授权 = 拒绝 · 功能权限独立生效
+
- -
-
- 授权对象 - -
- - +
+
-
+ -
- - - - - -
- - -
-
-

全部模块概览

-

{{ curUser.name }} · 点模块名进入详细配置

-
- - - - - - - - - - - - - - - - - -
模块入口已授权动作数据范围
-
{{ m.name }}
-
{{ m.id }}
-
- - - 未授权(默认拒绝) - - {{ a }} - - - {{ scopeName(scopeOf(m.id)) }} -
-
- - -
-
-
-

{{ selName }}

-

{{ state.selected }}

-
- page 节点 - {{ curUser.name }} · 全部默认拒绝,勾选即授权 -
- - -
-
入口
- - {{ hasEntry(state.selected) ? '已开通' : '未开通' }} - {{ entryCode }} -
- - -
-
动作
-
- -
-
-
页面节点只配入口,具体操作在下属模块上配置
- - -
-
数据范围
- - 未配置视为全部数据 -
- - -
-
敏感字段
-
-
该模块没有标记敏感字段,无需配置字段权限
-
-
- {{ f.l }}{{ f.n }} - - - - 已收紧 - 默认 -
-
-
-
-
-
- - - -
-
- - -
-
-
IT ADMINISTRATION
-

资源配置(客户不可见)

-

IT 定义「能分配什么」。客户只做分配,不碰元数据,也不能新建业务动作(动作需要后端代码)。

-
-
模块 / 页面
{{ nodeCount }}
-
业务动作
{{ actionDefCount }}
-
敏感字段
{{ sensitiveCount }}
-
权限点(自动生成)
{{ powerCodes.length }}
-
-
- -
- -
-
-

模块与敏感字段标记

-

只有标为敏感的字段才进入客户授权界面,其余字段不占配置量

-
-
- - - - - - - - - - - -
模块字段敏感
-
+
字段与数据范围
仍按技术模块配置,个人设置只能收紧
{{ module }}
字段策略:跟随模块默认
数据范围:全部数据
该功能不直接读取业务数据
- -
-
-
-

权限点清单

-

随元数据自动生成,只增不删、不覆盖已有配置

-
-
- -
-
-
- - - - - - - - - - - - - - - -
权限点编码名称默认
{{ p.code }}{{ p.name }}拒绝
-
-
- 业务动作(如 module.cw_fee.audit)由开发注册代码后生成,客户界面只能勾选、不能新建。 -
-
+
-
+
- - -
-
- 已选 {{ state.picked.length }} 人 - - - -
-
- 有 {{ diffList.length }} 项未保存变更 - - - -
-
- - -
-
-
-
-
保存前确认
-
共 {{ diffList.length }} 项变更,保存后立即生效
-
- -
-
- - - - - - - - - - - - - - - - - - - -
用户类别对象变更前变更后
{{ d.user }}{{ d.type }}{{ d.target }}{{ d.from }}{{ d.to }}
-
-
- - -
-
-
- -
{{ toastMsg }}
- - - - - +
IT CONFIGURATION

功能实例与权限生成

技术人员维护业务功能、公共模板和模块依赖,客户只负责授权。

功能实例
{{ features.length }}
公共模板
{{ templateCount }}
权限点
{{ allPowers.length }}
功能实例清单
功能入口与模块默认能力分层维护
功能类型公共模板使用模块功能权限
{{ feature.name }}
{{ feature.code }}
{{ typeName(feature.type) }}{{ feature.template }}{{ module }}无{{ powersFor(feature).length }}
技术配置详情
{{ configFeature.code }}
功能名称
{{ configFeature.name }}
模板
{{ configFeature.template }}
模块白名单
{{ module }}
无数据模块
自动生成权限
{{ power.code }}{{ capabilityName(power.capability) }}
+ + + diff --git a/code/fms/fms-api/config/migrations/000_reset_metadata.sql b/code/fms/fms-api/config/migrations/000_reset_metadata.sql deleted file mode 100644 index e6f16559..00000000 --- a/code/fms/fms-api/config/migrations/000_reset_metadata.sql +++ /dev/null @@ -1,220 +0,0 @@ -/* - WARNING: This script removes every user table except dbo.b_user. - Database views are intentionally preserved. Run it only against a selected - organization database after confirming the target connection. - - The metadata tables are rebuilt from scratch to match 新数据库结构.md. - Only the b_user table is preserved; every other user table is dropped. -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - EXEC sys.sp_set_session_context @key = N'allow_g3soft', @value = 1; - DECLARE @AdminId bigint = ( - SELECT TOP (1) b_id - FROM dbo.b_user - WHERE b_account = N'g3soft' AND b_canuse = 1 - ); - IF @AdminId IS NULL - THROW 51000, N'未找到启用的 g3soft 用户,已取消重置。', 1; - EXEC sys.sp_set_session_context @key = N'reset_admin_id', @value = @AdminId; - - DECLARE @Sql nvarchar(max) = N''; - SELECT @Sql = @Sql + N'ALTER TABLE ' - + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + N'.' - + QUOTENAME(OBJECT_NAME(parent_object_id)) + N' DROP CONSTRAINT ' - + QUOTENAME(name) + N';' - FROM sys.foreign_keys - WHERE OBJECT_NAME(parent_object_id) <> N'b_user' - OR OBJECT_NAME(referenced_object_id) <> N'b_user'; - IF @Sql <> N'' EXEC sys.sp_executesql @Sql; - - SET @Sql = N''; - SELECT @Sql = @Sql + N'DROP TABLE ' - + QUOTENAME(SCHEMA_NAME(schema_id)) + N'.' + QUOTENAME(name) + N';' - FROM sys.tables - WHERE is_ms_shipped = 0 AND name <> N'b_user'; - IF @Sql <> N'' EXEC sys.sp_executesql @Sql; - -GO - - DECLARE @AdminId bigint = TRY_CONVERT(bigint, SESSION_CONTEXT(N'reset_admin_id')); - IF @AdminId IS NULL - THROW 51001, N'重置会话缺少管理员 ID。', 1; - - CREATE TABLE dbo.s_module ( - b_id bigint NOT NULL, - b_code varchar(50) NOT NULL, - b_parent_id bigint NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_module_type varchar(20) NOT NULL, - b_route varchar(200) NULL, - b_viewtable varchar(128) NULL, - b_savetable varchar(128) NULL, - b_keyfield varchar(50) NULL, - b_orderfield varchar(500) NULL, - b_canmenu int NOT NULL CONSTRAINT DF_s_module_canmenu DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_module_xh DEFAULT (0), - CONSTRAINT PK_s_module PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_code UNIQUE (b_code) - ); - CREATE UNIQUE INDEX UX_s_module_route ON dbo.s_module (b_route) WHERE b_route IS NOT NULL; - CREATE INDEX IX_s_module_parent ON dbo.s_module (b_parent_id, b_xh, b_id); - - CREATE TABLE dbo.s_module_field ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_type varchar(30) NOT NULL, - b_default_value nvarchar(500) NULL, - b_options nvarchar(max) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field UNIQUE (b_module_id, b_field) - ); - CREATE INDEX IX_s_module_field_module ON dbo.s_module_field (b_module_id, b_canuse, b_id); - - CREATE TABLE dbo.s_module_auto_code ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_prefix nvarchar(100) NOT NULL CONSTRAINT DF_s_module_auto_code_prefix DEFAULT (N''), - b_date_format varchar(30) NOT NULL CONSTRAINT DF_s_module_auto_code_date_format DEFAULT ('yyyyMM'), - b_separator nvarchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_separator DEFAULT (N'-'), - b_sequence_width int NOT NULL CONSTRAINT DF_s_module_auto_code_sequence_width DEFAULT (5), - b_reset_type varchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_reset_type DEFAULT ('month'), - b_start_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_start_value DEFAULT (1), - b_current_period varchar(8) NULL, - b_current_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_current_value DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_auto_code_canuse DEFAULT (1), - CONSTRAINT PK_s_module_auto_code PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_auto_code_module UNIQUE (b_module_id) - ); - CREATE INDEX IX_s_module_auto_code_field ON dbo.s_module_auto_code (b_field_id); - - CREATE TABLE dbo.s_module_field_group ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_parent_id bigint NULL, - b_title nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_field_group_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_group_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field_group PRIMARY KEY (b_id) - ); - CREATE INDEX IX_s_module_field_group_module ON dbo.s_module_field_group (b_module_id, b_canuse, b_xh, b_id); - - CREATE TABLE dbo.s_module_field_list ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field_id bigint NULL, - b_group_id bigint NULL, - b_i18n varchar(150) NULL, - b_visible int NOT NULL CONSTRAINT DF_s_module_field_list_visible DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_module_field_list_xh DEFAULT (0), - b_width int NULL, - CONSTRAINT PK_s_module_field_list PRIMARY KEY (b_id) - ); - CREATE UNIQUE INDEX UX_s_module_field_list_field ON dbo.s_module_field_list (b_module_id, b_field_id) WHERE b_field_id IS NOT NULL; - CREATE INDEX IX_s_module_field_list_tree ON dbo.s_module_field_list (b_module_id, b_group_id, b_xh, b_id); - - CREATE TABLE dbo.s_module_field_edit ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_required int NOT NULL CONSTRAINT DF_s_module_field_edit_required DEFAULT (0), - b_readonly int NOT NULL CONSTRAINT DF_s_module_field_edit_readonly DEFAULT (0), - b_disabled int NOT NULL CONSTRAINT DF_s_module_field_edit_disabled DEFAULT (0), - b_visible int NOT NULL CONSTRAINT DF_s_module_field_edit_visible DEFAULT (1), - b_group_id bigint NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_field_edit_xh DEFAULT (0), - CONSTRAINT PK_s_module_field_edit PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field_edit UNIQUE (b_module_id, b_field_id) - ); - CREATE INDEX IX_s_module_field_edit_module ON dbo.s_module_field_edit (b_module_id, b_xh, b_id); - - CREATE TABLE dbo.s_module_field_query ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_component varchar(30) NOT NULL, - b_operator varchar(20) NOT NULL, - b_default_value nvarchar(500) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_field_query_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_query_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field_query PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field_query UNIQUE (b_module_id, b_field_id) - ); - CREATE INDEX IX_s_module_field_query_module ON dbo.s_module_field_query (b_module_id, b_canuse, b_xh, b_id); - - CREATE TABLE dbo.s_module_power ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_code varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_power_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_power_canuse DEFAULT (1), - CONSTRAINT PK_s_module_power PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_power UNIQUE (b_module_id, b_code) - ); - - CREATE TABLE dbo.b_user_module ( - b_id bigint NOT NULL, - b_user_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_inputuser_id bigint NOT NULL, - b_inputdatetime datetime NOT NULL CONSTRAINT DF_b_user_module_inputdatetime DEFAULT (GETDATE()), - CONSTRAINT PK_b_user_module PRIMARY KEY (b_id), - CONSTRAINT UQ_b_user_module UNIQUE (b_user_id, b_module_id) - ); - - CREATE TABLE dbo.b_user_power ( - b_id bigint NOT NULL, - b_user_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_power_id bigint NOT NULL, - b_inputuser_id bigint NOT NULL, - b_inputdatetime datetime NOT NULL CONSTRAINT DF_b_user_power_inputdatetime DEFAULT (GETDATE()), - CONSTRAINT PK_b_user_power PRIMARY KEY (b_id), - CONSTRAINT UQ_b_user_power UNIQUE (b_user_id, b_power_id) - ); - CREATE INDEX IX_b_user_power_module ON dbo.b_user_power (b_module_id, b_user_id); - - CREATE TABLE dbo.b_i18n ( - b_id bigint NOT NULL, - b_key varchar(150) NOT NULL, - b_locale varchar(20) NOT NULL, - b_value nvarchar(500) NOT NULL, - CONSTRAINT PK_b_i18n PRIMARY KEY (b_id), - CONSTRAINT UQ_b_i18n UNIQUE (b_key, b_locale) - ); - CREATE INDEX IX_b_i18n_key ON dbo.b_i18n (b_key, b_locale); - - DECLARE @SystemId bigint = 910000000000000001; - DECLARE @MetadataId bigint = 910000000000000002; - INSERT INTO dbo.s_module (b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, b_route, b_canmenu, b_canuse, b_xh) VALUES - (@SystemId, 'm_system', NULL, N'系统管理', 'module.m_system', 'directory', NULL, 1, 1, 100), - (@MetadataId, 'm_metadata', @SystemId, N'元数据配置', 'module.m_metadata', 'page', '/system/metadata', 1, 1, 10); - - INSERT INTO dbo.s_module_power (b_id, b_module_id, b_code, b_name, b_i18n, b_xh, b_canuse) VALUES - (910000000000000101, @MetadataId, 'create', N'新增', 'power.m_metadata.create', 10, 1), - (910000000000000102, @MetadataId, 'update', N'保存', 'power.m_metadata.update', 20, 1), - (910000000000000103, @MetadataId, 'delete', N'删除', 'power.m_metadata.delete', 30, 1), - (910000000000000104, @MetadataId, 'sync', N'同步字段', 'power.m_metadata.sync', 40, 1); - - INSERT INTO dbo.b_user_module (b_id, b_user_id, b_module_id, b_inputuser_id) VALUES - (910000000000000201, @AdminId, @MetadataId, @AdminId); - INSERT INTO dbo.b_user_power (b_id, b_user_id, b_module_id, b_power_id, b_inputuser_id) - SELECT 910000000000000300 + ROW_NUMBER() OVER (ORDER BY b_id), @AdminId, b_module_id, b_id, @AdminId - FROM dbo.s_module_power; - -EXEC sys.sp_set_session_context @key = N'allow_g3soft', @value = NULL; -EXEC sys.sp_set_session_context @key = N'reset_admin_id', @value = NULL; -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/001_add_i18n_type.sql b/code/fms/fms-api/config/migrations/001_add_i18n_type.sql deleted file mode 100644 index 7675c90e..00000000 --- a/code/fms/fms-api/config/migrations/001_add_i18n_type.sql +++ /dev/null @@ -1,77 +0,0 @@ -/* - 新增「多语言类型」表 dbo.s_i18n_type,并注册独立模块 m_i18n_type 与其权限、管理员授权。 - 用于维护系统支持的语言清单(简称、名称、是否默认、是否启用、排序),默认中文为内置默认语言。 - - 本脚本可重复执行:表、模块、权限均通过存在性判断避免重复播种; - 配合 000_reset_metadata.sql 使用(先跑 000 重置,再跑本脚本)即可重建。 - - 注意:b_user 表由 000 脚本保留,本脚本依赖其中 g3soft 管理员账号授于权限。 -*/ -SET NOCOUNT ON; - -BEGIN TRANSACTION; - - -- 管理员账号(与 000 脚本保持一致) - DECLARE @AdminId bigint = ( - SELECT TOP (1) b_id - FROM dbo.b_user - WHERE b_account = N'g3soft' AND b_canuse = 1 - ); - - -- 系统管理目录(000 脚本播种) - DECLARE @SystemId bigint = ( - SELECT TOP (1) b_id FROM dbo.s_module WHERE b_code = N'm_system' - ); - - -- 1. 多语言类型表 - IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE name = N's_i18n_type') - BEGIN - CREATE TABLE dbo.s_i18n_type ( - b_id bigint NOT NULL, - b_code varchar(20) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_i18n_type_canuse DEFAULT (1), - b_default int NOT NULL CONSTRAINT DF_s_i18n_type_default DEFAULT (0), - b_xh int NOT NULL CONSTRAINT DF_s_i18n_type_xh DEFAULT (0), - CONSTRAINT PK_s_i18n_type PRIMARY KEY (b_id), - CONSTRAINT UQ_s_i18n_type_code UNIQUE (b_code) - ); - CREATE INDEX IX_s_i18n_type_xh ON dbo.s_i18n_type (b_xh, b_id); - - -- 预置数据:默认中文不可删除,可选英文 - INSERT INTO dbo.s_i18n_type (b_id, b_code, b_name, b_canuse, b_default, b_xh) VALUES - (920000000000000001, N'zh-CN', N'简体中文', 1, 1, 0), - (920000000000000002, N'en-US', N'English', 1, 0, 10); - END - - -- 2. 注册模块与管理员权限(仅在模块不存在时播种) - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = N'm_i18n_type') - BEGIN - DECLARE @I18nTypeId bigint = 910000000000000003; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_canmenu, b_canuse, b_xh - ) VALUES ( - @I18nTypeId, N'm_i18n_type', @SystemId, N'多语言类型', 'module.m_i18n_type', - 'page', N'/system/i18n-type', 1, 1, 20 - ); - - INSERT INTO dbo.s_module_power (b_id, b_module_id, b_code, b_name, b_i18n, b_xh, b_canuse) VALUES - (910000000000000105, @I18nTypeId, 'create', N'新增', 'power.m_i18n_type.create', 10, 1), - (910000000000000106, @I18nTypeId, 'update', N'保存', 'power.m_i18n_type.update', 20, 1), - (910000000000000107, @I18nTypeId, 'delete', N'删除', 'power.m_i18n_type.delete', 30, 1); - - IF @AdminId IS NOT NULL - BEGIN - INSERT INTO dbo.b_user_module (b_id, b_user_id, b_module_id, b_inputuser_id) VALUES - (910000000000000202, @AdminId, @I18nTypeId, @AdminId); - - INSERT INTO dbo.b_user_power (b_id, b_user_id, b_module_id, b_power_id, b_inputuser_id) - SELECT 910000000000000303 + ROW_NUMBER() OVER (ORDER BY b_id), @AdminId, b_module_id, b_id, @AdminId - FROM dbo.s_module_power - WHERE b_module_id = @I18nTypeId; - END - END - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/002_add_system_dir.sql b/code/fms/fms-api/config/migrations/002_add_system_dir.sql deleted file mode 100644 index 936e4733..00000000 --- a/code/fms/fms-api/config/migrations/002_add_system_dir.sql +++ /dev/null @@ -1,36 +0,0 @@ -/* - 新增「系统管理」目录(m_system),并将「多语言类型」模块(m_i18n_type)挂到其下。 - - 本脚本可重复执行: - - m_system 仅在其不存在时创建; - - m_i18n_type 仅在其父级未指向系统管理目录时才更新。 - - 依赖:s_module 表已存在(由 001_add_i18n_type.sql 或业务库结构保证)。 -*/ - -SET NOCOUNT ON; -BEGIN TRANSACTION; - - -- 系统管理目录(若不存在则创建) - DECLARE @SystemId bigint = (SELECT TOP (1) b_id FROM dbo.s_module WHERE b_code = N'm_system'); - - IF @SystemId IS NULL - BEGIN - SET @SystemId = 911000000000000001; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @SystemId, N'm_system', NULL, N'系统管理', 'module.m_system', - 'directory', 1, 1, 10 - ); - END - - -- 多语言类型挂到系统管理目录 - UPDATE dbo.s_module - SET b_parent_id = @SystemId - WHERE b_code = N'm_i18n_type' - AND (b_parent_id IS NULL OR b_parent_id <> @SystemId); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/003_create_login_log.sql b/code/fms/fms-api/config/migrations/003_create_login_log.sql deleted file mode 100644 index bee10e54..00000000 --- a/code/fms/fms-api/config/migrations/003_create_login_log.sql +++ /dev/null @@ -1,44 +0,0 @@ -/* - 登录日志表 s_log_login:记录每次登录尝试(成功/失败)的客户端环境与结果,用于登录审计。 - 后端在登录时统一采集 IP、IP 归属地、浏览器/版本、操作系统/版本、设备类型、原始 User-Agent, - 并通过通用 saveobjt 接口写入本表;前端通过分页接口只读展示。 - 表名使用 s_ 前缀以区别于业务模块表(b_)。 - - 说明:表名原为 s_login_log,新系统统一更名为 s_log_login(见《FMS新系统核心表结构设计.md》 - 3.17 与 5.2 旧表映射),列结构同步更新(新增 b_login_type、b_request_id、b_trace_id, - 时间列由 b_login_time 改为 b_occurdatetime,UTC 存储)。 - - 可重复执行:通过 sys.tables 存在性判断避免重复建表。 -*/ -SET NOCOUNT ON; - -BEGIN TRANSACTION; - - IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE name = N's_log_login') - BEGIN - CREATE TABLE dbo.s_log_login ( - b_id bigint NOT NULL, - b_user_id bigint NULL, - b_login_type varchar(20) NOT NULL, -- 登录类型:password/token/oidc/ldap - b_login_result int NOT NULL CONSTRAINT DF_s_log_login_result DEFAULT (0), - b_fail_reason nvarchar(200) NULL, - b_ip varchar(50) NULL, - b_ip_location nvarchar(200) NULL, - b_browser varchar(100) NULL, - b_browser_version varchar(50) NULL, - b_os varchar(100) NULL, - b_os_version varchar(50) NULL, - b_device_type varchar(20) NULL, - b_user_agent nvarchar(max) NULL, - b_session_id varchar(50) NULL, - b_request_id varchar(64) NULL, - b_trace_id varchar(64) NULL, - b_occurdatetime datetime2 NULL CONSTRAINT DF_s_log_login_occur DEFAULT (sysutcdatetime()), - CONSTRAINT PK_s_log_login PRIMARY KEY (b_id) - ); - - CREATE INDEX IX_s_log_login_user ON dbo.s_log_login (b_user_id, b_occurdatetime DESC); - CREATE INDEX IX_s_log_login_result ON dbo.s_log_login (b_login_result, b_occurdatetime DESC); - END - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/004_rename_module_tables.sql b/code/fms/fms-api/config/migrations/004_rename_module_tables.sql deleted file mode 100644 index 9aec762d..00000000 --- a/code/fms/fms-api/config/migrations/004_rename_module_tables.sql +++ /dev/null @@ -1,163 +0,0 @@ -/* - 将新元数据结构的 b_module* 表无损重命名为 s_module*,与旧系统模块表前缀保持一致。 - 字段名 b_module_id、b_module_type 以及用户授权表 b_user_module、b_user_power 保持不变。 - - 如果数据库仍存在旧版 dbo.s_module(没有 b_code 字段),脚本会终止,避免覆盖同名旧结构。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.s_module', N'U') IS NOT NULL - AND COL_LENGTH(N'dbo.s_module', N'b_code') IS NULL - THROW 51020, N'检测到旧版 dbo.s_module,无法自动迁移新模块元数据表。', 1; - - DECLARE @Tables TABLE ( - b_old_name sysname NOT NULL, - b_new_name sysname NOT NULL, - b_xh int NOT NULL - ); - - INSERT INTO @Tables (b_old_name, b_new_name, b_xh) VALUES - (N'b_module', N's_module', 10), - (N'b_module_field', N's_module_field', 20), - (N'b_module_field_group', N's_module_field_group', 30), - (N'b_module_field_list', N's_module_field_list', 40), - (N'b_module_field_edit', N's_module_field_edit', 50), - (N'b_module_field_query', N's_module_field_query', 60), - (N'b_module_power', N's_module_power', 70); - - IF EXISTS ( - SELECT 1 - FROM @Tables - WHERE OBJECT_ID(N'dbo.' + b_old_name, N'U') IS NOT NULL - AND OBJECT_ID(N'dbo.' + b_new_name, N'U') IS NOT NULL - ) - THROW 51021, N'模块新旧表名同时存在,已取消自动重命名。', 1; - - DECLARE @OldName sysname; - DECLARE @NewName sysname; - DECLARE @QualifiedName nvarchar(517); - - DECLARE table_cursor CURSOR LOCAL FAST_FORWARD FOR - SELECT b_old_name, b_new_name - FROM @Tables - ORDER BY b_xh; - - OPEN table_cursor; - FETCH NEXT FROM table_cursor INTO @OldName, @NewName; - - WHILE @@FETCH_STATUS = 0 - BEGIN - IF OBJECT_ID(N'dbo.' + @OldName, N'U') IS NOT NULL - BEGIN - SET @QualifiedName = N'dbo.' + QUOTENAME(@OldName); - EXEC sys.sp_rename @objname = @QualifiedName, @newname = @NewName, @objtype = N'OBJECT'; - END; - FETCH NEXT FROM table_cursor INTO @OldName, @NewName; - END; - - CLOSE table_cursor; - DEALLOCATE table_cursor; - - IF OBJECT_ID(N'dbo.s_module', N'U') IS NOT NULL - BEGIN - UPDATE module - SET b_viewtable = CASE - WHEN module.b_viewtable = tables.b_old_name THEN tables.b_new_name - ELSE N'dbo.' + tables.b_new_name - END - FROM dbo.s_module AS module - INNER JOIN @Tables AS tables - ON module.b_viewtable IN (tables.b_old_name, N'dbo.' + tables.b_old_name); - - UPDATE module - SET b_savetable = CASE - WHEN module.b_savetable = tables.b_old_name THEN tables.b_new_name - ELSE N'dbo.' + tables.b_new_name - END - FROM dbo.s_module AS module - INNER JOIN @Tables AS tables - ON module.b_savetable IN (tables.b_old_name, N'dbo.' + tables.b_old_name); - END; - - DECLARE @ObjectName sysname; - DECLARE @RenamedObjectName sysname; - - DECLARE object_cursor CURSOR LOCAL FAST_FORWARD FOR - SELECT o.name, REPLACE(o.name, N'b_module', N's_module') - FROM sys.objects AS o - WHERE o.parent_object_id IN ( - OBJECT_ID(N'dbo.s_module'), - OBJECT_ID(N'dbo.s_module_field'), - OBJECT_ID(N'dbo.s_module_field_group'), - OBJECT_ID(N'dbo.s_module_field_list'), - OBJECT_ID(N'dbo.s_module_field_edit'), - OBJECT_ID(N'dbo.s_module_field_query'), - OBJECT_ID(N'dbo.s_module_power') - ) - AND o.name LIKE N'%b[_]module%' - AND NOT EXISTS ( - SELECT 1 - FROM sys.objects AS renamed - WHERE renamed.name = REPLACE(o.name, N'b_module', N's_module') - ); - - OPEN object_cursor; - FETCH NEXT FROM object_cursor INTO @ObjectName, @RenamedObjectName; - - WHILE @@FETCH_STATUS = 0 - BEGIN - SET @QualifiedName = N'dbo.' + QUOTENAME(@ObjectName); - EXEC sys.sp_rename - @objname = @QualifiedName, - @newname = @RenamedObjectName, - @objtype = N'OBJECT'; - FETCH NEXT FROM object_cursor INTO @ObjectName, @RenamedObjectName; - END; - - CLOSE object_cursor; - DEALLOCATE object_cursor; - - DECLARE @TableName sysname; - - DECLARE index_cursor CURSOR LOCAL FAST_FORWARD FOR - SELECT t.name, i.name, REPLACE(i.name, N'b_module', N's_module') - FROM sys.indexes AS i - INNER JOIN sys.tables AS t ON t.object_id = i.object_id - WHERE t.name IN ( - N's_module', - N's_module_field', - N's_module_field_group', - N's_module_field_list', - N's_module_field_edit', - N's_module_field_query', - N's_module_power' - ) - AND i.name LIKE N'%b[_]module%' - AND NOT EXISTS ( - SELECT 1 - FROM sys.indexes AS renamed - WHERE renamed.object_id = i.object_id - AND renamed.name = REPLACE(i.name, N'b_module', N's_module') - ); - - OPEN index_cursor; - FETCH NEXT FROM index_cursor INTO @TableName, @ObjectName, @RenamedObjectName; - - WHILE @@FETCH_STATUS = 0 - BEGIN - SET @QualifiedName = - N'dbo.' + QUOTENAME(@TableName) + N'.' + QUOTENAME(@ObjectName); - EXEC sys.sp_rename - @objname = @QualifiedName, - @newname = @RenamedObjectName, - @objtype = N'INDEX'; - FETCH NEXT FROM index_cursor INTO @TableName, @ObjectName, @RenamedObjectName; - END; - - CLOSE index_cursor; - DEALLOCATE index_cursor; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/005_cascade_user_power.sql b/code/fms/fms-api/config/migrations/005_cascade_user_power.sql deleted file mode 100644 index 20c1139a..00000000 --- a/code/fms/fms-api/config/migrations/005_cascade_user_power.sql +++ /dev/null @@ -1,53 +0,0 @@ -/* - 数据表之间仅保留逻辑关联: - 1. 为 b_user_power 增加模块 ID,并从权限定义回填存量数据; - 2. 删除当前数据库中的全部物理外键。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - -IF OBJECT_ID(N'dbo.b_user_power', N'U') IS NOT NULL - AND COL_LENGTH(N'dbo.b_user_power', N'b_module_id') IS NULL -BEGIN - ALTER TABLE dbo.b_user_power ADD b_module_id bigint NULL; -END; - -IF OBJECT_ID(N'dbo.b_user_power', N'U') IS NOT NULL - AND OBJECT_ID(N'dbo.s_module_power', N'U') IS NOT NULL -BEGIN - UPDATE user_power - SET b_module_id = module_power.b_module_id - FROM dbo.b_user_power AS user_power - INNER JOIN dbo.s_module_power AS module_power - ON module_power.b_id = user_power.b_power_id - WHERE user_power.b_module_id IS NULL; - - IF EXISTS (SELECT 1 FROM dbo.b_user_power WHERE b_module_id IS NULL) - THROW 51010, N'b_user_power 存在无法匹配模块的权限记录,迁移已取消。', 1; - - ALTER TABLE dbo.b_user_power ALTER COLUMN b_module_id bigint NOT NULL; - - IF NOT EXISTS ( - SELECT 1 - FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_user_power') - AND name = N'IX_b_user_power_module' - ) - CREATE INDEX IX_b_user_power_module - ON dbo.b_user_power (b_module_id, b_user_id); -END; - -DECLARE @Sql nvarchar(max) = N''; -SELECT @Sql = @Sql - + N'ALTER TABLE ' - + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + N'.' - + QUOTENAME(OBJECT_NAME(parent_object_id)) - + N' DROP CONSTRAINT ' + QUOTENAME(name) + N';' -FROM sys.foreign_keys; - -IF @Sql <> N'' - EXEC sys.sp_executesql @Sql; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/006_add_i18n_module_id.sql b/code/fms/fms-api/config/migrations/006_add_i18n_module_id.sql deleted file mode 100644 index c6c9e889..00000000 --- a/code/fms/fms-api/config/migrations/006_add_i18n_module_id.sql +++ /dev/null @@ -1,70 +0,0 @@ -/* - 为 dbo.b_i18n 增加 b_module_id 列,使多语言数据可按模块级联删除, - 解决「删除模块后 b_i18n 残留孤儿数据」的问题。 - - 本脚本可重复执行: - - 列不存在时才添加,并建索引; - - 对存量数据做一次基于键命名约定的回填(module./menu./field./power. 前缀, - 取第二段作为模块编码关联 s_module.b_code),已回填或无法匹配的行不受影响。 -*/ -SET NOCOUNT ON; - --- 第 1 批:DDL(列与索引) -BEGIN TRANSACTION; - - IF NOT EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_i18n') AND name = N'b_module_id' - ) - BEGIN - ALTER TABLE dbo.b_i18n - ADD b_module_id bigint NULL; - - CREATE INDEX IX_b_i18n_module_id ON dbo.b_i18n (b_module_id) - INCLUDE (b_key, b_locale, b_value); - END - -COMMIT TRANSACTION; -GO - --- 第 2 批:存量回填(依赖第 1 批列已存在,因此必须 GO 分隔) -SET NOCOUNT ON; - -BEGIN TRANSACTION; - - -- 键形如 module. / menu. / field.. / power.., - -- 模块编码恒为第二个以 "." 分隔的片段。 - UPDATE i - SET b_module_id = m.b_id - FROM dbo.b_i18n i - CROSS APPLY ( - SELECT - CASE - WHEN CHARINDEX(N'.', i.b_key) > 0 THEN - SUBSTRING( - i.b_key, - CHARINDEX(N'.', i.b_key) + 1, - CASE - WHEN CHARINDEX(N'.', i.b_key, CHARINDEX(N'.', i.b_key) + 1) > 0 - THEN CHARINDEX(N'.', i.b_key, CHARINDEX(N'.', i.b_key) + 1) - - CHARINDEX(N'.', i.b_key) - 1 - ELSE LEN(i.b_key) - CHARINDEX(N'.', i.b_key) - END - ) - ELSE NULL - END AS code - ) c - CROSS APPLY ( - SELECT TOP (1) sm.b_id - FROM dbo.s_module sm - WHERE sm.b_code = c.code - ) m - WHERE i.b_module_id IS NULL - AND ( - i.b_key LIKE N'module.%' - OR i.b_key LIKE N'menu.%' - OR i.b_key LIKE N'field.%' - OR i.b_key LIKE N'power.%' - ); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/007_remove_check_constraints.sql b/code/fms/fms-api/config/migrations/007_remove_check_constraints.sql deleted file mode 100644 index 20891938..00000000 --- a/code/fms/fms-api/config/migrations/007_remove_check_constraints.sql +++ /dev/null @@ -1,20 +0,0 @@ -/* 删除数据库中的 CHECK 约束。 */ -DECLARE @Sql nvarchar(max) = N''; - -SELECT @Sql = @Sql - + N'ALTER TABLE ' - + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + N'.' - + QUOTENAME(OBJECT_NAME(parent_object_id)) - + N' DROP CONSTRAINT ' + QUOTENAME(name) + N';' -FROM sys.check_constraints; - -IF @Sql <> N'' - EXEC sys.sp_executesql @Sql; - -/* 将旧的 switch 字段类型统一改为 checkbox。 */ -IF OBJECT_ID(N'dbo.s_module_field', N'U') IS NOT NULL -BEGIN - UPDATE dbo.s_module_field - SET b_type = 'checkbox' - WHERE b_type = 'switch'; -END; diff --git a/code/fms/fms-api/config/migrations/008_add_edit_visible.sql b/code/fms/fms-api/config/migrations/008_add_edit_visible.sql deleted file mode 100644 index ca69efbe..00000000 --- a/code/fms/fms-api/config/migrations/008_add_edit_visible.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* 为编辑配置增加显示开关,存量配置默认显示。 */ -SET NOCOUNT ON; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_module_field_edit') - AND name = N'b_visible' -) -BEGIN - ALTER TABLE dbo.s_module_field_edit - ADD b_visible int NOT NULL - CONSTRAINT DF_s_module_field_edit_visible DEFAULT (1) WITH VALUES; -END; diff --git a/code/fms/fms-api/config/migrations/009_add_module_auto_code.sql b/code/fms/fms-api/config/migrations/009_add_module_auto_code.sql deleted file mode 100644 index a80de0f2..00000000 --- a/code/fms/fms-api/config/migrations/009_add_module_auto_code.sql +++ /dev/null @@ -1,25 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF OBJECT_ID(N'dbo.s_module_auto_code', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_module_auto_code ( - b_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_prefix nvarchar(100) NOT NULL CONSTRAINT DF_s_module_auto_code_prefix DEFAULT (N''), - b_date_format varchar(30) NOT NULL CONSTRAINT DF_s_module_auto_code_date_format DEFAULT ('yyyyMM'), - b_separator nvarchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_separator DEFAULT (N'-'), - b_sequence_width int NOT NULL CONSTRAINT DF_s_module_auto_code_sequence_width DEFAULT (5), - b_reset_type varchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_reset_type DEFAULT ('month'), - b_start_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_start_value DEFAULT (1), - b_current_period varchar(8) NULL, - b_current_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_current_value DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_auto_code_canuse DEFAULT (1), - CONSTRAINT PK_s_module_auto_code PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_auto_code_module UNIQUE (b_module_id) - ); - - CREATE INDEX IX_s_module_auto_code_field - ON dbo.s_module_auto_code (b_field_id); -END; diff --git a/code/fms/fms-api/config/migrations/010_normalize_auto_code_rule.sql b/code/fms/fms-api/config/migrations/010_normalize_auto_code_rule.sql deleted file mode 100644 index 897b46e0..00000000 --- a/code/fms/fms-api/config/migrations/010_normalize_auto_code_rule.sql +++ /dev/null @@ -1,52 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF OBJECT_ID(N'dbo.s_module_auto_code', N'U') IS NOT NULL -BEGIN - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_prefix') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD b_prefix nvarchar(100) NULL; - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_date_format') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD b_date_format varchar(30) NULL; - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_separator') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD b_separator nvarchar(10) NULL; - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_sequence_width') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD b_sequence_width int NULL; - - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_rule_config') IS NOT NULL - BEGIN - EXEC sys.sp_executesql N' - UPDATE dbo.s_module_auto_code - SET b_prefix = COALESCE(JSON_VALUE(b_rule_config, ''$.prefix''), N''''), - b_date_format = COALESCE(JSON_VALUE(b_rule_config, ''$.dateFormat''), ''''), - b_separator = COALESCE(JSON_VALUE(b_rule_config, ''$.separator''), N''''), - b_sequence_width = COALESCE( - TRY_CONVERT(int, JSON_VALUE(b_rule_config, ''$.sequenceWidth'')), - 5 - );'; - END; - - EXEC sys.sp_executesql N' - UPDATE dbo.s_module_auto_code - SET b_prefix = COALESCE(b_prefix, N''''), - b_date_format = COALESCE(b_date_format, ''''), - b_separator = COALESCE(b_separator, N''''), - b_sequence_width = COALESCE(b_sequence_width, 5);'; - - EXEC sys.sp_executesql N' - ALTER TABLE dbo.s_module_auto_code ALTER COLUMN b_prefix nvarchar(100) NOT NULL; - ALTER TABLE dbo.s_module_auto_code ALTER COLUMN b_date_format varchar(30) NOT NULL; - ALTER TABLE dbo.s_module_auto_code ALTER COLUMN b_separator nvarchar(10) NOT NULL; - ALTER TABLE dbo.s_module_auto_code ALTER COLUMN b_sequence_width int NOT NULL;'; - - IF OBJECT_ID(N'dbo.DF_s_module_auto_code_prefix', N'D') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD CONSTRAINT DF_s_module_auto_code_prefix DEFAULT (N'') FOR b_prefix; - IF OBJECT_ID(N'dbo.DF_s_module_auto_code_date_format', N'D') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD CONSTRAINT DF_s_module_auto_code_date_format DEFAULT ('yyyyMM') FOR b_date_format; - IF OBJECT_ID(N'dbo.DF_s_module_auto_code_separator', N'D') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD CONSTRAINT DF_s_module_auto_code_separator DEFAULT (N'-') FOR b_separator; - IF OBJECT_ID(N'dbo.DF_s_module_auto_code_sequence_width', N'D') IS NULL - ALTER TABLE dbo.s_module_auto_code ADD CONSTRAINT DF_s_module_auto_code_sequence_width DEFAULT (5) FOR b_sequence_width; - - IF COL_LENGTH(N'dbo.s_module_auto_code', N'b_rule_config') IS NOT NULL - EXEC sys.sp_executesql N'ALTER TABLE dbo.s_module_auto_code DROP COLUMN b_rule_config;'; -END; diff --git a/code/fms/fms-api/config/migrations/011_migrate_othercompany.sql b/code/fms/fms-api/config/migrations/011_migrate_othercompany.sql deleted file mode 100644 index 374cbd80..00000000 --- a/code/fms/fms-api/config/migrations/011_migrate_othercompany.sql +++ /dev/null @@ -1,154 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_othercompany', N'U') IS NULL - BEGIN - CREATE TABLE dbo.b_othercompany ( - b_id varchar(50) NOT NULL, - b_pycode nvarchar(50) NULL, - b_type varchar(200) NULL, - b_name nvarchar(500) NULL, - b_shortname nvarchar(50) NULL, - b_linkman nvarchar(200) NULL, - b_phone nvarchar(500) NULL, - b_addr nvarchar(500) NULL, - b_firstlinkdate datetime NULL, - b_htno nvarchar(50) NULL, - b_htdate date NULL, - b_htexpiredate date NULL, - b_black varchar(1) NULL, - b_canuse varchar(1) NULL, - b_zl int NULL, - b_tel nvarchar(50) NULL, - b_fax nvarchar(500) NULL, - b_www nvarchar(50) NULL, - b_email nvarchar(50) NULL, - b_bankacount nvarchar(500) NULL, - b_invaccount nvarchar(500) NULL, - b_cate_id nvarchar(500) 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 nvarchar(50) NULL, - b_showcolor int NULL, - b_type_id nvarchar(200) NULL, - b_from_id nvarchar(50) NULL, - b_type1_id nvarchar(50) NULL, - b_type2_id nvarchar(50) NULL, - b_type3_id nvarchar(50) NULL, - b_type4_id nvarchar(50) NULL, - b_type5_id nvarchar(50) NULL, - b_owner_id varchar(50) NULL, - b_inputuser_id varchar(50) NULL, - b_inputdatetime datetime NULL, - b_updateuser_id varchar(50) NULL, - b_updatedatetime datetime NULL, - b_password varchar(50) 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) - ); - - 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_owner - ON dbo.b_othercompany (b_owner_id, b_id); - END; - - IF NOT EXISTS ( - SELECT 1 - FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_othercompany') - AND name = N'IX_b_othercompany_category' - ) - CREATE INDEX IX_b_othercompany_category - ON dbo.b_othercompany (b_cate_id, b_id); - - DECLARE @RebuildCategory bit = 0; - DECLARE @CategoryObjectId int = OBJECT_ID(N'dbo.b_othercompany_bmfl', N'U'); - - IF @CategoryObjectId IS NULL - SET @RebuildCategory = 1; - ELSE IF EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = @CategoryObjectId - AND name IN ( - N'mc_a', N'bm_b', N'mc_b', N'js', - N'bm_1_b', N'mc_1_b', N'bm_2_b', N'mc_2_b', - N'bm_3_b', N'mc_3_b', N'bm_4_b', N'mc_4_b', - N'bm_5_b', N'mc_5_b', N'bm_6_b', N'mc_6_b' - ) - ) - SET @RebuildCategory = 1; - ELSE IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = @CategoryObjectId - AND name = N'b_id' - AND system_type_id = TYPE_ID(N'bigint') - ) - SET @RebuildCategory = 1; - ELSE IF EXISTS ( - SELECT required.name - FROM (VALUES - (N'b_id'), (N'b_parent_id'), (N'b_code'), (N'b_name'), - (N'b_level'), (N'b_path'), (N'b_xh'), (N'b_canuse'), - (N'b_inputuser_id'), (N'b_inputdatetime'), - (N'b_updateuser_id'), (N'b_updatedatetime') - ) AS required(name) - WHERE NOT EXISTS ( - SELECT 1 - FROM sys.columns AS actual - WHERE actual.object_id = @CategoryObjectId - AND actual.name = required.name - ) - ) - SET @RebuildCategory = 1; - - IF @RebuildCategory = 1 - BEGIN - DELETE FROM dbo.b_othercompany; - - IF @CategoryObjectId IS NOT NULL - DROP TABLE dbo.b_othercompany_bmfl; - - CREATE TABLE dbo.b_othercompany_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_othercompany_bmfl_level DEFAULT (1), - b_path varchar(1000) NOT NULL, - b_xh int NOT NULL CONSTRAINT DF_b_othercompany_bmfl_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_b_othercompany_bmfl_canuse DEFAULT (1), - b_inputuser_id bigint NULL, - b_inputdatetime datetime NULL, - b_updateuser_id bigint NULL, - b_updatedatetime datetime NULL, - CONSTRAINT PK_b_othercompany_bmfl PRIMARY KEY (b_id), - 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 - ), - CONSTRAINT FK_b_othercompany_bmfl_parent FOREIGN KEY (b_parent_id) - REFERENCES dbo.b_othercompany_bmfl (b_id) - ); - - CREATE INDEX IX_b_othercompany_bmfl_parent - ON dbo.b_othercompany_bmfl (b_parent_id, b_xh, b_id); - CREATE INDEX IX_b_othercompany_bmfl_path - ON dbo.b_othercompany_bmfl (b_path, b_xh, b_id); - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/012_add_othercompany_module.sql b/code/fms/fms-api/config/migrations/012_add_othercompany_module.sql deleted file mode 100644 index 0295a305..00000000 --- a/code/fms/fms-api/config/migrations/012_add_othercompany_module.sql +++ /dev/null @@ -1,252 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF OBJECT_ID(N'dbo.b_othercompany', N'U') IS NULL - THROW 51210, N'dbo.b_othercompany does not exist. Run migration 011 first.', 1; - -BEGIN TRANSACTION; - - DECLARE @BaseId bigint = ( - SELECT TOP (1) b_id - FROM dbo.s_module - WHERE b_code = 'base' AND b_module_type = 'directory' - ORDER BY b_id - ); - IF @BaseId IS NULL - BEGIN - SET @BaseId = 920000000000001000; - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @BaseId) - THROW 51211, N'The reserved base data directory ID is already in use.', 1; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @BaseId, 'base', NULL, N'基础数据', 'menu.base', 'directory', - NULL, NULL, NULL, NULL, NULL, 1, 1, 20 - ); - END; - - DECLARE @PageId bigint = ( - SELECT TOP (1) b_id FROM dbo.s_module WHERE b_code = 'base_othercompany' - ); - IF @PageId IS NULL - BEGIN - SET @PageId = 920000000000001001; - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @PageId) - THROW 51212, N'The reserved other company page ID is already in use.', 1; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @PageId, 'base_othercompany', @BaseId, N'合作伙伴', - 'menu.base_othercompany', 'page', '/base/othercompany', - NULL, NULL, NULL, NULL, 1, 1, 10 - ); - END; - - DECLARE @DataId bigint = ( - SELECT TOP (1) b_id FROM dbo.s_module WHERE b_code = 'b_othercompany' - ); - IF @DataId IS NULL - BEGIN - SET @DataId = 920000000000001002; - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @DataId) - THROW 51213, N'The reserved other company data ID is already in use.', 1; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, 'b_othercompany', @PageId, N'合作伙伴列表', - 'module.b_othercompany', 'data', NULL, 'b_othercompany', - 'b_othercompany', 'b_id', 'b_name ASC, b_id ASC', 0, 1, 10 - ); - END; - - DECLARE @Fields TABLE ( - b_id bigint NOT NULL, - b_field varchar(50) NOT NULL, - b_name nvarchar(200) NOT NULL, - b_type varchar(30) NOT NULL, - b_xh int NOT NULL - ); - - INSERT INTO @Fields (b_id, b_field, b_name, b_type, b_xh) VALUES - (920000000000002001, 'b_id', N'系统编号', 'input', 10), - (920000000000002002, 'b_pycode', N'助记码', 'input', 20), - (920000000000002003, 'b_type', N'伙伴类型', 'input', 30), - (920000000000002004, 'b_name', N'公司全称', 'input', 40), - (920000000000002005, 'b_shortname', N'简称', 'input', 50), - (920000000000002006, 'b_linkman', N'主联系人', 'input', 60), - (920000000000002007, 'b_phone', N'联系电话', 'input', 70), - (920000000000002008, 'b_addr', N'详细地址', 'input', 80), - (920000000000002009, 'b_firstlinkdate', N'首次联系', 'datetime', 90), - (920000000000002010, 'b_htno', N'合同号', 'input', 100), - (920000000000002011, 'b_htdate', N'签订日期', 'date', 110), - (920000000000002012, 'b_htexpiredate', N'到期日期', 'date', 120), - (920000000000002013, 'b_black', N'黑名单', 'checkbox', 130), - (920000000000002014, 'b_canuse', N'启用', 'checkbox', 140), - (920000000000002015, 'b_zl', N'级别', 'number', 150), - (920000000000002016, 'b_tel', N'电话', 'input', 160), - (920000000000002017, 'b_fax', N'传真', 'input', 170), - (920000000000002018, 'b_www', N'网站', 'input', 180), - (920000000000002019, 'b_email', N'邮箱', 'input', 190), - (920000000000002020, 'b_bankacount', N'银行账号', 'input', 200), - (920000000000002021, 'b_invaccount', N'开票信息', 'input', 210), - (920000000000002022, 'b_cate_id', N'所属分类', 'input', 220), - (920000000000002023, 'b_bz1', N'备注1', 'input', 230), - (920000000000002024, 'b_bz2', N'备注2', 'input', 240), - (920000000000002025, 'b_bz3', N'备注3', 'input', 250), - (920000000000002026, 'b_bz4', N'备注4', 'input', 260), - (920000000000002027, 'b_province', N'省份', 'input', 270), - (920000000000002028, 'b_city', N'城市', 'input', 280), - (920000000000002029, 'b_area', N'区域', 'input', 290), - (920000000000002030, 'b_country', N'国家', 'input', 300), - (920000000000002031, 'b_edicode', N'EDI代码', 'input', 310), - (920000000000002032, 'b_showcolor', N'显示颜色', 'number', 320), - (920000000000002033, 'b_type_id', N'客户级别', 'input', 330), - (920000000000002034, 'b_from_id', N'客户来源', 'input', 340), - (920000000000002035, 'b_type1_id', N'分类1', 'input', 350), - (920000000000002036, 'b_type2_id', N'分类2', 'input', 360), - (920000000000002037, 'b_type3_id', N'分类3', 'input', 370), - (920000000000002038, 'b_type4_id', N'分类4', 'input', 380), - (920000000000002039, 'b_type5_id', N'分类5', 'input', 390), - (920000000000002040, 'b_owner_id', N'负责人', 'input', 400), - (920000000000002041, 'b_inputuser_id', N'录入账号', 'input', 410), - (920000000000002042, 'b_inputdatetime', N'录入时间', 'datetime', 420), - (920000000000002043, 'b_updateuser_id', N'修改账号', 'input', 430), - (920000000000002044, 'b_updatedatetime', N'修改时间', 'datetime', 440), - (920000000000002045, 'b_password', N'查询密码', 'input', 450), - (920000000000002046, 'b_state', N'审核状态', 'input', 460), - (920000000000002047, 'b_bankacount_e', N'英文银行账号', 'input', 470), - (920000000000002048, 'b_addr_e', N'英文地址', 'input', 480), - (920000000000002049, 'b_name_e', N'英文名称', 'input', 490); - - IF EXISTS ( - SELECT 1 - FROM @Fields source - JOIN dbo.s_module_field target ON target.b_id = source.b_id - WHERE target.b_module_id <> @DataId OR target.b_field <> source.b_field - ) - THROW 51214, N'A reserved other company field ID is already in use.', 1; - - INSERT INTO dbo.s_module_field ( - b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse - ) - SELECT - source.b_id, @DataId, source.b_field, source.b_name, - 'field.b_othercompany.' + source.b_field, source.b_type, 1 - FROM @Fields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field target - WHERE target.b_module_id = @DataId AND target.b_field = source.b_field - ); - - DECLARE @ListFields TABLE ( - b_id bigint NOT NULL, - b_field varchar(50) NOT NULL, - b_xh int NOT NULL, - b_width int NOT NULL - ); - INSERT INTO @ListFields (b_id, b_field, b_xh, b_width) VALUES - (920000000000003001, 'b_id', 10, 150), - (920000000000003002, 'b_name', 20, 220), - (920000000000003003, 'b_shortname', 30, 130), - (920000000000003004, 'b_pycode', 40, 100), - (920000000000003005, 'b_linkman', 50, 110), - (920000000000003006, 'b_phone', 60, 140), - (920000000000003007, 'b_type', 70, 120), - (920000000000003008, 'b_cate_id', 80, 140), - (920000000000003009, 'b_state', 90, 100), - (920000000000003010, 'b_canuse', 100, 76), - (920000000000003011, 'b_updatedatetime', 110, 150); - - IF EXISTS ( - SELECT 1 FROM @ListFields source - JOIN dbo.s_module_field_list target ON target.b_id = source.b_id - WHERE target.b_module_id <> @DataId - ) - THROW 51215, N'A reserved other company list ID is already in use.', 1; - - INSERT INTO dbo.s_module_field_list ( - b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width - ) - SELECT - source.b_id, @DataId, field.b_id, NULL, 1, source.b_xh, source.b_width - FROM @ListFields source - JOIN dbo.s_module_field field - ON field.b_module_id = @DataId AND field.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list target - WHERE target.b_module_id = @DataId AND target.b_field_id = field.b_id - ); - - DECLARE @QueryFields TABLE ( - b_id bigint NOT NULL, - b_field varchar(50) NOT NULL, - b_xh int NOT NULL - ); - INSERT INTO @QueryFields (b_id, b_field, b_xh) VALUES - (920000000000004001, 'b_name', 10), - (920000000000004002, 'b_shortname', 20), - (920000000000004003, 'b_pycode', 30), - (920000000000004004, 'b_linkman', 40), - (920000000000004005, 'b_phone', 50); - - IF EXISTS ( - SELECT 1 FROM @QueryFields source - JOIN dbo.s_module_field_query target ON target.b_id = source.b_id - WHERE target.b_module_id <> @DataId - ) - THROW 51216, N'A reserved other company query ID is already in use.', 1; - - 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 - ) - SELECT - source.b_id, @DataId, field.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @QueryFields source - JOIN dbo.s_module_field field - ON field.b_module_id = @DataId AND field.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query target - WHERE target.b_module_id = @DataId AND target.b_field_id = field.b_id - ); - - DECLARE @Powers TABLE ( - b_id bigint NOT NULL, - b_code varchar(50) NOT NULL, - b_name nvarchar(200) NOT NULL, - b_xh int NOT NULL - ); - INSERT INTO @Powers (b_id, b_code, b_name, b_xh) VALUES - (920000000000005001, 'create', N'新增', 10), - (920000000000005002, 'update', N'修改', 20), - (920000000000005003, 'delete', N'删除', 30); - - IF EXISTS ( - SELECT 1 FROM @Powers source - JOIN dbo.s_module_power target ON target.b_id = source.b_id - WHERE target.b_module_id <> @PageId OR target.b_code <> source.b_code - ) - THROW 51217, N'A reserved other company power ID is already in use.', 1; - - INSERT INTO dbo.s_module_power ( - b_id, b_module_id, b_code, b_name, b_i18n, b_xh, b_canuse - ) - SELECT - source.b_id, @PageId, source.b_code, source.b_name, - 'power.base_othercompany.' + source.b_code, source.b_xh, 1 - FROM @Powers source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_power target - WHERE target.b_module_id = @PageId AND target.b_code = source.b_code - ); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/013_drop_bmfl_bcode.sql b/code/fms/fms-api/config/migrations/013_drop_bmfl_bcode.sql deleted file mode 100644 index 4e854388..00000000 --- a/code/fms/fms-api/config/migrations/013_drop_bmfl_bcode.sql +++ /dev/null @@ -1,20 +0,0 @@ --- 删除 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; diff --git a/code/fms/fms-api/config/migrations/014_migrate_contact.sql b/code/fms/fms-api/config/migrations/014_migrate_contact.sql deleted file mode 100644 index f294cfd8..00000000 --- a/code/fms/fms-api/config/migrations/014_migrate_contact.sql +++ /dev/null @@ -1,125 +0,0 @@ -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; diff --git a/code/fms/fms-api/config/migrations/015_normalize_existing_business_tables.sql b/code/fms/fms-api/config/migrations/015_normalize_existing_business_tables.sql deleted file mode 100644 index f62a1f8d..00000000 --- a/code/fms/fms-api/config/migrations/015_normalize_existing_business_tables.sql +++ /dev/null @@ -1,244 +0,0 @@ -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; -'; diff --git a/code/fms/fms-api/config/migrations/016_create_base_tables.sql b/code/fms/fms-api/config/migrations/016_create_base_tables.sql deleted file mode 100644 index 43994e56..00000000 --- a/code/fms/fms-api/config/migrations/016_create_base_tables.sql +++ /dev/null @@ -1,746 +0,0 @@ -/* 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_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_i18n varchar(150) NULL, - b_node_type varchar(20) NOT NULL CONSTRAINT [DF_b_other_bmfl_node_type] DEFAULT ('category'), - b_module_code varchar(100) 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 [CK_b_other_bmfl_node_type] CHECK (b_node_type IN ('category', 'module')), - CONSTRAINT [CK_b_other_bmfl_module_ref] CHECK ( - (b_node_type = 'category' AND b_module_code IS NULL) - OR (b_node_type = 'module' AND b_module_code IS NOT NULL AND LEN(LTRIM(RTRIM(b_module_code))) > 0) - ), - 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_module] ON dbo.[b_other_bmfl] (b_node_type, b_module_code); - 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; diff --git a/code/fms/fms-api/config/migrations/017_create_contract_file_tables.sql b/code/fms/fms-api/config/migrations/017_create_contract_file_tables.sql deleted file mode 100644 index 593414f7..00000000 --- a/code/fms/fms-api/config/migrations/017_create_contract_file_tables.sql +++ /dev/null @@ -1,214 +0,0 @@ -/* 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; diff --git a/code/fms/fms-api/config/migrations/018_create_business_tables.sql b/code/fms/fms-api/config/migrations/018_create_business_tables.sql deleted file mode 100644 index 522c5d26..00000000 --- a/code/fms/fms-api/config/migrations/018_create_business_tables.sql +++ /dev/null @@ -1,396 +0,0 @@ -/* 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; diff --git a/code/fms/fms-api/config/migrations/019_create_finance_tables.sql b/code/fms/fms-api/config/migrations/019_create_finance_tables.sql deleted file mode 100644 index fc12d2fb..00000000 --- a/code/fms/fms-api/config/migrations/019_create_finance_tables.sql +++ /dev/null @@ -1,362 +0,0 @@ -/* 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; diff --git a/code/fms/fms-api/config/migrations/020_create_oa_tables.sql b/code/fms/fms-api/config/migrations/020_create_oa_tables.sql deleted file mode 100644 index 87e4ab75..00000000 --- a/code/fms/fms-api/config/migrations/020_create_oa_tables.sql +++ /dev/null @@ -1,179 +0,0 @@ -/* 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; diff --git a/code/fms/fms-api/config/migrations/021_create_business_views.sql b/code/fms/fms-api/config/migrations/021_create_business_views.sql deleted file mode 100644 index fd2b80a8..00000000 --- a/code/fms/fms-api/config/migrations/021_create_business_views.sql +++ /dev/null @@ -1,539 +0,0 @@ -/* 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; diff --git a/code/fms/fms-api/config/migrations/022_add_otherdata_module.sql b/code/fms/fms-api/config/migrations/022_add_otherdata_module.sql deleted file mode 100644 index 3f73ffda..00000000 --- a/code/fms/fms-api/config/migrations/022_add_otherdata_module.sql +++ /dev/null @@ -1,454 +0,0 @@ -/* 通用 "其他数据" 模块配置。左侧树,右侧按数据模块加载不同表格(独立列定义)。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - /* ========================================================================= - 1. 确定 base 目录 - ========================================================================= */ - DECLARE @BaseId bigint = ( - SELECT TOP (1) b_id - FROM dbo.s_module - WHERE b_code = 'base' AND b_module_type = 'directory' - ORDER BY b_id - ); - IF @BaseId IS NULL - THROW 52001, N'base directory not found. Run 012 / 002 migration first.', 1; - - /* ========================================================================= - 2. 创建 page 模块: base_otherdata - ========================================================================= */ - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = 'm_base_otherdata') - AND NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = 'base_otherdata') - BEGIN - UPDATE dbo.s_module - SET b_code = 'base_otherdata' - WHERE b_code = 'm_base_otherdata'; - END; - - DECLARE @PageId bigint = 920000000000001100; - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = 'base_otherdata') - BEGIN - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @PageId) - THROW 52002, N'The reserved otherdata page ID is already in use.', 1; - - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @PageId, 'base_otherdata', @BaseId, N'其他数据', - 'menu.base_otherdata', 'page', '/base/otherdata', - NULL, NULL, NULL, NULL, 1, 1, 30 - ); - END - ELSE - SET @PageId = (SELECT b_id FROM dbo.s_module WHERE b_code = 'base_otherdata'); - - /* ========================================================================= - 3. 创建 data 模块辅助存储过程 - ========================================================================= */ - DECLARE @DataId bigint; - DECLARE @DataCode varchar(100); - DECLARE @DataName nvarchar(200); - DECLARE @ViewTable varchar(100); - - /* ========================================================================= - 4. 港口 d_other_port → b_port - ========================================================================= */ - SET @DataCode = 'd_other_port'; - SET @DataName = N'港口'; - SET @ViewTable = 'b_port'; - SET @DataId = 920000000000001101; - - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @DataId) - THROW 52003, N'The reserved port data ID is already in use.', 1; - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, @DataName, - 'module.d_other_port', 'data', NULL, - 'b_port', 'b_port', 'b_id', 'b_code ASC', 0, 1, 10 - ); - END - ELSE - SET @DataId = (SELECT b_id FROM dbo.s_module WHERE b_code = @DataCode); - - -- 港口字段 - DECLARE @PortFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @PortFields VALUES - (920000000000010101, 'b_id', N'系统编号', 'input', 10), - (920000000000010102, 'b_code', N'港口代码', 'input', 20), - (920000000000010103, 'b_name_c', N'中文名称', 'input', 30), - (920000000000010104, 'b_name_e', N'英文名称', 'input', 40), - (920000000000010105, 'b_country', N'国家', 'input', 50), - (920000000000010106, 'b_oceanline', N'航线', 'input', 60), - (920000000000010107, 'b_edicode', N'EDI代码', 'input', 70), - (920000000000010108, 'b_bz', N'备注', 'input', 80), - (920000000000010109, 'b_tz', N'特征', 'input', 90); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.d_other_port.' + source.b_field, source.b_type, 1 - FROM @PortFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_module_id = @DataId AND t.b_field = source.b_field - ); - - -- 港口列表列 - DECLARE @PortList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @PortList VALUES - (920000000000020101, 'b_code', 10, 120), - (920000000000020102, 'b_name_c', 20, 150), - (920000000000020103, 'b_name_e', 30, 180), - (920000000000020104, 'b_country', 40, 120), - (920000000000020105, 'b_oceanline', 50, 120), - (920000000000020106, 'b_edicode', 60, 120); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, NULL, 1, source.b_xh, source.b_width - FROM @PortList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - -- 港口查询字段 - DECLARE @PortQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @PortQuery VALUES - (920000000000030101, 'b_code', 10), - (920000000000030102, 'b_name_c', 20), - (920000000000030103, 'b_name_e', 30); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @PortQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - /* ========================================================================= - 5. 城市 d_other_city → b_city - ========================================================================= */ - SET @DataCode = 'd_other_city'; - SET @DataName = N'城市'; - SET @ViewTable = 'b_city'; - SET @DataId = 920000000000001102; - - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @DataId) - THROW 52004, N'The reserved city data ID is already in use.', 1; - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, @DataName, - 'module.d_other_city', 'data', NULL, - 'b_city', 'b_city', 'b_id', 'b_code ASC', 0, 1, 20 - ); - END - ELSE - SET @DataId = (SELECT b_id FROM dbo.s_module WHERE b_code = @DataCode); - - -- 城市字段 - DECLARE @CityFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @CityFields VALUES - (920000000000010201, 'b_id', N'系统编号', 'input', 10), - (920000000000010202, 'b_code', N'城市代码', 'input', 20), - (920000000000010203, 'b_name_c', N'中文名称', 'input', 30), - (920000000000010204, 'b_name_e', N'英文名称', 'input', 40), - (920000000000010205, 'b_country_name_c', N'国家(中)', 'input', 50), - (920000000000010206, 'b_country_name_e', N'国家(英)', 'input', 60), - (920000000000010207, 'b_bz', N'备注', 'input', 70); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.d_other_city.' + source.b_field, source.b_type, 1 - FROM @CityFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_module_id = @DataId AND t.b_field = source.b_field - ); - - -- 城市列表列 - DECLARE @CityList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @CityList VALUES - (920000000000020201, 'b_code', 10, 120), - (920000000000020202, 'b_name_c', 20, 150), - (920000000000020203, 'b_name_e', 30, 180), - (920000000000020204, 'b_country_name_c', 40, 140), - (920000000000020205, 'b_country_name_e', 50, 140); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, NULL, 1, source.b_xh, source.b_width - FROM @CityList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - -- 城市查询字段 - DECLARE @CityQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @CityQuery VALUES - (920000000000030201, 'b_code', 10), - (920000000000030202, 'b_name_c', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @CityQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - /* ========================================================================= - 6. 币种 d_other_money → b_money - ========================================================================= */ - SET @DataCode = 'd_other_money'; - SET @DataName = N'币种'; - SET @ViewTable = 'b_money'; - SET @DataId = 920000000000001103; - - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @DataId) - THROW 52005, N'The reserved money data ID is already in use.', 1; - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, @DataName, - 'module.d_other_money', 'data', NULL, - 'b_money', 'b_money', 'b_id', 'b_code ASC', 0, 1, 30 - ); - END - ELSE - SET @DataId = (SELECT b_id FROM dbo.s_module WHERE b_code = @DataCode); - - -- 币种字段 - DECLARE @MoneyFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @MoneyFields VALUES - (920000000000010301, 'b_id', N'系统编号', 'input', 10), - (920000000000010302, 'b_code', N'币种代码', 'input', 20), - (920000000000010303, 'b_name', N'名称', 'input', 30), - (920000000000010304, 'b_edicode', N'EDI代码', 'input', 40), - (920000000000010305, 'b_symbol', N'符号', 'input', 50), - (920000000000010306, 'b_hl', N'汇率', 'number', 60), - (920000000000010307, 'b_isconvert', N'可兑换', 'checkbox', 70), - (920000000000010308, 'b_canuse', N'启用', 'checkbox', 80), - (920000000000010309, 'b_xh', N'排序', 'number', 90), - (920000000000010310, 'b_bz', N'备注', 'input', 100); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.d_other_money.' + source.b_field, source.b_type, 1 - FROM @MoneyFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_module_id = @DataId AND t.b_field = source.b_field - ); - - -- 币种列表列 - DECLARE @MoneyList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @MoneyList VALUES - (920000000000020301, 'b_code', 10, 120), - (920000000000020302, 'b_name', 20, 150), - (920000000000020303, 'b_edicode', 30, 120), - (920000000000020304, 'b_symbol', 40, 80), - (920000000000020305, 'b_hl', 50, 120), - (920000000000020306, 'b_canuse', 60, 80); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, NULL, 1, source.b_xh, source.b_width - FROM @MoneyList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - -- 币种查询字段 - DECLARE @MoneyQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @MoneyQuery VALUES - (920000000000030301, 'b_code', 10), - (920000000000030302, 'b_name', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @MoneyQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - /* ========================================================================= - 7. 航线 d_other_oceanline → b_oceanline - ========================================================================= */ - SET @DataCode = 'd_other_oceanline'; - SET @DataName = N'航线'; - SET @ViewTable = 'b_oceanline'; - SET @DataId = 920000000000001104; - - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_id = @DataId) - THROW 52006, N'The reserved oceanline data ID is already in use.', 1; - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, - b_route, b_viewtable, b_savetable, b_keyfield, b_orderfield, - b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, @DataName, - 'module.d_other_oceanline', 'data', NULL, - 'b_oceanline', 'b_oceanline', 'b_id', 'b_code ASC', 0, 1, 40 - ); - END - ELSE - SET @DataId = (SELECT b_id FROM dbo.s_module WHERE b_code = @DataCode); - - -- 航线字段 - DECLARE @OceanlineFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @OceanlineFields VALUES - (920000000000010401, 'b_id', N'系统编号', 'input', 10), - (920000000000010402, 'b_code', N'航线代码', 'input', 20), - (920000000000010403, 'b_name', N'名称', 'input', 30), - (920000000000010404, 'b_edicode', N'EDI代码', 'input', 40), - (920000000000010405, 'b_bz', N'备注', 'input', 50); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.d_other_oceanline.' + source.b_field, source.b_type, 1 - FROM @OceanlineFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_module_id = @DataId AND t.b_field = source.b_field - ); - - -- 航线列表列 - DECLARE @OceanlineList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @OceanlineList VALUES - (920000000000020401, 'b_code', 10, 120), - (920000000000020402, 'b_name', 20, 180), - (920000000000020403, 'b_edicode', 30, 120); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, NULL, 1, source.b_xh, source.b_width - FROM @OceanlineList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - -- 航线查询字段 - DECLARE @OceanlineQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @OceanlineQuery VALUES - (920000000000030401, 'b_code', 10), - (920000000000030402, 'b_name', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @OceanlineQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_module_id = @DataId AND t.b_field_id = f.b_id - ); - - /* ========================================================================= - 8. s_module_power 权限 - ========================================================================= */ - DECLARE @Powers TABLE (b_id bigint NOT NULL, b_code varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_xh int NOT NULL); - INSERT INTO @Powers VALUES - (920000000000040101, 'create', N'新增', 10), - (920000000000040102, 'update', N'修改', 20), - (920000000000040103, 'delete', N'删除', 30); - - INSERT INTO dbo.s_module_power (b_id, b_module_id, b_code, b_name, b_i18n, b_xh, b_canuse) - SELECT source.b_id, @PageId, source.b_code, source.b_name, - 'power.base_otherdata.' + source.b_code, source.b_xh, 1 - FROM @Powers source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_power t - WHERE t.b_module_id = @PageId AND t.b_code = source.b_code - ); - - /* ========================================================================= - 9. Mock 测试数据 - ========================================================================= */ - -- 港口 - IF NOT EXISTS (SELECT 1 FROM dbo.b_port WHERE b_code = 'CNSHA') - INSERT INTO dbo.b_port (b_id, b_code, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz) VALUES - (920000000000110001, 'CNSHA', N'上海港', 'Shanghai', N'中国', 'ASIA', 'CNSHA', NULL, NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_port WHERE b_code = 'CNNGB') - INSERT INTO dbo.b_port (b_id, b_code, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz) VALUES - (920000000000110002, 'CNNGB', N'宁波港', 'Ningbo', N'中国', 'ASIA', 'CNNGB', NULL, NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_port WHERE b_code = 'HKKG') - INSERT INTO dbo.b_port (b_id, b_code, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz) VALUES - (920000000000110003, 'HKKG', N'香港港', 'Hong Kong', N'中国', 'ASIA', 'HKKG', NULL, NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_port WHERE b_code = 'USLAX') - INSERT INTO dbo.b_port (b_id, b_code, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz) VALUES - (920000000000110004, 'USLAX', N'洛杉矶港', 'Los Angeles', N'美国', 'AMERICA', 'USLAX', NULL, NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_port WHERE b_code = 'NLRTM') - INSERT INTO dbo.b_port (b_id, b_code, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz) VALUES - (920000000000110005, 'NLRTM', N'鹿特丹港', 'Rotterdam', N'荷兰', 'EUROPE', 'NLRTM', NULL, NULL); - - -- 城市 - IF NOT EXISTS (SELECT 1 FROM dbo.b_city WHERE b_code = 'SH') - INSERT INTO dbo.b_city (b_id, b_code, b_name_c, b_name_e, b_country_name_c, b_country_name_e, b_bz) VALUES - (920000000000110101, 'SH', N'上海', 'Shanghai', N'中国', 'China', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_city WHERE b_code = 'SZ') - INSERT INTO dbo.b_city (b_id, b_code, b_name_c, b_name_e, b_country_name_c, b_country_name_e, b_bz) VALUES - (920000000000110102, 'SZ', N'深圳', 'Shenzhen', N'中国', 'China', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_city WHERE b_code = 'NJ') - INSERT INTO dbo.b_city (b_id, b_code, b_name_c, b_name_e, b_country_name_c, b_country_name_e, b_bz) VALUES - (920000000000110103, 'NJ', N'南京', 'Nanjing', N'中国', 'China', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_city WHERE b_code = 'NY') - INSERT INTO dbo.b_city (b_id, b_code, b_name_c, b_name_e, b_country_name_c, b_country_name_e, b_bz) VALUES - (920000000000110104, 'NY', N'纽约', 'New York', N'美国', 'America', NULL); - - -- 币种 - IF NOT EXISTS (SELECT 1 FROM dbo.b_money WHERE b_code = 'CNY') - INSERT INTO dbo.b_money (b_id, b_code, b_name, b_edicode, b_symbol, b_hl, b_isconvert, b_canuse, b_xh) VALUES - (920000000000110201, 'CNY', N'人民币', 'CNY', N'¥', 1.0000, '1', 1, 10); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_money WHERE b_code = 'USD') - INSERT INTO dbo.b_money (b_id, b_code, b_name, b_edicode, b_symbol, b_hl, b_isconvert, b_canuse, b_xh) VALUES - (920000000000110202, 'USD', N'美元', 'USD', N'$', 7.2500, '1', 1, 20); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_money WHERE b_code = 'EUR') - INSERT INTO dbo.b_money (b_id, b_code, b_name, b_edicode, b_symbol, b_hl, b_isconvert, b_canuse, b_xh) VALUES - (920000000000110203, 'EUR', N'欧元', 'EUR', N'€', 7.8900, '1', 1, 30); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_money WHERE b_code = 'JPY') - INSERT INTO dbo.b_money (b_id, b_code, b_name, b_edicode, b_symbol, b_hl, b_isconvert, b_canuse, b_xh) VALUES - (920000000000110204, 'JPY', N'日元', 'JPY', N'¥', 0.0490, '1', 1, 40); - - -- 航线 - IF NOT EXISTS (SELECT 1 FROM dbo.b_oceanline WHERE b_code = 'ASIA') - INSERT INTO dbo.b_oceanline (b_id, b_code, b_name, b_edicode, b_bz) VALUES - (920000000000110301, 'ASIA', N'亚洲线', 'ASIA', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_oceanline WHERE b_code = 'EUROPE') - INSERT INTO dbo.b_oceanline (b_id, b_code, b_name, b_edicode, b_bz) VALUES - (920000000000110302, 'EUROPE', N'欧洲线', 'EUROPE', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_oceanline WHERE b_code = 'AMERICA') - INSERT INTO dbo.b_oceanline (b_id, b_code, b_name, b_edicode, b_bz) VALUES - (920000000000110303, 'AMERICA', N'美洲线', 'AMERICA', NULL); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_oceanline WHERE b_code = 'AFRICA') - INSERT INTO dbo.b_oceanline (b_id, b_code, b_name, b_edicode, b_bz) VALUES - (920000000000110304, 'AFRICA', N'非洲线', 'AFRICA', NULL); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/023_add_otherdata_bmfl_module_code.sql b/code/fms/fms-api/config/migrations/023_add_otherdata_bmfl_module_code.sql deleted file mode 100644 index a5d21c9a..00000000 --- a/code/fms/fms-api/config/migrations/023_add_otherdata_bmfl_module_code.sql +++ /dev/null @@ -1,175 +0,0 @@ -/* 其他数据分类树采用引用设计: - category 节点只维护树结构和分类名称,module 节点只引用 s_module.data 的 b_code。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NULL - THROW 52301, N'dbo.b_other_bmfl does not exist.', 1; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_node_type') IS NULL - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_node_type varchar(20) NOT NULL - CONSTRAINT [DF_b_other_bmfl_node_type] DEFAULT ('category') WITH VALUES; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_module_code') IS NULL - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_module_code varchar(100) NULL; - END; - - IF EXISTS ( - SELECT 1 FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'IX_b_other_bmfl_path' - ) - DROP INDEX [IX_b_other_bmfl_path] ON dbo.b_other_bmfl; - - DECLARE @DropSql nvarchar(max); - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_level') IS NOT NULL - BEGIN - SET @DropSql = NULL; - SELECT @DropSql = N'ALTER TABLE dbo.b_other_bmfl DROP CONSTRAINT [' + REPLACE(dc.name, N']', N']]') + N']' - FROM sys.default_constraints dc - JOIN sys.columns c - ON c.object_id = dc.parent_object_id - AND c.column_id = dc.parent_column_id - WHERE dc.parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND c.name = N'b_level'; - IF @DropSql IS NOT NULL EXEC sys.sp_executesql @DropSql; - - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_other_bmfl DROP COLUMN b_level'; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_path') IS NOT NULL - BEGIN - SET @DropSql = NULL; - SELECT @DropSql = N'ALTER TABLE dbo.b_other_bmfl DROP CONSTRAINT [' + REPLACE(dc.name, N']', N']]') + N']' - FROM sys.default_constraints dc - JOIN sys.columns c - ON c.object_id = dc.parent_object_id - AND c.column_id = dc.parent_column_id - WHERE dc.parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND c.name = N'b_path'; - IF @DropSql IS NOT NULL EXEC sys.sp_executesql @DropSql; - - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_other_bmfl DROP COLUMN b_path'; - END; - - EXEC sys.sp_executesql N' - UPDATE dbo.b_other_bmfl - SET b_module_code = NULLIF(LTRIM(RTRIM(COALESCE(b_module_code, ''''))), ''''); - - UPDATE dbo.b_other_bmfl - SET b_node_type = CASE - WHEN b_module_code IS NULL THEN ''category'' - ELSE ''module'' - END'; - - IF NOT EXISTS ( - SELECT 1 FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'CK_b_other_bmfl_node_type' - ) - EXEC sys.sp_executesql N' - ALTER TABLE dbo.b_other_bmfl - ADD CONSTRAINT [CK_b_other_bmfl_node_type] - CHECK (b_node_type IN (''category'', ''module''))'; - - IF NOT EXISTS ( - SELECT 1 FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'CK_b_other_bmfl_module_ref' - ) - EXEC sys.sp_executesql N' - ALTER TABLE dbo.b_other_bmfl - ADD CONSTRAINT [CK_b_other_bmfl_module_ref] - CHECK ( - (b_node_type = ''category'' AND b_module_code IS NULL) - OR ( - b_node_type = ''module'' - AND b_module_code IS NOT NULL - AND LEN(LTRIM(RTRIM(b_module_code))) > 0 - ) - )'; - - IF NOT EXISTS ( - SELECT 1 FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'IX_b_other_bmfl_module' - ) - EXEC sys.sp_executesql N' - CREATE INDEX [IX_b_other_bmfl_module] ON dbo.b_other_bmfl (b_node_type, b_module_code)'; - - EXEC sys.sp_executesql N' - DECLARE @CatBasic bigint = 930000000000000101; - DECLARE @CatFinance bigint = 930000000000000102; - DECLARE @CatLogistics bigint = 930000000000000103; - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatBasic) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES (@CatBasic, NULL, N''基础信息'', ''category'', NULL, 10, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatFinance) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES (@CatFinance, NULL, N''财务信息'', ''category'', NULL, 20, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatLogistics) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES (@CatLogistics, NULL, N''物流信息'', ''category'', NULL, 30, 1); - - DECLARE @NodePort bigint = 930000000000000201; - DECLARE @NodeCity bigint = 930000000000000202; - DECLARE @NodeMoney bigint = 930000000000000203; - DECLARE @NodeOceanline bigint = 930000000000000204; - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodePort) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES ( - @NodePort, @CatBasic, N''港口'', ''module'', ''d_other_port'', 10, 1 - ); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeCity) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES ( - @NodeCity, @CatBasic, N''城市'', ''module'', ''d_other_city'', 20, 1 - ); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeMoney) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES ( - @NodeMoney, @CatFinance, N''币种'', ''module'', ''d_other_money'', 10, 1 - ); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeOceanline) - INSERT INTO dbo.b_other_bmfl ( - b_id, b_parent_id, b_name, b_node_type, b_module_code, - b_xh, b_canuse - ) - VALUES ( - @NodeOceanline, @CatLogistics, N''航线'', ''module'', ''d_other_oceanline'', 10, 1 - );'; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/024_drop_unused_b_other.sql b/code/fms/fms-api/config/migrations/024_drop_unused_b_other.sql deleted file mode 100644 index d1cfd599..00000000 --- a/code/fms/fms-api/config/migrations/024_drop_unused_b_other.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* 删除未使用的旧版其他数据通用表。当前其他数据使用 b_other_bmfl 分类树 - 关联 s_module 数据节点,并由具体基础表保存数据。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_other', N'U') IS NOT NULL - BEGIN - DROP TABLE dbo.b_other; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/025_add_otherdata_category_i18n.sql b/code/fms/fms-api/config/migrations/025_add_otherdata_category_i18n.sql deleted file mode 100644 index ed706f41..00000000 --- a/code/fms/fms-api/config/migrations/025_add_otherdata_category_i18n.sql +++ /dev/null @@ -1,29 +0,0 @@ -/* 为其他数据分类树增加多语言键。分类节点归属 base_otherdata 页面模块; - 数据节点名称继续使用其关联 s_module data 节点的 b_i18n。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NOT NULL - BEGIN - IF NOT EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') AND name = 'b_i18n' - ) - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_i18n varchar(150) NULL; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_module_code') IS NOT NULL - BEGIN - EXEC sys.sp_executesql N' - UPDATE dbo.b_other_bmfl - SET b_i18n = ''category.base_otherdata.'' + CAST(b_id AS varchar(30)) - WHERE b_module_code IS NULL - AND (b_i18n IS NULL OR b_i18n = '''')'; - END; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/026_normalize_otherdata_tree_reference.sql b/code/fms/fms-api/config/migrations/026_normalize_otherdata_tree_reference.sql deleted file mode 100644 index c09c2677..00000000 --- a/code/fms/fms-api/config/migrations/026_normalize_otherdata_tree_reference.sql +++ /dev/null @@ -1,132 +0,0 @@ -/* 规范其他数据分类树为引用设计。 - 仅修正目标库元数据结构,不从模块管理同步树节点。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = 'm_base_otherdata') - AND NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = 'base_otherdata') - BEGIN - UPDATE dbo.s_module - SET b_code = 'base_otherdata' - WHERE b_code = 'm_base_otherdata'; - END; - - IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NOT NULL - BEGIN - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_node_type') IS NULL - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_node_type varchar(20) NOT NULL - CONSTRAINT [DF_b_other_bmfl_node_type] DEFAULT ('category') WITH VALUES; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_module_code') IS NULL - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_module_code varchar(100) NULL; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_i18n') IS NULL - BEGIN - ALTER TABLE dbo.b_other_bmfl - ADD b_i18n varchar(150) NULL; - END; - - IF EXISTS ( - SELECT 1 FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'IX_b_other_bmfl_path' - ) - DROP INDEX [IX_b_other_bmfl_path] ON dbo.b_other_bmfl; - - EXEC sys.sp_executesql N' - UPDATE dbo.b_other_bmfl - SET b_module_code = NULLIF(LTRIM(RTRIM(COALESCE(b_module_code, ''''))), ''''); - - UPDATE dbo.b_other_bmfl - SET b_node_type = CASE - WHEN b_module_code IS NULL THEN ''category'' - ELSE ''module'' - END; - - UPDATE dbo.b_other_bmfl - SET b_i18n = ''category.base_otherdata.'' + CAST(b_id AS varchar(30)) - WHERE b_node_type = ''category'' - AND (b_i18n IS NULL OR b_i18n = ''''); - - UPDATE dbo.b_other_bmfl - SET b_i18n = REPLACE(b_i18n, ''category.m_base_otherdata.'', ''category.base_otherdata.'') - WHERE b_node_type = ''category'' - AND b_i18n LIKE ''category.m_base_otherdata.%'''; - - IF NOT EXISTS ( - SELECT 1 FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'CK_b_other_bmfl_node_type' - ) - EXEC sys.sp_executesql N' - ALTER TABLE dbo.b_other_bmfl - ADD CONSTRAINT [CK_b_other_bmfl_node_type] - CHECK (b_node_type IN (''category'', ''module''))'; - - IF NOT EXISTS ( - SELECT 1 FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'CK_b_other_bmfl_module_ref' - ) - EXEC sys.sp_executesql N' - ALTER TABLE dbo.b_other_bmfl - ADD CONSTRAINT [CK_b_other_bmfl_module_ref] - CHECK ( - (b_node_type = ''category'' AND b_module_code IS NULL) - OR ( - b_node_type = ''module'' - AND b_module_code IS NOT NULL - AND LEN(LTRIM(RTRIM(b_module_code))) > 0 - ) - )'; - - IF NOT EXISTS ( - SELECT 1 FROM sys.indexes - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND name = N'IX_b_other_bmfl_module' - ) - EXEC sys.sp_executesql N' - CREATE INDEX [IX_b_other_bmfl_module] ON dbo.b_other_bmfl (b_node_type, b_module_code)'; - - DECLARE @DropSql nvarchar(max); - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_level') IS NOT NULL - BEGIN - SET @DropSql = NULL; - SELECT @DropSql = N'ALTER TABLE dbo.b_other_bmfl DROP CONSTRAINT [' + REPLACE(dc.name, N']', N']]') + N']' - FROM sys.default_constraints dc - JOIN sys.columns c - ON c.object_id = dc.parent_object_id - AND c.column_id = dc.parent_column_id - WHERE dc.parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND c.name = N'b_level'; - IF @DropSql IS NOT NULL EXEC sys.sp_executesql @DropSql; - - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_other_bmfl DROP COLUMN b_level'; - END; - - IF COL_LENGTH(N'dbo.b_other_bmfl', N'b_path') IS NOT NULL - BEGIN - SET @DropSql = NULL; - SELECT @DropSql = N'ALTER TABLE dbo.b_other_bmfl DROP CONSTRAINT [' + REPLACE(dc.name, N']', N']]') + N']' - FROM sys.default_constraints dc - JOIN sys.columns c - ON c.object_id = dc.parent_object_id - AND c.column_id = dc.parent_column_id - WHERE dc.parent_object_id = OBJECT_ID(N'dbo.b_other_bmfl') - AND c.name = N'b_path'; - IF @DropSql IS NOT NULL EXEC sys.sp_executesql @DropSql; - - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_other_bmfl DROP COLUMN b_path'; - END; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/027_add_othercompany_category_i18n.sql b/code/fms/fms-api/config/migrations/027_add_othercompany_category_i18n.sql deleted file mode 100644 index d7904e9e..00000000 --- a/code/fms/fms-api/config/migrations/027_add_othercompany_category_i18n.sql +++ /dev/null @@ -1,24 +0,0 @@ -/* 为合作伙伴分类树增加多语言键。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_othercompany_bmfl', N'U') IS NOT NULL - BEGIN - IF NOT EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_othercompany_bmfl') AND name = 'b_i18n' - ) - BEGIN - ALTER TABLE dbo.b_othercompany_bmfl - ADD b_i18n varchar(150) NULL; - END; - - EXEC sys.sp_executesql N' - UPDATE dbo.b_othercompany_bmfl - SET b_i18n = ''category.base_othercompany.'' + CAST(b_id AS varchar(30)) - WHERE b_i18n IS NULL OR b_i18n = ''''''; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/028_add_edit_width.sql b/code/fms/fms-api/config/migrations/028_add_edit_width.sql deleted file mode 100644 index 1f516304..00000000 --- a/code/fms/fms-api/config/migrations/028_add_edit_width.sql +++ /dev/null @@ -1,13 +0,0 @@ -/* 为编辑配置增加列宽字段,支持可编辑表格保存栏位设置。 */ -SET NOCOUNT ON; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_module_field_edit') - AND name = N'b_width' -) -BEGIN - ALTER TABLE dbo.s_module_field_edit - ADD b_width int NULL; -END; diff --git a/code/fms/fms-api/config/migrations/029_add_otherdata_sort_field.sql b/code/fms/fms-api/config/migrations/029_add_otherdata_sort_field.sql deleted file mode 100644 index 18e51e94..00000000 --- a/code/fms/fms-api/config/migrations/029_add_otherdata_sort_field.sql +++ /dev/null @@ -1,63 +0,0 @@ -/* 为"其他数据"可编辑表格的行拖拽排序提供排序字段。 - 1) b_port / b_city / b_oceanline 补 b_xh 列(b_money 已有); - 2) 按 b_code 顺序为 b_xh 为空的存量数据初始化排序值(幂等,不覆盖已有排序); - 3) 对应数据模块默认排序改为 b_xh ASC,使拖拽后的顺序在刷新后保持。 */ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - /* ================= 1. b_port ================= */ - IF COL_LENGTH(N'dbo.b_port', N'b_xh') IS NULL - BEGIN - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_port ADD b_xh int NULL;'; - END; - - EXEC sys.sp_executesql N' - WITH numbered AS ( - SELECT b_id, b_xh, ROW_NUMBER() OVER (ORDER BY b_code ASC, b_id ASC) AS row_no - FROM dbo.b_port - WHERE b_xh IS NULL - ) - UPDATE numbered SET b_xh = row_no * 10;'; - - /* ================= 2. b_city ================= */ - IF COL_LENGTH(N'dbo.b_city', N'b_xh') IS NULL - BEGIN - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_city ADD b_xh int NULL;'; - END; - - EXEC sys.sp_executesql N' - WITH numbered AS ( - SELECT b_id, b_xh, ROW_NUMBER() OVER (ORDER BY b_code ASC, b_id ASC) AS row_no - FROM dbo.b_city - WHERE b_xh IS NULL - ) - UPDATE numbered SET b_xh = row_no * 10;'; - - /* ================= 3. b_oceanline ================= */ - IF COL_LENGTH(N'dbo.b_oceanline', N'b_xh') IS NULL - BEGIN - EXEC sys.sp_executesql N'ALTER TABLE dbo.b_oceanline ADD b_xh int NULL;'; - END; - - EXEC sys.sp_executesql N' - WITH numbered AS ( - SELECT b_id, b_xh, ROW_NUMBER() OVER (ORDER BY b_code ASC, b_id ASC) AS row_no - FROM dbo.b_oceanline - WHERE b_xh IS NULL - ) - UPDATE numbered SET b_xh = row_no * 10;'; - - /* ================= 4. 模块默认排序切到 b_xh ================= - base_otherdata 页面下的所有数据模块统一按 b_xh 排序, - 拖拽后的顺序在刷新后才会保持。 */ - UPDATE m - SET m.b_orderfield = N'b_xh ASC' - FROM dbo.s_module m - INNER JOIN dbo.s_module p - ON p.b_id = m.b_parent_id - AND p.b_code = N'base_otherdata' - WHERE m.b_module_type = N'data'; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/030_drop_otherdata_category_i18n.sql b/code/fms/fms-api/config/migrations/030_drop_otherdata_category_i18n.sql deleted file mode 100644 index b4eb7947..00000000 --- a/code/fms/fms-api/config/migrations/030_drop_otherdata_category_i18n.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* 移除其他数据分类树的多语言列。此前通过 025 添加,现决定暂不做多语言。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NOT NULL - BEGIN - IF EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_other_bmfl') AND name = 'b_i18n' - ) - BEGIN - ALTER TABLE dbo.b_other_bmfl - DROP COLUMN b_i18n; - END; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/031_drop_othercompany_category_i18n.sql b/code/fms/fms-api/config/migrations/031_drop_othercompany_category_i18n.sql deleted file mode 100644 index 5bd0e94f..00000000 --- a/code/fms/fms-api/config/migrations/031_drop_othercompany_category_i18n.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* 移除合作伙伴分类树的多语言列。此前通过 027 添加,现决定暂不做多语言。*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_othercompany_bmfl', N'U') IS NOT NULL - BEGIN - IF EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_othercompany_bmfl') AND name = 'b_i18n' - ) - BEGIN - ALTER TABLE dbo.b_othercompany_bmfl - DROP COLUMN b_i18n; - END; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/032_rebuild_otherdata.sql b/code/fms/fms-api/config/migrations/032_rebuild_otherdata.sql deleted file mode 100644 index 6044171d..00000000 --- a/code/fms/fms-api/config/migrations/032_rebuild_otherdata.sql +++ /dev/null @@ -1,384 +0,0 @@ -/* 032_rebuild_otherdata.sql — 重做"其他数据"子系统迁移 - * - * 背景:此前用 OtherDataMigration 工具迁移产生错误结果—— - * 1. 分类树被连跑 7 次产生重复分支; - * 2. 只有 b_port 一个数据模块,城市/币种/航线模块缺失; - * 3. b_port 真实数据未迁入(旧 b_id 含中文港口名,b_code 列 SQL_Latin1 排序规则存不下, - * 插入时中文转 '?' 触发 UQ_b_port_b_code 唯一索引冲突而整表回滚)。 - * - * 本脚本(前置:026、030 已应用,b_other_bmfl 已无 b_level/b_path/b_i18n 列): - * 1. 清空并重建分类树(基础信息/财务信息/物流信息 + 4 个数据节点,模块编码沿用表名 b_*); - * 2. 移除 022 的 mock 占位数据; - * 3. b_port.b_code 排序规则改为 Chinese_PRC_CI_AS,迁入 193 条真实港口数据; - * 4. 补建 b_city / b_money / b_oceanline 数据模块(字段/列表/查询/编辑配置); - * 5. 回填 b_city / b_oceanline 迁移数据的 b_xh 排序值。 - * - * 幂等:可重复执行。 - */ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - /* ========================================================================= - 1. 清理错乱的分类树 - ========================================================================= */ - DELETE FROM dbo.b_other_bmfl; - - /* ========================================================================= - 2. 移除 022 mock 占位数据(按预留 ID 段精确删除) - ========================================================================= */ - DELETE FROM dbo.b_port WHERE b_id BETWEEN 920000000000110001 AND 920000000000110005; - DELETE FROM dbo.b_city WHERE b_id BETWEEN 920000000000110101 AND 920000000000110104; - DELETE FROM dbo.b_money WHERE b_id BETWEEN 920000000000110201 AND 920000000000110204; - DELETE FROM dbo.b_oceanline WHERE b_id BETWEEN 920000000000110301 AND 920000000000110304; - - /* ========================================================================= - 3. b_port.b_code 排序规则改为 Chinese_PRC_CI_AS(容纳中文港口代码) - (需先删依赖该列的唯一索引,改完再重建) - ========================================================================= */ - IF EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.b_port') - AND name = N'b_code' - AND collation_name <> N'Chinese_PRC_CI_AS' - ) - BEGIN - IF EXISTS ( - SELECT 1 FROM sys.key_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_port') - AND name = N'UQ_b_port_b_code' - ) - ALTER TABLE dbo.b_port DROP CONSTRAINT [UQ_b_port_b_code]; - - ALTER TABLE dbo.b_port ALTER COLUMN b_code varchar(50) COLLATE Chinese_PRC_CI_AS NOT NULL; - - IF NOT EXISTS ( - SELECT 1 FROM sys.key_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.b_port') - AND name = N'UQ_b_port_b_code' - ) - ALTER TABLE dbo.b_port ADD CONSTRAINT [UQ_b_port_b_code] UNIQUE NONCLUSTERED (b_code); - END; - -GO - - /* ========================================================================= - 4. 迁移 b_port 真实数据(193 行,含中文代码) - ========================================================================= */ - INSERT INTO dbo.b_port ( - b_id, b_name_c, b_name_e, b_country, b_oceanline, b_edicode, b_bz, b_tz, - b_inputdatetime, b_code, b_xh - ) - SELECT 920000000000110005 + ROW_NUMBER() OVER (ORDER BY LTRIM(RTRIM(old.b_id))), - old.b_name_c, old.b_name_e, old.b_country, old.b_oceanline, old.b_edicode, - old.b_bz, old.b_tz, - SYSDATETIME(), - LTRIM(RTRIM(old.b_id)), - ROW_NUMBER() OVER (ORDER BY LTRIM(RTRIM(old.b_id))) * 10 - FROM G3HY2025.dbo.b_port old - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.b_port new WHERE new.b_code = LTRIM(RTRIM(old.b_id)) - ); - - /* ========================================================================= - 5. 补建数据模块 b_city / b_money / b_oceanline - ========================================================================= */ - DECLARE @PageId bigint = 920000000000001100; - DECLARE @DataId bigint; - DECLARE @DataCode varchar(100); - - /* ---- 5.1 b_city(城市) ---- */ - SET @DataCode = 'b_city'; - SET @DataId = 920000000000001102; - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, b_route, - b_viewtable, b_savetable, b_keyfield, b_orderfield, b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, N'城市', 'module.b_city', 'data', NULL, - 'b_city', 'b_city', 'b_id', 'b_xh ASC', 0, 1, 20 - ); - END - - DECLARE @CityFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @CityFields VALUES - (920000000000010201, 'b_id', N'系统编号', 'input', 10), - (920000000000010202, 'b_code', N'城市代码', 'input', 20), - (920000000000010203, 'b_name_c', N'中文名称', 'input', 30), - (920000000000010204, 'b_name_e', N'英文名称', 'input', 40), - (920000000000010205, 'b_country_name_c', N'国家(中)', 'input', 50), - (920000000000010206, 'b_country_name_e', N'国家(英)', 'input', 60), - (920000000000010207, 'b_bz', N'备注', 'input', 70); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.b_city.' + source.b_field, source.b_type, 1 - FROM @CityFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_id = source.b_id - ); - - DECLARE @CityList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @CityList VALUES - (920000000000020201, 'b_code', 10, 120), - (920000000000020202, 'b_name_c', 20, 150), - (920000000000020203, 'b_name_e', 30, 180), - (920000000000020204, 'b_country_name_c', 40, 140), - (920000000000020205, 'b_country_name_e', 50, 140); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, 'field.b_city.' + f.b_field, 1, source.b_xh, source.b_width - FROM @CityList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_id = source.b_id - ); - - DECLARE @CityQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @CityQuery VALUES - (920000000000030201, 'b_code', 10), - (920000000000030202, 'b_name_c', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @CityQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_id = source.b_id - ); - - DECLARE @CityEdit TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_visible int NOT NULL, b_xh int NOT NULL); - INSERT INTO @CityEdit VALUES - (920000000000050201, 'b_id', 0, 10), - (920000000000050202, 'b_code', 1, 20), - (920000000000050203, 'b_name_c', 1, 30), - (920000000000050204, 'b_name_e', 1, 40), - (920000000000050205, 'b_country_name_c', 1, 50), - (920000000000050206, 'b_country_name_e', 1, 60), - (920000000000050207, 'b_bz', 1, 70); - - INSERT INTO dbo.s_module_field_edit (b_id, b_module_id, b_field_id, b_required, b_readonly, b_disabled, b_xh, b_visible) - SELECT source.b_id, @DataId, f.b_id, 0, 0, 0, source.b_xh, source.b_visible - FROM @CityEdit source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_edit t WHERE t.b_id = source.b_id - ); - - /* ---- 5.2 b_money(币种) ---- */ - SET @DataCode = 'b_money'; - SET @DataId = 920000000000001103; - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, b_route, - b_viewtable, b_savetable, b_keyfield, b_orderfield, b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, N'币种', 'module.b_money', 'data', NULL, - 'b_money', 'b_money', 'b_id', 'b_xh ASC', 0, 1, 30 - ); - END - - DECLARE @MoneyFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @MoneyFields VALUES - (920000000000010301, 'b_id', N'系统编号', 'input', 10), - (920000000000010302, 'b_code', N'币种代码', 'input', 20), - (920000000000010303, 'b_name', N'名称', 'input', 30), - (920000000000010304, 'b_edicode', N'EDI代码', 'input', 40), - (920000000000010305, 'b_symbol', N'符号', 'input', 50), - (920000000000010306, 'b_hl', N'汇率', 'number', 60), - (920000000000010307, 'b_isconvert', N'可兑换', 'checkbox', 70), - (920000000000010308, 'b_canuse', N'启用', 'checkbox', 80), - (920000000000010309, 'b_xh', N'排序', 'number', 90), - (920000000000010310, 'b_bz', N'备注', 'input', 100); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.b_money.' + source.b_field, source.b_type, 1 - FROM @MoneyFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_id = source.b_id - ); - - DECLARE @MoneyList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @MoneyList VALUES - (920000000000020301, 'b_code', 10, 120), - (920000000000020302, 'b_name', 20, 150), - (920000000000020303, 'b_edicode', 30, 120), - (920000000000020304, 'b_symbol', 40, 80), - (920000000000020305, 'b_hl', 50, 120), - (920000000000020306, 'b_canuse', 60, 80); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, 'field.b_money.' + f.b_field, 1, source.b_xh, source.b_width - FROM @MoneyList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_id = source.b_id - ); - - DECLARE @MoneyQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @MoneyQuery VALUES - (920000000000030301, 'b_code', 10), - (920000000000030302, 'b_name', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @MoneyQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_id = source.b_id - ); - - DECLARE @MoneyEdit TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_visible int NOT NULL, b_xh int NOT NULL); - INSERT INTO @MoneyEdit VALUES - (920000000000050301, 'b_id', 0, 10), - (920000000000050302, 'b_code', 1, 20), - (920000000000050303, 'b_name', 1, 30), - (920000000000050304, 'b_edicode', 1, 40), - (920000000000050305, 'b_symbol', 1, 50), - (920000000000050306, 'b_hl', 1, 60), - (920000000000050307, 'b_isconvert', 1, 70), - (920000000000050308, 'b_canuse', 1, 80), - (920000000000050309, 'b_xh', 1, 90), - (920000000000050310, 'b_bz', 1, 100); - - INSERT INTO dbo.s_module_field_edit (b_id, b_module_id, b_field_id, b_required, b_readonly, b_disabled, b_xh, b_visible) - SELECT source.b_id, @DataId, f.b_id, 0, 0, 0, source.b_xh, source.b_visible - FROM @MoneyEdit source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_edit t WHERE t.b_id = source.b_id - ); - - /* ---- 5.3 b_oceanline(航线) ---- */ - SET @DataCode = 'b_oceanline'; - SET @DataId = 920000000000001104; - IF NOT EXISTS (SELECT 1 FROM dbo.s_module WHERE b_code = @DataCode) - BEGIN - INSERT INTO dbo.s_module ( - b_id, b_code, b_parent_id, b_name, b_i18n, b_module_type, b_route, - b_viewtable, b_savetable, b_keyfield, b_orderfield, b_canmenu, b_canuse, b_xh - ) VALUES ( - @DataId, @DataCode, @PageId, N'航线', 'module.b_oceanline', 'data', NULL, - 'b_oceanline', 'b_oceanline', 'b_id', 'b_xh ASC', 0, 1, 40 - ); - END - - DECLARE @OceanFields TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_name nvarchar(200) NOT NULL, b_type varchar(30) NOT NULL, b_xh int NOT NULL); - INSERT INTO @OceanFields VALUES - (920000000000010401, 'b_id', N'系统编号', 'input', 10), - (920000000000010402, 'b_code', N'航线代码', 'input', 20), - (920000000000010403, 'b_name', N'名称', 'input', 30), - (920000000000010404, 'b_edicode', N'EDI代码', 'input', 40), - (920000000000010405, 'b_bz', N'备注', 'input', 50); - - INSERT INTO dbo.s_module_field (b_id, b_module_id, b_field, b_name, b_i18n, b_type, b_canuse) - SELECT source.b_id, @DataId, source.b_field, source.b_name, - 'field.b_oceanline.' + source.b_field, source.b_type, 1 - FROM @OceanFields source - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field t WHERE t.b_id = source.b_id - ); - - DECLARE @OceanList TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL, b_width int NOT NULL); - INSERT INTO @OceanList VALUES - (920000000000020401, 'b_code', 10, 120), - (920000000000020402, 'b_name', 20, 180), - (920000000000020403, 'b_edicode', 30, 120); - - INSERT INTO dbo.s_module_field_list (b_id, b_module_id, b_field_id, b_i18n, b_visible, b_xh, b_width) - SELECT source.b_id, @DataId, f.b_id, 'field.b_oceanline.' + f.b_field, 1, source.b_xh, source.b_width - FROM @OceanList source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_list t WHERE t.b_id = source.b_id - ); - - DECLARE @OceanQuery TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_xh int NOT NULL); - INSERT INTO @OceanQuery VALUES - (920000000000030401, 'b_code', 10), - (920000000000030402, 'b_name', 20); - - 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) - SELECT source.b_id, @DataId, f.b_id, 'input', 'like', NULL, source.b_xh, 1 - FROM @OceanQuery source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_query t WHERE t.b_id = source.b_id - ); - - DECLARE @OceanEdit TABLE (b_id bigint NOT NULL, b_field varchar(50) NOT NULL, b_visible int NOT NULL, b_xh int NOT NULL); - INSERT INTO @OceanEdit VALUES - (920000000000050401, 'b_id', 0, 10), - (920000000000050402, 'b_code', 1, 20), - (920000000000050403, 'b_name', 1, 30), - (920000000000050404, 'b_edicode', 1, 40), - (920000000000050405, 'b_bz', 1, 50); - - INSERT INTO dbo.s_module_field_edit (b_id, b_module_id, b_field_id, b_required, b_readonly, b_disabled, b_xh, b_visible) - SELECT source.b_id, @DataId, f.b_id, 0, 0, 0, source.b_xh, source.b_visible - FROM @OceanEdit source - JOIN dbo.s_module_field f ON f.b_module_id = @DataId AND f.b_field = source.b_field - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_module_field_edit t WHERE t.b_id = source.b_id - ); - - /* ========================================================================= - 6. 回填 b_city / b_oceanline 迁移数据的 b_xh(b_money 旧库自带 b_xh) - ========================================================================= */ - WITH numbered AS ( - SELECT b_id, b_xh, ROW_NUMBER() OVER (ORDER BY b_code ASC, b_id ASC) AS row_no - FROM dbo.b_city WHERE b_xh IS NULL - ) - UPDATE numbered SET b_xh = row_no * 10; - - WITH numbered AS ( - SELECT b_id, b_xh, ROW_NUMBER() OVER (ORDER BY b_code ASC, b_id ASC) AS row_no - FROM dbo.b_oceanline WHERE b_xh IS NULL - ) - UPDATE numbered SET b_xh = row_no * 10; - - /* ========================================================================= - 7. 重建分类树(引用设计:category 仅结构,module 引用 s_module.b_code) - ========================================================================= */ - DECLARE @CatBasic bigint = 930000000000000101; - DECLARE @CatFinance bigint = 930000000000000102; - DECLARE @CatLogistics bigint = 930000000000000103; - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatBasic) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@CatBasic, NULL, N'基础信息', 'category', NULL, 10, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatFinance) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@CatFinance, NULL, N'财务信息', 'category', NULL, 20, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @CatLogistics) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@CatLogistics, NULL, N'物流信息', 'category', NULL, 30, 1); - - DECLARE @NodePort bigint = 930000000000000201; - DECLARE @NodeCity bigint = 930000000000000202; - DECLARE @NodeMoney bigint = 930000000000000203; - DECLARE @NodeOceanline bigint = 930000000000000204; - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodePort) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@NodePort, @CatBasic, N'港口', 'module', 'b_port', 10, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeCity) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@NodeCity, @CatBasic, N'城市', 'module', 'b_city', 20, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeMoney) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@NodeMoney, @CatFinance, N'币种', 'module', 'b_money', 10, 1); - - IF NOT EXISTS (SELECT 1 FROM dbo.b_other_bmfl WHERE b_id = @NodeOceanline) - INSERT INTO dbo.b_other_bmfl (b_id, b_parent_id, b_name, b_node_type, b_module_code, b_xh, b_canuse) - VALUES (@NodeOceanline, @CatLogistics, N'航线', 'module', 'b_oceanline', 10, 1); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/033_drop_unused_b_other_bmfl.sql b/code/fms/fms-api/config/migrations/033_drop_unused_b_other_bmfl.sql deleted file mode 100644 index 5afa5723..00000000 --- a/code/fms/fms-api/config/migrations/033_drop_unused_b_other_bmfl.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* 删除 b_other_bmfl 分类树表。 - 其他数据分类树已完全迁移至 s_module(b_module_type = 'data_category'), - 前端不再读写此表。 */ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.b_other_bmfl', N'U') IS NOT NULL - BEGIN - DROP TABLE dbo.b_other_bmfl; - END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/035_restore_simple_module_tree.sql b/code/fms/fms-api/config/migrations/035_restore_simple_module_tree.sql deleted file mode 100644 index f821f1e0..00000000 --- a/code/fms/fms-api/config/migrations/035_restore_simple_module_tree.sql +++ /dev/null @@ -1,563 +0,0 @@ -/* - Restore the pre-2026-08-03 module model and keep one intentional extension: - s_module.b_module_type = 'data_category'. Data categories belong to a page or - another data category, so arbitrary nesting needs no separate composition model. - - This script is executed by ApplySimpleModuleRestore in one JDBC transaction. -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS' - THROW 53500, N'This migration can only run against the FMS database.', 1; - -IF OBJECT_ID(N'dbo.s_module_page', N'U') IS NULL - THROW 53501, N'The split module architecture is not installed.', 1; - -IF COL_LENGTH(N'dbo.s_module', N'b_parent_id') IS NOT NULL - THROW 53502, N'The simple module tree is already installed.', 1; - -IF OBJECT_ID(N'dbo.z_restore_module', N'U') IS NOT NULL - THROW 53503, N'A previous restore staging table exists.', 1; - -DECLARE @AdminId bigint = ( - SELECT TOP (1) b_id - FROM dbo.b_user - WHERE b_canuse = 1 - ORDER BY CASE WHEN b_account = N'g3soft' THEN 0 ELSE 1 END, b_id -); -IF @AdminId IS NULL - THROW 53504, N'Enabled administrator user not found.', 1; - -CREATE TABLE dbo.z_restore_module ( - b_id bigint NOT NULL, - b_code varchar(50) NOT NULL, - b_parent_id bigint NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_module_type varchar(20) NOT NULL, - b_route varchar(200) NULL, - b_viewtable varchar(128) NULL, - b_savetable varchar(128) NULL, - b_keyfield varchar(50) NULL, - b_orderfield varchar(500) NULL, - b_canmenu int NOT NULL, - b_canuse int NOT NULL, - b_xh int NOT NULL -); - -CREATE TABLE dbo.z_restore_i18n_map ( - b_new_key varchar(150) NOT NULL, - b_old_key varchar(150) NOT NULL, - CONSTRAINT PK_z_restore_i18n_map PRIMARY KEY (b_new_key) -); - -/* Menu directories remain ordinary tree nodes. */ -INSERT INTO dbo.z_restore_module -SELECT node.b_id, node.b_code, node.b_parent_id, node.b_name, - 'menu.' + node.b_code, 'directory', NULL, NULL, NULL, NULL, NULL, - node.b_canmenu, node.b_canuse, node.b_xh -FROM dbo.s_function_node AS node -WHERE node.b_node_type = 'directory'; - -INSERT INTO dbo.z_restore_i18n_map -SELECT node.b_i18n, 'menu.' + node.b_code -FROM dbo.s_function_node AS node -WHERE node.b_node_type = 'directory'; - -/* A page module and its function entry collapse back into one row. */ -;WITH page_entry AS ( - SELECT node.*, - ROW_NUMBER() OVER (PARTITION BY node.b_module_id ORDER BY node.b_id) AS rn - FROM dbo.s_function_node AS node - WHERE node.b_node_type = 'entry' -) -INSERT INTO dbo.z_restore_module -SELECT module_row.b_id, module_row.b_code, entry.b_parent_id, module_row.b_name, - 'menu.' + module_row.b_code, 'page', page_row.b_route, - NULL, NULL, NULL, NULL, - COALESCE(entry.b_canmenu, 0), - CASE WHEN module_row.b_canuse = 1 AND COALESCE(entry.b_canuse, 1) = 1 THEN 1 ELSE 0 END, - COALESCE(entry.b_xh, 0) -FROM dbo.s_module AS module_row -INNER JOIN dbo.s_module_page AS page_row ON page_row.b_module_id = module_row.b_id -LEFT JOIN page_entry AS entry ON entry.b_module_id = module_row.b_id AND entry.rn = 1; - -INSERT INTO dbo.z_restore_i18n_map -SELECT module_row.b_i18n, 'menu.' + module_row.b_code -FROM dbo.s_module AS module_row -WHERE module_row.b_module_type = 'page'; - -/* Page containers become lightweight, arbitrarily nested data categories. */ -INSERT INTO dbo.z_restore_module -SELECT node.b_id, - CONVERT(varchar(50), 'data_category_' + CONVERT(varchar(30), node.b_id)), - COALESCE(node.b_parent_id, node.b_page_module_id), - node.b_name, - CONVERT(varchar(150), 'menu.data_category_' + CONVERT(varchar(30), node.b_id)), - 'data_category', NULL, NULL, NULL, NULL, NULL, - 0, node.b_canuse, node.b_xh -FROM dbo.s_page_node AS node -WHERE node.b_node_type IN ('group', 'tab', 'section'); - -INSERT INTO dbo.z_restore_i18n_map -SELECT node.b_i18n, - CONVERT(varchar(150), 'menu.data_category_' + CONVERT(varchar(30), node.b_id)) -FROM dbo.s_page_node AS node -WHERE node.b_node_type IN ('group', 'tab', 'section'); - -/* A data module has one owning parent again. Prefer its first active page reference. */ -;WITH module_reference AS ( - SELECT node.*, - ROW_NUMBER() OVER ( - PARTITION BY node.b_module_id - ORDER BY node.b_canuse DESC, node.b_page_module_id, node.b_xh, node.b_id - ) AS rn - FROM dbo.s_page_node AS node - WHERE node.b_node_type = 'module_ref' AND node.b_module_type = 'data' -) -INSERT INTO dbo.z_restore_module -SELECT module_row.b_id, module_row.b_code, - COALESCE(reference.b_parent_id, reference.b_page_module_id), - module_row.b_name, 'module.' + module_row.b_code, 'data', NULL, - data_row.b_viewtable, data_row.b_savetable, data_row.b_keyfield, data_row.b_orderfield, - 0, module_row.b_canuse, COALESCE(reference.b_xh, 0) -FROM dbo.s_module AS module_row -INNER JOIN dbo.s_module_data AS data_row ON data_row.b_module_id = module_row.b_id -LEFT JOIN module_reference AS reference - ON reference.b_module_id = module_row.b_id AND reference.rn = 1; - -INSERT INTO dbo.z_restore_i18n_map -SELECT module_row.b_i18n, 'module.' + module_row.b_code -FROM dbo.s_module AS module_row -WHERE module_row.b_module_type = 'data'; - -IF EXISTS ( - SELECT b_id FROM dbo.z_restore_module GROUP BY b_id HAVING COUNT(*) > 1 -) - THROW 53505, N'Module IDs collide while restoring the simple tree.', 1; - -IF EXISTS ( - SELECT b_code FROM dbo.z_restore_module GROUP BY b_code HAVING COUNT(*) > 1 -) - THROW 53506, N'Module codes collide while restoring the simple tree.', 1; - -IF EXISTS ( - SELECT 1 - FROM dbo.z_restore_module AS child - LEFT JOIN dbo.z_restore_module AS parent_row ON parent_row.b_id = child.b_parent_id - WHERE child.b_parent_id IS NOT NULL AND parent_row.b_id IS NULL -) - THROW 53507, N'A restored module has an unresolved parent.', 1; - -/* Flatten the default Profile back to the original module-owned configuration. */ -SELECT field_row.b_id, field_row.b_module_id, field_row.b_field, field_row.b_name, - CONVERT(varchar(150), 'field.' + module_row.b_code + '.' + field_row.b_field) AS b_i18n, - field_row.b_type, field_row.b_default_value, field_row.b_options, field_row.b_canuse -INTO dbo.z_restore_module_field -FROM dbo.s_module_field AS field_row -INNER JOIN dbo.s_module AS module_row ON module_row.b_id = field_row.b_module_id; - -INSERT INTO dbo.z_restore_i18n_map -SELECT field_row.b_i18n, - CONVERT(varchar(150), 'field.' + module_row.b_code + '.' + field_row.b_field) -FROM dbo.s_module_field AS field_row -INNER JOIN dbo.s_module AS module_row ON module_row.b_id = field_row.b_module_id; - -SELECT auto_row.b_id, auto_row.b_module_id, auto_row.b_field_id, auto_row.b_prefix, - auto_row.b_date_format, auto_row.b_separator, auto_row.b_sequence_width, - auto_row.b_reset_type, auto_row.b_start_value, auto_row.b_current_period, - auto_row.b_current_value, auto_row.b_canuse -INTO dbo.z_restore_module_auto_code -FROM dbo.s_module_auto_code AS auto_row; - -SELECT group_row.b_id, group_row.b_module_id, group_row.b_parent_id, - group_row.b_name AS b_title, group_row.b_i18n, group_row.b_xh, group_row.b_canuse -INTO dbo.z_restore_module_field_group -FROM dbo.s_module_layout_group AS group_row -INNER JOIN dbo.s_module_profile AS profile_row - ON profile_row.b_id = group_row.b_profile_id AND profile_row.b_default = 1; - -SELECT config.b_id, config.b_module_id, config.b_field_id, config.b_group_id, - config.b_i18n, config.b_visible, config.b_xh, config.b_width -INTO dbo.z_restore_module_field_list -FROM dbo.s_module_field_list AS config -INNER JOIN dbo.s_module_profile AS profile_row - ON profile_row.b_id = config.b_profile_id AND profile_row.b_default = 1; - -SELECT config.b_id, config.b_module_id, config.b_field_id, config.b_required, - config.b_readonly, config.b_disabled, config.b_visible, config.b_group_id, config.b_xh -INTO dbo.z_restore_module_field_edit -FROM dbo.s_module_field_form AS config -INNER JOIN dbo.s_module_profile AS profile_row - ON profile_row.b_id = config.b_profile_id AND profile_row.b_default = 1; - -SELECT config.b_id, config.b_module_id, config.b_field_id, config.b_component, - config.b_operator, config.b_default_value, config.b_xh, config.b_canuse -INTO dbo.z_restore_module_field_query -FROM dbo.s_module_field_query AS config -INNER JOIN dbo.s_module_profile AS profile_row - ON profile_row.b_id = config.b_profile_id AND profile_row.b_default = 1; - -SELECT action_row.b_id, action_row.b_module_id, action_row.b_code, action_row.b_name, - CONVERT(varchar(150), 'power.' + module_row.b_code + '.' + action_row.b_code) AS b_i18n, - action_row.b_xh, action_row.b_canuse -INTO dbo.z_restore_module_power -FROM dbo.s_module_action AS action_row -INNER JOIN dbo.s_module AS module_row ON module_row.b_id = action_row.b_module_id; - -INSERT INTO dbo.z_restore_i18n_map -SELECT action_row.b_i18n, - CONVERT(varchar(150), 'power.' + module_row.b_code + '.' + action_row.b_code) -FROM dbo.s_module_action AS action_row -INNER JOIN dbo.s_module AS module_row ON module_row.b_id = action_row.b_module_id; - -CREATE TABLE dbo.z_restore_user_module ( - b_user_id bigint NOT NULL, - b_module_id bigint NOT NULL, - CONSTRAINT PK_z_restore_user_module PRIMARY KEY (b_user_id, b_module_id) -); - -;WITH allowed_page AS ( - SELECT permission.b_user_id, node.b_module_id - FROM dbo.v_s_user_function_permission AS permission - INNER JOIN dbo.s_function_node AS node - ON node.b_id = permission.b_function_node_id AND node.b_node_type = 'entry' -), allowed_module AS ( - SELECT b_user_id, b_module_id FROM allowed_page - UNION - SELECT page_permission.b_user_id, page_node.b_module_id - FROM allowed_page AS page_permission - INNER JOIN dbo.s_page_node AS page_node - ON page_node.b_page_module_id = page_permission.b_module_id - AND page_node.b_node_type = 'module_ref' - LEFT JOIN dbo.v_s_user_page_permission AS node_permission - ON node_permission.b_user_id = page_permission.b_user_id - AND node_permission.b_page_node_id = page_node.b_id - WHERE page_node.b_permission_required = 0 OR node_permission.b_page_node_id IS NOT NULL - UNION - SELECT permission.b_user_id, action_row.b_module_id - FROM dbo.v_s_user_action_permission AS permission - INNER JOIN dbo.s_module_action AS action_row ON action_row.b_id = permission.b_action_id -) -INSERT INTO dbo.z_restore_user_module (b_user_id, b_module_id) -SELECT DISTINCT allowed_module.b_user_id, allowed_module.b_module_id -FROM allowed_module -INNER JOIN dbo.z_restore_module AS module_row ON module_row.b_id = allowed_module.b_module_id; - -SELECT permission.b_user_id, action_row.b_module_id, permission.b_action_id AS b_power_id -INTO dbo.z_restore_user_power -FROM dbo.v_s_user_action_permission AS permission -INNER JOIN dbo.s_module_action AS action_row ON action_row.b_id = permission.b_action_id -INNER JOIN dbo.z_restore_module AS module_row ON module_row.b_id = action_row.b_module_id; - -/* Preserve translations while returning generated keys to their old code-based form. */ -UPDATE old_translation -SET old_translation.b_value = new_translation.b_value -FROM dbo.b_i18n AS old_translation -INNER JOIN dbo.z_restore_i18n_map AS key_map ON key_map.b_old_key = old_translation.b_key -INNER JOIN dbo.b_i18n AS new_translation - ON new_translation.b_key = key_map.b_new_key - AND new_translation.b_locale = old_translation.b_locale; - -DELETE new_translation -FROM dbo.b_i18n AS new_translation -INNER JOIN dbo.z_restore_i18n_map AS key_map ON key_map.b_new_key = new_translation.b_key -WHERE EXISTS ( - SELECT 1 FROM dbo.b_i18n AS old_translation - WHERE old_translation.b_key = key_map.b_old_key - AND old_translation.b_locale = new_translation.b_locale -); - -UPDATE translation -SET translation.b_key = key_map.b_old_key -FROM dbo.b_i18n AS translation -INNER JOIN dbo.z_restore_i18n_map AS key_map ON key_map.b_new_key = translation.b_key; -GO - -/* Remove runtime views before replacing their source tables. */ -IF OBJECT_ID(N'dbo.v_s_user_action_permission', N'V') IS NOT NULL DROP VIEW dbo.v_s_user_action_permission; -IF OBJECT_ID(N'dbo.v_s_user_page_permission', N'V') IS NOT NULL DROP VIEW dbo.v_s_user_page_permission; -IF OBJECT_ID(N'dbo.v_s_user_function_permission', N'V') IS NOT NULL DROP VIEW dbo.v_s_user_function_permission; -IF OBJECT_ID(N'dbo.v_s_module_action', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_action; -IF OBJECT_ID(N'dbo.v_s_module_field_query', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_field_query; -IF OBJECT_ID(N'dbo.v_s_module_field_form', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_field_form; -IF OBJECT_ID(N'dbo.v_s_module_field_list', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_field_list; -IF OBJECT_ID(N'dbo.v_s_module_runtime', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_runtime; -IF OBJECT_ID(N'dbo.v_s_module_profile', N'V') IS NOT NULL DROP VIEW dbo.v_s_module_profile; -IF OBJECT_ID(N'dbo.v_s_page_node', N'V') IS NOT NULL DROP VIEW dbo.v_s_page_node; -IF OBJECT_ID(N'dbo.v_s_function_node', N'V') IS NOT NULL DROP VIEW dbo.v_s_function_node; - -/* Drop all foreign keys owned by or referencing the split architecture. */ -DECLARE @DropForeignKeys nvarchar(max) = N''; -SELECT @DropForeignKeys = @DropForeignKeys - + N'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(fk.parent_object_id)) + N'.' - + QUOTENAME(OBJECT_NAME(fk.parent_object_id)) + N' DROP CONSTRAINT ' + QUOTENAME(fk.name) + N';' -FROM sys.foreign_keys AS fk -WHERE OBJECT_SCHEMA_NAME(fk.parent_object_id) = N'dbo' - AND ( - OBJECT_NAME(fk.parent_object_id) IN ( - N's_module', N's_module_page', N's_module_data', N's_module_report', - N's_module_dashboard', N's_module_workflow', N's_module_profile', - N's_function_node', N's_page_node', N's_module_field', N's_module_layout_group', - N's_module_field_list', N's_module_field_form', N's_module_field_query', - N's_module_action', N's_module_relation', N's_module_auto_code', - N's_module_import', N's_module_export', N's_module_file', - N's_module_workflow_binding', N'b_role', N'b_user_role', - N'b_role_function_node', N'b_role_page_node', N'b_role_action', - N'b_role_data_scope', N'b_user_function_node', N'b_user_page_node', N'b_user_action' - ) - OR OBJECT_NAME(fk.referenced_object_id) IN ( - N's_module', N's_module_profile', N's_function_node', N's_page_node', - N's_module_field', N's_module_layout_group', N's_module_action', N'b_role' - ) - ); -IF @DropForeignKeys <> N'' EXEC sys.sp_executesql @DropForeignKeys; - -DROP TABLE dbo.s_module_workflow_binding; -DROP TABLE dbo.s_module_relation; -DROP TABLE dbo.s_module_import; -DROP TABLE dbo.s_module_export; -DROP TABLE dbo.s_module_file; -DROP TABLE dbo.s_module_field_list; -DROP TABLE dbo.s_module_field_form; -DROP TABLE dbo.s_module_field_query; -DROP TABLE dbo.s_module_layout_group; -DROP TABLE dbo.s_module_auto_code; -DROP TABLE dbo.b_user_action; -DROP TABLE dbo.b_user_page_node; -DROP TABLE dbo.b_user_function_node; -DROP TABLE dbo.b_role_data_scope; -DROP TABLE dbo.b_role_action; -DROP TABLE dbo.b_role_page_node; -DROP TABLE dbo.b_role_function_node; -DROP TABLE dbo.b_user_role; -DROP TABLE dbo.b_role; -DROP TABLE dbo.s_page_node; -DROP TABLE dbo.s_function_node; -DROP TABLE dbo.s_module_action; -DROP TABLE dbo.s_module_field; -DROP TABLE dbo.s_module_report; -DROP TABLE dbo.s_module_dashboard; -DROP TABLE dbo.s_module_workflow; -DROP TABLE dbo.s_module_page; -DROP TABLE dbo.s_module_data; -DROP TABLE dbo.s_module_profile; -DROP TABLE dbo.s_module; -GO - -/* Recreate the compact pre-refactor model. */ -DECLARE @AdminId bigint = ( - SELECT TOP (1) b_id - FROM dbo.b_user - WHERE b_canuse = 1 - ORDER BY CASE WHEN b_account = N'g3soft' THEN 0 ELSE 1 END, b_id -); - -CREATE TABLE dbo.s_module ( - b_id bigint NOT NULL, - b_code varchar(50) NOT NULL, - b_parent_id bigint NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_module_type varchar(20) NOT NULL, - b_route varchar(200) NULL, - b_viewtable varchar(128) NULL, - b_savetable varchar(128) NULL, - b_keyfield varchar(50) NULL, - b_orderfield varchar(500) NULL, - b_canmenu int NOT NULL CONSTRAINT DF_s_module_canmenu DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_module_xh DEFAULT (0), - CONSTRAINT PK_s_module PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_code UNIQUE (b_code), - CONSTRAINT CK_s_module_type CHECK (b_module_type IN ('directory', 'page', 'data_category', 'data')), - CONSTRAINT CK_s_module_flags CHECK (b_canmenu IN (0, 1) AND b_canuse IN (0, 1)), - CONSTRAINT CK_s_module_parent CHECK (b_parent_id IS NULL OR b_parent_id <> b_id), - CONSTRAINT FK_s_module_parent FOREIGN KEY (b_parent_id) REFERENCES dbo.s_module (b_id) -); -CREATE UNIQUE INDEX UX_s_module_route ON dbo.s_module (b_route) WHERE b_route IS NOT NULL; -CREATE INDEX IX_s_module_parent ON dbo.s_module (b_parent_id, b_xh, b_id); - -CREATE TABLE dbo.s_module_field ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_field varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, b_i18n varchar(150) NULL, b_type varchar(30) NOT NULL, - b_default_value nvarchar(500) NULL, b_options nvarchar(max) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field UNIQUE (b_module_id, b_field), - CONSTRAINT FK_s_module_field_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id) -); -CREATE INDEX IX_s_module_field_module ON dbo.s_module_field (b_module_id, b_canuse, b_id); - -CREATE TABLE dbo.s_module_auto_code ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_field_id bigint NOT NULL, - b_prefix nvarchar(100) NOT NULL CONSTRAINT DF_s_module_auto_code_prefix DEFAULT (N''), - b_date_format varchar(30) NOT NULL CONSTRAINT DF_s_module_auto_code_date_format DEFAULT ('yyyyMM'), - b_separator nvarchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_separator DEFAULT (N'-'), - b_sequence_width int NOT NULL CONSTRAINT DF_s_module_auto_code_sequence_width DEFAULT (5), - b_reset_type varchar(10) NOT NULL CONSTRAINT DF_s_module_auto_code_reset_type DEFAULT ('month'), - b_start_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_start_value DEFAULT (1), - b_current_period varchar(8) NULL, - b_current_value bigint NOT NULL CONSTRAINT DF_s_module_auto_code_current_value DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_auto_code_canuse DEFAULT (1), - CONSTRAINT PK_s_module_auto_code PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_auto_code_module UNIQUE (b_module_id), - CONSTRAINT FK_s_module_auto_code_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id), - CONSTRAINT FK_s_module_auto_code_field FOREIGN KEY (b_field_id) REFERENCES dbo.s_module_field (b_id) -); -CREATE INDEX IX_s_module_auto_code_field ON dbo.s_module_auto_code (b_field_id); - -CREATE TABLE dbo.s_module_field_group ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_parent_id bigint NULL, - b_title nvarchar(100) NOT NULL, b_i18n varchar(150) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_field_group_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_group_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field_group PRIMARY KEY (b_id), - CONSTRAINT FK_s_module_field_group_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id) -); -CREATE INDEX IX_s_module_field_group_module ON dbo.s_module_field_group (b_module_id, b_canuse, b_xh, b_id); - -CREATE TABLE dbo.s_module_field_list ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_field_id bigint NULL, - b_group_id bigint NULL, b_i18n varchar(150) NULL, - b_visible int NOT NULL CONSTRAINT DF_s_module_field_list_visible DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_module_field_list_xh DEFAULT (0), b_width int NULL, - CONSTRAINT PK_s_module_field_list PRIMARY KEY (b_id), - CONSTRAINT FK_s_module_field_list_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id), - CONSTRAINT FK_s_module_field_list_field FOREIGN KEY (b_field_id) REFERENCES dbo.s_module_field (b_id), - CONSTRAINT FK_s_module_field_list_group FOREIGN KEY (b_group_id) REFERENCES dbo.s_module_field_group (b_id) -); -CREATE UNIQUE INDEX UX_s_module_field_list_field ON dbo.s_module_field_list (b_module_id, b_field_id) WHERE b_field_id IS NOT NULL; -CREATE INDEX IX_s_module_field_list_tree ON dbo.s_module_field_list (b_module_id, b_group_id, b_xh, b_id); - -CREATE TABLE dbo.s_module_field_edit ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_field_id bigint NOT NULL, - b_required int NOT NULL CONSTRAINT DF_s_module_field_edit_required DEFAULT (0), - b_readonly int NOT NULL CONSTRAINT DF_s_module_field_edit_readonly DEFAULT (0), - b_disabled int NOT NULL CONSTRAINT DF_s_module_field_edit_disabled DEFAULT (0), - b_visible int NOT NULL CONSTRAINT DF_s_module_field_edit_visible DEFAULT (1), - b_group_id bigint NULL, b_xh int NOT NULL CONSTRAINT DF_s_module_field_edit_xh DEFAULT (0), - CONSTRAINT PK_s_module_field_edit PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field_edit UNIQUE (b_module_id, b_field_id), - CONSTRAINT FK_s_module_field_edit_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id), - CONSTRAINT FK_s_module_field_edit_field FOREIGN KEY (b_field_id) REFERENCES dbo.s_module_field (b_id), - CONSTRAINT FK_s_module_field_edit_group FOREIGN KEY (b_group_id) REFERENCES dbo.s_module_field_group (b_id) -); -CREATE INDEX IX_s_module_field_edit_module ON dbo.s_module_field_edit (b_module_id, b_xh, b_id); - -CREATE TABLE dbo.s_module_field_query ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_field_id bigint NOT NULL, - b_component varchar(30) NOT NULL, b_operator varchar(20) NOT NULL, - b_default_value nvarchar(500) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_field_query_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_field_query_canuse DEFAULT (1), - CONSTRAINT PK_s_module_field_query PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_field_query UNIQUE (b_module_id, b_field_id), - CONSTRAINT FK_s_module_field_query_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id), - CONSTRAINT FK_s_module_field_query_field FOREIGN KEY (b_field_id) REFERENCES dbo.s_module_field (b_id) -); -CREATE INDEX IX_s_module_field_query_module ON dbo.s_module_field_query (b_module_id, b_canuse, b_xh, b_id); - -CREATE TABLE dbo.s_module_power ( - b_id bigint NOT NULL, b_module_id bigint NOT NULL, b_code varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, b_i18n varchar(150) NULL, - b_xh int NOT NULL CONSTRAINT DF_s_module_power_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_module_power_canuse DEFAULT (1), - CONSTRAINT PK_s_module_power PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_power UNIQUE (b_module_id, b_code), - CONSTRAINT FK_s_module_power_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id) -); - -CREATE TABLE dbo.b_user_module ( - b_id bigint NOT NULL, b_user_id bigint NOT NULL, b_module_id bigint NOT NULL, - b_inputuser_id bigint NOT NULL, - b_inputdatetime datetime NOT NULL CONSTRAINT DF_b_user_module_inputdatetime DEFAULT (GETDATE()), - CONSTRAINT PK_b_user_module PRIMARY KEY (b_id), - CONSTRAINT UQ_b_user_module UNIQUE (b_user_id, b_module_id), - CONSTRAINT FK_b_user_module_user FOREIGN KEY (b_user_id) REFERENCES dbo.b_user (b_id), - CONSTRAINT FK_b_user_module_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id) -); - -CREATE TABLE dbo.b_user_power ( - b_id bigint NOT NULL, b_user_id bigint NOT NULL, b_module_id bigint NOT NULL, - b_power_id bigint NOT NULL, b_inputuser_id bigint NOT NULL, - b_inputdatetime datetime NOT NULL CONSTRAINT DF_b_user_power_inputdatetime DEFAULT (GETDATE()), - CONSTRAINT PK_b_user_power PRIMARY KEY (b_id), - CONSTRAINT UQ_b_user_power UNIQUE (b_user_id, b_power_id), - CONSTRAINT FK_b_user_power_user FOREIGN KEY (b_user_id) REFERENCES dbo.b_user (b_id), - CONSTRAINT FK_b_user_power_module FOREIGN KEY (b_module_id) REFERENCES dbo.s_module (b_id), - CONSTRAINT FK_b_user_power_power FOREIGN KEY (b_power_id) REFERENCES dbo.s_module_power (b_id) -); -CREATE INDEX IX_b_user_power_module ON dbo.b_user_power (b_module_id, b_user_id); - -INSERT INTO dbo.s_module SELECT * FROM dbo.z_restore_module; -INSERT INTO dbo.s_module_field SELECT * FROM dbo.z_restore_module_field; -INSERT INTO dbo.s_module_auto_code SELECT * FROM dbo.z_restore_module_auto_code; -INSERT INTO dbo.s_module_field_group SELECT * FROM dbo.z_restore_module_field_group; -INSERT INTO dbo.s_module_field_list SELECT * FROM dbo.z_restore_module_field_list; -INSERT INTO dbo.s_module_field_edit SELECT * FROM dbo.z_restore_module_field_edit; -INSERT INTO dbo.s_module_field_query SELECT * FROM dbo.z_restore_module_field_query; -INSERT INTO dbo.s_module_power SELECT * FROM dbo.z_restore_module_power; - -INSERT INTO dbo.b_user_module (b_id, b_user_id, b_module_id, b_inputuser_id) -SELECT 860000000000000000 + ROW_NUMBER() OVER (ORDER BY b_user_id, b_module_id), - b_user_id, b_module_id, @AdminId -FROM dbo.z_restore_user_module; - -INSERT INTO dbo.b_user_power (b_id, b_user_id, b_module_id, b_power_id, b_inputuser_id) -SELECT 870000000000000000 + ROW_NUMBER() OVER (ORDER BY b_user_id, b_power_id), - b_user_id, b_module_id, b_power_id, @AdminId -FROM dbo.z_restore_user_power; - -DROP TABLE dbo.z_restore_user_power; -DROP TABLE dbo.z_restore_user_module; -DROP TABLE dbo.z_restore_module_power; -DROP TABLE dbo.z_restore_module_field_query; -DROP TABLE dbo.z_restore_module_field_edit; -DROP TABLE dbo.z_restore_module_field_list; -DROP TABLE dbo.z_restore_module_field_group; -DROP TABLE dbo.z_restore_module_auto_code; -DROP TABLE dbo.z_restore_module_field; -DROP TABLE dbo.z_restore_i18n_map; -DROP TABLE dbo.z_restore_module; -GO - -CREATE OR ALTER TRIGGER dbo.TR_s_module_simple_tree -ON dbo.s_module -AFTER INSERT, UPDATE -AS -BEGIN - SET NOCOUNT ON; - - IF EXISTS ( - SELECT 1 - FROM inserted AS child - INNER JOIN dbo.s_module AS parent_row ON parent_row.b_id = child.b_parent_id - WHERE (child.b_module_type = 'directory' AND parent_row.b_module_type <> 'directory') - OR (child.b_module_type = 'page' AND parent_row.b_module_type <> 'directory') - OR (child.b_module_type = 'data_category' AND parent_row.b_module_type NOT IN ('page', 'data_category')) - OR (child.b_module_type = 'data' AND parent_row.b_module_type NOT IN ('page', 'data_category')) - ) - THROW 53508, N'Invalid parent type in the simple module tree.', 1; - - IF EXISTS ( - SELECT 1 FROM inserted - WHERE b_module_type IN ('data_category', 'data') AND b_parent_id IS NULL - ) - THROW 53509, N'Data categories and data modules require a page parent.', 1; - - DECLARE @Cycle bit = 0; - ;WITH tree AS ( - SELECT child.b_id AS origin_id, child.b_parent_id AS current_id - FROM inserted AS child - WHERE child.b_parent_id IS NOT NULL - UNION ALL - SELECT tree.origin_id, parent_row.b_parent_id - FROM tree - INNER JOIN dbo.s_module AS parent_row ON parent_row.b_id = tree.current_id - WHERE tree.current_id IS NOT NULL - ) - SELECT TOP (1) @Cycle = 1 FROM tree WHERE current_id = origin_id OPTION (MAXRECURSION 32767); - IF @Cycle = 1 THROW 53510, N'Module tree cycle detected.', 1; -END; diff --git a/code/fms/fms-api/config/migrations/036_add_module_icon.sql b/code/fms/fms-api/config/migrations/036_add_module_icon.sql deleted file mode 100644 index b96cc31a..00000000 --- a/code/fms/fms-api/config/migrations/036_add_module_icon.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Add b_icon column to s_module so directory/page modules can assign a - Lucide icon for sidebar menu display. -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS' - THROW 53600, N'This migration can only run against the FMS database.', 1; - -IF COL_LENGTH(N'dbo.s_module', N'b_icon') IS NOT NULL - THROW 53601, N'Column b_icon already exists on s_module.', 1; - -ALTER TABLE dbo.s_module ADD b_icon VARCHAR(50) NULL; - -PRINT N'Migration 036 applied: added s_module.b_icon.'; diff --git a/code/fms/fms-api/config/migrations/037_add_field_edit_colspan.sql b/code/fms/fms-api/config/migrations/037_add_field_edit_colspan.sql deleted file mode 100644 index 92b10f19..00000000 --- a/code/fms/fms-api/config/migrations/037_add_field_edit_colspan.sql +++ /dev/null @@ -1,24 +0,0 @@ -/* 为编辑配置(s_field_edit)增加栅格宽度列,支持表单设计器自定义表单项宽度(24 栅格制)。 */ -SET NOCOUNT ON; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'b_colspan' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD b_colspan int NOT NULL CONSTRAINT DF_s_field_edit_colspan DEFAULT (12); -END; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'CK_s_field_edit_colspan' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD CONSTRAINT CK_s_field_edit_colspan CHECK (b_colspan BETWEEN 1 AND 24); -END; diff --git a/code/fms/fms-api/config/migrations/038_add_form_design_layout.sql b/code/fms/fms-api/config/migrations/038_add_form_design_layout.sql deleted file mode 100644 index 257a52d0..00000000 --- a/code/fms/fms-api/config/migrations/038_add_form_design_layout.sql +++ /dev/null @@ -1,54 +0,0 @@ -/* - 为表单设计器补充两个布局字段: - 1. s_field_edit.b_height —— textarea 控件的自定义高度(px),仅 textarea 类型使用。 - 2. s_field_group.b_layout_direction —— 分组内字段的排列方向(vertical 上下 / horizontal 左右)。 - 配合 037_add_field_edit_colspan.sql(b_colspan)一起支撑设计器的栅格与高度配置。 - 可重复执行:列与约束均通过存在性判断避免重复。 -*/ -SET NOCOUNT ON; - --- 1. s_field_edit.b_height -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'b_height' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD b_height int NULL; -END; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'CK_s_field_edit_height' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD CONSTRAINT CK_s_field_edit_height CHECK (b_height IS NULL OR (b_height BETWEEN 64 AND 480)); -END; - --- 2. s_field_group.b_layout_direction -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_group') - AND name = N'b_layout_direction' -) -BEGIN - ALTER TABLE dbo.s_field_group - ADD b_layout_direction varchar(10) NULL CONSTRAINT DF_s_field_group_layout_direction DEFAULT ('vertical'); -END; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_field_group') - AND name = N'CK_s_field_group_layout_direction' -) -BEGIN - ALTER TABLE dbo.s_field_group - ADD CONSTRAINT CK_s_field_group_layout_direction CHECK (b_layout_direction IS NULL OR b_layout_direction IN ('vertical', 'horizontal')); -END; diff --git a/code/fms/fms-api/config/migrations/039_add_field_edit_placeholder.sql b/code/fms/fms-api/config/migrations/039_add_field_edit_placeholder.sql deleted file mode 100644 index 88fc586d..00000000 --- a/code/fms/fms-api/config/migrations/039_add_field_edit_placeholder.sql +++ /dev/null @@ -1,17 +0,0 @@ -/* - 为表单设计器补充占位符(placeholder)字段。 - 每个表单控件的占位提示文字,画布所见即所得渲染时使用,运行期表单同样读取。 - 可重复执行:通过存在性判断避免重复。 -*/ -SET NOCOUNT ON; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'b_placeholder' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD b_placeholder nvarchar(200) NULL; -END; diff --git a/code/fms/fms-api/config/migrations/040_log_account_to_nvarchar.sql b/code/fms/fms-api/config/migrations/040_log_account_to_nvarchar.sql deleted file mode 100644 index b87acca1..00000000 --- a/code/fms/fms-api/config/migrations/040_log_account_to_nvarchar.sql +++ /dev/null @@ -1,50 +0,0 @@ -/* - 日志表账号列改为 nvarchar:s_log_login.b_account / s_log_technical.b_account 原为 varchar(50), - 中文账号写入会因代码页转换变为 '?'(b_user.b_account 本身是 nvarchar,账号支持中文,见 - 100_initialize_fms_new.sql)。改为 nvarchar(50) 与用户表对齐。 - - 已废弃(2026-09-05):s_log_login / s_log_technical 的 b_account 列已按《FMS新系统核心表结构设计.md》 - 从结构中移除(账号即 b_user.b_id,见 b_user_id 列),详见 203_drop_log_account.sql。 - 本脚本仅针对历史 schema 保留幂等逻辑:列已不存在时自动跳过,无副作用。 - - 可重复执行:仅在列存在且当前类型为 varchar 时才 ALTER。 - s_log_login.b_account 上有索引 IX_s_log_login_account,SQL Server 修改列类型前需先删除、改完重建。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - - IF OBJECT_ID(N'dbo.s_log_login', N'U') IS NOT NULL - AND EXISTS ( - SELECT 1 - FROM sys.columns c - JOIN sys.types t ON t.user_type_id = c.user_type_id - WHERE c.object_id = OBJECT_ID(N'dbo.s_log_login') - AND c.name = N'b_account' - AND t.name = N'varchar' - ) - BEGIN - IF OBJECT_ID(N'dbo.IX_s_log_login_account', N'INDEX') IS NOT NULL - DROP INDEX IX_s_log_login_account ON dbo.s_log_login; - - ALTER TABLE dbo.s_log_login ALTER COLUMN b_account nvarchar(50) NULL; - - IF OBJECT_ID(N'dbo.IX_s_log_login_account', N'INDEX') IS NULL - CREATE INDEX IX_s_log_login_account ON dbo.s_log_login (b_account, b_occurdatetime DESC); - END - - IF OBJECT_ID(N'dbo.s_log_technical', N'U') IS NOT NULL - AND EXISTS ( - SELECT 1 - FROM sys.columns c - JOIN sys.types t ON t.user_type_id = c.user_type_id - WHERE c.object_id = OBJECT_ID(N'dbo.s_log_technical') - AND c.name = N'b_account' - AND t.name = N'varchar' - ) - BEGIN - ALTER TABLE dbo.s_log_technical ALTER COLUMN b_account nvarchar(50) NULL; - END - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/041_add_s_i18n_module_id.sql b/code/fms/fms-api/config/migrations/041_add_s_i18n_module_id.sql deleted file mode 100644 index 7d7dd2ba..00000000 --- a/code/fms/fms-api/config/migrations/041_add_s_i18n_module_id.sql +++ /dev/null @@ -1,75 +0,0 @@ -/* - 为 dbo.s_i18n 增加 b_module_id 列,使多语言数据可按模块级联删除/查询, - 解决「删除模块后 s_i18n 残留孤儿数据」的问题(前端按 b_key 前缀匹配清理易漏)。 - - 与 006_add_i18n_module_id.sql 的区别:006 作用于旧表 dbo.b_i18n; - 本脚本作用于当前前端实际使用的 dbo.s_i18n。 - - 本脚本可重复执行: - - 列不存在时才添加,并建索引; - - 对存量数据做一次基于键命名约定的回填(module./menu./field./power./group. 前缀, - 取第二段作为模块编码关联 s_module.b_code),已回填或无法匹配的行不受影响。 - - 通用文案键(common.* 等)不关联模块,b_module_id 保持 NULL。 -*/ -SET NOCOUNT ON; - --- 第 1 批:DDL(列与索引) -BEGIN TRANSACTION; - - IF NOT EXISTS ( - SELECT 1 FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_i18n') AND name = N'b_module_id' - ) - BEGIN - ALTER TABLE dbo.s_i18n - ADD b_module_id bigint NULL; - - CREATE INDEX IX_s_i18n_module_id ON dbo.s_i18n (b_module_id) - INCLUDE (b_key, b_locale, b_value); - END - -COMMIT TRANSACTION; -GO - --- 第 2 批:存量回填(依赖第 1 批列已存在,因此必须 GO 分隔) -SET NOCOUNT ON; - -BEGIN TRANSACTION; - - -- 键形如 module. / menu. / field.. / power.. - -- / group..,模块编码恒为第二个以 "." 分隔的片段。 - UPDATE i - SET b_module_id = m.b_id - FROM dbo.s_i18n i - CROSS APPLY ( - SELECT - CASE - WHEN CHARINDEX(N'.', i.b_key) > 0 THEN - SUBSTRING( - i.b_key, - CHARINDEX(N'.', i.b_key) + 1, - CASE - WHEN CHARINDEX(N'.', i.b_key, CHARINDEX(N'.', i.b_key) + 1) > 0 - THEN CHARINDEX(N'.', i.b_key, CHARINDEX(N'.', i.b_key) + 1) - - CHARINDEX(N'.', i.b_key) - 1 - ELSE LEN(i.b_key) - CHARINDEX(N'.', i.b_key) - END - ) - ELSE NULL - END AS code - ) c - CROSS APPLY ( - SELECT TOP (1) sm.b_id - FROM dbo.s_module sm - WHERE sm.b_code = c.code - ) m - WHERE i.b_module_id IS NULL - AND ( - i.b_key LIKE N'module.%' - OR i.b_key LIKE N'menu.%' - OR i.b_key LIKE N'field.%' - OR i.b_key LIKE N'power.%' - OR i.b_key LIKE N'group.%' - ); - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/042_add_group_colspan_and_drop_edit_check.sql b/code/fms/fms-api/config/migrations/042_add_group_colspan_and_drop_edit_check.sql deleted file mode 100644 index 39bd8083..00000000 --- a/code/fms/fms-api/config/migrations/042_add_group_colspan_and_drop_edit_check.sql +++ /dev/null @@ -1,34 +0,0 @@ -/* - 表单设计器分组宽度持久化: - 1. s_field_group.b_colspan —— 分组在外层 48 宫格中的占格数(默认 48 独占一行)。 - 与 s_field_edit.b_colspan 同义(栅格占格数),仅进制不同:分组 48 宫格、字段 24 宫格。 - 不加 CHECK 约束(与前端钳制逻辑一致,边界由应用层保证)。 - 2. 删除 s_field_edit 的 CK_s_field_edit_colspan CHECK 约束(b_colspan BETWEEN 1 AND 24), - 放开栅格宽度的数据库层限制,校验统一交由前端与应用层。 - 可重复执行:列与约束均通过存在性判断避免重复。 -*/ -SET NOCOUNT ON; - --- 1. s_field_group.b_colspan -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_group') - AND name = N'b_colspan' -) -BEGIN - ALTER TABLE dbo.s_field_group - ADD b_colspan int NOT NULL CONSTRAINT DF_s_field_group_colspan DEFAULT (48); -END; - --- 2. 删除 s_field_edit 的 CK_s_field_edit_colspan CHECK 约束 -IF EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'CK_s_field_edit_colspan' -) -BEGIN - ALTER TABLE dbo.s_field_edit - DROP CONSTRAINT CK_s_field_edit_colspan; -END; diff --git a/code/fms/fms-api/config/migrations/100_initialize_fms_new.sql b/code/fms/fms-api/config/migrations/100_initialize_fms_new.sql deleted file mode 100644 index 90260162..00000000 --- a/code/fms/fms-api/config/migrations/100_initialize_fms_new.sql +++ /dev/null @@ -1,529 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'This migration can only run against FMS-NEW.', 1; - -BEGIN TRANSACTION; - -IF OBJECT_ID(N'dbo.b_user', N'U') IS NULL -BEGIN - CREATE TABLE dbo.b_user ( - b_id bigint IDENTITY(1,1) NOT NULL, - b_account nvarchar(50) NOT NULL, - b_name nvarchar(50) NULL, - b_department nvarchar(50) NULL, - b_subcode nvarchar(50) NULL, - b_machineid nvarchar(50) NULL, - b_bz nvarchar(200) NULL, - b_password nvarchar(255) NOT NULL, - b_canuse tinyint NOT NULL CONSTRAINT DF_b_user_canuse DEFAULT (1), - b_othermachinelogin tinyint NOT NULL CONSTRAINT DF_b_user_othermachinelogin DEFAULT (0), - b_salesman tinyint NOT NULL CONSTRAINT DF_b_user_salesman DEFAULT (0), - b_docman tinyint NOT NULL CONSTRAINT DF_b_user_docman DEFAULT (0), - b_dealman tinyint NOT NULL CONSTRAINT DF_b_user_dealman DEFAULT (0), - b_receivelevel tinyint NULL, - b_paylevel tinyint NULL, - b_visible_customer tinyint NOT NULL CONSTRAINT DF_b_user_visible_customer DEFAULT (0), - b_visible_supply tinyint NOT NULL CONSTRAINT DF_b_user_visible_supply DEFAULT (0), - b_levelvisible tinyint NOT NULL CONSTRAINT DF_b_user_levelvisible DEFAULT (0), - b_fromcustomer tinyint NOT NULL CONSTRAINT DF_b_user_fromcustomer DEFAULT (0), - b_logintime tinyint NOT NULL CONSTRAINT DF_b_user_logintime DEFAULT (0), - b_checkxy tinyint NOT NULL CONSTRAINT DF_b_user_checkxy DEFAULT (0), - b_loginfee tinyint NOT NULL CONSTRAINT DF_b_user_loginfee DEFAULT (0), - b_phone nvarchar(50) NULL, - CONSTRAINT PK_b_user PRIMARY KEY (b_id), - CONSTRAINT UQ_b_user_account UNIQUE (b_account) - ); -END; - -IF NOT EXISTS (SELECT 1 FROM dbo.b_user) -BEGIN - INSERT INTO dbo.b_user ( - b_id, b_account, b_name, b_department, b_subcode, 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, - b_fromcustomer, b_logintime, b_checkxy, b_loginfee, b_phone - ) - SELECT - b_id, b_account, b_name, b_department, b_subcode, 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, - b_fromcustomer, b_logintime, b_checkxy, b_loginfee, b_phone - FROM [FMS].dbo.b_user; -END; - -IF OBJECT_ID(N'dbo.s_module', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_module ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_code varchar(50) NOT NULL, - b_parent_id bigint NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_module_type varchar(20) NOT NULL, - b_viewtable varchar(128) NULL, - b_savetable varchar(128) NULL, - b_keyfield varchar(50) NULL, - b_orderfield varchar(500) NULL, - b_delete_policy varchar(20) NULL, - b_edit_mode varchar(10) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_module_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_module_xh DEFAULT (0), - b_bz nvarchar(1000) NULL, - b_inputuser_id bigint NULL, - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_module_inputdatetime DEFAULT (SYSUTCDATETIME()), - b_updateuser_id bigint NULL, - b_updatedatetime datetime2 NULL, - CONSTRAINT PK_s_module PRIMARY KEY (b_id), - CONSTRAINT UQ_s_module_code UNIQUE (b_code), - CONSTRAINT CK_s_module_type CHECK (b_module_type IN ('category','data','query')), - CONSTRAINT CK_s_module_delete_policy CHECK (b_delete_policy IS NULL OR b_delete_policy IN ('restrict','lifecycle','hard')), - CONSTRAINT CK_s_module_edit_mode CHECK (b_edit_mode IS NULL OR b_edit_mode IN ('form','table')), - CONSTRAINT CK_s_module_config CHECK ( - (b_module_type = 'category' AND b_viewtable IS NULL AND b_savetable IS NULL AND b_keyfield IS NULL AND b_orderfield IS NULL AND b_delete_policy IS NULL) - OR (b_module_type = 'data' AND b_viewtable IS NOT NULL AND b_savetable IS NOT NULL AND b_keyfield IS NOT NULL AND b_delete_policy IS NOT NULL) - OR (b_module_type = 'query' AND b_viewtable IS NOT NULL AND b_savetable IS NULL AND b_delete_policy IS NULL) - ), - CONSTRAINT CK_s_module_parent CHECK (b_parent_id IS NULL OR b_parent_id <> b_id) - ); - CREATE INDEX IX_s_module_parent ON dbo.s_module (b_parent_id, b_xh, b_canuse, b_id); - CREATE INDEX IX_s_module_savetable ON dbo.s_module (b_savetable); -END; - -IF OBJECT_ID(N'dbo.s_field', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_field ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_field varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_type varchar(30) NOT NULL, - b_dbtype varchar(30) NOT NULL, - b_length int NULL, - b_precision int NULL, - b_scale int NULL, - b_nullable int NOT NULL CONSTRAINT DF_s_field_nullable DEFAULT (1), - b_default_value nvarchar(500) NULL, - b_db_default nvarchar(500) NULL, - b_writemode varchar(20) NOT NULL CONSTRAINT DF_s_field_writemode DEFAULT ('direct'), - b_options nvarchar(max) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_field_canuse DEFAULT (1), - b_inputuser_id bigint NULL, - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_field_inputdatetime DEFAULT (SYSUTCDATETIME()), - b_updateuser_id bigint NULL, - b_updatedatetime datetime2 NULL, - CONSTRAINT PK_s_field PRIMARY KEY (b_id), - CONSTRAINT UQ_s_field_module_field UNIQUE (b_module_id, b_field), - CONSTRAINT UQ_s_field_module_id UNIQUE (b_module_id, b_id), - CONSTRAINT CK_s_field_type CHECK (b_type IN ('input','textarea','number','money','date','datetime','checkbox','select','selectId')), - CONSTRAINT CK_s_field_dbtype CHECK (b_dbtype IN ('varchar','nvarchar','char','nchar','int','bigint','smallint','tinyint','decimal','numeric','float','real','date','datetime','datetime2','bit','text','ntext','uniqueidentifier')), - CONSTRAINT CK_s_field_writemode CHECK (b_writemode IN ('direct','createOnly','readOnly','computed','system')) - ); - CREATE INDEX IX_s_field_module ON dbo.s_field (b_module_id, b_canuse, b_id); -END; - -IF OBJECT_ID(N'dbo.s_field_group', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_field_group ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_parent_id bigint NULL, - b_title nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_layout_direction varchar(10) NULL CONSTRAINT DF_s_field_group_layout_direction DEFAULT ('vertical'), - b_colspan int NOT NULL CONSTRAINT DF_s_field_group_colspan DEFAULT (48), - b_xh int NOT NULL CONSTRAINT DF_s_field_group_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_field_group_canuse DEFAULT (1), - CONSTRAINT PK_s_field_group PRIMARY KEY (b_id), - CONSTRAINT UQ_s_field_group_module_id UNIQUE (b_module_id, b_id), - CONSTRAINT CK_s_field_group_parent CHECK (b_parent_id IS NULL OR b_parent_id <> b_id), - CONSTRAINT CK_s_field_group_layout_direction CHECK (b_layout_direction IS NULL OR b_layout_direction IN ('vertical', 'horizontal')) - ); - CREATE INDEX IX_s_field_group_module ON dbo.s_field_group (b_module_id, b_xh, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_field_view', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_field_view ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_group_id bigint NULL, - b_i18n varchar(150) NULL, - b_visible int NOT NULL CONSTRAINT DF_s_field_view_visible DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_field_view_xh DEFAULT (0), - b_width int NULL, - CONSTRAINT PK_s_field_view PRIMARY KEY (b_id), - CONSTRAINT UQ_s_field_view_field UNIQUE (b_module_id, b_field_id) - ); - CREATE INDEX IX_s_field_view_order ON dbo.s_field_view (b_xh, b_id); -END; - -IF OBJECT_ID(N'dbo.s_field_edit', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_field_edit ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_group_id bigint NULL, - b_visible int NOT NULL CONSTRAINT DF_s_field_edit_visible DEFAULT (1), - b_required int NOT NULL CONSTRAINT DF_s_field_edit_required DEFAULT (0), - b_readonly int NOT NULL CONSTRAINT DF_s_field_edit_readonly DEFAULT (0), - b_disabled int NOT NULL CONSTRAINT DF_s_field_edit_disabled DEFAULT (0), - b_colspan int NOT NULL CONSTRAINT DF_s_field_edit_colspan DEFAULT (12), - b_height int NULL, - b_placeholder nvarchar(200) NULL, - b_width int NULL, - b_xh int NOT NULL CONSTRAINT DF_s_field_edit_xh DEFAULT (0), - CONSTRAINT PK_s_field_edit PRIMARY KEY (b_id), - CONSTRAINT UQ_s_field_edit_field UNIQUE (b_module_id, b_field_id), - CONSTRAINT CK_s_field_edit_height CHECK (b_height IS NULL OR (b_height BETWEEN 64 AND 480)) - ); - CREATE INDEX IX_s_field_edit_order ON dbo.s_field_edit (b_xh, b_id); -END; - -IF OBJECT_ID(N'dbo.s_field_query', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_field_query ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_field_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_relation_id bigint NULL, - b_component varchar(30) NULL, - b_condition_no int NOT NULL CONSTRAINT DF_s_field_query_condition_no DEFAULT (1), - b_operator varchar(20) NOT NULL, - b_default_value nvarchar(500) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_field_query_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_field_query_xh DEFAULT (0), - CONSTRAINT PK_s_field_query PRIMARY KEY (b_id), - CONSTRAINT UQ_s_field_query_condition UNIQUE (b_module_id, b_field_module_id, b_field_id, b_relation_id, b_operator, b_condition_no), - CONSTRAINT CK_s_field_query_condition_no CHECK (b_condition_no > 0) - ); - CREATE INDEX IX_s_field_query_order ON dbo.s_field_query (b_canuse, b_xh, b_id); -END; - -IF OBJECT_ID(N'dbo.s_relation', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_relation ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_code varchar(50) NOT NULL, - b_module_id bigint NOT NULL, - b_target_module_id bigint NOT NULL, - b_relation_type varchar(20) NOT NULL, - b_module_field_id bigint NOT NULL, - b_target_field_id bigint NOT NULL, - b_foreign_side varchar(10) NULL, - b_junction_module_id bigint NULL, - b_junction_module_field_id bigint NULL, - b_junction_target_field_id bigint NULL, - b_ownership varchar(20) NOT NULL CONSTRAINT DF_s_relation_ownership DEFAULT ('reference'), - b_owner_side varchar(10) NULL, - b_delete_policy varchar(20) NULL, - b_order_module_id bigint NULL, - b_order_field_id bigint NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_relation_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_relation_xh DEFAULT (0), - CONSTRAINT PK_s_relation PRIMARY KEY (b_id), - CONSTRAINT UQ_s_relation_code UNIQUE (b_code), - CONSTRAINT UQ_s_relation_key UNIQUE (b_module_id, b_target_module_id, b_module_field_id, b_target_field_id), - CONSTRAINT CK_s_relation_self_fields CHECK (b_module_id <> b_target_module_id OR b_module_field_id <> b_target_field_id), - CONSTRAINT CK_s_relation_type CHECK (b_relation_type IN ('one-to-one','one-to-many','many-to-one','many-to-many')), - CONSTRAINT CK_s_relation_foreign_side CHECK (b_foreign_side IS NULL OR b_foreign_side IN ('module','target')), - CONSTRAINT CK_s_relation_ownership CHECK (b_ownership IN ('reference','owned')), - CONSTRAINT CK_s_relation_owner_side CHECK (b_owner_side IS NULL OR b_owner_side IN ('module','target')), - CONSTRAINT CK_s_relation_shape CHECK ( - (b_relation_type = 'many-to-many' AND b_foreign_side IS NULL AND b_junction_module_id IS NOT NULL AND b_junction_module_field_id IS NOT NULL AND b_junction_target_field_id IS NOT NULL) - OR (b_relation_type <> 'many-to-many' AND b_foreign_side IS NOT NULL AND b_junction_module_id IS NULL AND b_junction_module_field_id IS NULL AND b_junction_target_field_id IS NULL) - ), - CONSTRAINT CK_s_relation_owned CHECK ((b_ownership = 'reference' AND b_owner_side IS NULL) OR (b_ownership = 'owned' AND b_owner_side IS NOT NULL AND b_relation_type <> 'many-to-many')), - CONSTRAINT CK_s_relation_order CHECK ((b_order_module_id IS NULL AND b_order_field_id IS NULL) OR (b_order_module_id IS NOT NULL AND b_order_field_id IS NOT NULL)), - CONSTRAINT CK_s_relation_delete_policy CHECK (b_delete_policy IS NULL OR b_delete_policy IN ('restrict','set-null','cascade','archive')) - ); - CREATE INDEX IX_s_relation_target ON dbo.s_relation (b_target_module_id); -END; - -IF OBJECT_ID(N'dbo.s_menu', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_menu ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_parent_id bigint NULL, - b_code varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_menu_type varchar(20) NOT NULL, - b_route varchar(200) NULL, - b_module_id bigint NULL, - b_icon nvarchar(max) NULL, -- 图标:lucide:Name 引用 lucide,否则为 SVG 标记 - b_xh int NOT NULL CONSTRAINT DF_s_menu_xh DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_menu_canuse DEFAULT (1), - CONSTRAINT PK_s_menu PRIMARY KEY (b_id), - CONSTRAINT UQ_s_menu_code UNIQUE (b_code) - ); - CREATE INDEX IX_s_menu_parent ON dbo.s_menu (b_parent_id, b_xh, b_canuse); - CREATE INDEX IX_s_menu_module ON dbo.s_menu (b_module_id); -END; - -IF OBJECT_ID(N'dbo.s_autocode', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_autocode ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_module_id bigint NOT NULL, - b_field_id bigint NOT NULL, - b_prefix nvarchar(100) NOT NULL CONSTRAINT DF_s_autocode_prefix DEFAULT (N''), - b_dateformat varchar(30) NOT NULL CONSTRAINT DF_s_autocode_dateformat DEFAULT ('yyyyMM'), - b_separator nvarchar(10) NOT NULL CONSTRAINT DF_s_autocode_separator DEFAULT (N'-'), - b_seqwidth int NOT NULL CONSTRAINT DF_s_autocode_seqwidth DEFAULT (5), - b_resettype varchar(10) NOT NULL CONSTRAINT DF_s_autocode_resettype DEFAULT ('month'), - b_startvalue bigint NOT NULL CONSTRAINT DF_s_autocode_startvalue DEFAULT (1), - b_currentperiod varchar(8) NULL, - b_currentvalue bigint NOT NULL CONSTRAINT DF_s_autocode_currentvalue DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_autocode_canuse DEFAULT (1), - CONSTRAINT PK_s_autocode PRIMARY KEY (b_id), - CONSTRAINT UQ_s_autocode_module_field UNIQUE (b_module_id, b_field_id), - CONSTRAINT CK_s_autocode_resettype CHECK (b_resettype IN ('none','day','month','year')), - CONSTRAINT CK_s_autocode_values CHECK (b_seqwidth > 0 AND b_startvalue >= 0 AND b_currentvalue >= 0) - ); -END; - -IF OBJECT_ID(N'dbo.s_role', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_role ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_code varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_remark nvarchar(500) NULL, - b_is_system int NOT NULL CONSTRAINT DF_s_role_is_system DEFAULT (0), - b_bypass_power int NOT NULL CONSTRAINT DF_s_role_bypass_power DEFAULT (0), - b_canuse int NOT NULL CONSTRAINT DF_s_role_canuse DEFAULT (1), - b_inputuser_id bigint NULL, - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_role_inputdatetime DEFAULT (SYSUTCDATETIME()), - b_updateuser_id bigint NULL, - b_updatedatetime datetime2 NULL, - CONSTRAINT PK_s_role PRIMARY KEY (b_id), - CONSTRAINT UQ_s_role_code UNIQUE (b_code), - CONSTRAINT CK_s_role_system_bypass CHECK (b_bypass_power = 0 OR b_is_system = 1) - ); -END; - -IF OBJECT_ID(N'dbo.s_user_role', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_user_role ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_user_id bigint NOT NULL, - b_role_id bigint NOT NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_user_role_canuse DEFAULT (1), - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_user_role_inputdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_user_role PRIMARY KEY (b_id), - CONSTRAINT UQ_s_user_role UNIQUE (b_user_id, b_role_id) - ); - CREATE INDEX IX_s_user_role_role ON dbo.s_user_role (b_role_id, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_power', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_power ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_code varchar(50) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_i18n varchar(150) NULL, - b_power_type varchar(20) NOT NULL, - b_resource varchar(128) NULL, - b_module_id bigint NULL, - b_field_id bigint NULL, - b_operation varchar(30) NOT NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_power_canuse DEFAULT (1), - b_xh int NOT NULL CONSTRAINT DF_s_power_xh DEFAULT (0), - CONSTRAINT PK_s_power PRIMARY KEY (b_id), - CONSTRAINT UQ_s_power_code UNIQUE (b_code), - CONSTRAINT CK_s_power_type CHECK (b_power_type IN ('menu','module','action','field')), - CONSTRAINT CK_s_power_shape CHECK ( - (b_power_type = 'menu' AND b_resource IS NOT NULL AND b_module_id IS NULL AND b_field_id IS NULL AND b_operation = 'access') - OR (b_power_type = 'module' AND b_resource IS NULL AND b_module_id IS NOT NULL AND b_field_id IS NULL AND b_operation IN ('read','create','update','delete','export')) - OR (b_power_type = 'action' AND b_resource IS NOT NULL AND b_module_id IS NOT NULL AND b_field_id IS NULL AND b_operation = 'execute') - OR (b_power_type = 'field' AND b_resource IS NULL AND b_module_id IS NOT NULL AND b_field_id IS NOT NULL AND b_operation IN ('view','edit')) - ) - ); - CREATE INDEX IX_s_power_resource ON dbo.s_power (b_power_type, b_resource, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_role_power', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_role_power ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_role_id bigint NOT NULL, - b_power_id bigint NOT NULL, - b_effect varchar(10) NOT NULL CONSTRAINT DF_s_role_power_effect DEFAULT ('allow'), - b_canuse int NOT NULL CONSTRAINT DF_s_role_power_canuse DEFAULT (1), - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_role_power_inputdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_role_power PRIMARY KEY (b_id), - CONSTRAINT UQ_s_role_power UNIQUE (b_role_id, b_power_id), - CONSTRAINT CK_s_role_power_effect CHECK (b_effect IN ('allow','deny')) - ); - CREATE INDEX IX_s_role_power_power ON dbo.s_role_power (b_power_id, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_role_scope', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_role_scope ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_role_id bigint NOT NULL, - b_module_id bigint NOT NULL, - b_operation varchar(20) NOT NULL, - b_scope_type varchar(30) NOT NULL, - b_scope_no int NOT NULL CONSTRAINT DF_s_role_scope_no DEFAULT (1), - b_scope_field_id bigint NULL, - b_scope_value nvarchar(max) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_role_scope_canuse DEFAULT (1), - b_inputdatetime datetime2 NULL CONSTRAINT DF_s_role_scope_inputdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_role_scope PRIMARY KEY (b_id), - CONSTRAINT UQ_s_role_scope UNIQUE (b_role_id, b_module_id, b_operation, b_scope_type, b_scope_field_id, b_scope_no), - CONSTRAINT CK_s_role_scope_operation CHECK (b_operation IN ('read','update','delete','export')), - CONSTRAINT CK_s_role_scope_type CHECK (b_scope_type IN ('all','creator','owner','department','department-tree','custom')), - CONSTRAINT CK_s_role_scope_no CHECK (b_scope_no > 0), - CONSTRAINT CK_s_role_scope_shape CHECK ( - (b_scope_type IN ('all','creator') AND b_scope_field_id IS NULL AND b_scope_value IS NULL) - OR (b_scope_type IN ('owner','department','department-tree') AND b_scope_field_id IS NOT NULL) - OR (b_scope_type = 'custom' AND b_scope_value IS NOT NULL) - ) - ); - CREATE INDEX IX_s_role_scope_role ON dbo.s_role_scope (b_role_id, b_module_id, b_operation, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_i18n_type', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_i18n_type ( - b_id bigint NOT NULL, - b_code varchar(20) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_i18n_type_canuse DEFAULT (1), - b_default int NOT NULL CONSTRAINT DF_s_i18n_type_default DEFAULT (0), - b_xh int NOT NULL CONSTRAINT DF_s_i18n_type_xh DEFAULT (0), - CONSTRAINT PK_s_i18n_type PRIMARY KEY (b_id), - CONSTRAINT UQ_s_i18n_type_code UNIQUE (b_code) - ); - CREATE INDEX IX_s_i18n_type_xh ON dbo.s_i18n_type (b_xh, b_id); - - INSERT INTO dbo.s_i18n_type (b_id, b_code, b_name, b_canuse, b_default, b_xh) VALUES - (920000000000000001, N'zh-CN', N'简体中文', 1, 1, 0), - (920000000000000002, N'en-US', N'English', 1, 0, 10); -END; - -IF OBJECT_ID(N'dbo.s_i18n', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_i18n ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_key varchar(150) NOT NULL, - b_locale varchar(20) NOT NULL, - b_value nvarchar(500) NOT NULL, - b_i18ntype varchar(20) NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_i18n_canuse DEFAULT (1), - CONSTRAINT PK_s_i18n PRIMARY KEY (b_id), - CONSTRAINT UQ_s_i18n_key_locale UNIQUE (b_key, b_locale) - ); - CREATE INDEX IX_s_i18n_locale ON dbo.s_i18n (b_locale, b_canuse); -END; - -IF OBJECT_ID(N'dbo.s_log_technical', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_log_technical ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_user_id bigint NULL, - b_sourcetype varchar(20) NULL, - b_loglevel varchar(16) NOT NULL, - b_logcategory varchar(64) NULL, - b_operation varchar(100) NULL, - b_module_code varchar(50) NULL, - b_request_id varchar(64) NULL, - b_trace_id varchar(64) NULL, - b_server_node varchar(128) NULL, - b_duration_ms bigint NULL, - b_result_code varchar(50) NULL, - b_error_code varchar(50) NULL, - b_error_message nvarchar(2000) NULL, - b_exception_text nvarchar(max) NULL, - b_context_text nvarchar(max) NULL, - b_occurdatetime datetime2 NULL CONSTRAINT DF_s_log_technical_occurdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_log_technical PRIMARY KEY (b_id) - ); - CREATE INDEX IX_s_log_technical_trace ON dbo.s_log_technical (b_trace_id, b_occurdatetime DESC); - CREATE INDEX IX_s_log_technical_level ON dbo.s_log_technical (b_loglevel, b_occurdatetime DESC); -END; - -IF OBJECT_ID(N'dbo.s_log_login', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_log_login ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_user_id bigint NULL, - b_login_type varchar(20) NOT NULL, - b_login_result int NOT NULL CONSTRAINT DF_s_log_login_result DEFAULT (0), - b_fail_reason nvarchar(200) NULL, - b_ip varchar(50) NULL, - b_ip_location nvarchar(200) NULL, - b_browser varchar(100) NULL, - b_browser_version varchar(50) NULL, - b_os varchar(100) NULL, - b_os_version varchar(50) NULL, - b_device_type varchar(20) NULL, - b_user_agent nvarchar(max) NULL, - b_session_id varchar(50) NULL, - b_request_id varchar(64) NULL, - b_trace_id varchar(64) NULL, - b_occurdatetime datetime2 NULL CONSTRAINT DF_s_log_login_occurdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_log_login PRIMARY KEY (b_id) - ); - CREATE INDEX IX_s_log_login_user ON dbo.s_log_login (b_user_id, b_occurdatetime DESC); - CREATE INDEX IX_s_log_login_result ON dbo.s_log_login (b_login_result, b_occurdatetime DESC); -END; - -IF OBJECT_ID(N'dbo.s_log_audit', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_log_audit ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_event_code varchar(50) NOT NULL, - b_module_code varchar(50) NULL, - b_data_id varchar(50) NULL, - b_business_no varchar(50) NULL, - b_operation varchar(100) NULL, - b_operator_id bigint NULL, - b_operator_name nvarchar(100) NULL, - b_source_type varchar(20) NOT NULL CONSTRAINT DF_s_log_audit_source_type DEFAULT ('user'), - b_visibility varchar(20) NOT NULL CONSTRAINT DF_s_log_audit_visibility DEFAULT ('internal'), - b_request_id varchar(64) NULL, - b_trace_id varchar(64) NULL, - b_payload_text nvarchar(max) NULL, - b_occurdatetime datetime2 NULL CONSTRAINT DF_s_log_audit_occurdatetime DEFAULT (SYSUTCDATETIME()), - CONSTRAINT PK_s_log_audit PRIMARY KEY (b_id) - ); - CREATE INDEX IX_s_log_audit_module ON dbo.s_log_audit (b_module_code, b_data_id, b_occurdatetime DESC); - CREATE INDEX IX_s_log_audit_trace ON dbo.s_log_audit (b_trace_id); -END; - -IF OBJECT_ID(N'dbo.s_log_audit_field', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_log_audit_field ( - b_id bigint NOT NULL, -- 雪花主键(应用层生成,全局唯一) - b_event_id bigint NOT NULL, - b_module_code varchar(50) NULL, - b_data_id varchar(50) NULL, - b_field varchar(50) NOT NULL, - b_field_label nvarchar(100) NULL, - b_before_value nvarchar(max) NULL, - b_after_value nvarchar(max) NULL, - b_before_display nvarchar(500) NULL, - b_after_display nvarchar(500) NULL, - b_visibility varchar(20) NOT NULL CONSTRAINT DF_s_log_audit_field_visibility DEFAULT ('internal'), - CONSTRAINT PK_s_log_audit_field PRIMARY KEY (b_id) - ); - CREATE INDEX IX_s_log_audit_field_event ON dbo.s_log_audit_field (b_event_id); - CREATE INDEX IX_s_log_audit_field_customer ON dbo.s_log_audit_field (b_module_code, b_data_id, b_visibility, b_event_id); -END; - -COMMIT TRANSACTION; - -SELECT DB_NAME() AS database_name, - (SELECT COUNT(*) FROM dbo.b_user) AS user_count, - (SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0) AS user_table_count; diff --git a/code/fms/fms-api/config/migrations/101_drop_physical_foreign_keys.sql b/code/fms/fms-api/config/migrations/101_drop_physical_foreign_keys.sql deleted file mode 100644 index 35cdf3ba..00000000 --- a/code/fms/fms-api/config/migrations/101_drop_physical_foreign_keys.sql +++ /dev/null @@ -1,44 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS-NEW' - THROW 51001, N'This migration can only run against FMS-NEW.', 1; - -BEGIN TRANSACTION; - -DECLARE @sql nvarchar(max) = N''; -SELECT @sql = @sql - + N'ALTER TABLE ' + QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + N'.' - + QUOTENAME(OBJECT_NAME(parent_object_id)) + N' DROP CONSTRAINT ' + QUOTENAME(name) + N';' -FROM sys.foreign_keys -ORDER BY object_id; - -IF @sql <> N'' - EXEC sys.sp_executesql @sql; - -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_group') AND name = N'IX_s_field_group_parent') - CREATE INDEX IX_s_field_group_parent ON dbo.s_field_group (b_module_id, b_parent_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_view') AND name = N'IX_s_field_view_group') - CREATE INDEX IX_s_field_view_group ON dbo.s_field_view (b_module_id, b_group_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_edit') AND name = N'IX_s_field_edit_group') - CREATE INDEX IX_s_field_edit_group ON dbo.s_field_edit (b_module_id, b_group_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_query') AND name = N'IX_s_field_query_module') - CREATE INDEX IX_s_field_query_module ON dbo.s_field_query (b_module_id, b_canuse, b_xh, b_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_query') AND name = N'IX_s_field_query_field') - CREATE INDEX IX_s_field_query_field ON dbo.s_field_query (b_field_module_id, b_field_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_field_query') AND name = N'IX_s_field_query_relation') - CREATE INDEX IX_s_field_query_relation ON dbo.s_field_query (b_relation_id) WHERE b_relation_id IS NOT NULL; -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_relation') AND name = N'IX_s_relation_module') - CREATE INDEX IX_s_relation_module ON dbo.s_relation (b_module_id, b_canuse, b_xh, b_id); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_relation') AND name = N'IX_s_relation_junction') - CREATE INDEX IX_s_relation_junction ON dbo.s_relation (b_junction_module_id) WHERE b_junction_module_id IS NOT NULL; -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_relation') AND name = N'IX_s_relation_order_module') - CREATE INDEX IX_s_relation_order_module ON dbo.s_relation (b_order_module_id) WHERE b_order_module_id IS NOT NULL; -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_power') AND name = N'IX_s_power_module') - CREATE INDEX IX_s_power_module ON dbo.s_power (b_module_id, b_field_id, b_canuse); -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.s_role_scope') AND name = N'IX_s_role_scope_field') - CREATE INDEX IX_s_role_scope_field ON dbo.s_role_scope (b_module_id, b_scope_field_id) WHERE b_scope_field_id IS NOT NULL; - -COMMIT TRANSACTION; - -SELECT COUNT(*) AS foreign_key_count FROM sys.foreign_keys; diff --git a/code/fms/fms-api/config/migrations/102_add_module_edit_mode.sql b/code/fms/fms-api/config/migrations/102_add_module_edit_mode.sql deleted file mode 100644 index 4a431db9..00000000 --- a/code/fms/fms-api/config/migrations/102_add_module_edit_mode.sql +++ /dev/null @@ -1,45 +0,0 @@ -/* - 支持模块「编辑方式」: - 1. s_module.b_edit_mode —— 数据模块的编辑形态: - form (主表):单条记录以表单形式编辑(配合 s_field_edit 的分组 / 栅格 / 占位符设计) - table (子表):作为子表以可编辑表格(grid)编辑(配合 s_field_edit 的列顺序 / 列宽设计) - 每个 data 模块只能存在一种编辑方式,默认 form。 - 2. s_field_edit.b_width —— 子表(表格)模式下列的宽度(px),仅表格编辑方式使用。 - 可重复执行:列与约束均通过存在性判断避免重复。 -*/ -SET NOCOUNT ON; - --- 1. s_module.b_edit_mode -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_module') - AND name = N'b_edit_mode' -) -BEGIN - ALTER TABLE dbo.s_module - ADD b_edit_mode varchar(10) NULL; -END; - -IF NOT EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_module') - AND name = N'CK_s_module_edit_mode' -) -BEGIN - ALTER TABLE dbo.s_module - ADD CONSTRAINT CK_s_module_edit_mode CHECK (b_edit_mode IS NULL OR b_edit_mode IN ('form', 'table')); -END; - --- 2. s_field_edit.b_width -IF NOT EXISTS ( - SELECT 1 - FROM sys.columns - WHERE object_id = OBJECT_ID(N'dbo.s_field_edit') - AND name = N'b_width' -) -BEGIN - ALTER TABLE dbo.s_field_edit - ADD b_width int NULL; -END; diff --git a/code/fms/fms-api/config/migrations/103_add_menu_icon_nvarchar.sql b/code/fms/fms-api/config/migrations/103_add_menu_icon_nvarchar.sql deleted file mode 100644 index afaafec1..00000000 --- a/code/fms/fms-api/config/migrations/103_add_menu_icon_nvarchar.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - 扩展 s_menu.b_icon 以支持自定义 SVG 图标。 - b_icon 从 varchar(50) 改为 nvarchar(max): - - lucide:Settings —— 引用 lucide 图标 - - 其他字符串 —— 当作 SVG 标记直接渲染 - 可重复执行:存在性判断避免重复变更。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS' - THROW 53600, N'This migration can only run against the FMS database.', 1; - -IF COL_LENGTH(N'dbo.s_menu', N'b_icon') IS NOT NULL -BEGIN - ALTER TABLE dbo.s_menu ALTER COLUMN b_icon nvarchar(max) NULL; -END; - -PRINT N'Migration 103 applied: s_menu.b_icon expanded to nvarchar(max).'; \ No newline at end of file diff --git a/code/fms/fms-api/config/migrations/104_drop_menu_power_code.sql b/code/fms/fms-api/config/migrations/104_drop_menu_power_code.sql deleted file mode 100644 index 8af5fbff..00000000 --- a/code/fms/fms-api/config/migrations/104_drop_menu_power_code.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - 菜单访问权限统一由 s_menu.b_code 派生,不再保存独立的 b_power_code。 - 可重复执行:仅在旧列存在时删除。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS' - THROW 53600, N'This migration can only run against the FMS database.', 1; - -IF COL_LENGTH(N'dbo.s_menu', N'b_power_code') IS NOT NULL -BEGIN - ALTER TABLE dbo.s_menu DROP COLUMN b_power_code; -END; - -PRINT N'Migration 104 applied: s_menu.b_power_code removed.'; diff --git a/code/fms/fms-api/config/migrations/105_normalize_menu_types.sql b/code/fms/fms-api/config/migrations/105_normalize_menu_types.sql deleted file mode 100644 index c19c4040..00000000 --- a/code/fms/fms-api/config/migrations/105_normalize_menu_types.sql +++ /dev/null @@ -1,39 +0,0 @@ -/* - 菜单类型由业务层校验,不在数据库中使用 CHECK 约束限制。 - 现有 data 菜单统一迁移为 page:页面现在同时填写路由和绑定模块。 - 可重复执行:仅处理仍存在的旧数据或约束。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -IF DB_NAME() <> N'FMS' - THROW 53600, N'This migration can only run against the FMS database.', 1; - -IF OBJECT_ID(N'dbo.s_menu', N'U') IS NOT NULL -BEGIN - UPDATE dbo.s_menu - SET b_menu_type = 'page' - WHERE b_menu_type = 'data'; - - IF EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_menu') - AND name = N'CK_s_menu_type' - ) - BEGIN - ALTER TABLE dbo.s_menu DROP CONSTRAINT CK_s_menu_type; - END; - - IF EXISTS ( - SELECT 1 - FROM sys.check_constraints - WHERE parent_object_id = OBJECT_ID(N'dbo.s_menu') - AND name = N'CK_s_menu_parent' - ) - BEGIN - ALTER TABLE dbo.s_menu DROP CONSTRAINT CK_s_menu_parent; - END; -END; - -PRINT N'Migration 105 applied: s_menu uses directory/page/external and business-layer validation.'; diff --git a/code/fms/fms-api/config/migrations/106_normalize_i18n_type_table.sql b/code/fms/fms-api/config/migrations/106_normalize_i18n_type_table.sql deleted file mode 100644 index 42470658..00000000 --- a/code/fms/fms-api/config/migrations/106_normalize_i18n_type_table.sql +++ /dev/null @@ -1,45 +0,0 @@ -/* - 将旧版 dbo.b_i18n_type 统一为系统表 dbo.s_i18n_type。 - 可重复执行,兼容新库未建表、旧库已有 b_i18n_type,以及两张表同时存在的情况。 -*/ -SET NOCOUNT ON; -SET XACT_ABORT ON; - -BEGIN TRANSACTION; - -IF OBJECT_ID(N'dbo.s_i18n_type', N'U') IS NULL -BEGIN - CREATE TABLE dbo.s_i18n_type ( - b_id bigint NOT NULL, - b_code varchar(20) NOT NULL, - b_name nvarchar(100) NOT NULL, - b_canuse int NOT NULL CONSTRAINT DF_s_i18n_type_canuse DEFAULT (1), - b_default int NOT NULL CONSTRAINT DF_s_i18n_type_default DEFAULT (0), - b_xh int NOT NULL CONSTRAINT DF_s_i18n_type_xh DEFAULT (0), - CONSTRAINT PK_s_i18n_type PRIMARY KEY (b_id), - CONSTRAINT UQ_s_i18n_type_code UNIQUE (b_code) - ); - CREATE INDEX IX_s_i18n_type_xh ON dbo.s_i18n_type (b_xh, b_id); -END; - -IF OBJECT_ID(N'dbo.b_i18n_type', N'U') IS NOT NULL -BEGIN - INSERT INTO dbo.s_i18n_type (b_id, b_code, b_name, b_canuse, b_default, b_xh) - SELECT old.b_id, old.b_code, old.b_name, old.b_canuse, old.b_default, old.b_xh - FROM dbo.b_i18n_type AS old - WHERE NOT EXISTS ( - SELECT 1 FROM dbo.s_i18n_type AS current_row - WHERE current_row.b_code = old.b_code - ); - - DROP TABLE dbo.b_i18n_type; -END; - -IF NOT EXISTS (SELECT 1 FROM dbo.s_i18n_type) -BEGIN - INSERT INTO dbo.s_i18n_type (b_id, b_code, b_name, b_canuse, b_default, b_xh) VALUES - (920000000000000001, N'zh-CN', N'简体中文', 1, 1, 0), - (920000000000000002, N'en-US', N'English', 1, 0, 10); -END; - -COMMIT TRANSACTION; diff --git a/code/fms/fms-api/config/migrations/200_rebuild_business_keys.sql b/code/fms/fms-api/config/migrations/200_rebuild_business_keys.sql deleted file mode 100644 index d937f538..00000000 --- a/code/fms/fms-api/config/migrations/200_rebuild_business_keys.sql +++ /dev/null @@ -1,462 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - --- ============================================================================ --- 200_rebuild_business_keys.sql --- 目的: 按《FMS新系统核心表结构设计.md》(2026-09-04) 将 FMS-NEW 元数据表 --- 从 bigint 雪花ID 方案重构为【字符串业务键】方案。 --- 目标库: FMS-NEW (118.89.70.199:1433), 执行前已备份: --- /var/opt/mssql/data/FMS-NEW_pre_refactor_20260905.bak --- 数据迁移范围: --- 迁移 : b_user(3) / s_module(2) / s_field+view/edit/query(6字段配置) --- / s_menu(5) / s_i18n_type(3) / s_i18n(8) --- 不迁移: s_log_* 日志数据 / s_power 权限数据(结构保留,建空表) --- 删除 : s_role / s_user_role / s_role_power / s_role_scope (文档不含,数据空) --- 视图 v_b_user / v_s_log_login / v_s_log_technical / v_s_log_audit (文档不含) --- 说明: 旧表先改名 *_pre200 -> 建新表 -> 迁移数据 -> 删除 *_pre200。 --- 逻辑全部在一个事务内, 失败自动回滚。 --- ============================================================================ - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'200_rebuild_business_keys can only run against FMS-NEW.', 1; - -BEGIN TRANSACTION; - --- --------------------------------------------------------------------------- --- 1. 删除文档中不存在的对象: 旧视图 + RBAC 表 --- --------------------------------------------------------------------------- -IF OBJECT_ID(N'dbo.v_s_log_audit', N'V') IS NOT NULL DROP VIEW dbo.v_s_log_audit; -IF OBJECT_ID(N'dbo.v_s_log_technical', N'V') IS NOT NULL DROP VIEW dbo.v_s_log_technical; -IF OBJECT_ID(N'dbo.v_s_log_login', N'V') IS NOT NULL DROP VIEW dbo.v_s_log_login; -IF OBJECT_ID(N'dbo.v_b_user', N'V') IS NOT NULL DROP VIEW dbo.v_b_user; - -IF OBJECT_ID(N'dbo.s_role_power', N'U') IS NOT NULL DROP TABLE dbo.s_role_power; -IF OBJECT_ID(N'dbo.s_user_role', N'U') IS NOT NULL DROP TABLE dbo.s_user_role; -IF OBJECT_ID(N'dbo.s_role_scope', N'U') IS NOT NULL DROP TABLE dbo.s_role_scope; -IF OBJECT_ID(N'dbo.s_role', N'U') IS NOT NULL DROP TABLE dbo.s_role; - --- --------------------------------------------------------------------------- --- 2. 旧表改名留档 *_pre200 (数据保留至迁移完成) --- --------------------------------------------------------------------------- -EXEC sys.sp_rename N'dbo.b_user', N'b_user_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_module', N's_module_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_field', N's_field_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_field_group', N's_field_group_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_field_view', N's_field_view_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_field_edit', N's_field_edit_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_field_query', N's_field_query_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_autocode', N's_autocode_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_relation', N's_relation_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_menu', N's_menu_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_power', N's_power_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_i18n_type', N's_i18n_type_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_i18n', N's_i18n_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_log_technical', N's_log_technical_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_log_login', N's_log_login_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_log_audit', N's_log_audit_pre200', N'OBJECT'; -EXEC sys.sp_rename N'dbo.s_log_audit_field', N's_log_audit_field_pre200', N'OBJECT'; - --- --------------------------------------------------------------------------- --- 3. 按设计文档创建新表 --- --------------------------------------------------------------------------- - --- 3.1 用户表 -CREATE TABLE dbo.b_user ( - b_id varchar(50) not null primary key, -- 用户账号本身 - b_name nvarchar(100) null, - b_bz nvarchar(400) null, - b_password nvarchar(255) not null, - b_canuse tinyint not null default 1, - b_logintime tinyint not null default 0 -); - --- 3.2 模块 -CREATE TABLE dbo.s_module ( - b_id varchar(50) not null primary key, -- 模块编码本身, 创建后不可修改 - b_parent_id varchar(50) null, - b_name nvarchar(200) not null, - b_i18n varchar(150) null, - b_module_type varchar(20) not null, - b_viewtable varchar(128) null, - b_savetable varchar(128) null, - b_keyfield varchar(50) null, - b_orderfield varchar(500) null, - b_delete_policy varchar(20) null, - b_canuse tinyint not null default 1, - b_xh int not null default 0, - b_bz nvarchar(2000) null, - b_edit_mode varchar(10) null -); -CREATE INDEX ix_s_module_parent ON dbo.s_module (b_parent_id, b_xh, b_canuse, b_id); -CREATE INDEX ix_s_module_order ON dbo.s_module (b_xh, b_id); -CREATE INDEX ix_s_module_savetable ON dbo.s_module (b_savetable); - --- 3.3 字段与布局 -CREATE TABLE dbo.s_field ( - b_module_id varchar(50) not null, - b_field varchar(50) not null, - b_name nvarchar(200) not null, - b_i18n varchar(150) null, - b_type varchar(30) not null, - b_dbtype varchar(30) not null, - b_length int null, - b_precision int null, - b_scale int null, - b_nullable tinyint not null default 1, - b_default_value nvarchar(1000) null, - b_db_default nvarchar(1000) null, - b_writemode varchar(20) not null default 'direct', - b_options nvarchar(max) null, - b_canuse tinyint not null default 1, - b_xh int not null default 0, -- 字段定义顺序:同步时按视图列序重排(10 起步) - primary key (b_module_id, b_field) -); -CREATE INDEX ix_s_field_module_order ON dbo.s_field (b_module_id, b_xh, b_field); - -CREATE TABLE dbo.s_field_group ( - b_id varchar(50) not null, -- 分组编码本身, 模块内唯一, 创建后不可修改 - b_module_id varchar(50) not null, - b_parent_id varchar(50) null, -- 父分组编码, NULL 表示根分组 - b_title nvarchar(200) not null, - b_i18n varchar(150) null, - b_xh int not null default 0, - b_canuse tinyint not null default 1, - b_colspan int not null default 48, - b_layout_direction varchar(10) null default 'vertical', - primary key (b_module_id, b_id) -); -CREATE INDEX ix_s_field_group_parent ON dbo.s_field_group (b_module_id, b_parent_id, b_xh, b_id); -CREATE INDEX ix_s_field_group_order ON dbo.s_field_group (b_module_id, b_xh, b_id); - -CREATE TABLE dbo.s_field_view ( - b_module_id varchar(50) not null, - b_field varchar(50) not null, - b_group_id varchar(50) null, - b_visible tinyint not null default 1, - b_xh int not null default 0, - b_width int null, - primary key (b_module_id, b_field) -); -CREATE INDEX ix_s_field_view_order ON dbo.s_field_view (b_module_id, b_xh, b_field); - -CREATE TABLE dbo.s_field_edit ( - b_module_id varchar(50) not null, - b_field varchar(50) not null, - b_group_id varchar(50) null, - b_visible tinyint not null default 1, - b_required tinyint not null default 0, - b_readonly tinyint not null default 0, - b_disabled tinyint not null default 0, - b_xh int not null default 0, - b_width int null, - b_placeholder nvarchar(400) null, - b_colspan int not null default 12, - b_height int null, - primary key (b_module_id, b_field) -); -CREATE INDEX ix_s_field_edit_order ON dbo.s_field_edit (b_module_id, b_xh, b_field); - -CREATE TABLE dbo.s_field_query ( - b_module_id varchar(50) not null, - b_field varchar(50) not null, - b_component varchar(30) null, - b_condition_no int not null default 1, - b_operator varchar(20) not null, - b_default_value nvarchar(1000) null, - b_canuse tinyint not null default 1, - b_xh int not null default 0, - primary key (b_module_id, b_field, b_condition_no) -); -CREATE INDEX ix_s_field_query_order ON dbo.s_field_query (b_module_id, b_xh, b_field, b_condition_no); - --- 3.4 自动编码 -CREATE TABLE dbo.s_autocode ( - b_module_id varchar(50) not null, - b_field varchar(50) not null, - b_prefix nvarchar(200) not null default N'', - b_dateformat varchar(30) not null default 'yyyyMM', - b_separator nvarchar(20) not null default N'-', - b_seqwidth int not null default 5, - b_resettype varchar(10) not null default 'month', - b_startvalue bigint not null default 1, - b_currentperiod varchar(8) null, - b_currentvalue bigint not null default 0, - b_canuse tinyint not null default 1, - primary key (b_module_id, b_field) -); - --- 3.5 模块关系 -CREATE TABLE dbo.s_relation ( - b_module_id varchar(50) not null, - b_target_module_id varchar(50) not null, - b_relation_type varchar(20) not null, - b_field varchar(50) not null, - b_target_field varchar(50) not null, - b_foreign_side varchar(10) null, - b_junction_module_id varchar(50) null, - b_junction_field varchar(50) null, - b_junction_target_field varchar(50) null, - b_ownership varchar(20) not null default 'reference', - b_owner_side varchar(10) null, - b_delete_policy varchar(20) null, - b_order_module_id varchar(50) null, - b_order_field varchar(50) null, - b_canuse tinyint not null default 1, - b_xh int not null default 0, - primary key (b_module_id, b_field, b_target_module_id, b_target_field) -); -CREATE INDEX ix_s_relation_module ON dbo.s_relation (b_module_id, b_canuse, b_xh, b_field, b_target_module_id); -CREATE INDEX ix_s_relation_target ON dbo.s_relation (b_target_module_id); - --- 3.6 菜单 -CREATE TABLE dbo.s_menu ( - b_id varchar(50) not null primary key, -- 菜单编码本身 - b_parent_id varchar(50) null, - b_name nvarchar(200) not null, - b_i18n varchar(150) null, - b_menu_type varchar(20) not null, - b_route varchar(200) null, - b_module_id varchar(50) null, - b_icon varchar(50) null, - b_xh int not null default 0, - b_canuse tinyint not null default 1 -); -CREATE INDEX ix_s_menu_parent ON dbo.s_menu (b_parent_id, b_xh, b_canuse, b_id); -CREATE INDEX ix_s_menu_order ON dbo.s_menu (b_xh, b_id); -CREATE INDEX ix_s_menu_module ON dbo.s_menu (b_module_id); -CREATE INDEX ix_s_menu_route ON dbo.s_menu (b_route, b_canuse, b_id); - --- 3.7 权限(结构保留, 数据不迁移) -CREATE TABLE dbo.s_power ( - b_id varchar(50) not null primary key, -- 权限编码本身 - b_name nvarchar(200) not null, - b_i18n varchar(150) null, - b_power_type varchar(20) not null, - b_resource varchar(128) null, - b_module_id varchar(50) null, - b_field varchar(50) null, - b_operation varchar(30) not null, - b_canuse tinyint not null default 1, - b_xh int not null default 0 -); -CREATE INDEX ix_s_power_module ON dbo.s_power (b_module_id, b_field, b_canuse); -CREATE INDEX ix_s_power_resource ON dbo.s_power (b_power_type, b_resource, b_canuse); - --- 3.8 多语言 -CREATE TABLE dbo.s_i18n_type ( - b_id varchar(20) not null primary key, -- 语言编码本身 - b_name nvarchar(200) not null, - b_canuse tinyint not null default 1, - b_default tinyint not null default 0, - b_xh int not null default 0 -); - -CREATE TABLE dbo.s_i18n ( - b_id varchar(200) not null primary key, -- b_key + ':' + b_locale - b_key varchar(150) not null, - b_locale varchar(20) not null, - b_value nvarchar(1000) not null, - b_i18ntype varchar(20) null, - b_canuse tinyint not null default 1, - b_module_id varchar(50) null, - unique (b_key, b_locale) -); -CREATE INDEX ix_s_i18n_module_key ON dbo.s_i18n (b_module_id, b_key, b_locale); -CREATE INDEX ix_s_i18n_locale ON dbo.s_i18n (b_locale, b_canuse); - --- 3.9 日志(仅结构, 数据不迁移) -CREATE TABLE dbo.s_log_technical ( - b_id uniqueidentifier not null, - b_user_id varchar(50) null, - b_sourcetype varchar(20) null, - b_loglevel varchar(16) not null, - b_logcategory varchar(64) null, - b_operation varchar(100) null, - b_module_id varchar(50) null, - b_request_id varchar(64) null, - b_trace_id varchar(64) null, - b_server_node varchar(128) null, - b_duration_ms bigint null, - b_result_code varchar(50) null, - b_error_code varchar(50) null, - b_error_message nvarchar(4000) null, - b_exception_text nvarchar(max) null, - b_context_text nvarchar(max) null, - b_occurdatetime datetime2 default sysutcdatetime(), - primary key nonclustered (b_id) -); - -CREATE TABLE dbo.s_log_login ( - b_id uniqueidentifier not null, - b_user_id varchar(50) null, - b_login_type varchar(20) not null, - b_login_result tinyint not null default 0, - b_fail_reason nvarchar(400) null, - b_ip varchar(50) null, - b_ip_location nvarchar(400) null, - b_browser varchar(100) null, - b_browser_version varchar(50) null, - b_os varchar(100) null, - b_os_version varchar(50) null, - b_device_type varchar(20) null, - b_user_agent nvarchar(max) null, - b_session_id varchar(50) null, - b_request_id varchar(64) null, - b_trace_id varchar(64) null, - b_occurdatetime datetime2 default sysutcdatetime(), - primary key nonclustered (b_id) -); - -CREATE TABLE dbo.s_log_audit ( - b_id uniqueidentifier not null, - b_event_code varchar(50) not null, - b_module_id varchar(50) null, - b_data_id varchar(50) null, - b_business_no varchar(50) null, - b_operation varchar(100) null, - b_operator_id varchar(50) null, - b_operator_name nvarchar(200) null, - b_source_type varchar(20) not null default 'user', - b_visibility varchar(20) not null default 'internal', - b_request_id varchar(64) null, - b_trace_id varchar(64) null, - b_payload_text nvarchar(max) null, - b_occurdatetime datetime2 default sysutcdatetime(), - primary key nonclustered (b_id) -); - -CREATE TABLE dbo.s_log_audit_field ( - b_id uniqueidentifier not null, - b_event_id uniqueidentifier not null, - b_module_id varchar(50) null, - b_data_id varchar(50) null, - b_field varchar(50) not null, - b_field_label nvarchar(200) null, - b_before_value nvarchar(max) null, - b_after_value nvarchar(max) null, - b_before_display nvarchar(1000) null, - b_after_display nvarchar(1000) null, - b_visibility varchar(20) not null default 'internal', - primary key nonclustered (b_id) -); - -CREATE CLUSTERED INDEX cx_s_log_technical_occur ON dbo.s_log_technical (b_occurdatetime, b_id); -CREATE CLUSTERED INDEX cx_s_log_login_occur ON dbo.s_log_login (b_occurdatetime, b_id); -CREATE CLUSTERED INDEX cx_s_log_audit_occur ON dbo.s_log_audit (b_occurdatetime, b_id); -CREATE CLUSTERED INDEX cx_s_log_audit_field_event ON dbo.s_log_audit_field (b_event_id, b_id); -CREATE INDEX ix_s_log_technical_trace ON dbo.s_log_technical (b_trace_id, b_occurdatetime); -CREATE INDEX ix_s_log_login_user ON dbo.s_log_login (b_user_id, b_occurdatetime); -CREATE INDEX ix_s_log_audit_module ON dbo.s_log_audit (b_module_id, b_data_id, b_occurdatetime); - --- --------------------------------------------------------------------------- --- 4. 数据迁移 (旧 *_pre200 -> 新表) --- --------------------------------------------------------------------------- - --- 4.1 b_user: b_account -> b_id, 丢弃业务系统冗余列 -INSERT INTO dbo.b_user (b_id, b_name, b_bz, b_password, b_canuse, b_logintime) -SELECT b_account, b_name, b_bz, b_password, b_canuse, b_logintime -FROM dbo.b_user_pre200; - --- 4.2 s_module: b_code -> b_id, 父模块与录入/更新人引用改业务键 -INSERT INTO dbo.s_module ( - b_id, b_parent_id, b_name, b_i18n, b_module_type, b_viewtable, b_savetable, - b_keyfield, b_orderfield, b_delete_policy, b_canuse, b_xh, b_bz, - b_edit_mode -) -SELECT - m.b_code, p.b_code, m.b_name, m.b_i18n, m.b_module_type, m.b_viewtable, m.b_savetable, - m.b_keyfield, m.b_orderfield, m.b_delete_policy, m.b_canuse, m.b_xh, m.b_bz, - m.b_edit_mode -FROM dbo.s_module_pre200 m -LEFT JOIN dbo.s_module_pre200 p ON p.b_id = m.b_parent_id; - --- 4.3 s_field: b_module_id 引用改业务键 -INSERT INTO dbo.s_field ( - b_module_id, b_field, b_name, b_i18n, b_type, b_dbtype, b_length, - b_precision, b_scale, b_nullable, b_default_value, b_db_default, b_writemode, - b_options, b_canuse -) -SELECT - mo.b_code, f.b_field, f.b_name, f.b_i18n, f.b_type, f.b_dbtype, f.b_length, - f.b_precision, f.b_scale, f.b_nullable, f.b_default_value, f.b_db_default, f.b_writemode, - f.b_options, f.b_canuse -FROM dbo.s_field_pre200 f -JOIN dbo.s_module_pre200 mo ON mo.b_id = f.b_module_id; - --- 4.4 s_field_view / s_field_edit / s_field_query: b_field_id -> b_field -INSERT INTO dbo.s_field_view (b_module_id, b_field, b_group_id, b_visible, b_xh, b_width) -SELECT mo.b_code, f.b_field, NULL, v.b_visible, v.b_xh, v.b_width -FROM dbo.s_field_view_pre200 v -JOIN dbo.s_module_pre200 mo ON mo.b_id = v.b_module_id -JOIN dbo.s_field_pre200 f ON f.b_id = v.b_field_id AND f.b_module_id = v.b_module_id; - -INSERT INTO dbo.s_field_edit (b_module_id, b_field, b_group_id, b_visible, b_required, b_readonly, b_disabled, b_xh, b_width, b_placeholder, b_colspan, b_height) -SELECT mo.b_code, f.b_field, NULL, e.b_visible, e.b_required, e.b_readonly, e.b_disabled, e.b_xh, e.b_width, e.b_placeholder, e.b_colspan, e.b_height -FROM dbo.s_field_edit_pre200 e -JOIN dbo.s_module_pre200 mo ON mo.b_id = e.b_module_id -JOIN dbo.s_field_pre200 f ON f.b_id = e.b_field_id AND f.b_module_id = e.b_module_id; - -INSERT INTO dbo.s_field_query (b_module_id, b_field, b_component, b_condition_no, b_operator, b_default_value, b_canuse, b_xh) -SELECT mo.b_code, f.b_field, q.b_component, q.b_condition_no, q.b_operator, q.b_default_value, q.b_canuse, q.b_xh -FROM dbo.s_field_query_pre200 q -JOIN dbo.s_module_pre200 mo ON mo.b_id = q.b_field_module_id -JOIN dbo.s_field_pre200 f ON f.b_id = q.b_field_id AND f.b_module_id = q.b_field_module_id; - --- s_field_group / s_autocode / s_relation: 无有效数据, 保持空表 --- (原 s_field_group 仅存的 1 行数据其 b_module_id 已不存在, 属孤儿数据, 不迁移) - --- 4.5 s_menu: b_code -> b_id, 父菜单/绑定模块引用改业务键 -INSERT INTO dbo.s_menu (b_id, b_parent_id, b_name, b_i18n, b_menu_type, b_route, b_module_id, b_icon, b_xh, b_canuse) -SELECT - m.b_code, p.b_code, m.b_name, m.b_i18n, m.b_menu_type, m.b_route, mo.b_code, - NULLIF(LEFT(CONVERT(nvarchar(max), m.b_icon), 50), N''), m.b_xh, m.b_canuse -FROM dbo.s_menu_pre200 m -LEFT JOIN dbo.s_menu_pre200 p ON p.b_id = m.b_parent_id -LEFT JOIN dbo.s_module_pre200 mo ON mo.b_id = m.b_module_id; - --- 4.6 s_i18n_type: b_code -> b_id -INSERT INTO dbo.s_i18n_type (b_id, b_name, b_canuse, b_default, b_xh) -SELECT b_code, b_name, b_canuse, b_default, b_xh -FROM dbo.s_i18n_type_pre200; - --- 4.7 s_i18n: b_id = b_key + ':' + b_locale, 模块引用改业务键(0 -> NULL) -INSERT INTO dbo.s_i18n (b_id, b_key, b_locale, b_value, b_i18ntype, b_canuse, b_module_id) -SELECT - i.b_key + N':' + i.b_locale, i.b_key, i.b_locale, i.b_value, i.b_i18ntype, i.b_canuse, - CASE WHEN i.b_module_id = 0 THEN NULL ELSE mo.b_code END -FROM dbo.s_i18n_pre200 i -LEFT JOIN dbo.s_module_pre200 mo ON mo.b_id = i.b_module_id; - --- s_power / s_log_* : 按需求不迁移数据 - --- --------------------------------------------------------------------------- --- 5. 删除 *_pre200 旧表 --- --------------------------------------------------------------------------- -DROP TABLE dbo.b_user_pre200; -DROP TABLE dbo.s_module_pre200; -DROP TABLE dbo.s_field_pre200; -DROP TABLE dbo.s_field_group_pre200; -DROP TABLE dbo.s_field_view_pre200; -DROP TABLE dbo.s_field_edit_pre200; -DROP TABLE dbo.s_field_query_pre200; -DROP TABLE dbo.s_autocode_pre200; -DROP TABLE dbo.s_relation_pre200; -DROP TABLE dbo.s_menu_pre200; -DROP TABLE dbo.s_power_pre200; -DROP TABLE dbo.s_i18n_type_pre200; -DROP TABLE dbo.s_i18n_pre200; -DROP TABLE dbo.s_log_technical_pre200; -DROP TABLE dbo.s_log_login_pre200; -DROP TABLE dbo.s_log_audit_pre200; -DROP TABLE dbo.s_log_audit_field_pre200; - -COMMIT TRANSACTION; - --- 验证输出 -SELECT DB_NAME() AS database_name, - (SELECT COUNT(*) FROM sys.tables WHERE is_ms_shipped = 0) AS user_table_count, - (SELECT COUNT(*) FROM dbo.b_user) AS user_count, - (SELECT COUNT(*) FROM dbo.s_module) AS module_count, - (SELECT COUNT(*) FROM dbo.s_field) AS field_count, - (SELECT COUNT(*) FROM dbo.s_menu) AS menu_count, - (SELECT COUNT(*) FROM dbo.s_i18n) AS i18n_count; diff --git a/code/fms/fms-api/config/migrations/201_add_bf_files.sql b/code/fms/fms-api/config/migrations/201_add_bf_files.sql deleted file mode 100644 index 3b68c3ee..00000000 --- a/code/fms/fms-api/config/migrations/201_add_bf_files.sql +++ /dev/null @@ -1,45 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - --- ============================================================================ --- 201_add_bf_files.sql --- 目的: 在 FMS-NEW 补建文件表 bf_files(旧 FMS 系统已有,代码 FileService 仍依赖)。 --- 参考旧库 FMS.dbo.bf_files 列结构;将"引用类"列改为字符串业务键: --- mx_moduleid -> varchar(50) 引用 s_module.b_id(模块编码) --- mx_inputuser_id / mx_updateuser_id / mx_shuser_id --- -> varchar(50) 引用 b_user.b_id(账号) --- father 仍为 bigint,引用本表 subid(文件树父节点)。 --- 主键 subid 为应用层雪花 bigint,由 FileService/IdGenerator 生成。 --- ============================================================================ - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'201_add_bf_files can only run against FMS-NEW.', 1; - -IF OBJECT_ID(N'dbo.bf_files', N'U') IS NULL -BEGIN - CREATE TABLE dbo.bf_files ( - subid bigint not null, -- 雪花主键(应用层生成) - father bigint null, -- 父节点(引用同表 subid) - mx_xh int null default 0, - mx_filename nvarchar(500) null, - mx_filesize varchar(50) null, - mx_fileext varchar(50) null, - mx_mapfilename nvarchar(500) null, - mx_moduleid varchar(50) null, -- 引用 s_module.b_id(模块编码) - mx_cutfilename nvarchar(500) null, - mx_cutfilesize varchar(50) null, - mx_cate_id varchar(50) null, - mx_bz nvarchar(500) null, - mx_orderid varchar(50) null, - mx_sh int not null default 0, - mx_shdatetime datetime2 null, - mx_shuser_id varchar(50) null, -- 引用 b_user.b_id(账号) - mx_inputuser_id varchar(50) null, -- 引用 b_user.b_id(账号) - mx_inputdatetime datetime2 null default sysutcdatetime(), - mx_updateuser_id varchar(50) null, - mx_updatedatetime datetime2 null, - CONSTRAINT PK_bf_files PRIMARY KEY (subid) - ); - CREATE INDEX ix_bf_files_module ON dbo.bf_files (mx_moduleid); - CREATE INDEX ix_bf_files_father ON dbo.bf_files (father); -END; diff --git a/code/fms/fms-api/config/migrations/202_add_bf_files_cateid.sql b/code/fms/fms-api/config/migrations/202_add_bf_files_cateid.sql deleted file mode 100644 index 8b783149..00000000 --- a/code/fms/fms-api/config/migrations/202_add_bf_files_cateid.sql +++ /dev/null @@ -1,26 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - --- ============================================================================ --- 202_add_bf_files_cateid.sql --- 目的: 在 FMS-NEW 补建文件分类表 bf_files_cateid(旧 FMS 系统已有, --- 前端 fms-file 组件 FileListPanel / useFileCategory 仍按该表加载分类)。 --- 参考旧库 G3HY2025.dbo.bf_files_cateid 列结构,并按字符串业务键/状态列 --- 统一规范:b_id 即分类编码(varchar,被 bf_files.mx_cate_id 引用)。 --- ============================================================================ - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'202_add_bf_files_cateid can only run against FMS-NEW.', 1; - -IF OBJECT_ID(N'dbo.bf_files_cateid', N'U') IS NULL -BEGIN - CREATE TABLE dbo.bf_files_cateid ( - b_id varchar(50) not null, -- 分类编码(字符串业务键),被 bf_files.mx_cate_id 引用 - b_name nvarchar(200) not null, -- 分类名称 - b_files_type varchar(50) null, -- 用途标识(如 file_sh 附件),可选 - b_xh int not null default 0, - b_canuse tinyint not null default 1, -- 启用 - b_bz nvarchar(500) null, -- 备注 - CONSTRAINT PK_bf_files_cateid PRIMARY KEY (b_id) - ); -END; diff --git a/code/fms/fms-api/config/migrations/203_drop_log_account.sql b/code/fms/fms-api/config/migrations/203_drop_log_account.sql deleted file mode 100644 index 482f3b0e..00000000 --- a/code/fms/fms-api/config/migrations/203_drop_log_account.sql +++ /dev/null @@ -1,30 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - --- ============================================================================ --- 203_drop_log_account.sql --- 目的: 从日志表移除冗余的 b_account 列,与《FMS新系统核心表结构设计.md》对齐: --- s_log_technical: 删除 b_account,保留 b_user_id --- s_log_login: 删除 b_account,保留 b_user_id --- 新结构中账号即 b_user.b_id(字符串业务键),日志通过 b_user_id 记录用户; --- b_account 列系历史建表脚本(100/200)多余引入,数据库中无其索引依赖。 --- ============================================================================ - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'203_drop_log_account can only run against FMS-NEW.', 1; - --- 若历史库中残留依赖 b_account 的索引,先显式删除 -IF OBJECT_ID(N'dbo.IX_s_log_login_account', N'INDEX') IS NOT NULL - DROP INDEX IX_s_log_login_account ON dbo.s_log_login; - -IF OBJECT_ID(N'dbo.s_log_login', N'U') IS NOT NULL - AND COL_LENGTH(N'dbo.s_log_login', N'b_account') IS NOT NULL -BEGIN - ALTER TABLE dbo.s_log_login DROP COLUMN b_account; -END; - -IF OBJECT_ID(N'dbo.s_log_technical', N'U') IS NOT NULL - AND COL_LENGTH(N'dbo.s_log_technical', N'b_account') IS NOT NULL -BEGIN - ALTER TABLE dbo.s_log_technical DROP COLUMN b_account; -END; diff --git a/code/fms/fms-api/config/migrations/204_add_s_field_xh.sql b/code/fms/fms-api/config/migrations/204_add_s_field_xh.sql deleted file mode 100644 index 731b281c..00000000 --- a/code/fms/fms-api/config/migrations/204_add_s_field_xh.sql +++ /dev/null @@ -1,69 +0,0 @@ -SET NOCOUNT ON; -SET XACT_ABORT ON; - --- ============================================================================ --- 204_add_s_field_xh.sql --- 目的: 给 s_field 增加排序列 b_xh(对齐 s_field_group/view/edit/query 的 b_xh 惯例)。 --- 此前 s_field 无顺序列,前端只能按 b_field 字母排序,模块「同步字段」后 --- 保存再加载,顺序会被字母序打乱,无法按数据库视图/表的列顺序持久化。 --- 目标库: FMS-NEW --- 说明: 1) 已存在 s_field 的库执行本脚本(新增列并回填初值)。 --- 2) b_xh 初值按各模块 b_viewtable 的列顺序(sys.columns.column_id)赋序, --- 步长 10;视图里找不到的字段保持 0(排在末位,按 b_field 兜底)。 --- 3) 全新库在 200_rebuild_business_keys.sql 建表定义中已含 b_xh, --- 此处 COL_LENGTH 判断将跳过 ADD,仅执行回填与建索引(幂等)。 --- 4) 批次按 GO 拆分:同一批次内 ALTER 加列后引用新列会在解析期 --- 报 Invalid column name,必须拆批执行(sqlcmd / JDBC 均按 GO 分批)。 --- ============================================================================ - -IF DB_NAME() <> N'FMS-NEW' - THROW 51000, N'204_add_s_field_xh can only run against FMS-NEW.', 1; - -BEGIN TRANSACTION; - -IF COL_LENGTH(N'dbo.s_field', N'b_xh') IS NULL -BEGIN - ALTER TABLE dbo.s_field - ADD b_xh int NOT NULL CONSTRAINT DF_s_field_xh DEFAULT (0); -END; -GO - --- 按模块查询视图的列顺序给既有字段行赋序(10 起步,与其它配置表一致) -UPDATE f -SET f.b_xh = ranked.xh -FROM dbo.s_field f -JOIN ( - SELECT f.b_module_id, - f.b_field, - ROW_NUMBER() OVER ( - PARTITION BY f.b_module_id - ORDER BY c.column_id - ) * 10 AS xh - FROM dbo.s_field f - JOIN dbo.s_module m ON m.b_id = f.b_module_id - JOIN sys.columns c ON c.object_id = OBJECT_ID(m.b_viewtable) - AND c.name = f.b_field -) ranked - ON ranked.b_module_id = f.b_module_id - AND ranked.b_field = f.b_field; -GO - -IF OBJECT_ID(N'dbo.ix_s_field_module_order', N'I') IS NULL -BEGIN - CREATE INDEX ix_s_field_module_order - ON dbo.s_field (b_module_id, b_xh, b_field); -END; -GO - -COMMIT TRANSACTION; -GO - --- 验证输出 -SELECT m.b_id AS module_id, - m.b_viewtable, - f.b_xh, - f.b_field -FROM dbo.s_module m -JOIN dbo.s_field f ON f.b_module_id = m.b_id -ORDER BY m.b_id, f.b_xh, f.b_field; -GO diff --git a/code/fms/fms-api/config/migrations/verify_business_schema.sql b/code/fms/fms-api/config/migrations/verify_business_schema.sql deleted file mode 100644 index d80ba03d..00000000 --- a/code/fms/fms-api/config/migrations/verify_business_schema.sql +++ /dev/null @@ -1,32 +0,0 @@ -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; diff --git a/code/fms/fms-vue/src/components/captcha/SliderCaptcha.vue b/code/fms/fms-vue/src/components/captcha/SliderCaptcha.vue index 4102d78e..36930ee6 100644 --- a/code/fms/fms-vue/src/components/captcha/SliderCaptcha.vue +++ b/code/fms/fms-vue/src/components/captcha/SliderCaptcha.vue @@ -47,9 +47,28 @@ watch(isPassing, (val) => { /* ================= 拖拽逻辑 ================= */ function getEventPageX(e) { - if ('pageX' in e) return e.pageX - if ('touches' in e && e.touches[0]) return e.touches[0].pageX - return 0 + if (typeof e.pageX === 'number') return e.pageX + // touchend 事件没有 touches,需要取 changedTouches,否则会误判为拖到 0 而回退 + const touch = e.changedTouches?.[0] || e.touches?.[0] + return touch ? touch.pageX : 0 +} + +/** + * 拖拽中把 move 事件挂到 document 上: + * 只挂在组件根节点时,鼠标移出组件后收不到 mousemove,滑块会卡在原地。 + */ +function bindDragEvents() { + document.addEventListener('mousemove', handleDragMoving) + document.addEventListener('touchmove', handleDragMoving, { passive: false }) + document.body.style.userSelect = 'none' + document.body.style.cursor = 'grabbing' +} + +function unbindDragEvents() { + document.removeEventListener('mousemove', handleDragMoving) + document.removeEventListener('touchmove', handleDragMoving) + document.body.style.userSelect = '' + document.body.style.cursor = '' } function getOffset() { @@ -64,15 +83,18 @@ function getOffset() { function handleDragStart(e) { if (isPassing.value || props.disabled) return + if (e.cancelable && e.type !== 'touchstart') e.preventDefault() // 阻止拖拽时选中文本 moveStartX.value = getEventPageX(e) const currentLeft = Number.parseInt(actionLeft.value || '0', 10) moveDistance.value = moveStartX.value - currentLeft isMoving.value = true + bindDragEvents() emit('start', e) } function handleDragMoving(e) { if (!isMoving.value || isPassing.value) return + if (e.cancelable) e.preventDefault() // 移动端阻止页面跟随滚动 const action = actionRef.value const bar = barRef.value if (!action || !bar) return @@ -103,6 +125,7 @@ function onDocumentMouseUp(e) { function handleDragEnd(e) { if (!isMoving.value || isPassing.value) return + unbindDragEvents() emit('end', e) const action = actionRef.value const bar = barRef.value @@ -123,12 +146,14 @@ function handleDragEnd(e) { } function checkPass() { + unbindDragEvents() isPassing.value = true isMoving.value = false emit('update:modelValue', true) } function resume() { + unbindDragEvents() isMoving.value = false isPassing.value = false moveDistance.value = 0 @@ -144,14 +169,23 @@ function resume() { }) } +// 鼠标在窗口外松开 / 切换窗口时收不到 mouseup,兜底取消拖拽,避免一直跟随鼠标 +function onWindowBlur() { + if (!isMoving.value) return + resume() +} + onMounted(() => { document.addEventListener('mouseup', onDocumentMouseUp) document.addEventListener('touchend', onDocumentMouseUp) + window.addEventListener('blur', onWindowBlur) }) onBeforeUnmount(() => { + unbindDragEvents() document.removeEventListener('mouseup', onDocumentMouseUp) document.removeEventListener('touchend', onDocumentMouseUp) + window.removeEventListener('blur', onWindowBlur) }) defineExpose({ resume }) @@ -162,8 +196,6 @@ defineExpose({ resume }) ref="wrapperRef" class="scaptcha" :class="{ 'scaptcha--disabled': disabled, 'scaptcha--passed': isPassing }" - @mousemove="handleDragMoving" - @touchmove="handleDragMoving" >
.<操作>`),不是数据范围;数据范围只描述行的可见与可操作边界,即使拥有删除权限也仍受范围限制。 + +### 权限编码规范 + +权限点编码即 `s_power.b_id`,也是 `s_user_power.b_power_id` 的外键值。格式为 `类型.对象[.能力]`,用**点号分隔层级**,全小写: + +| 类型 | 编码 | 含义 | 生成时机 | +| --- | --- | --- | --- | +| `page` | `page.<页面编码>` | 逻辑页面入口(按需启用) | 定义页面时 | +| `menu` | `menu.<菜单编码>` | 菜单入口 | 保存菜单时自动生成 | +| `module` | `module.<模块编码>` | 模块访问(≈ read,能否查看该模块数据) | 模块启用时自动生成 | +| `action` | `action.<模块编码>.<操作或动作>` | 数据操作 `create` / `update` / `delete` / `export`,以及业务动作 `audit` / `settle` 等 | 模块启用或动作注册时自动生成 | +| `report` | `report.<报表编码>` | 报表入口 | 定义报表时 | + +约定: + +- 点号分隔层级,从左到右依次为 `类型` → `对象` → `能力`; +- **对象编码本身不允许包含 `.`**:模块 / 菜单 / 页面 / 报表编码统一不含点号,否则无法按段解析; +- `_` 只用于编码内部(如 `container_main`),**不做分隔符**; +- 不使用 `/`、`#`、`|`、`:`(与路由冲突或需转义); +- 最长编码为 `action.container_main.cancel_settle`(33 字符),`b_id` 预留 `varchar(100)`; +- 编码生成后**不可编辑**,需要变更时删除重建; +- 判断权限时使用完整编码(前端用 Set 判断,零 join);查询时可用前缀,如 `b_id LIKE 'action.cw_fee.%'` 取某模块全部动作;注意 `_` 在 `LIKE` 中是单字符通配符,前缀查询时需用 `ESCAPE '\'` 转义或改用 `LEFT(b_id, n)` 比较。 + +权限采用“入口默认拒绝、字段与数据范围默认不限制、用户配置负责收紧”的策略(模块操作的默认行为见「待确认事项」第 1 条): + +- `menu.*`、`page.*`、`report.*` 与 `action.*` 属于入口或动作权限,必须存在有效的用户授权记录;`page`、`report` 仅在页面或报表需要独立入口控制时启用,启用后同样必须存在有效授权记录; +- `module.<模块编码>` 表示模块访问;模块级数据操作统一编码为 `action.<模块编码>.<操作>`,与业务动作同级;模块操作没有用户授权记录时的默认行为见「待确认事项」第 1 条;`s_power` 权限点或用户授权记录存在 `b_canuse = 0` 时明确禁用; - 字段没有有效的用户字段策略时,按模块字段默认配置执行,不额外限制查询、编辑和导出;有效字段策略只能收紧权限; - 数据范围没有配置时按 `all` 处理;有配置时先使用操作级 `override`,没有 `override` 再使用模块默认的 `*` 范围;同一层级多条范围按 OR 合并; - 用户个性化只影响列表布局、查询收起态、顺序和宽度,不得越过字段权限、字段启用状态或数据范围; - 数据库层不建 check 约束,字段取值及组合规则由业务层校验(见各表下方「业务层约束」)。 -权限过滤、字段裁剪和数据范围条件最终必须在后端 SQL 中落实,前端隐藏菜单、按钮和字段只用于界面展示。 +权限过滤、字段裁剪和数据范围条件最终必须落实到查询 SQL 中,前端隐藏菜单、按钮和字段只用于界面展示。 + +**当前落地方式(阶段性)**:后端是通用数据网关,`/data/loaddata` 直接接受 `search_condition`(行过滤)与 `search_columns`(列裁剪),自身不做权限判断。因此本阶段由**前端拼装 SQL 条件**实现权限过滤: + +- 数据范围 → 拼进 `search_condition`; +- 字段 `hidden` 策略 → 从 `search_columns` 中剔除; +- 拼装逻辑收敛在前端唯一的纯函数工具里(不散落在各页面),后续后端具备能力时可原样下沉; +- 这只是执行位置的前移,不改变任何权限规则;前端拼装属于界面层控制,敏感数据仍应在具备条件后补充后端校验。 ### 资源与权限归属 @@ -21,15 +62,15 @@ | --- | --- | --- | | `menu` | 导航入口、菜单显示 | 否 | | `page` | 逻辑页面访问(按需启用) | 否 | -| `module` | 读取、新增、修改、删除、导出、字段和数据范围 | 是 | -| `action` | 审核、反审核、核销等具体业务动作 | 通常绑定业务模块 | +| `module` | 模块访问(`module.<模块编码>`)、字段和数据范围;数据操作以 `action.<模块编码>.<操作>` 表示 | 是 | +| `action` | 审核、反审核、核销等具体业务动作,以及 create/update/delete/export | 通常绑定业务模块 | | Vue 路由/组件 | 技术实现和页面复用 | 否 | - 菜单或页面权限不会自动授予所使用模块的权限; - 一个页面可以使用多个模块,一个模块可以被多个页面复用,模块权限始终按模块自身计算; - Vue 路由和组件不是稳定的权限标识。`page` 权限使用稳定的逻辑页面编码,不使用路由路径或组件名称; - `s_menu.b_module_id`(如果保留)只表示菜单的默认/主模块,不能表示页面使用的全部模块,也不能触发权限继承; -- 普通菜单页面通常只配置菜单入口权限。只有需要独立直接访问的页面,才额外定义 `page/access` 权限,避免客户重复勾选菜单和页面。 +- 普通菜单页面通常只配置菜单入口权限。只有需要独立直接访问的页面,才额外定义 `page.<页面编码>` 权限,避免客户重复勾选菜单和页面。 ### 复合页面和公共页面 @@ -51,7 +92,7 @@ - 页面权限、菜单权限和模块权限互不继承; - 同一个公共 Vue 页面被多个模块使用时,以当前页面配置和实际 `module_id` 判断权限,不以路由名称判断权限。 -动作权限按业务归属配置:有明确业务主模块时使用 `action.module...execute`;真正跨模块且没有主模块的页面流程才使用 `action.page...execute`;不把动作绑定到 Vue 路由或公共组件。 +动作权限按业务归属配置:有明确业务主模块时使用 `action..`(`b_owner_type = 'module'`);真正跨模块且没有主模块的页面流程才使用 `action..`(`b_owner_type = 'page'`);不把动作绑定到 Vue 路由或公共组件,也不把动作绑定到菜单。 ### 权限计算顺序 @@ -59,10 +100,10 @@ 1. 用户账号和对应资源是否启用; 2. 菜单入口是否有有效授权;存在独立页面/报表权限时,再检查对应入口授权; -3. 当前动作是否有有效 `action/execute` 授权; -4. 当前模块操作是否被 `s_power` 或 `s_user_power.b_canuse = 0` 明确禁用,未配置时按默认放行; -5. 根据模块字段元数据和用户字段策略裁剪字段、查询和导出能力; -6. 根据数据范围的 `override`、`default` 或 `all` 生成 SQL 行条件; +3. 当前动作是否有有效 `action.<模块>.<动作>` 授权; +4. 当前模块操作是否被 `s_power` 或 `s_user_power.b_canuse = 0` 明确禁用;未配置授权记录时的默认行为见「待确认事项」第 1 条; +5. 根据模块字段元数据和用户字段策略裁剪字段、查询和导出能力(当前由前端从 `search_columns` 中剔除隐藏列); +6. 根据数据范围的 `override`、`default` 或 `all` 生成 SQL 行条件(当前由前端拼装进 `search_condition`); 7. 在以上结果基础上应用用户列表布局和查询布局偏好。 页面显示权限和接口执行权限必须使用同一套计算规则。前端可以提前隐藏无权限内容,但不能代替后端 SQL 的最终判断。 @@ -73,39 +114,41 @@ ```sql create table dbo.s_power ( - b_id bigint not null, -- 内部主键,雪花/序列生成,不表达业务含义 - b_code varchar(300) not null, -- 稳定、全局唯一的业务键,由系统生成 - -- 示例:menu.cw_fee.access / module.cw_fee.read / action.module.cw_fee.audit.execute + b_id varchar(100) not null, -- 权限编码本身即主键:menu.cw_fee / module.cw_fee / action.cw_fee.audit b_name nvarchar(200) not null, b_i18n varchar(150) null, - b_power_type varchar(20) not null, -- menu/page/report/module/action - b_resource_id varchar(128) not null, -- 当前权限对应的资源编码 - b_owner_type varchar(20) null, -- action 的 owner 类型:menu/page/module - b_owner_id varchar(128) null, -- action 的 owner 编码 - b_capability varchar(30) not null, -- access/execute/read/create/update/delete/export + b_power_type varchar(20) not null, -- page/menu/module/action/report + b_owner_type varchar(20) not null, -- 归属对象类型:page/menu/module/report;action 时为所属模块或页面 + b_owner_id varchar(50) not null, -- 归属对象编码:菜单/模块/页面/报表编码 + b_capability varchar(30) null, -- action 的操作或动作编码:create/update/delete/export/audit...;入口类为 null + b_operation varchar(30) null, -- 兼容列:access/execute,由 b_power_type 派生,后续可移除 b_canuse tinyint not null default 1, b_xh int not null default 0, - constraint PK_s_power primary key (b_id), - constraint UQ_s_power_code unique (b_code) + constraint PK_s_power primary key (b_id) ); -create index IX_s_power_resource - on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_resource_id, b_canuse); +create index IX_s_power_owner + on dbo.s_power (b_power_type, b_owner_type, b_owner_id, b_capability, b_canuse); ``` 业务层约束(数据库不建 check 约束,由业务层校验): -- `b_power_type` 只能取 `menu / page / report / module / action`; -- `menu / page / report` 类型:`b_owner_type`、`b_owner_id` 必须为空,`b_capability` 固定为 `access`; -- `module` 类型:`b_owner_type`、`b_owner_id` 必须为空,`b_capability` 只能取 `read / create / update / delete / export`; -- `action` 类型:`b_owner_type` 只能取 `menu / page / module`,`b_owner_id` 必填,`b_capability` 固定为 `execute`。 +- `b_id` 由 `类型.对象[.能力]` 规则生成(见「权限编码规范」),**生成后不可编辑**,变更时删除重建; +- `b_power_type` 只能取 `page / menu / module / action / report`; +- `page / menu / module / report` 类型:`b_capability` 必须为 `null`,`b_operation` 固定为 `access`; + - `module.<模块编码>` 表示模块访问(≈ read);模块的数据操作不在这里定义,统一用 `action.<模块编码>.<操作>`; +- `action` 类型:`b_owner_type` 只能取 `module / page`,`b_owner_id` 必填,`b_capability` 必填,`b_operation` 固定为 `execute`; +- **动作归属模块、不归属菜单**:业务动作统一 `b_owner_type = 'module'`,避免同一个动作在不同菜单下被重复配置; +- `b_id` 与 `(b_power_type, b_owner_type, b_owner_id, b_capability)` 一一对应,新建前先按组合查重。 + +> 与现有库(FMS-NEW)的差异:现有 `s_power` 已采用 `b_id varchar(50)` 编码主键,并含 `b_resource`、`b_module_id`、`b_operation` 列。迁移时把 `b_id` 放宽到 `varchar(100)`,补 `b_owner_type` / `b_owner_id` / `b_capability` 三列;`b_module_id` 与 `b_resource` 作为兼容列保留,新代码统一读写 `b_owner_*`。全部元数据表(`s_module`、`s_menu`、`s_field*`)均为字符串业务键主键,权限点保持一致,不引入代理键。 ### 1.2 s_user_power(用户权限授权表) ```sql create table dbo.s_user_power ( b_user_id varchar(50) not null, - b_power_id bigint not null, -- 引用 s_power.b_id(内部主键) + b_power_id varchar(100) not null, -- 引用 s_power.b_id,即权限编码:menu.cw_fee / action.cw_fee.audit b_canuse tinyint not null default 1, b_updatedatetime datetime2 null, constraint PK_s_user_power primary key (b_user_id, b_power_id) @@ -115,6 +158,13 @@ create index IX_s_user_power_user on dbo.s_user_power (b_user_id, b_canuse, b_power_id); ``` +业务层约束: + +- `b_power_id` 存权限**编码**而非内部 ID,可直接阅读与按前缀查询,判断时无需 join `s_power`; +- 采用「默认拒绝」策略时只保存 `b_canuse = 1` 的授权记录,没有记录即无权限; +- 采用「默认放行」策略时,被明确禁止的权限点保存 `b_canuse = 0`(见「待确认事项」第 1 条); +- 权限点本身 `b_canuse = 0` 时,所有用户的该权限一律不生效。 + ### 1.3 s_user_field_permission(用户字段访问策略表) ```sql @@ -152,6 +202,7 @@ create table dbo.s_user_data_scope ( b_operation varchar(30) not null, -- * / read / create / update / delete / export -- * 表示模块默认范围,仅 b_scope_level = 'default' 时允许使用 + -- 值域与 action.<模块编码>.<操作> 的 capability 一致,用于把「操作」和「该操作的行范围」串起来 b_scope_level varchar(10) not null default 'default', -- default / override;default 使用 b_operation='*',override 为操作级覆盖 @@ -245,44 +296,47 @@ create index IX_s_user_query_field_pref_order ### 2.1 s_power(权限定义) -| b_id | b_code | b_name | b_power_type | b_resource_id | b_owner_type | b_owner_id | b_capability | b_canuse | b_xh | -| ---: | --- | --- | --- | --- | --- | --- | --- | ---: | ---: | -| 1001 | menu.cw_fee.access | 费用管理菜单 | menu | cw_fee | null | null | access | 1 | 10 | -| 1002 | page.cw_fee.access | 费用页面 | page | cw_fee | null | null | access | 1 | 20 | -| 1003 | action.module.cw_fee.audit.execute | 费用审核 | action | audit | module | cw_fee | execute | 1 | 30 | -| 1004 | action.module.cw_fee.unaudit.execute | 费用反审核 | action | unaudit | module | cw_fee | execute | 1 | 40 | -| 1005 | module.cw_fee.read | 费用读取 | module | cw_fee | null | null | read | 1 | 50 | -| 1006 | module.cw_fee.create | 费用新增 | module | cw_fee | null | null | create | 1 | 60 | -| 1007 | module.cw_fee.update | 费用修改 | module | cw_fee | null | null | update | 1 | 70 | -| 1008 | module.cw_fee.delete | 费用删除 | module | cw_fee | null | null | delete | 1 | 80 | -| 1009 | module.cw_fee.export | 费用导出 | module | cw_fee | null | null | export | 1 | 90 | -| 1010 | report.cw_fee_summary.access | 费用汇总报表 | report | cw_fee_summary | null | null | access | 1 | 100 | +| b_id | b_name | b_power_type | b_owner_type | b_owner_id | b_capability | b_operation | b_canuse | b_xh | +| --- | --- | --- | --- | --- | --- | --- | ---: | ---: | +| menu.cw_fee | 费用管理菜单 | menu | menu | cw_fee | null | access | 1 | 10 | +| page.cw_fee | 费用页面 | page | page | cw_fee | null | access | 1 | 20 | +| module.cw_fee | 费用模块访问 | module | module | cw_fee | null | access | 1 | 30 | +| action.cw_fee.create | 费用新增 | action | module | cw_fee | create | execute | 1 | 40 | +| action.cw_fee.update | 费用修改 | action | module | cw_fee | update | execute | 1 | 50 | +| action.cw_fee.delete | 费用删除 | action | module | cw_fee | delete | execute | 1 | 60 | +| action.cw_fee.export | 费用导出 | action | module | cw_fee | export | execute | 1 | 70 | +| action.cw_fee.audit | 费用审核 | action | module | cw_fee | audit | execute | 1 | 80 | +| action.cw_fee.unaudit | 费用反审核 | action | module | cw_fee | unaudit | execute | 1 | 90 | +| report.cw_fee_summary | 费用汇总报表 | report | report | cw_fee_summary | null | access | 1 | 100 | ### 2.2 s_user_power(用户授权) | b_user_id | b_power_id | b_canuse | b_updatedatetime | -| --- | ---: | ---: | --- | -| zhangsan | 1001 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1002 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1005 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1007 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1009 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1006 | 0 | 2026-02-10 14:30:00 | -| zhangsan | 1008 | 0 | 2026-02-10 14:30:00 | -| zhangsan | 1003 | 1 | 2026-02-01 09:00:00 | -| zhangsan | 1010 | 1 | 2026-02-01 09:00:00 | -| lisi | 1001 | 1 | 2026-01-15 10:00:00 | -| lisi | 1002 | 1 | 2026-01-15 10:00:00 | -| lisi | 1005 | 1 | 2026-01-15 10:00:00 | -| lisi | 1006 | 1 | 2026-01-15 10:00:00 | -| lisi | 1007 | 1 | 2026-01-15 10:00:00 | -| lisi | 1008 | 1 | 2026-01-15 10:00:00 | -| lisi | 1009 | 1 | 2026-01-15 10:00:00 | -| lisi | 1003 | 1 | 2026-01-15 10:00:00 | -| lisi | 1004 | 1 | 2026-01-15 10:00:00 | -| lisi | 1010 | 1 | 2026-01-15 10:00:00 | +| --- | --- | ---: | --- | +| zhangsan | menu.cw_fee | 1 | 2026-02-01 09:00:00 | +| zhangsan | page.cw_fee | 1 | 2026-02-01 09:00:00 | +| zhangsan | module.cw_fee | 1 | 2026-02-01 09:00:00 | +| zhangsan | action.cw_fee.update | 1 | 2026-02-01 09:00:00 | +| zhangsan | action.cw_fee.export | 1 | 2026-02-01 09:00:00 | +| zhangsan | action.cw_fee.audit | 1 | 2026-02-01 09:00:00 | +| zhangsan | report.cw_fee_summary | 1 | 2026-02-01 09:00:00 | +| zhangsan | action.cw_fee.create | 0 | 2026-02-10 14:30:00 | +| zhangsan | action.cw_fee.delete | 0 | 2026-02-10 14:30:00 | +| lisi | menu.cw_fee | 1 | 2026-01-15 10:00:00 | +| lisi | page.cw_fee | 1 | 2026-01-15 10:00:00 | +| lisi | module.cw_fee | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.create | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.update | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.delete | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.export | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.audit | 1 | 2026-01-15 10:00:00 | +| lisi | action.cw_fee.unaudit | 1 | 2026-01-15 10:00:00 | +| lisi | report.cw_fee_summary | 1 | 2026-01-15 10:00:00 | -张三的 `1006` 对应 `module.cw_fee.create`,`1008` 对应 `module.cw_fee.delete`,两条记录都已停用(`b_canuse = 0`),因此张三没有新增和删除权限。模块操作权限没有用户授权记录时默认放行,所以需要显式停用记录表达禁止操作。 +张三没有 `action.cw_fee.create` / `action.cw_fee.delete` 权限: + +- **默认放行**策略下,模块操作没有授权记录即视为允许,因此必须显式保存 `b_canuse = 0` 来禁止(表中后两条); +- **默认拒绝**策略下则不需要这两行,没有记录就是没有权限(见「待确认事项」第 1 条)。 ### 2.3 s_user_field_permission(字段访问策略) @@ -308,3 +362,33 @@ create index IX_s_user_query_field_pref_order - 张三使用模块默认范围(`*` + department)读取本部门数据,update 有操作级覆盖(override + own),只能修改本人录入的费用; - 李四使用默认范围 department_tree 处理一般操作,delete 有操作级覆盖为 all,可删全模块数据。 + +--- + +## 3. 权限在哪里配置 + +权限分「定义端」和「授权端」,两者分离: + +| 位置 | 配置内容 | 写入的表 | +| --- | --- | --- | +| **模块管理** | 字段敏感标记(只有敏感字段才进入授权界面);自动生成 `module.<模块编码>` 与 `action.<模块编码>.<操作或动作>`(数据操作由模块元数据生成,业务动作由动作注册生成) | `s_module`、`s_field`、`s_power` | +| **菜单管理** | 只管入口:`menu.<菜单编码>` 随菜单保存自动生成;`b_module_id` 仅表示主模块,**不继承任何权限**;不再在菜单上手工录入 action 权限点 | `s_menu`、`s_power` | +| **用户授权(授权端)** | 选用户 → 勾入口 / 动作 → 设字段策略 → 设数据范围;支持角色模板批量套用 | `s_user_power`、`s_user_field_permission`、`s_user_data_scope` | +| **个人偏好** | 列可见 / 顺序 / 宽度、查询收起态字段 | `s_user_field_pref`、`s_user_query_field_pref` | + +规则: + +- 动作归属**模块**而非菜单,同一个动作只配置一次,不随菜单重复; +- 勾了菜单不等于拥有模块权限,反之亦然,两者分别授权; +- 授权界面可为操作便利做联动(勾菜单时自动带出其 `b_module_id` 指向的模块),但落库仍是两条独立记录; +- 菜单 `b_canuse = 0` 时一票否决,所有用户均不可见。 + +> 现状提示:当前系统只有菜单管理维护权限点字典,`s_user_power` 等授权表尚未建立,也没有授权界面;权限过滤目前只有登录态校验,其余全部未落地。 + +## 4. 待确认事项 + +1. **默认拒绝 还是 默认放行**(未拍板):入口类(`menu` / `page` / `report`)一律默认拒绝;`action.<模块>.<操作>` 在没有授权记录时——默认拒绝(没有记录即无权限,更安全,配合角色模板降低配置量,**推荐**)还是默认放行(只存 `b_canuse = 0` 的例外,配置量小但新增动作会自动对所有人生效)。本文示例按两种都做了说明,定稿后需统一。 +2. **角色**:`s_role` / `s_user_role` / `s_role_power` 等表已在 `200_rebuild_business_keys.sql` 中删除。是只做「用户级授权 + 角色模板批量展开」,还是重建角色表。 +3. **action 归属修正**:现有实现把 action 权限点挂在菜单上(`s_power.b_module_id` 存的是菜单 id),需改为挂模块;菜单未绑定 `b_module_id` 时的兜底规则待定。 +4. **数据范围的数据来源**:登录态目前只有 `userId`,没有部门 / 部门树信息,`own` / `department` / `department_tree` 条件的取值来源待定(需要在登录返回或用户信息中补充)。 +5. **后端校验**:当前阶段权限过滤由前端拼 SQL 实现,后端仅校验登录态与 SQL 只读性。敏感数据的最终防线仍需后端校验,待后端具备能力后下沉。 diff --git a/code/fms/权限与功能实例简化设计.md b/code/fms/权限与功能实例简化设计.md new file mode 100644 index 00000000..af410a99 --- /dev/null +++ b/code/fms/权限与功能实例简化设计.md @@ -0,0 +1,252 @@ +# FMS 权限与功能实例简化设计 + +## 1. 设计原则 + +- 客户按菜单查找功能,但权限不绑定菜单位置。 +- `s_feature` 表示客户能理解的业务功能或页面区域,是入口和显示权限边界。 +- `s_module` 是技术数据对象,负责字段、数据范围和默认数据能力,不直接出现在客户菜单树中。 +- 同一模块被多个功能使用时,模块默认能力只配置一次。 +- 某个功能使用同一模块但权限更严时,增加功能-模块例外,只能收紧,不能扩大权限。 +- 同一物理表但业务语义、字段或数据范围完全不同,拆成不同逻辑模块。 +- 公共 Vue 页面、路由和组件可以复用,但不同业务场景使用不同 `s_feature`。 + +## 2. 对象关系 + +```text +菜单(既有表) + └── 引用 s_feature.b_code,只负责导航 + +s_feature + └── 技术配置:使用哪些 s_module、模板、页面区域或报表卡片 + +s_module + └── 字段、默认数据能力、默认数据范围 + +s_power + ├── feature.* 功能入口、区域/卡片显示、功能专属动作 + └── module.* 模块默认数据能力 + +s_user_power + └── 用户对 feature.* / module.* 的授权 + +s_user_feature_module_override + └── 某用户在某功能使用某模块时的收紧例外 +``` + +## 3. 表结构 + +### 3.1 s_feature(业务功能实例) + +```sql +create table dbo.s_feature ( + b_code varchar(100) not null, + b_name nvarchar(200) not null, + b_feature_type varchar(20) not null, -- page / panel / report_card + b_parent_code varchar(100) null, + b_template_code varchar(100) null, + b_canuse tinyint not null default 1, + b_xh int not null default 0, + primary key (b_code) +); +``` + +菜单、模块及功能-模块关系属于既有技术配置表,本文件只约定语义,不重复定义其表结构。 + +### 3.2 s_power(权限点) + +```sql +create table dbo.s_power ( + b_code varchar(180) not null, + b_scope_type varchar(20) not null, -- feature / module + b_scope_code varchar(100) not null, -- feature_code 或 module_id + b_name nvarchar(200) not null, + b_capability varchar(30) not null, -- access/read/create/update/delete/export/业务动作 + b_i18n varchar(220) null, + b_canuse tinyint not null default 1, + b_xh int not null default 0, + primary key (b_code) +); +``` + +业务层校验 `b_code`、`b_scope_type`、`b_scope_code` 和 `b_capability` 的组合关系。权限编码由系统生成,创建后不可修改。 + +### 3.3 s_user_power(用户默认授权) + +```sql +create table dbo.s_user_power ( + b_user_id varchar(50) not null, + b_power_code varchar(180) not null, + b_canuse tinyint not null default 1, + b_updatedatetime datetime2 null, + primary key (b_user_id, b_power_code), + foreign key (b_power_code) references dbo.s_power(b_code) +); +``` + +### 3.4 s_user_feature_module_override(功能-模块收紧例外) + +```sql +create table dbo.s_user_feature_module_override ( + b_user_id varchar(50) not null, + b_feature_code varchar(100) not null, + b_module_id varchar(50) not null, + b_capability varchar(30) not null, -- read/create/update/delete/export + b_canuse tinyint not null default 0, -- 0 表示在该场景禁止 + b_updatedatetime datetime2 null, + primary key (b_user_id, b_feature_code, b_module_id, b_capability) +); +``` + +该表只保存例外限制,不保存默认允许记录,也不能用于突破 `s_user_power` 的模块权限。 + +字段和数据范围仍按逻辑模块配置: + +```text +s_user_field_permission(user_id, module_id, field, ...) +s_user_data_scope(user_id, module_id, operation, ...) +``` + +如果某功能需要不同字段或数据范围,可将例外表扩展为功能-模块维度;仍只允许收紧权限。 + +## 4. 权限计算 + +### 4.1 入口和显示 + +```text +页面进入 = feature..access +页面区域显示 = 父页面已进入 + feature..access +报表卡片显示 = 父看板已进入 + feature..access +``` + +### 4.2 模块操作 + +```text +模块读取 = feature.access + module..read +模块新增 = feature.access + module..create +模块修改 = feature.access + module..update +模块删除 = feature.access + module..delete +模块导出 = feature.access + module..export +``` + +如果存在 `s_user_feature_module_override` 对应的禁止记录,则该功能场景下的能力被收紧。 + +```text +最终模块能力 = 功能入口 ∩ 用户模块能力 ∩ 功能-模块例外 +``` + +### 4.3 功能专属动作 + +审核、反审核、核销等不属于通用 CRUD 的动作,直接绑定功能实例: + +```text +feature.sea_detail.audit +feature.cw_fee_list.settle +``` + +## 5. Demo 数据 + +### 5.1 功能实例 + +| b_code | b_name | b_feature_type | b_parent_code | b_template_code | +| --- | --- | --- | --- | --- | +| sea_detail | 海运详细 | page | null | DetailPage | +| sea_detail_container | 海运详细-装箱区域 | panel | sea_detail | DetailPanel | +| container_query | 装箱查询 | page | null | CommonListPage | +| cw_fee_list | 费用列表 | page | null | CommonListPage | +| finance_dashboard | 财务看板 | page | null | DashboardPage | +| ar_aging_card | 应收账龄 | report_card | finance_dashboard | ReportCard | + +### 5.2 功能使用的模块 + +| b_feature_code | b_module_id | b_usage_type | b_required | +| --- | --- | --- | ---: | +| sea_detail | sea_main | main | 1 | +| sea_detail | cw_fee | detail | 0 | +| sea_detail_container | container_main | detail | 0 | +| container_query | container_main | main | 1 | +| cw_fee_list | cw_fee | main | 1 | +| ar_aging_card | finance_main | source | 1 | + +### 5.3 权限点 + +| b_code | b_scope_type | b_scope_code | b_capability | b_name | +| --- | --- | --- | --- | --- | +| feature.sea_detail.access | feature | sea_detail | access | 进入海运详细 | +| feature.sea_detail.audit | feature | sea_detail | audit | 海运审核 | +| feature.sea_detail_container.access | feature | sea_detail_container | access | 显示装箱区域 | +| feature.container_query.access | feature | container_query | access | 进入装箱查询 | +| feature.cw_fee_list.access | feature | cw_fee_list | access | 进入费用列表 | +| feature.finance_dashboard.access | feature | finance_dashboard | access | 进入财务看板 | +| feature.ar_aging_card.access | feature | ar_aging_card | access | 显示应收账龄 | +| feature.ar_aging_card.export | feature | ar_aging_card | export | 导出应收账龄 | +| module.sea_main.read | module | sea_main | read | 查看海运主表 | +| module.cw_fee.read | module | cw_fee | read | 查看费用 | +| module.cw_fee.create | module | cw_fee | create | 新增费用 | +| module.cw_fee.update | module | cw_fee | update | 修改费用 | +| module.cw_fee.export | module | cw_fee | export | 导出费用 | +| module.container_main.read | module | container_main | read | 查看装箱 | +| module.container_main.export | module | container_main | export | 导出装箱 | + +### 5.4 用户默认授权 + +| b_user_id | b_power_code | b_canuse | +| --- | --- | ---: | +| zhangsan | feature.sea_detail.access | 1 | +| zhangsan | feature.sea_detail_container.access | 1 | +| zhangsan | feature.container_query.access | 1 | +| zhangsan | feature.cw_fee_list.access | 1 | +| zhangsan | module.sea_main.read | 1 | +| zhangsan | module.container_main.read | 1 | +| zhangsan | module.cw_fee.read | 1 | +| zhangsan | module.cw_fee.create | 1 | +| zhangsan | module.cw_fee.update | 1 | +| lisi | feature.sea_detail.access | 1 | +| lisi | feature.sea_detail_container.access | 1 | +| lisi | feature.container_query.access | 1 | +| lisi | feature.cw_fee_list.access | 1 | +| lisi | feature.finance_dashboard.access | 1 | +| lisi | feature.ar_aging_card.access | 1 | +| lisi | module.sea_main.read | 1 | +| lisi | module.container_main.read | 1 | +| lisi | module.container_main.export | 1 | +| lisi | module.cw_fee.read | 1 | +| lisi | module.cw_fee.create | 1 | +| lisi | module.cw_fee.update | 1 | +| lisi | module.cw_fee.export | 1 | + +### 5.5 功能-模块例外 + +李四可以在费用列表维护费用,但海运详细中的费用只读: + +| b_user_id | b_feature_code | b_module_id | b_capability | b_canuse | +| --- | --- | --- | --- | ---: | +| lisi | sea_detail | cw_fee | create | 0 | +| lisi | sea_detail | cw_fee | update | 0 | +| lisi | sea_detail | cw_fee | export | 0 | + +结果: + +```text +费用列表:可查看、新增、修改、导出 +海运详细:可查看费用,不可新增、修改、导出 +``` + +## 6. 运行规则 + +```text +请求 -> 服务端确定 feature_code + -> 检查 feature..access + -> 按功能配置取得允许的 module_id + -> 检查 module.. + -> 检查功能-模块例外 + -> 应用字段权限和数据范围 + -> 执行查询、写入或导出 +``` + +- 菜单只负责定位功能实例,同一功能挂在多个菜单时只授权一次。 +- 同一公共页面模板对应不同功能实例时,权限按功能实例区分。 +- 同一模块被多个功能使用时,模块默认能力只配置一次。 +- 功能场景差异通过例外限制表达,例外只能收紧。 +- 页面内可独立隐藏的区域定义为 `panel` 功能实例;看板卡片定义为 `report_card`。 +- 前端传入的 `module_id` 必须经过当前功能的模块白名单校验。 +- 后端接口必须重复校验 `access`、模块操作权限和例外限制,不能只依赖前端按钮隐藏。