Files
urbanLifeline/.kiro/specs/urbanlifeline-to-pigx-migration/permission-mapping.md
2026-01-14 15:42:26 +08:00

253 lines
11 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.

# 权限标识映射表
## 概述
本文档定义了从 urbanLifelineServ 权限标识到 pigx 权限标识的映射规则。
## 映射规则
### 格式转换规则
- **源格式**: `module:resource:action` (使用冒号分隔)
- **目标格式**: `module_resource_action` (使用下划线分隔)
- **动作映射**:
- `create``add`
- `update``edit`
- `delete``del`
- `view``view`
- 其他保持不变
### 权限注解转换
- **源注解**: `@PreAuthorize("hasAuthority('module:resource:action')")`
- **目标注解**: `@PreAuthorize("@pms.hasPermission('module_resource_action')")`
## 权限映射表
### 工单模块 (workcase)
| 源权限标识 | 目标权限标识 | 说明 | 菜单类型 |
|-----------|-------------|------|----------|
| workcase:ticket:create | workcase_ticket_add | 创建工单 | 按钮 |
| workcase:ticket:update | workcase_ticket_edit | 更新工单 | 按钮 |
| workcase:ticket:view | workcase_ticket_view | 查看工单 | 菜单 |
| workcase:ticket:delete | workcase_ticket_del | 删除工单 | 按钮 |
| workcase:ticket:process | workcase_ticket_process | 处理工单 | 按钮 |
| workcase:ticket:device | workcase_ticket_device | 工单设备管理 | 按钮 |
| workcase:room:create | workcase_room_add | 创建聊天室 | 按钮 |
| workcase:room:update | workcase_room_edit | 更新聊天室 | 按钮 |
| workcase:room:close | workcase_room_close | 关闭聊天室 | 按钮 |
| workcase:room:view | workcase_room_view | 查看聊天室 | 菜单 |
### AI模块 (dify)
| 源权限标识 | 目标权限标识 | 说明 | 菜单类型 |
|-----------|-------------|------|----------|
| ai:agent:create | dify_agent_add | 创建智能体 | 按钮 |
| ai:agent:update | dify_agent_edit | 更新智能体 | 按钮 |
| ai:agent:delete | dify_agent_del | 删除智能体 | 按钮 |
| ai:agent:view | dify_agent_view | 查看智能体 | 菜单 |
| ai:knowledge:create | dify_knowledge_add | 创建知识库 | 按钮 |
| ai:knowledge:update | dify_knowledge_edit | 更新知识库 | 按钮 |
| ai:knowledge:delete | dify_knowledge_del | 删除知识库 | 按钮 |
| ai:knowledge:view | dify_knowledge_view | 查看知识库 | 菜单 |
| ai:knowledge:file:view | dify_knowledge_file_view | 查看知识库文件 | 按钮 |
| ai:knowledge:file:upload | dify_knowledge_file_upload | 上传知识库文件 | 按钮 |
| ai:knowledge:file:update | dify_knowledge_file_edit | 更新知识库文件 | 按钮 |
| ai:knowledge:file:delete | dify_knowledge_file_del | 删除知识库文件 | 按钮 |
| ai:dify:segment:view | dify_segment_view | 查看文档片段 | 按钮 |
| ai:dify:segment:create | dify_segment_add | 创建文档片段 | 按钮 |
| ai:dify:segment:update | dify_segment_edit | 更新文档片段 | 按钮 |
| ai:dify:segment:delete | dify_segment_del | 删除文档片段 | 按钮 |
| ai:dify:document:status | dify_document_status | 查看文档状态 | 按钮 |
| ai:chat:create | dify_chat_add | 创建对话 | 按钮 |
| ai:chat:view | dify_chat_view | 查看对话 | 菜单 |
| ai:chat:message | dify_chat_message | 发送消息 | 按钮 |
### 招标模块 (bidding)
| 源权限标识 | 目标权限标识 | 说明 | 菜单类型 |
|-----------|-------------|------|----------|
| bidding:project:create | bidding_project_add | 创建招标项目 | 按钮 |
| bidding:project:update | bidding_project_edit | 更新招标项目 | 按钮 |
| bidding:project:delete | bidding_project_del | 删除招标项目 | 按钮 |
| bidding:project:view | bidding_project_view | 查看招标项目 | 菜单 |
| bidding:bid:create | bidding_bid_add | 创建投标 | 按钮 |
| bidding:bid:update | bidding_bid_edit | 更新投标 | 按钮 |
| bidding:bid:view | bidding_bid_view | 查看投标 | 菜单 |
| bidding:document:view | bidding_document_view | 查看招标文件 | 按钮 |
| bidding:document:upload | bidding_document_upload | 上传招标文件 | 按钮 |
### 平台管理模块 (platform)
| 源权限标识 | 目标权限标识 | 说明 | 菜单类型 |
|-----------|-------------|------|----------|
| platform:config:view | platform_config_view | 查看配置 | 菜单 |
| platform:config:update | platform_config_edit | 更新配置 | 按钮 |
| platform:log:view | platform_log_view | 查看日志 | 菜单 |
| platform:monitor:view | platform_monitor_view | 查看监控 | 菜单 |
| platform:stat:view | platform_stat_view | 查看统计 | 菜单 |
### 消息模块 (message)
| 源权限标识 | 目标权限标识 | 说明 | 菜单类型 |
|-----------|-------------|------|----------|
| message:notification:create | message_notification_add | 创建通知 | 按钮 |
| message:notification:view | message_notification_view | 查看通知 | 菜单 |
| message:notification:send | message_notification_send | 发送通知 | 按钮 |
| message:template:create | message_template_add | 创建消息模板 | 按钮 |
| message:template:update | message_template_edit | 更新消息模板 | 按钮 |
| message:template:delete | message_template_del | 删除消息模板 | 按钮 |
| message:template:view | message_template_view | 查看消息模板 | 菜单 |
## 菜单配置SQL示例
```sql
-- 工单管理菜单
INSERT INTO sys_menu (menu_id, name, permission, path, parent_id, icon, sort, type, tenant_id) VALUES
(10000, '工单管理', NULL, '/workcase', 0, 'el-icon-tickets', 1, '0', 1),
(10001, '工单列表', 'workcase_ticket_view', '/workcase/list', 10000, '', 1, '1', 1),
(10002, '创建工单', 'workcase_ticket_add', NULL, 10001, '', 1, '2', 1),
(10003, '编辑工单', 'workcase_ticket_edit', NULL, 10001, '', 2, '2', 1),
(10004, '删除工单', 'workcase_ticket_del', NULL, 10001, '', 3, '2', 1),
(10005, '处理工单', 'workcase_ticket_process', NULL, 10001, '', 4, '2', 1),
(10006, '设备管理', 'workcase_ticket_device', NULL, 10001, '', 5, '2', 1),
(10010, '聊天室', 'workcase_room_view', '/workcase/room', 10000, '', 2, '1', 1),
(10011, '创建聊天室', 'workcase_room_add', NULL, 10010, '', 1, '2', 1),
(10012, '编辑聊天室', 'workcase_room_edit', NULL, 10010, '', 2, '2', 1),
(10013, '关闭聊天室', 'workcase_room_close', NULL, 10010, '', 3, '2', 1);
-- AI管理菜单Dify
INSERT INTO sys_menu (menu_id, name, permission, path, parent_id, icon, sort, type, tenant_id) VALUES
(11000, 'AI管理', NULL, '/dify', 0, 'el-icon-cpu', 2, '0', 1),
(11001, '智能体管理', 'dify_agent_view', '/dify/agent', 11000, '', 1, '1', 1),
(11002, '创建智能体', 'dify_agent_add', NULL, 11001, '', 1, '2', 1),
(11003, '编辑智能体', 'dify_agent_edit', NULL, 11001, '', 2, '2', 1),
(11004, '删除智能体', 'dify_agent_del', NULL, 11001, '', 3, '2', 1),
(11010, '知识库管理', 'dify_knowledge_view', '/dify/knowledge', 11000, '', 2, '1', 1),
(11011, '创建知识库', 'dify_knowledge_add', NULL, 11010, '', 1, '2', 1),
(11012, '编辑知识库', 'dify_knowledge_edit', NULL, 11010, '', 2, '2', 1),
(11013, '删除知识库', 'dify_knowledge_del', NULL, 11010, '', 3, '2', 1),
(11014, '上传文件', 'dify_knowledge_file_upload', NULL, 11010, '', 4, '2', 1),
(11020, 'AI对话', 'dify_chat_view', '/dify/chat', 11000, '', 3, '1', 1),
(11021, '创建对话', 'dify_chat_add', NULL, 11020, '', 1, '2', 1);
-- 招标管理菜单
INSERT INTO sys_menu (menu_id, name, permission, path, parent_id, icon, sort, type, tenant_id) VALUES
(12000, '招标管理', NULL, '/bidding', 0, 'el-icon-document', 3, '0', 1),
(12001, '招标项目', 'bidding_project_view', '/bidding/project', 12000, '', 1, '1', 1),
(12002, '创建项目', 'bidding_project_add', NULL, 12001, '', 1, '2', 1),
(12003, '编辑项目', 'bidding_project_edit', NULL, 12001, '', 2, '2', 1),
(12004, '删除项目', 'bidding_project_del', NULL, 12001, '', 3, '2', 1),
(12010, '投标管理', 'bidding_bid_view', '/bidding/bid', 12000, '', 2, '1', 1),
(12011, '创建投标', 'bidding_bid_add', NULL, 12010, '', 1, '2', 1),
(12012, '编辑投标', 'bidding_bid_edit', NULL, 12010, '', 2, '2', 1);
-- 平台管理菜单
INSERT INTO sys_menu (menu_id, name, permission, path, parent_id, icon, sort, type, tenant_id) VALUES
(13000, '平台管理', NULL, '/platform', 0, 'el-icon-setting', 4, '0', 1),
(13001, '系统配置', 'platform_config_view', '/platform/config', 13000, '', 1, '1', 1),
(13002, '编辑配置', 'platform_config_edit', NULL, 13001, '', 1, '2', 1),
(13010, '操作日志', 'platform_log_view', '/platform/log', 13000, '', 2, '1', 1),
(13020, '系统监控', 'platform_monitor_view', '/platform/monitor', 13000, '', 3, '1', 1),
(13030, '统计报表', 'platform_stat_view', '/platform/stat', 13000, '', 4, '1', 1);
-- 消息管理菜单
INSERT INTO sys_menu (menu_id, name, permission, path, parent_id, icon, sort, type, tenant_id) VALUES
(14000, '消息管理', NULL, '/message', 0, 'el-icon-message', 5, '0', 1),
(14001, '通知管理', 'message_notification_view', '/message/notification', 14000, '', 1, '1', 1),
(14002, '创建通知', 'message_notification_add', NULL, 14001, '', 1, '2', 1),
(14003, '发送通知', 'message_notification_send', NULL, 14001, '', 2, '2', 1),
(14010, '消息模板', 'message_template_view', '/message/template', 14000, '', 2, '1', 1),
(14011, '创建模板', 'message_template_add', NULL, 14010, '', 1, '2', 1),
(14012, '编辑模板', 'message_template_edit', NULL, 14010, '', 2, '2', 1),
(14013, '删除模板', 'message_template_del', NULL, 14010, '', 3, '2', 1);
```
## 角色权限分配示例
```sql
-- 为管理员角色分配所有业务权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, menu_id FROM sys_menu WHERE menu_id >= 10000 AND menu_id < 15000;
-- 为普通用户角色分配查看权限
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 2, menu_id FROM sys_menu
WHERE menu_id >= 10000 AND menu_id < 15000
AND (type = '0' OR type = '1' OR permission LIKE '%_view');
```
## 代码转换示例
### Java Controller 转换
```java
// 转换前 (urbanLifelineServ)
@RestController
@RequestMapping("/api/workcase")
public class WorkcaseController {
@PostMapping("/create")
@PreAuthorize("hasAuthority('workcase:ticket:create')")
public ResultDomain<TbWorkcaseDTO> createWorkcase(@RequestBody TbWorkcaseDTO workcase) {
return ResultDomain.success(workcaseService.save(workcase));
}
}
// 转换后 (pigx-app-server)
@RestController
@RequestMapping("/workcase")
public class WorkcaseController {
@PostMapping
@PreAuthorize("@pms.hasPermission('workcase_ticket_add')")
public R<TbWorkcaseDTO> createWorkcase(@RequestBody TbWorkcaseDTO workcase) {
return R.ok(workcaseService.save(workcase));
}
}
```
### 前端权限判断转换
```javascript
// 转换前 (urbanLifelineWeb)
if (hasPermission('workcase:ticket:create')) {
// 显示创建按钮
}
// 转换后 (pigx-ai-ui)
if (checkPermission(['workcase_ticket_add'])) {
// 显示创建按钮
}
```
## 注意事项
1. **权限格式严格**: 必须使用下划线 `_` 而不是冒号 `:`
2. **注解格式**: 必须包含 `@pms.` 前缀
3. **动作映射**: `create` 统一改为 `add``update` 改为 `edit``delete` 改为 `del`
4. **菜单类型**:
- type='0': 目录
- type='1': 菜单
- type='2': 按钮
5. **menu_id分配**:
- 10000-10999: 工单模块
- 11000-11999: AI模块(Dify)
- 12000-12999: 招标模块
- 13000-13999: 平台管理
- 14000-14999: 消息模块
## 批量转换脚本
可以使用以下正则表达式进行批量替换:
```regex
# 查找
@PreAuthorize\("hasAuthority\('([^:]+):([^:]+):([^']+)'\)"\)
# 替换为
@PreAuthorize("@pms.hasPermission('$1_$2_$3')")
# 特殊处理 create -> add
将 _create 替换为 _add
将 _update 替换为 _edit
将 _delete 替换为 _del
```