Files
yunzerwebsiteallinone/sql/add_contacts_table.sql
T
2026-08-28 13:06:54 +08:00

39 lines
2.5 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.
-- 通讯录表(全局表,已从 yz_backend_erp_contact 改名):与组织架构联动,支持内部员工(自动同步)和外部联系人
-- 已合并 alter_contact_add_dept_position.sql 的 dept_name / position_id 字段
-- tenant 隔离:通过 tid 字段实现租户间数据隔离
CREATE TABLE IF NOT EXISTS `yz_backend_contact` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`tid` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '租户ID',
`employee_id` bigint(20) unsigned DEFAULT NULL COMMENT '关联员工ID(内部联系人自动关联)',
`org_id` bigint(20) unsigned DEFAULT NULL COMMENT '所属组织/部门ID(关联yz_backend_organization)',
`contact_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '联系人类型:1=内部员工 2=外部联系人',
`contact_name` varchar(64) NOT NULL COMMENT '联系人姓名',
`gender` tinyint(4) NOT NULL DEFAULT 0 COMMENT '性别:0=未知 1=男 2=女',
`phone` varchar(20) DEFAULT NULL COMMENT '手机号',
`work_phone` varchar(20) DEFAULT NULL COMMENT '办公电话',
`email` varchar(128) DEFAULT NULL COMMENT '邮箱',
`wechat` varchar(64) DEFAULT NULL COMMENT '微信号',
`avatar` varchar(512) DEFAULT NULL COMMENT '头像URL',
`company_name` varchar(128) DEFAULT NULL COMMENT '公司名称(外部联系人)',
`dept_name` varchar(128) DEFAULT NULL COMMENT '外部联系人手填部门名称',
`position_id` bigint(20) unsigned DEFAULT NULL COMMENT '职位ID,关联yz_backend_position',
`position_title` varchar(100) DEFAULT NULL COMMENT '职位名称',
`address` varchar(512) DEFAULT NULL COMMENT '地址',
`remark` varchar(512) DEFAULT NULL COMMENT '备注',
`is_starred` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否收藏:0=否 1=是',
`sort` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '排序值',
`status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态:1=正常 0=停用',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间(软删除)',
PRIMARY KEY (`id`),
KEY `idx_tid` (`tid`),
KEY `idx_employee_id` (`employee_id`),
KEY `idx_org_id` (`org_id`),
KEY `idx_contact_type` (`contact_type`),
KEY `idx_contact_name` (`contact_name`),
KEY `idx_phone` (`phone`),
KEY `idx_delete_time` (`delete_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='通讯录表';