20260914172820
This commit is contained in:
1 parent
c31329d387
commit
549c8bd2eb
38 files changed
+3430
-502
No files matched your search
@@ -0,0 +1,235 @@
|
||||
/* ============================================================================
|
||||
FMS 新系统业务表建表脚本 — 往来单位(合作伙伴)
|
||||
依据文档:FMS业务表设计.md
|
||||
|
||||
使用说明:
|
||||
1. 执行前先切换到目标数据库(USE [数据库名])。
|
||||
2. 脚本只建表、索引和查询视图,不含初始化数据和迁移数据。
|
||||
3. 不使用外键、CHECK、触发器;关联完整性和业务校验由业务层处理。
|
||||
4. 表已存在时先用「重建」段落删除旧对象,再执行建表段落。
|
||||
============================================================================ */
|
||||
|
||||
SET NOCOUNT ON;
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
重建(仅旧结构需要重建时执行,会删除这些表及其数据)
|
||||
============================================================================ */
|
||||
|
||||
drop view if exists dbo.v_b_othercompany;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_othercompany_accountbank;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_othercompany_bmfl;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_othercompany_partner_type;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_othercompany;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_grade;
|
||||
GO
|
||||
|
||||
drop table if exists dbo.b_from;
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
主表
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_othercompany (
|
||||
b_id bigint not null primary key, -- 主键(雪花)
|
||||
b_ywid varchar(50) not null, -- 业务ID
|
||||
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 varchar(50) null, -- 合同号
|
||||
b_htdate date null, -- 签订日期
|
||||
b_htexpiredate date null, -- 到期日期
|
||||
b_black tinyint not null default 0, -- 黑名单(0/1)
|
||||
b_canuse tinyint not null default 0, -- 开通自助(0/1)
|
||||
b_zl int null, -- 帐龄天数
|
||||
b_tel nvarchar(50) null, -- 电话
|
||||
b_fax nvarchar(500) null, -- 传真
|
||||
b_www varchar(50) null, -- 网址
|
||||
b_email varchar(50) null, -- 邮件
|
||||
b_bankacount nvarchar(500) null, -- 银行账号
|
||||
b_invaccount nvarchar(500) null, -- 开票信息
|
||||
b_cate_id varchar(150) null, -- 分类树节点编码
|
||||
b_bz1 nvarchar(500) null, -- 备注1
|
||||
b_bz2 nvarchar(500) null, -- 备注2
|
||||
b_bz3 nvarchar(500) null, -- 备注3
|
||||
b_bz4 nvarchar(500) null, -- 备注4
|
||||
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, -- EDI 代码
|
||||
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_created_by varchar(50) null, -- 创建人
|
||||
b_created_at datetime2 null, -- 创建时间
|
||||
b_updated_by varchar(50) null, -- 最后修改人
|
||||
b_updated_at datetime2 null, -- 最后修改时间
|
||||
b_password varchar(50) null, -- 自助登录密码
|
||||
b_state nvarchar(50) null, -- 审核状态
|
||||
b_bankacount_e varchar(500) null, -- 英文账号
|
||||
b_addr_e varchar(500) null, -- 英文地址
|
||||
b_name_e nvarchar(500) null -- 英文名称
|
||||
);
|
||||
GO
|
||||
|
||||
create unique index ux_b_othercompany_ywid on dbo.b_othercompany (b_ywid);
|
||||
GO
|
||||
|
||||
create index ix_b_othercompany_cate on dbo.b_othercompany (b_cate_id, b_canuse, b_id);
|
||||
GO
|
||||
|
||||
create index ix_b_othercompany_name on dbo.b_othercompany (b_name, b_canuse, b_id);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
伙伴类型字典
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_othercompany_partner_type (
|
||||
b_id varchar(50) not null primary key, -- 类型编码
|
||||
b_name nvarchar(50) null, -- 类型名称
|
||||
b_i18n varchar(150) null, -- 多语言资源键
|
||||
b_canuse tinyint not null default 1, -- 是否启用(0/1)
|
||||
b_xh int not null default 0, -- 显示顺序
|
||||
b_bz nvarchar(50) null, -- 备注
|
||||
b_created_by varchar(50) null,
|
||||
b_created_at datetime2 null,
|
||||
b_updated_by varchar(50) null,
|
||||
b_updated_at datetime2 null
|
||||
);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
分类树
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_othercompany_bmfl (
|
||||
b_id varchar(150) not null primary key, -- 节点编码(创建后不可改)
|
||||
b_parent_id varchar(150) null, -- 父节点编码,NULL 表示根节点
|
||||
b_depth int not null default 0, -- 树层级,根节点为 0
|
||||
b_path varchar(1000) not null, -- 根到当前节点的路径,例如 /dl/dl_NOVCC/
|
||||
b_name nvarchar(200) not null, -- 节点名称
|
||||
b_i18n varchar(150) null, -- 多语言资源键
|
||||
b_canuse tinyint not null default 1, -- 是否启用(0/1)
|
||||
b_xh int not null default 0, -- 同级显示顺序
|
||||
b_created_by varchar(50) null,
|
||||
b_created_at datetime2 null,
|
||||
b_updated_by varchar(50) null,
|
||||
b_updated_at datetime2 null
|
||||
);
|
||||
GO
|
||||
|
||||
create index ix_b_othercompany_bmfl_parent
|
||||
on dbo.b_othercompany_bmfl (b_parent_id, b_canuse, b_depth, b_xh, b_id);
|
||||
GO
|
||||
|
||||
create index ix_b_othercompany_bmfl_path
|
||||
on dbo.b_othercompany_bmfl (b_path, b_canuse, b_id);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
客户级别字典
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_grade (
|
||||
b_id varchar(50) not null primary key, -- 级别编码
|
||||
b_name nvarchar(50) null, -- 级别名称
|
||||
b_i18n varchar(150) null, -- 多语言资源键
|
||||
b_canuse tinyint not null default 1, -- 是否启用(0/1)
|
||||
b_xh int not null default 0, -- 显示顺序
|
||||
b_bz nvarchar(50) null, -- 备注
|
||||
b_created_by varchar(50) null,
|
||||
b_created_at datetime2 null,
|
||||
b_updated_by varchar(50) null,
|
||||
b_updated_at datetime2 null
|
||||
);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
客户来源字典
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_from (
|
||||
b_id varchar(50) not null primary key, -- 来源编码
|
||||
b_name nvarchar(50) null, -- 来源名称
|
||||
b_i18n varchar(150) null, -- 多语言资源键
|
||||
b_canuse tinyint not null default 1, -- 是否启用(0/1)
|
||||
b_xh int not null default 0, -- 显示顺序
|
||||
b_bz nvarchar(50) null, -- 备注
|
||||
b_created_by varchar(50) null,
|
||||
b_created_at datetime2 null,
|
||||
b_updated_by varchar(50) null,
|
||||
b_updated_at datetime2 null
|
||||
);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
银行账号明细子表
|
||||
============================================================================ */
|
||||
|
||||
create table dbo.b_othercompany_accountbank (
|
||||
subid bigint not null primary key, -- 主键(雪花)
|
||||
mx_xh int null, -- 序号
|
||||
father bigint null, -- 主表 b_othercompany.b_id
|
||||
mx_bank nvarchar(800) null, -- 银行信息
|
||||
mx_bz1 nvarchar(200) null, -- 备注
|
||||
mx_created_by varchar(50) null,
|
||||
mx_created_at datetime2 null,
|
||||
mx_updated_by varchar(50) null,
|
||||
mx_updated_at datetime2 null
|
||||
);
|
||||
GO
|
||||
|
||||
create index ix_b_othercompany_accountbank_father
|
||||
on dbo.b_othercompany_accountbank (father, mx_xh, subid);
|
||||
GO
|
||||
|
||||
/* ============================================================================
|
||||
查询视图
|
||||
|
||||
用途:作为 s_module.b_view_table 的数据源。列表查询直接 select ... from 该视图,
|
||||
s_field.b_field 必须是视图里真实存在的列。
|
||||
说明:视图只供查询,写库仍走 s_module.b_save_table = b_othercompany。
|
||||
============================================================================ */
|
||||
|
||||
create or alter view dbo.v_b_othercompany as
|
||||
select o.b_id, o.b_ywid, o.b_pycode, o.b_type, o.b_name, o.b_shortname,
|
||||
o.b_linkman, o.b_phone, o.b_addr, o.b_firstlinkdate,
|
||||
o.b_htno, o.b_htdate, o.b_htexpiredate, o.b_black, o.b_canuse,
|
||||
o.b_zl, o.b_tel, o.b_fax, o.b_www, o.b_email,
|
||||
o.b_bankacount, o.b_invaccount, o.b_cate_id,
|
||||
o.b_bz1, o.b_bz2, o.b_bz3, o.b_bz4,
|
||||
o.b_province, o.b_city, o.b_area, o.b_country,
|
||||
o.b_edicode, o.b_showcolor, o.b_type_id, o.b_from_id,
|
||||
o.b_type1_id, o.b_type2_id, o.b_type3_id, o.b_type4_id, o.b_type5_id,
|
||||
o.b_owner_id, o.b_created_by, o.b_created_at,
|
||||
o.b_updated_by, o.b_updated_at,
|
||||
o.b_password, o.b_state,
|
||||
o.b_bankacount_e, o.b_addr_e, o.b_name_e,
|
||||
u.b_name as v_ownername -- 业务员姓名
|
||||
from dbo.b_othercompany o
|
||||
left join dbo.b_user u on u.b_id = o.b_owner_id;
|
||||
GO
|
||||
Reference in new issue
Block a user