hr-system/docs/02-develop/dev-notes.md

49 lines
2.4 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.

# 开发记录批次1 / T09
## 任务hr-system 审计日志底座F12
### 交付内容
- `app/hr_system/audit.py`:审计底座核心实现
- `write_audit_log(module, target_type, target_id, operation, before=None, after=None, **kw)`
横切公共入口(其他模块 T03/T05/T10 等直接调用,签名对齐 api-design.md §1
- `audit_log_list(params, env)`:按时间/操作类型/操作人/模块筛选 + 分页
- `audit_log_detail(params, env)`:详情(含前后值 JSON已脱敏
- 敏感字段脱敏:`mask_id_number`(身份证前 3 后 3`mask_mobile`(手机前 3 后 4`mask_json` 递归脱敏
- `app/hr_system/__init__.py`ServerEnv 注册横切函数与端点write_audit_log / 脱敏 / audit_log_list / audit_log_detail
- `wwwroot/audit_log_list.ui`:列表 + 详情前后值对比展示DiffPanel
- `app/hr_system/selftest_audit.py`:自测脚本
### 操作类型字典AUDIT_OP
create / update / delete / import / export / approve / reject / login / logout
### 敏感字段脱敏规则
- 身份证/证件号:前 3 后 3中间打星示例 110************234
- 手机号:前 3 后 4中间打星示例 138****5678
- 字段自动识别id_number/id_card/mobile/phone/tel 等 hint递归覆盖嵌套 dict/list
### 自测结果
```
python3 app/hr_system/selftest_audit.py
[PASS] 身份证前3后3
[PASS] 手机前3后4
[PASS] mask_json 递归脱敏
[PASS] audit.module / operation / id 自动生成
[PASS] audit before 手机/身份证脱敏落库
[PASS] audit INSERT 落库
[PASS] login before/after 空 + IP 记录
[PASS] import / export / approve 动作
[PASS] audit_log_list total
[PASS] audit_log_detail 操作人
ALL PASS
```
### 验收对照F12 全 4 项)
1. 按操作时间/类型查看操作记录,详情含操作前后对比、操作人、时间 → audit_log_list + audit_log_detail
2. 全量记录增删改操作 → write_audit_log 覆盖 create/update/delete/import/export/approve/login
3. 操作人、IP、时间记录 → operator_id/operator_name/request_ip/created_at 字段
4. 敏感字段脱敏 → mask_id_number / mask_mobile / mask_json 在 before_json/after_json 落库前生效
### 备注
- 契约基线models/hr_system/sys_audit_log.json已冻结只增表字段与实现一一对应。
- db 兼容 sqlor/ahserver 执行上下文execute/run/query/query_one/scalar 多形态)。