216 lines
10 KiB
Transact-SQL
216 lines
10 KiB
Transact-SQL
/* ============================================================================
|
|
其他数据:模块注册(base_otherdata 根 + 6 个分组 + 64 个数据模块 + 字段定义)
|
|
|
|
依据文档:FMS业务表设计.md「其他数据」节
|
|
前置脚本:fms_business_otherdata.sql(建表 + 视图)
|
|
说明:
|
|
1. 三层组织:其他数据(base_otherdata)→ 分组(常用/系统/仓库/物流/铁运/空运,module 类型)
|
|
→ 数据模块(data);模块编码 = 表名(如 b_money),b_view_table / b_save_table 都指向表;
|
|
2. b_canuse 沿用旧库 b_other_bmfl 的启用状态(启用 46、停用 16);
|
|
3. s_field 的字段名先用字段编码占位,重跑本脚本后需执行
|
|
FieldNameSync --all-otherdata --force 重建字段名与 view/edit 配置;
|
|
4. b_from / b_grade 也在此注册(表由迁移工具重建为雪花);
|
|
5. b_othercompany_partner_type(树形分类)不在本脚本注册,由 othercompany 页面维护。
|
|
============================================================================ */
|
|
|
|
SET NOCOUNT ON;
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
1. 清理(脚本可重复执行)
|
|
---------------------------------------------------------------------------- */
|
|
|
|
delete from dbo.s_field where b_module_id in (select b_id from dbo.s_module where b_path like '/base/base_otherdata/%');
|
|
GO
|
|
|
|
delete from dbo.s_module where b_path like '/base/base_otherdata/%' or b_id = 'base_otherdata';
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
2. 根模块
|
|
---------------------------------------------------------------------------- */
|
|
|
|
insert into dbo.s_module (b_id, b_parent_id, b_depth, b_path, b_name, b_i18n, b_module_type, b_canuse, b_xh, b_bz)
|
|
values ('base_otherdata', 'base', 1, '/base/base_otherdata/', N'其他数据', 'module.base_otherdata', 'module', 1, 30,
|
|
N'原 G3HY「其他数据」的 62 张基础字典 + b_from / b_grade');
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
3. 分组(6 个 module 节点):常用 / 系统 / 仓库 / 物流 / 铁运 / 空运
|
|
---------------------------------------------------------------------------- */
|
|
|
|
declare @groups table (id varchar(50) primary key, name nvarchar(200) not null, xh int not null);
|
|
insert into @groups (id, name, xh) values
|
|
('od_common', N'常用', 10),
|
|
('od_system', N'系统', 20),
|
|
('od_depot', N'仓库', 30),
|
|
('od_logistics', N'物流', 40),
|
|
('od_rail', N'铁运', 50),
|
|
('od_air', N'空运', 60);
|
|
|
|
insert into dbo.s_module (b_id, b_parent_id, b_depth, b_path, b_name, b_i18n, b_module_type, b_canuse, b_xh)
|
|
select g.id, 'base_otherdata', 2, '/base/base_otherdata/' + g.id + '/', g.name, 'module.' + g.id, 'module', 1, g.xh
|
|
from @groups g;
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
4. 数据模块(64 个):id 为 'v_' + 表名(列表统一写法),插入时取表名作为模块编码;
|
|
分组按 xh 段划分(与列表中的分组顺序一致);b_view_table / b_save_table 都指向表本身
|
|
---------------------------------------------------------------------------- */
|
|
|
|
declare @mods table (id varchar(50) primary key, name nvarchar(200) not null, canuse tinyint not null, xh int not null);
|
|
insert into @mods (id, name, canuse, xh) values
|
|
-- 1.常用
|
|
('v_b_feetype', N'费用类别', 1, 10),
|
|
('v_b_oceanline', N'航线', 1, 20),
|
|
('v_b_goodssource', N'货物来源', 1, 30),
|
|
('v_b_dailyfeetype', N'日常费用', 1, 40),
|
|
('v_b_dailytype', N'收支类型', 0, 50),
|
|
('v_b_ywtype', N'业务类型', 1, 60),
|
|
('v_b_ysfs', N'运输方式', 1, 70),
|
|
('v_b_port', N'港口', 1, 80),
|
|
('v_b_money', N'币种', 1, 90),
|
|
-- 2.系统
|
|
('v_b_cargo_damage_status', N'货损状态', 1, 100),
|
|
('v_b_bulkforkliftpersonname', N'散货铲车人员', 1, 110),
|
|
('v_b_bulktype', N'散货类型', 1, 120),
|
|
('v_b_bulkpersonname', N'散货理货人员', 1, 130),
|
|
('v_b_bulkstevedorepersonname', N'散货装卸人员', 1, 140),
|
|
('v_b_charging_method', N'收费方式', 1, 150),
|
|
('v_b_unloading_method', N'卸货方式', 1, 160),
|
|
('v_b_sys_b_lessfull', N'装箱', 1, 170),
|
|
('v_b_sys_edittype', N'字段编辑选择', 0, 180),
|
|
('v_b_vessel', N'船名船次', 1, 190),
|
|
('v_b_freightpayment', N'运费条款', 1, 200),
|
|
('v_b_con_type', N'箱型管理', 1, 210),
|
|
('v_b_jsfs', N'结算方式', 0, 220),
|
|
('v_b_city', N'城市', 0, 230),
|
|
('v_b_ivtype', N'发票类型', 1, 240),
|
|
('v_b_sys_sex', N'性别', 0, 250),
|
|
('v_b_sys_copies', N'提单份数', 0, 260),
|
|
('v_b_cztype', N'称重方式', 1, 270),
|
|
('v_b_sys_level', N'级别', 0, 280),
|
|
('v_b_sys_operator', N'条件设置操作符', 0, 290),
|
|
('v_b_blstate', N'提单方式', 0, 300),
|
|
('v_b_sys_state', N'审核状态', 0, 310),
|
|
('v_b_sys_feesf', N'费用收付', 0, 320),
|
|
('v_bc_priceList_type', N'价目表类型', 0, 330),
|
|
('v_b_sys_yesno', N'是否', 0, 340),
|
|
('v_b_sys_pricelisttype', N'合作伙伴类型', 0, 350),
|
|
('v_b_ystype', N'付款类型', 1, 360),
|
|
('v_b_billtype', N'账单类型', 1, 370),
|
|
('v_b_bgtype', N'报关方式', 1, 380),
|
|
('v_b_httype', N'合同类型', 0, 390),
|
|
('v_b_transway', N'运输条款', 1, 400),
|
|
('v_b_from', N'客户来源', 1, 410),
|
|
('v_b_grade', N'客户级别', 1, 420),
|
|
('v_b_sys_hdtype', N'回单类型', 1, 430),
|
|
('v_b_package', N'包装单位', 1, 440),
|
|
('v_b_progress', N'进度情况', 1, 450),
|
|
('v_b_zxstate', N'执行状态', 0, 460),
|
|
-- 3.仓库
|
|
('v_b_depot', N'仓库', 1, 470),
|
|
('v_b_depotouttype', N'出库类型', 1, 480),
|
|
('v_b_depotintype', N'入库类型', 1, 490),
|
|
-- 5.物流
|
|
('v_car_daily_feetype', N'费用报销-费用类型', 1, 500),
|
|
('v_car_jiayou_jsfs', N'计算方式', 1, 510),
|
|
('v_car_jiayou_type', N'加油类型', 1, 520),
|
|
('v_car_jiayou_youliao', N'燃油种类', 1, 530),
|
|
('v_b_cdtype', N'派车类型', 1, 540),
|
|
('v_b_shfs', N'派送方式', 1, 550),
|
|
('v_b_thfs', N'提货方式', 1, 560),
|
|
('v_b_wangdian', N'网点', 1, 570),
|
|
('v_b_ywfrom', N'业务来源', 1, 580),
|
|
('v_b_ywtype_tc', N'业务类型', 1, 590),
|
|
-- 6.铁运
|
|
('v_b_servicetype', N'服务内容', 1, 600),
|
|
('v_b_contype', N'箱属', 1, 610),
|
|
('v_b_ywtype_ht', N'业务类型', 1, 620),
|
|
-- 7.空运
|
|
('v_b_dcterm', N'订舱条款', 1, 630),
|
|
('v_b_ywtype_ky', N'业务类型', 1, 640);
|
|
|
|
insert into dbo.s_module (b_id, b_parent_id, b_depth, b_path, b_name, b_i18n, b_module_type,
|
|
b_view_table, b_save_table, b_key_field, b_canuse, b_xh)
|
|
select t.code, g.id, 3, '/base/base_otherdata/' + g.id + '/' + t.code + '/', m.name, 'module.' + t.code, 'data',
|
|
t.code, t.code, 'b_id', m.canuse, m.xh
|
|
from @mods m
|
|
cross apply (select stuff(m.id, 1, 2, '') as code) t
|
|
cross apply (select case
|
|
when m.xh < 100 then 'od_common'
|
|
when m.xh < 470 then 'od_system'
|
|
when m.xh < 500 then 'od_depot'
|
|
when m.xh < 600 then 'od_logistics'
|
|
when m.xh < 630 then 'od_rail'
|
|
else 'od_air' end as id) g;
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
5. 字段定义:从各模块 b_save_table 的列生成(审计字段也保留)
|
|
b_name 先占位,随后由 FieldNameSync 从旧库 s_columnLib 同步中文名
|
|
---------------------------------------------------------------------------- */
|
|
|
|
insert into dbo.s_field (b_module_id, b_field, b_name, b_i18n, b_type, b_canuse, b_xh)
|
|
select sm.b_id,
|
|
c.name,
|
|
c.name,
|
|
null,
|
|
case
|
|
when ty.name in ('bigint', 'int', 'decimal', 'numeric') then 'number'
|
|
when ty.name = 'tinyint' then 'checkbox'
|
|
when ty.name in ('datetime2', 'date', 'datetime') then 'datetime'
|
|
else 'input'
|
|
end,
|
|
1,
|
|
row_number() over (partition by sm.b_id order by c.column_id) * 10
|
|
from dbo.s_module sm
|
|
join sys.columns c on c.object_id = object_id('dbo.' + sm.b_save_table)
|
|
join sys.types ty on ty.user_type_id = c.user_type_id
|
|
where sm.b_path like '/base/base_otherdata/%'
|
|
and sm.b_module_type = 'data';
|
|
GO
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
6. 字典模块直接查表(b_view_table = 表名),不建 v_ 直通视图;
|
|
单表无需叠加 join / 计算列时,不加视图,与旧库一致。
|
|
---------------------------------------------------------------------------- */
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
7. 通用字段中文名:旧库 s_columnLib 没有这些新增字段的记录,FieldNameSync
|
|
同步不到,这里统一补上(只填占位,不覆盖已同步的名称)
|
|
---------------------------------------------------------------------------- */
|
|
|
|
update dbo.s_field
|
|
set b_name = case b_field
|
|
when 'b_id' then N'系统编号'
|
|
when 'b_i18n' then N'多语言键'
|
|
when 'b_canuse' then N'是否启用'
|
|
when 'b_xh' then N'显示顺序'
|
|
when 'b_created_by' then N'创建人'
|
|
when 'b_created_at' then N'创建时间'
|
|
when 'b_updated_by' then N'更新人'
|
|
when 'b_updated_at' then N'更新时间'
|
|
when 'b_edicode' then N'EDI编码'
|
|
when 'b_name' then N'名称'
|
|
when 'b_name_e' then N'英文名'
|
|
when 'b_bz' then N'备注'
|
|
when 'b_money_id' then N'币种'
|
|
when 'b_country' then N'国家'
|
|
when 'b_country_name_c' then N'国家(中文)'
|
|
when 'b_country_name_e' then N'国家(英文)'
|
|
when 'b_voy' then N'船次'
|
|
when 'b_type' then N'类型'
|
|
when 'b_linkcon' then N'关联箱型'
|
|
when 'b_dw_id' then N'关联单位字段'
|
|
when 'b_dw_name' then N'关联单位视图'
|
|
when 'b_hl' then N'汇率'
|
|
when 'b_symbol' then N'货币符号'
|
|
when 'b_isconvert' then N'参与折算'
|
|
when 'b_tz' then N'标志位'
|
|
else b_name
|
|
end
|
|
where b_name = b_field
|
|
and b_module_id in (select b_id from dbo.s_module where b_path like '/base/base_otherdata/%');
|
|
GO
|