Files
loan-pricing/doc/implementation-report-2026-05-19-sys-user-role-sql.md

51 lines
2.6 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_role 角色关系 SQL 生成记录
## 修改日期
2026-05-20
## 需求范围
- 根据 `/Users/wkc/Downloads/892.xlsx``Sheet1` 生成 `sys_user_role` 插入语句。
- Excel 字段使用规则:`柜员号` 匹配 `sys_user.user_name` 后取 `sys_user.user_id``类型` 匹配 `sys_role.role_name` 后取 `sys_role.role_id`
- 未将 Excel 柜员号直接写入 `sys_user_role.user_id`
- 本次只生成 SQL 文件,未执行写入数据库。
## 输出文件
- `sql/insert_sys_user_role_892_20260519.sql`
## 数据统计
- Excel 有效数据行257 行。
- 管理员4 行。
- 支行管理员37 行。
- 客户经理213 行。
- Excel 中 3 个重复柜员号同时出现客户经理和支行管理员,本次按支行管理员优先处理,不插入客户经理角色。
## 重复柜员号
- `8922557`: 裘朝山 / 892220 / 客户经理 / Excel 第 26 行、裘朝山 / 892220 / 支行管理员 / Excel 第 117 行
- `8922667`: 徐华源 / 892080 / 客户经理 / Excel 第 66 行、徐华源 / 892080 / 支行管理员 / Excel 第 121 行
- `8923504`: 陈俊杰 / 892170 / 客户经理 / Excel 第 28 行、陈俊杰 / 892170 / 支行管理员 / Excel 第 118 行
- 处理规则:以上重复柜员号只保留在支行管理员插入语句中。
## 数据库映射确认
- 已查询开发库 `sys_role`,当前有效角色为:
- `管理员` -> `role_id=100`, `role_key=headAdmin`
- `客户经理` -> `role_id=101`, `role_key=common`
- `支行管理员` -> `role_id=102`, `role_key=branchAdmin`
- SQL 文件不硬编码 `role_id`,执行时按 `sys_role.role_name` 动态匹配,避免不同环境角色自增 ID 不一致。
- SQL 使用 `INSERT IGNORE`,重复执行不会重复写入相同 `(user_id, role_id)`
- SQL 不创建临时表,已按 `管理员``支行管理员``客户经理` 拆成三条独立插入语句,便于分角色执行和核对影响范围。
## 验证记录
- 已读取 Excel 并校验 `类型` 只包含 `管理员``支行管理员``客户经理`
- 已确认 `sys_user_role` 表结构为 `user_id``role_id` 联合主键。
- 已对开发库做不写入目标表的干跑校验257 行角色均可匹配,当前库 Excel 柜员号匹配到的有效用户数为 0。
- 批量执行该 SQL 前需先导入 Excel 对应用户,否则三条插入语句因匹配不到 `sys_user.user_name` 不会写入关系。
- 已按要求移除临时表建表、临时表插入和临时表删除语句。
- 已在事务内执行 SQL 脚本并 `ROLLBACK`,确认三条插入语句语法通过且未落库。