RuoYi-Vue-Plus/script/sql/pms/deploy_pms_complete.sql

1292 lines
26 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- ========================================
-- PMS模块完整部署脚本
-- 包含:表结构、基础数据、菜单配置、测试数据
-- ========================================
SET FOREIGN_KEY_CHECKS = 0;
-- ========================================
-- 1. 创建表结构
-- ========================================
-- 客户联系人表
DROP TABLE IF EXISTS `pms_customer_contacts`;
CREATE TABLE `pms_customer_contacts` (
`contact_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '联系人唯一ID',
`tenant_id` varchar(20) NOT NULL COMMENT '租户ID',
`contact_type` varchar(50) DEFAULT NULL COMMENT '联系人类型',
`full_name` varchar(255) DEFAULT NULL COMMENT '联系人姓名',
`phone_number` varchar(50) DEFAULT NULL COMMENT '主要联系电话',
`email` varchar(255) DEFAULT NULL COMMENT '电子邮件地址',
`wechat_openid` varchar(128) DEFAULT NULL COMMENT '微信OpenID',
`wechat_unionid` varchar(128) DEFAULT NULL COMMENT '微信UnionID',
`gender` varchar(50) DEFAULT NULL COMMENT '性别',
`date_of_birth` date DEFAULT NULL COMMENT '出生日期',
`id_type` varchar(50) DEFAULT NULL COMMENT '证件类型',
`id_number_encrypted` varchar(255) DEFAULT NULL COMMENT '证件号码 (加密存储)',
`nationality_country_code` varchar(10) DEFAULT NULL COMMENT '国籍代码',
`address_province` varchar(100) DEFAULT NULL COMMENT '地址-省份',
`address_city` varchar(100) DEFAULT NULL COMMENT '地址-城市',
`address_district` varchar(100) DEFAULT NULL COMMENT '地址-区县',
`address_detail` varchar(500) DEFAULT NULL COMMENT '地址-详细地址',
`postal_code` varchar(20) DEFAULT NULL COMMENT '邮政编码',
`contact_status` varchar(50) DEFAULT NULL COMMENT '联系人状态',
`member_level` varchar(50) DEFAULT NULL COMMENT '会员等级',
`total_stays` int(11) DEFAULT '0' COMMENT '总入住次数',
`total_amount` decimal(10, 2) DEFAULT '0.00' COMMENT '总消费金额',
`last_stay_date` date DEFAULT NULL COMMENT '最后入住日期',
`remarks` text COMMENT '备注信息',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建记录的操作员所属部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志0代表存在 1代表删除',
PRIMARY KEY (`contact_id`),
KEY `idx_pms_cc_tenant` (`tenant_id`),
KEY `idx_pms_cc_tenant_name` (`tenant_id`, `full_name`),
KEY `idx_pms_cc_tenant_phone` (`tenant_id`, `phone_number`),
KEY `idx_pms_cc_tenant_status_type` (`tenant_id`, `contact_status`, `contact_type`)
) ENGINE = InnoDB AUTO_INCREMENT = 100 DEFAULT CHARSET = utf8mb4 COMMENT = '客户联系人表';
-- 联系人标签表
DROP TABLE IF EXISTS `pms_contact_tags`;
CREATE TABLE `pms_contact_tags` (
`tag_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '标签唯一ID',
`tenant_id` varchar(20) NOT NULL COMMENT '租户ID',
`dept_id` bigint(20) DEFAULT NULL COMMENT '部门ID (门店, 可空)',
`name` varchar(100) DEFAULT NULL COMMENT '标签名称',
`color` varchar(20) DEFAULT NULL COMMENT '标签显示颜色',
`category` varchar(50) DEFAULT NULL COMMENT '标签分类',
`description` varchar(500) DEFAULT NULL COMMENT '标签描述',
`is_system` tinyint(1) DEFAULT '0' COMMENT '是否为系统预设标签',
`sort_order` int(11) DEFAULT '0' COMMENT '排序值',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志0代表存在 1代表删除',
PRIMARY KEY (`tag_id`),
KEY `idx_pms_ct_tenant_dept` (`tenant_id`, `dept_id`),
KEY `idx_pms_ct_tenant_dept_name_category` (`tenant_id`, `dept_id`, `name`, `category`),
KEY `idx_pms_ct_category` (`category`)
) ENGINE = InnoDB AUTO_INCREMENT = 100 DEFAULT CHARSET = utf8mb4 COMMENT = '联系人标签表';
-- 联系人标签关联表
DROP TABLE IF EXISTS `pms_contact_tag_relations`;
CREATE TABLE `pms_contact_tag_relations` (
`relation_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '关联唯一ID',
`tenant_id` varchar(20) NOT NULL COMMENT '租户ID',
`contact_id` bigint(20) NOT NULL COMMENT '联系人ID',
`tag_id` bigint(20) NOT NULL COMMENT '标签ID',
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`del_flag` char(1) NOT NULL DEFAULT '0' COMMENT '删除标志0代表存在 1代表删除',
PRIMARY KEY (`relation_id`),
UNIQUE KEY `unq_pms_ctr_tenant_contact_tag` (`tenant_id`, `contact_id`, `tag_id`, `del_flag`),
KEY `idx_pms_ctr_tenant_contact` (`tenant_id`, `contact_id`),
KEY `idx_pms_ctr_tenant_tag` (`tenant_id`, `tag_id`),
KEY `idx_pms_ctr_contact_id` (`contact_id`),
KEY `idx_pms_ctr_tag_id` (`tag_id`)
) ENGINE = InnoDB AUTO_INCREMENT = 100 DEFAULT CHARSET = utf8mb4 COMMENT = '联系人标签关联表';
-- ========================================
-- 2. 插入基础字典数据
-- ========================================
-- 删除已存在的字典数据
DELETE FROM sys_dict_data
WHERE dict_type IN (
'pms_contact_type',
'pms_contact_status',
'pms_gender',
'pms_member_level',
'pms_contact_tag_category'
);
DELETE FROM sys_dict_type
WHERE dict_type IN (
'pms_contact_type',
'pms_contact_status',
'pms_gender',
'pms_member_level',
'pms_contact_tag_category'
);
-- 插入字典类型
INSERT INTO sys_dict_type (
dict_id,
tenant_id,
dict_name,
dict_type,
status,
create_dept,
create_by,
create_time,
remark
)
VALUES (
1020,
'000000',
'联系人类型',
'pms_contact_type',
'0',
103,
1,
NOW(),
'PMS联系人类型'
),
(
1021,
'000000',
'联系人状态',
'pms_contact_status',
'0',
103,
1,
NOW(),
'PMS联系人状态'
),
(
1022,
'000000',
'性别',
'pms_gender',
'0',
103,
1,
NOW(),
'PMS性别'
),
(
1023,
'000000',
'会员等级',
'pms_member_level',
'0',
103,
1,
NOW(),
'PMS会员等级'
),
(
1024,
'000000',
'标签分类',
'pms_contact_tag_category',
'0',
103,
1,
NOW(),
'PMS联系人标签分类'
);
-- 插入字典数据
INSERT INTO sys_dict_data (
dict_code,
tenant_id,
dict_sort,
dict_label,
dict_value,
dict_type,
css_class,
list_class,
is_default,
create_dept,
create_by,
create_time,
remark
)
VALUES -- 联系人类型
(
1025,
'000000',
1,
'个人客户',
'guest_individual',
'pms_contact_type',
'',
'primary',
'Y',
103,
1,
NOW(),
'个人客户'
),
(
1026,
'000000',
2,
'团队负责人',
'group_leader',
'pms_contact_type',
'',
'info',
'N',
103,
1,
NOW(),
'团队负责人'
),
(
1027,
'000000',
3,
'企业联系人',
'corporate_contact',
'pms_contact_type',
'',
'warning',
'N',
103,
1,
NOW(),
'企业联系人'
),
(
1028,
'000000',
4,
'VIP会员',
'vip_member',
'pms_contact_type',
'',
'success',
'N',
103,
1,
NOW(),
'VIP会员'
),
(
1029,
'000000',
5,
'其他',
'other',
'pms_contact_type',
'',
'default',
'N',
103,
1,
NOW(),
'其他类型'
),
-- 联系人状态
(
1030,
'000000',
1,
'活跃',
'active',
'pms_contact_status',
'',
'success',
'Y',
103,
1,
NOW(),
'活跃状态'
),
(
1031,
'000000',
2,
'非活跃',
'inactive',
'pms_contact_status',
'',
'warning',
'N',
103,
1,
NOW(),
'非活跃状态'
),
(
1032,
'000000',
3,
'黑名单',
'blacklisted',
'pms_contact_status',
'',
'danger',
'N',
103,
1,
NOW(),
'黑名单'
),
(
1033,
'000000',
4,
'潜在客户',
'prospect',
'pms_contact_status',
'',
'info',
'N',
103,
1,
NOW(),
'潜在客户'
),
-- 性别
(
1034,
'000000',
1,
'',
'male',
'pms_gender',
'',
'primary',
'N',
103,
1,
NOW(),
'男性'
),
(
1035,
'000000',
2,
'',
'female',
'pms_gender',
'',
'danger',
'N',
103,
1,
NOW(),
'女性'
),
(
1036,
'000000',
3,
'未知',
'unknown',
'pms_gender',
'',
'default',
'Y',
103,
1,
NOW(),
'未知'
),
-- 会员等级
(
1037,
'000000',
1,
'普通会员',
'bronze',
'pms_member_level',
'',
'default',
'Y',
103,
1,
NOW(),
'普通会员'
),
(
1038,
'000000',
2,
'白银会员',
'silver',
'pms_member_level',
'',
'info',
'N',
103,
1,
NOW(),
'白银会员'
),
(
1039,
'000000',
3,
'黄金会员',
'gold',
'pms_member_level',
'',
'warning',
'N',
103,
1,
NOW(),
'黄金会员'
),
(
1040,
'000000',
4,
'铂金会员',
'platinum',
'pms_member_level',
'',
'primary',
'N',
103,
1,
NOW(),
'铂金会员'
),
(
1041,
'000000',
5,
'钻石会员',
'diamond',
'pms_member_level',
'',
'success',
'N',
103,
1,
NOW(),
'钻石会员'
),
-- 标签分类
(
1042,
'000000',
1,
'客户等级',
'contact_level',
'pms_contact_tag_category',
'',
'primary',
'Y',
103,
1,
NOW(),
'客户等级标签'
),
(
1043,
'000000',
2,
'客户来源',
'contact_source',
'pms_contact_tag_category',
'',
'info',
'N',
103,
1,
NOW(),
'客户来源标签'
),
(
1044,
'000000',
3,
'客户偏好',
'contact_preference',
'pms_contact_tag_category',
'',
'warning',
'N',
103,
1,
NOW(),
'客户偏好标签'
),
(
1045,
'000000',
4,
'服务记录',
'service_record',
'pms_contact_tag_category',
'',
'success',
'N',
103,
1,
NOW(),
'服务记录标签'
),
(
1046,
'000000',
5,
'营销标签',
'marketing_tag',
'pms_contact_tag_category',
'',
'danger',
'N',
103,
1,
NOW(),
'营销标签'
),
(
1047,
'000000',
6,
'自定义',
'custom',
'pms_contact_tag_category',
'',
'default',
'N',
103,
1,
NOW(),
'自定义标签'
);
-- ========================================
-- 3. 菜单配置
-- ========================================
-- 删除已存在的菜单
DELETE FROM sys_menu
WHERE menu_id IN (
1925809154452340738,
1926240962230853634,
1926240962230853635,
1926240962230853636,
1926240962230853637,
1926240962230853638,
1926240962230853639,
1926240963610779650,
1926240963610779651,
1926240963610779652,
1926240963610779653,
1926240963610779654,
1926240963610779655,
1926240964416086017,
1926240964416086018,
1926240964416086019,
1926240964416086020,
1926240964416086021,
1926240964416086022
);
-- PMS主菜单
INSERT INTO sys_menu (
menu_id,
menu_name,
parent_id,
order_num,
path,
component,
is_frame,
is_cache,
menu_type,
visible,
status,
perms,
icon,
create_dept,
create_by,
create_time,
remark
)
VALUES (
1925809154452340738,
'PMS管理',
'0',
'5',
'pms',
null,
1,
0,
'M',
'0',
'0',
'',
'ep:office-building',
103,
1,
NOW(),
'PMS管理目录'
);
-- 客户联系人菜单及权限
INSERT INTO sys_menu (
menu_id,
menu_name,
parent_id,
order_num,
path,
component,
is_frame,
is_cache,
menu_type,
visible,
status,
perms,
icon,
create_dept,
create_by,
create_time,
remark
)
VALUES (
1926240962230853634,
'客户联系人',
'1925809154452340738',
'1',
'contact',
'pms/contact/index',
1,
0,
'C',
'0',
'0',
'pms:contacts:list',
'#',
103,
1,
NOW(),
'客户联系人菜单'
),
(
1926240962230853635,
'客户联系人查询',
1926240962230853634,
'1',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contacts:query',
'#',
103,
1,
NOW(),
''
),
(
1926240962230853636,
'客户联系人新增',
1926240962230853634,
'2',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contacts:add',
'#',
103,
1,
NOW(),
''
),
(
1926240962230853637,
'客户联系人修改',
1926240962230853634,
'3',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contacts:edit',
'#',
103,
1,
NOW(),
''
),
(
1926240962230853638,
'客户联系人删除',
1926240962230853634,
'4',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contacts:remove',
'#',
103,
1,
NOW(),
''
),
(
1926240962230853639,
'客户联系人导出',
1926240962230853634,
'5',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contacts:export',
'#',
103,
1,
NOW(),
''
);
-- 联系人标签菜单及权限
INSERT INTO sys_menu (
menu_id,
menu_name,
parent_id,
order_num,
path,
component,
is_frame,
is_cache,
menu_type,
visible,
status,
perms,
icon,
create_dept,
create_by,
create_time,
remark
)
VALUES (
1926240963610779650,
'联系人标签',
'1925809154452340738',
'2',
'tag',
'pms/tag/index',
1,
0,
'C',
'0',
'0',
'pms:contactTags:list',
'#',
103,
1,
NOW(),
'联系人标签菜单'
),
(
1926240963610779651,
'联系人标签查询',
1926240963610779650,
'1',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTags:query',
'#',
103,
1,
NOW(),
''
),
(
1926240963610779652,
'联系人标签新增',
1926240963610779650,
'2',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTags:add',
'#',
103,
1,
NOW(),
''
),
(
1926240963610779653,
'联系人标签修改',
1926240963610779650,
'3',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTags:edit',
'#',
103,
1,
NOW(),
''
),
(
1926240963610779654,
'联系人标签删除',
1926240963610779650,
'4',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTags:remove',
'#',
103,
1,
NOW(),
''
),
(
1926240963610779655,
'联系人标签导出',
1926240963610779650,
'5',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTags:export',
'#',
103,
1,
NOW(),
''
);
-- 标签关联管理菜单及权限
INSERT INTO sys_menu (
menu_id,
menu_name,
parent_id,
order_num,
path,
component,
is_frame,
is_cache,
menu_type,
visible,
status,
perms,
icon,
create_dept,
create_by,
create_time,
remark
)
VALUES (
1926240964416086017,
'标签关联管理',
'1925809154452340738',
'3',
'tag-relation',
'pms/tag-relation/index',
1,
0,
'C',
'0',
'0',
'pms:contactTagRelations:list',
'#',
103,
1,
NOW(),
'联系人标签关联菜单'
),
(
1926240964416086018,
'标签关联查询',
1926240964416086017,
'1',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTagRelations:query',
'#',
103,
1,
NOW(),
''
),
(
1926240964416086019,
'标签关联新增',
1926240964416086017,
'2',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTagRelations:add',
'#',
103,
1,
NOW(),
''
),
(
1926240964416086020,
'标签关联修改',
1926240964416086017,
'3',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTagRelations:edit',
'#',
103,
1,
NOW(),
''
),
(
1926240964416086021,
'标签关联删除',
1926240964416086017,
'4',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTagRelations:remove',
'#',
103,
1,
NOW(),
''
),
(
1926240964416086022,
'标签关联导出',
1926240964416086017,
'5',
'#',
'',
1,
0,
'F',
'0',
'0',
'pms:contactTagRelations:export',
'#',
103,
1,
NOW(),
''
);
-- 为超级管理员角色分配所有PMS权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1,
menu_id
FROM sys_menu
WHERE menu_id IN (
1925809154452340738,
1926240962230853634,
1926240962230853635,
1926240962230853636,
1926240962230853637,
1926240962230853638,
1926240962230853639,
1926240963610779650,
1926240963610779651,
1926240963610779652,
1926240963610779653,
1926240963610779654,
1926240963610779655,
1926240964416086017,
1926240964416086018,
1926240964416086019,
1926240964416086020,
1926240964416086021,
1926240964416086022
)
AND NOT EXISTS (
SELECT 1
FROM sys_role_menu
WHERE role_id = 1
AND sys_role_menu.menu_id = sys_menu.menu_id
);
-- ========================================
-- 4. 插入测试数据
-- ========================================
-- 插入测试联系人数据
INSERT INTO pms_customer_contacts (
contact_id,
tenant_id,
contact_type,
full_name,
phone_number,
email,
gender,
date_of_birth,
id_type,
id_number_encrypted,
nationality_country_code,
address_province,
address_city,
address_district,
address_detail,
postal_code,
contact_status,
member_level,
total_stays,
total_amount,
last_stay_date,
remarks,
create_dept,
create_by,
create_time,
update_by,
update_time,
del_flag
)
VALUES (
1,
'000000',
'guest_individual',
'张三',
'13800138000',
'zhangsan@example.com',
'male',
'1990-01-15',
'ID_CARD',
'encrypted_id_123',
'CHN',
'北京市',
'北京市',
'朝阳区',
'建国门外大街1号',
'100000',
'active',
'gold',
5,
2500.00,
'2023-08-15',
'常客,喜欢安静房间',
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
2,
'000000',
'vip_member',
'李四',
'13900139000',
'lisi@example.com',
'female',
'1985-05-20',
'ID_CARD',
'encrypted_id_456',
'CHN',
'上海市',
'上海市',
'浦东新区',
'陆家嘴环路1000号',
'200000',
'active',
'platinum',
10,
8000.00,
'2023-09-01',
'VIP客户要求高楼层',
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
3,
'000000',
'corporate_contact',
'王五',
'13700137000',
'wangwu@example.com',
'male',
'1988-12-10',
'ID_CARD',
'encrypted_id_789',
'CHN',
'广东省',
'深圳市',
'南山区',
'科技园南区2号',
'518000',
'active',
'silver',
3,
1200.00,
'2023-07-20',
'企业客户联系人',
103,
1,
NOW(),
1,
NOW(),
'0'
);
-- 插入测试标签数据
INSERT INTO pms_contact_tags (
tag_id,
tenant_id,
dept_id,
name,
color,
category,
description,
is_system,
sort_order,
create_dept,
create_by,
create_time,
update_by,
update_time,
del_flag
)
VALUES (
1,
'000000',
103,
'常客',
'#FF0000',
'contact_level',
'经常入住的客户',
0,
1,
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
2,
'000000',
103,
'喜欢安静房间',
'#00FF00',
'contact_preference',
'偏好安静环境的客户',
0,
2,
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
3,
'000000',
103,
'VIP客户',
'#FFD700',
'contact_level',
'重要客户',
0,
3,
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
4,
'000000',
103,
'商务客户',
'#0000FF',
'contact_source',
'商务出行客户',
0,
4,
103,
1,
NOW(),
1,
NOW(),
'0'
),
(
5,
'000000',
103,
'度假客户',
'#FF69B4',
'contact_source',
'度假休闲客户',
0,
5,
103,
1,
NOW(),
1,
NOW(),
'0'
);
-- 插入测试标签关联数据
INSERT INTO pms_contact_tag_relations (
contact_id,
tag_id,
tenant_id,
create_dept,
create_by,
create_time,
del_flag
)
VALUES (1, 1, '000000', 103, 1, NOW(), '0'),
(1, 2, '000000', 103, 1, NOW(), '0'),
(2, 3, '000000', 103, 1, NOW(), '0'),
(2, 4, '000000', 103, 1, NOW(), '0'),
(3, 4, '000000', 103, 1, NOW(), '0');
SET FOREIGN_KEY_CHECKS = 1;
COMMIT;
-- ========================================
-- 部署完成提示
-- ========================================
SELECT 'PMS模块部署完成包含' as '部署状态',
'1. 表结构创建完成' as '表结构',
'2. 基础字典数据插入完成' as '字典数据',
'3. 菜单权限配置完成' as '菜单配置',
'4. 测试数据插入完成' as '测试数据';