20260729173317

This commit is contained in:
oneao committed 2026-07-29 17:33:21 +08:00
1 parent f6b79ea09a
commit 1c839b707a
26 files changed
+1902 -29

No files matched your search

@@ -80,6 +80,24 @@ GO
);
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,
@@ -113,6 +131,7 @@ GO
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),
@@ -0,0 +1,14 @@
/* 为编辑配置增加显示开关,存量配置默认显示。 */
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;
@@ -0,0 +1,25 @@
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;
@@ -0,0 +1,52 @@
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;
@@ -0,0 +1,156 @@
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_code varchar(50) NOT NULL,
b_name nvarchar(150) NOT NULL,
b_level int NOT NULL CONSTRAINT DF_b_othercompany_bmfl_level DEFAULT (1),
b_path varchar(1000) NOT NULL,
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 UQ_b_othercompany_bmfl_code UNIQUE (b_code),
CONSTRAINT CK_b_othercompany_bmfl_level CHECK (b_level >= 1),
CONSTRAINT CK_b_othercompany_bmfl_parent CHECK (
b_parent_id IS NULL OR b_parent_id <> b_id
),
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;
@@ -0,0 +1,252 @@
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;