forked from erp-dev/erp
feat: improved wecomm message field
This commit is contained in:
@@ -191,18 +191,6 @@ def on_printing_job_state_advanced(sender, **kwargs):
|
||||
else timezone.localtime(timezone.now()).strftime('%Y-%m-%d %H:%M:%S')
|
||||
)
|
||||
|
||||
template = getattr(
|
||||
settings,
|
||||
'PRINTING_JOB_STATE_ADVANCED_WECOM_MARKDOWN_TEMPLATE',
|
||||
(
|
||||
"### PrintingJob 状态推进\n"
|
||||
"\n"
|
||||
"- **PrintingOrder.id**: `{printing_order_id}`\n"
|
||||
"- **PrintingJob.id**: `{printing_job_id}`\n"
|
||||
"- **State**: **{state_name}**\n"
|
||||
"- **AdvancedAt**: `{advanced_at}`\n"
|
||||
),
|
||||
)
|
||||
sender_label = None
|
||||
completed_by = kwargs.get('completed_by')
|
||||
if completed_by:
|
||||
@@ -212,13 +200,33 @@ def on_printing_job_state_advanced(sender, **kwargs):
|
||||
else:
|
||||
sender_label = '系统自动发送'
|
||||
|
||||
message = template.format(
|
||||
printing_order_id=str(printing_order_id) if printing_order_id is not None else '-',
|
||||
printing_job_id=str(printing_job_id) if printing_job_id is not None else '-',
|
||||
state_name=str(state_name),
|
||||
advanced_at=str(advanced_at),
|
||||
sender=str(sender_label),
|
||||
)
|
||||
# 工序参数:取该 state_log 的最新汇总
|
||||
try:
|
||||
params = state_log.get_all_parameters_summary(include_cancelled=False) if state_log else {}
|
||||
except Exception:
|
||||
logger.exception('[printing.handlers] 读取工序参数失败,降级为空')
|
||||
params = {}
|
||||
|
||||
try:
|
||||
from printing.services import (
|
||||
build_printing_job_followup_url,
|
||||
render_printing_job_state_markdown,
|
||||
render_process_params_markdown,
|
||||
)
|
||||
followup_url = build_printing_job_followup_url(printing_order_id=printing_order_id)
|
||||
process_params_markdown = render_process_params_markdown(params=params)
|
||||
message = render_printing_job_state_markdown(
|
||||
printing_order_id=str(printing_order_id) if printing_order_id is not None else '-',
|
||||
printing_job_id=str(printing_job_id) if printing_job_id is not None else '-',
|
||||
state_name=str(state_name),
|
||||
advanced_at=str(advanced_at),
|
||||
sender_label=str(sender_label),
|
||||
followup_url=str(followup_url),
|
||||
process_params_markdown=str(process_params_markdown),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception('[printing.handlers] 渲染企业微信消息失败,跳过通知')
|
||||
return
|
||||
|
||||
def _send_wecom():
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user