1
0
forked from erp-dev/erp
Files
erpnew/docs/2026-01-23_summary.md
2026-01-23 18:02:55 +08:00

54 lines
3.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-23 工作记录
#### 1) 新增:企业微信机器人 Webhooktext 消息util 与测试命令
- settings
- `flower/settings.py` 新增 `WECOM_WEBHOOK_BASE_URL` / `WECOM_WEBHOOK_KEY`
- `WECOM_WEBHOOK_KEY` 已改为从 `.env` 读取(默认空);若为空,发送时会报错(不会静默吞掉)
- 仓库内提供 `env.example`(等价于常见的 `.env.example`),可用 `cp env.example .env` 生成本地 `.env`
- util
- `api_v1/utils/wecom_webhook.py`
- 提供 `send_wecom_webhook_message(content=..., msgtype=..., key=..., timeout_seconds=...)`
- `msgtype` 支持:`text`(默认)、`markdown`
- command
- `api_v1/management/commands/wecom_webhook_send_text.py`
- 用法示例:
- `uv run python manage.py wecom_webhook_send_text "hello world"`
- 发送 markdown`uv run python manage.py wecom_webhook_send_text "**bold**" --msgtype markdown`
- 可选覆盖 key`uv run python manage.py wecom_webhook_send_text "hello" --key xxx`
- 参数:
- `text`:必填,消息内容
- `--msgtype`:可选,`text`(默认)或 `markdown`
- `--key`:可选,临时覆盖 `settings.WECOM_WEBHOOK_KEY`
- `--timeout`可选HTTP 超时秒数(默认 10
#### 2) 新增PrintingJob 每次状态推进state_advanced发送企业微信 markdown 通知
- 信号来源:`stateflow.signals.state_advanced`(每次推进都会触发,发送点在 `stateflow.services.advance_to_next_state()` 内)
- 监听注册:`printing/apps.py``state_advanced.connect(..., sender=PrintingJob)`
- handler`printing/handlers.py::on_printing_job_state_advanced`
- 使用 `transaction.on_commit(...)`,确保事务提交后再发送企业微信(避免回滚导致通知不一致)
- 发送内容markdown包含
- `PrintingOrder.id`
- `PrintingJob.id`
- `state.name`
- 推进时间(取 `state_log.completed_at`
- 发送者(默认取推进人 `completed_by` 的员工姓名/username兜底为“系统自动发送”
- 模板位置(便于后续改文案):`flower/settings.py`
- `PRINTING_JOB_STATE_ADVANCED_WECOM_MARKDOWN_TEMPLATE`
- 开关:`PRINTING_JOB_STATE_ADVANCED_WECOM_NOTIFY_ENABLED`(默认测试环境关闭,非测试环境开启)
- 模板已增加字段:`{sender}`(发送者)
- 跟进地址:
- `.env``PRINTING_JOB_STATE_ADVANCED_FOLLOWUP_URL_TEMPLATE`(默认空)
- 若为空则**消息中省略“跟进地址”字段**,但消息仍然发送
- 模板占位符:
- `{followup_line}`(由 service 渲染:有 url 才会输出“跟进地址”行)
- 模板已增加字段:`{process_params_markdown}`(工序参数,来自 `state_log.get_all_parameters_summary()`
#### 3) 重构:提取“发送最新状态到企业微信”逻辑为可复用 service便于后续 API 化)
- 新增:`printing/services.py`
- `send_printing_job_latest_state_wecom(printing_job_id, sender_label, ...)`
- `render_printing_job_state_markdown(...)`
- command`printing/management/commands/wecom_notify_printing_job_latest_state.py`
- 发送者强制为“系统自动发送”(后续 API 化可传入基于 `request.user` 的 sender_label