# 公海池模块迁移方案 — 02 数据库表模型 > **规范约束**:`docs/crm-migration/ref-database-rules.md` --- ## 2.1 crm_customer_pool(公海池操作记录表) ### 2.1.1 原始 DDL(来自 sx.sql 第 859 行) ```sql CREATE TABLE `crm_customer_pool` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', `customer_id` bigint(20) NOT NULL COMMENT '客户ID', `customer_name` varchar(200) DEFAULT NULL COMMENT '客户名称(冗余)', `operation_type` varchar(20) NOT NULL COMMENT '操作类型(into/claim/assign/recycle)', `from_user_id` bigint(20) DEFAULT NULL COMMENT '原负责人ID', `from_user_name` varchar(50) DEFAULT NULL COMMENT '原负责人姓名(冗余)', `to_user_id` bigint(20) DEFAULT NULL COMMENT '新负责人ID', `to_user_name` varchar(50) DEFAULT NULL COMMENT '新负责人姓名(冗余)', `reason` varchar(500) DEFAULT NULL COMMENT '操作原因', `tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号', `create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门', `create_by` bigint(20) DEFAULT NULL COMMENT '创建者(操作人)', `create_by_name` varchar(50) DEFAULT NULL COMMENT '操作人姓名(冗余)', `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(操作时间)', `update_by` bigint(20) DEFAULT NULL COMMENT '更新者', `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `del_flag` tinyint(1) DEFAULT '0', `version` int(11) DEFAULT '0', `remark` varchar(500) DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_customer_id` (`customer_id`), KEY `idx_operation_type` (`operation_type`), KEY `idx_from_user` (`from_user_id`), KEY `idx_to_user` (`to_user_id`), KEY `idx_create_time` (`create_time`), KEY `idx_tenant` (`tenant_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CRM-客户公海池记录表'; ``` ### 2.1.2 迁移后 DDL ```sql DROP TABLE IF EXISTS `crm_customer_pool`; CREATE TABLE `crm_customer_pool` ( `id` varchar(64) NOT NULL COMMENT '主键ID(UUID)', `customer_id` varchar(64) NOT NULL COMMENT '客户ID', `customer_name` varchar(200) DEFAULT NULL COMMENT '客户名称(冗余)', `operation_type` varchar(20) NOT NULL COMMENT '操作类型(into/claim/assign/recycle)', `from_user_id` varchar(64) DEFAULT NULL COMMENT '原负责人ID', `from_user_name` varchar(50) DEFAULT NULL COMMENT '原负责人姓名(冗余)', `to_user_id` varchar(64) DEFAULT NULL COMMENT '新负责人ID', `to_user_name` varchar(50) DEFAULT NULL COMMENT '新负责人姓名(冗余)', `reason` varchar(500) DEFAULT NULL COMMENT '操作原因', `create_by_name` varchar(50) DEFAULT NULL COMMENT '操作人姓名(冗余)', `tenant_no` varchar(64) NOT NULL DEFAULT 'shanxia2.0' COMMENT '租户编号', `order_num` int(11) DEFAULT NULL COMMENT '排序号', `remark` varchar(512) DEFAULT NULL COMMENT '备注', `create_by` varchar(64) DEFAULT NULL COMMENT '创建人ID', `create_dept_id` varchar(64) NOT NULL DEFAULT '' COMMENT '创建人部门ID', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_by` varchar(64) DEFAULT NULL COMMENT '更新人ID', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `del_flag` smallint(6) NOT NULL DEFAULT '0' COMMENT '删除标记(0存在 1删除)', PRIMARY KEY (`id`), KEY `idx_customer_id` (`customer_id`), KEY `idx_operation_type` (`operation_type`), KEY `idx_from_user` (`from_user_id`), KEY `idx_to_user` (`to_user_id`), KEY `idx_create_time` (`create_time`), KEY `idx_tenant` (`tenant_no`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CRM-客户公海池记录表'; ``` ### 2.1.3 字段对照表 | # | 数据库字段 | API 字段(camelCase) | 类型 | 必填 | 说明 | |---|-----------|---------------------|------|------|------| | 1 | id | id | string(UUID) | 自动 | 主键 | | 2 | customer_id | customerId | string | 是 | 客户ID | | 3 | customer_name | customerName | string | 否 | 客户名称(冗余) | | 4 | operation_type | operationType | string | 是 | into/claim/assign/recycle | | 5 | from_user_id | fromUserId | string | 否 | 原负责人ID | | 6 | from_user_name | fromUserName | string | 否 | 原负责人姓名 | | 7 | to_user_id | toUserId | string | 否 | 新负责人ID | | 8 | to_user_name | toUserName | string | 否 | 新负责人姓名 | | 9 | reason | reason | string | 否 | 操作原因 | | 10 | create_by_name | createByName | string | 否 | 操作人姓名 | ### 2.1.4 与现有实现的差异(需修正) | 现有字段名(错误) | 正确字段名(回归 sx.sql) | |-------------------|-------------------------| | `before_owner_user_id` | `from_user_id` | | `before_owner_user_name` | `from_user_name` | | `after_owner_user_id` | `to_user_id` | | `after_owner_user_name` | `to_user_name` | | `pool_reason` | `reason` | | `customer_no` | **删除**(sx.sql 无此字段) | | `recycle_rule_id` | **删除**(sx.sql 无此字段) | --- ## 2.2 crm_customer_pool_rule(公海池规则表) ### 2.2.1 原始 DDL(来自 sx.sql 第 892 行) ```sql CREATE TABLE `crm_customer_pool_rule` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', `pool_name` varchar(100) NOT NULL COMMENT '规则名称', `rule_type` varchar(20) NOT NULL COMMENT '规则类型(no_follow/no_deal)', `timeout_days` int(11) NOT NULL COMMENT '超时天数', `protect_days` int(11) NOT NULL DEFAULT '0' COMMENT '保护期天数', `status` varchar(20) DEFAULT 'enable' COMMENT '状态(enable/disable)', `sort` int(11) DEFAULT '0' COMMENT '排序号', `tenant_id` varchar(20) DEFAULT '000000', `create_dept` bigint(20) DEFAULT NULL, `create_by` bigint(20) DEFAULT NULL, `create_time` datetime DEFAULT CURRENT_TIMESTAMP, `update_by` bigint(20) DEFAULT NULL, `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `del_flag` tinyint(1) DEFAULT '0', `version` int(11) DEFAULT '0', `remark` varchar(500) DEFAULT NULL, PRIMARY KEY (`id`), KEY `idx_status` (`status`), KEY `idx_rule_type` (`rule_type`), KEY `idx_tenant` (`tenant_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CRM-客户公海池规则表'; ``` ### 2.2.2 迁移后 DDL ```sql DROP TABLE IF EXISTS `crm_customer_pool_rule`; CREATE TABLE `crm_customer_pool_rule` ( `id` varchar(64) NOT NULL COMMENT '主键ID(UUID)', `pool_name` varchar(100) NOT NULL COMMENT '规则名称', `rule_type` varchar(20) NOT NULL COMMENT '规则类型(no_follow/no_deal)', `timeout_days` int(11) NOT NULL COMMENT '超时天数', `protect_days` int(11) NOT NULL DEFAULT '0' COMMENT '保护期天数', `status` varchar(20) DEFAULT 'enable' COMMENT '状态(enable/disable)', `sort` int(11) DEFAULT '0' COMMENT '排序号', `tenant_no` varchar(64) NOT NULL DEFAULT 'shanxia2.0' COMMENT '租户编号', `order_num` int(11) DEFAULT NULL COMMENT '排序号', `remark` varchar(512) DEFAULT NULL COMMENT '备注', `create_by` varchar(64) DEFAULT NULL COMMENT '创建人ID', `create_dept_id` varchar(64) NOT NULL DEFAULT '' COMMENT '创建人部门ID', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_by` varchar(64) DEFAULT NULL COMMENT '更新人ID', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `del_flag` smallint(6) NOT NULL DEFAULT '0' COMMENT '删除标记(0存在 1删除)', PRIMARY KEY (`id`), KEY `idx_status` (`status`), KEY `idx_rule_type` (`rule_type`), KEY `idx_tenant` (`tenant_no`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='CRM-客户公海池规则表'; ``` ### 2.2.3 字段对照表 | # | 数据库字段 | API 字段 | 类型 | 必填 | 说明 | |---|-----------|---------|------|------|------| | 1 | id | id | string(UUID) | 自动 | 主键 | | 2 | pool_name | poolName | string | 是 | 规则名称 | | 3 | rule_type | ruleType | string | 是 | no_follow / no_deal | | 4 | timeout_days | timeoutDays | int | 是 | 超时天数(≥1) | | 5 | protect_days | protectDays | int | 是 | 保护期天数(≥0) | | 6 | status | status | string | 否 | enable / disable | | 7 | sort | sort | int | 否 | 排序号 | ### 2.2.4 与现有实现的差异(需修正) | 现有字段名/值(错误) | 正确字段名/值(回归 sx.sql) | |----------------------|----------------------------| | `rule_name` | `pool_name` | | `limit_days` | `timeout_days` | | `order_num`(作为排序字段) | `sort` | | `rule_type` = `follow_time` / `deal_time` | `no_follow` / `no_deal` | | `status` = `smallint(0/1)` | `varchar('enable'/'disable')` | | `deal_status_limit` | **删除**(sx.sql 无此字段) | | `description` | **删除**(sx.sql 无此字段) | ### 2.2.5 字典关联 | 字段 | 字典类型(dict_type) | 字典值 | |------|----------------------|--------| | rule_type | `crm_pool_rule_type` | `no_follow`=未跟进 / `no_deal`=未成交 | | status | `crm_pool_rule_status` | `enable`=启用 / `disable`=禁用 | | operation_type | `crm_pool_operation_type` | `into`=进入公海 / `claim`=领取 / `assign`=分配 / `recycle`=回收 |