Files
Mutual_Fund/utils/order_no.py

16 lines
536 B
Python
Raw Permalink 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.
"""单号生成:前缀 + 日期 + 随机序列(唯一性由 DB 唯一键兜底)。"""
from __future__ import annotations
import secrets
from datetime import datetime
def gen_order_no(prefix: str = "PO") -> str:
"""生成全局唯一单号,如 PO20260912A1B2C3D4。
- PO:交易申请单(trade_order.order_no)
- TR:成交流水(fin_transaction.transaction_no)
- WO:业务工单(biz_work_order.work_order_no)
"""
return f"{prefix}{datetime.now():%Y%m%d}{secrets.token_hex(4).upper()}"