1
0
forked from erp-dev/erp
Files
erpnew/docs/2026-01-16_summary.md
2026-01-16 17:25:21 +08:00

52 lines
2.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.
# 2026-01-16 工作日志
## 背景
需要在 `stateflow` 模块提供一种通用查询能力按“已完成的状态节点state_id+ 工艺参数 key/value”反查相关的 `BusinessObject` 列表。
典型场景:查找所有 **已完成**“画图中”节点且工艺参数“设计师名称”为“AAA”的业务对象并可通过 `content_type/object_id` 追溯到实际业务对象,如 `printing.plateorder`)。
---
## 今日任务
-`GET /api/v1/stateflow/business-objects/` 增加过滤条件:`state_id` + `param_key` + `param_value`
- 增加 PostgreSQL JSONB 查询性能优化:为 `StateLogParameterRecord.parameters` 添加 GIN`jsonb_path_ops`)索引
- 补齐/更新测试用例,验证过滤行为与撤销记录处理
---
## 今日完成
### 1) BusinessObject 查询能力增强(按已完成节点 + 工艺参数过滤)
`api_v1/views/stateflow/business_object.py``BusinessObjectFilterSet` 中新增过滤参数:
- `state_id`:状态节点 ID表示“已完成该节点”仅匹配 `StateFlowRecord.is_cancelled=False`
- `param_key`:工艺参数 key
- `param_value`:工艺参数 value
典型用法(示例:查 `printing.plateorder` 类型):
- `GET /api/v1/stateflow/business-objects/?content_type_str=printing.plateorder&state_id=<id>&param_key=设计师名称&param_value=AAA&limit=500&offset=0`
实现方式使用 `Exists(OuterRef)` 子查询,避免 join + distinct 的重复行问题,性能更稳定。
### 2) PostgreSQL JSONB 索引优化
新增迁移:`stateflow/migrations/0022_statelogparameterrecord_parameters_gin_index.py`
-`StateLogParameterRecord.parameters` 增加 `GIN(jsonb_path_ops)` 索引
- 主要加速 `parameters__contains={key: value}`(即 `jsonb @> ...`)这类查询
### 3) 测试补齐
`stateflow/tests/test_business_object_crud_and_filters_api.py` 增加用例,覆盖:
- 命中:已完成节点 + 参数匹配
- 不命中:参数值不一致
- 排除:已撤销的 `StateFlowRecord` 不参与匹配
另外,为保证 `stateflow` 测试集可持续运行,恢复了 `stateflow.services.clone_business_object()` 的实现(此前曾临时禁用导致测试失败)。