Files
shanxia2.0/docs/data-migration/02-user-unification.md
T
2026-07-13 20:26:43 +08:00

164 lines
6.2 KiB
Markdown
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.
# 用户统一方案
> **决策**:登录账号(`sys_user.user_no`)**以中文名为准**。
> **例外**:超级管理员固定为 `admin`。
---
## 1. 三源用户概览
| 来源表 | 库 | 记录数 | 有效(未删除/启用) | 说明 |
|--------|-----|--------|---------------------|------|
| `bx_user` | sx | 26 | 25 | 报销员工,有 `real_name` + bcrypt |
| `sys_user` | sx(CRM) | 12 | 8 | 若依用户,`user_name` 混用拼音/中文 |
| `users` | dibang | 15 | 6 | 地磅账号,多为拼音/数字,仅 `过磅员` 为中文 |
| `sys_user` | shanxia2.0 | 1 | 1 | 仅 `admin`,目标写入表 |
---
## 2. 字段映射规则
门户 `sys_user` 目标字段:
| 目标字段 | 规则 |
|----------|------|
| `user_no` | **中文真实姓名**;管理员为 `admin`;地磅无中文名见 §4 |
| `nick_name` | 与 `user_no` 相同(管理员为「系统管理员」) |
| `phone_no` | 优先 bx `phone`,其次 CRM `phonenumber` |
| `email` | bx `email` 或 CRM `email` |
| `password` | 优先 bx bcrypt(`$2b$12`);CRM 为 `$2a$10` 可保留或统一重哈希 |
| `status` | 门户 `1`=正常:`bx.status=1` / CRM `status='0'` / 地磅 `is_active=1` |
| `del_flag` | `0`;旧系统已删除用户不导入 |
| `tenant_no` | `'shanxia2.0'` |
| `dept_id` | 默认销售部门 UUID(P0 部门迁移后填入) |
---
## 3. 去重与合并规则
按以下优先级识别**同一自然人**:
1. **手机号相同**(11 位,去空格)
2. **中文姓名相同**(`bx.real_name` = CRM `nick_name` 或 `user_name`)
3. 仅一方存在且 `del_flag=0` / 未删除 → 单独建档
合并后只保留 **一条** `sys_user`,在 `user_mapping.csv` 记录各源 ID → 门户 `new_user_id`。
> **与全局 ID 策略的关系**:业务表主键一律原样保留([05-id-preservation-policy.md](./05-id-preservation-policy.md));**仅用户表**因 P0 已执行而使用新生成的门户 UUID,所有 `create_by` / `owner_user_id` 等用户外键必须经本映射转换。
### 3.1 需人工确认
| 姓名 | 说明 |
|------|------|
| 方金强 | CRM 有两条历史(`wwww` 已删、`方金强` 活跃);只导入活跃条 |
> 吴九华手机号已确认:`18656008189`(bx 与 CRM 合并为一条)。
### 3.2 不导入
- CRM:`lisi`、`nana`、`wwww`、`admin1`(均已 `del_flag=1`)
- bx:`冯传忠`(`del_flag=1`)
- 地磅:id 7–16 测试账号(`is_active=0`)
---
## 4. 地磅用户处理(无中文名)
地磅账号将并入门户,登录名规则:
| 原地磅 username | 建议 user_no | nick_name | 角色 |
|----------------|-------------|-----------|------|
| admin | 不单独建账号 | — | 复用门户 `admin` |
| gly | 管理员 | 管理员 | 地磅管理员(或合并到业务管理员) |
| shanxia | 山峡 | 山峡 | 地磅操作员 |
| user1 | 过磅员1 | 过磅员1 | 地磅操作员 |
| user2 | 过磅员2 | 过磅员2 | 地磅操作员 |
| 过磅员 | 过磅员 | 过磅员 | 地磅操作员 |
> 若「管理员」「山峡」与员工姓名冲突,在 `user_no` 后加后缀,如 `管理员_地磅`。
地磅密码均为明文弱密码,**迁入时统一重置**为临时密码(首次登录强制修改)。
---
## 5. 完整用户清单(初稿)
以下为基于 `docs/sql/sx.sql`、`docs/sql/dibang.sql` 快照整理的 **待导入** 清单(不含已删除、不含门户已有 `admin`)。
### 5.1 员工账号(bx 为主,中文名登录)
| user_no | 来源 bx_id | 来源 CRM user_id | 手机 | 备注 |
|---------|-----------|------------------|------|------|
| 吴九华 | 16 | 1988153817824903170 | 18656008189 | |
| 汪璇 | 17 | 1984880722460753922 | 18895395317 | |
| 刘茂生 | 18 | — | 18955618780 | 仅 bx |
| 吴良萍 | 19 | 1984881464336662529 | 18855101814 | |
| 方金强 | 20 | 1984880121521848321 | 18110402102 | |
| 黄天宝 | 21 | — | 13865153716 | 仅 bx |
| 程欢欢 | 22 | 1984881038509948929 | 18855677446 | |
| 刘丹 | 23 | — | 13865565378 | 仅 bx |
| 郑丽娜 | 24 | 1993942552906809345 | 13522116225 | |
| 李勤 | 26 | — | 13470794894 | 仅 bx |
| 吴春生 | 27 | — | 18805561555 | 仅 bx |
| 吴自国 | 28 | — | 15155081585 | 仅 bx |
| 潘光荣 | 29 | — | 13955614150 | 仅 bx |
| 刘道银 | 30 | — | 15855555833 | 仅 bx |
| 汪华胜 | 31 | — | 13976616618 | 仅 bx |
| 王晓阳 | 32 | — | 19939016266 | 仅 bx |
| 郭奇 | 33 | — | 13805683372 | 仅 bx |
| 刘端 | 34 | — | 18749617637 | 仅 bx |
| 方长彪 | 35 | — | 13225569301 | 仅 bx |
| 吴自寨 | 36 | — | 13855607262 | 仅 bx |
| 吴祚权 | 37 | — | 19855069273 | 仅 bx |
| 沈卫斌 | 45 | — | 18756693937 | 仅 bx |
| 王伍云 | 47 | — | 18815716809 | 仅 bx |
| 胡银池 | 48 | — | 13955508997 | 仅 bx |
| 宋健 | — | 1984880895001837569 | 18297798890 | 仅 CRM |
**合计:25 名员工 + 1 管理员(admin 已存在)**
### 5.2 地磅专用账号(+5,若不与员工合并)
见 §4 表。
---
## 6. 角色分配建议(P0 执行时配置)
| 角色 | 适用用户 |
|------|---------|
| 超级管理员 | `admin` |
| 销售人员 | CRM 销售相关(方金强、汪璇、程欢欢等,按现网 CRM 角色对照) |
| 报销-员工 | bx 全体申请人 |
| 报销-财务 / 总经理 | 按 bx 原 `bx_role_user` 对照 |
| 地磅操作员 | 地磅 §4 账号 |
具体 `sys_role` 名称与 `sys_role_menu` 在 `phase-0-foundation/step-03-role-menu.md` 定义(待编写)。
---
## 7. 映射表结构
`mappings/user_mapping.csv` 列:
```
new_user_id,user_no,nick_name,phone_no,bx_user_id,crm_user_id,dibang_user_id,password_source,status,remark
```
- `new_user_id`:新生成 UUID(脚本写入前为空,执行后回填)
- `password_source`:`bx` | `crm` | `reset`(地磅)
---
## 8. 对下游数据迁移的影响
| 下游 | 旧字段 | 新字段 |
|------|--------|--------|
| CRM 全表 | `create_by` bigint | `user_mapping.crm_user_id` → `new_user_id` |
| CRM 全表 | `owner_user_id` bigint | 同上 |
| bx 全表 | `applicant_id` / 审批人 int | `user_mapping.bx_user_id` → `new_user_id` |
| bx 工作流节点 | `approver_id` | 重绑为新 UUID |
| 地磅 | 无用户 FK | 仅操作员需能登录门户 |
**P0 用户迁移完成并验收后**,方可启动 P1/P2/P3。