56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""批量初始化常用快递公司(biz_express_company),已存在编码则跳过。"""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.core.database import SessionLocal
|
|
from app.crud import express_company as express_company_svc
|
|
|
|
# (express_code, express_name, order_num, remark)
|
|
EXPRESS_COMPANIES = [
|
|
("SF", "顺丰速运", 1, "常用快递"),
|
|
("YTO", "圆通速递", 2, "常用快递"),
|
|
("ZTO", "中通快递", 3, "常用快递"),
|
|
("STO", "申通快递", 4, "常用快递"),
|
|
("YD", "韵达速递", 5, "常用快递"),
|
|
("JD", "京东物流", 6, "常用快递"),
|
|
("EMS", "中国邮政EMS", 7, "常用快递"),
|
|
("HTKY", "百世快递", 8, "常用快递"),
|
|
("JTSD", "极兔速递", 9, "常用快递"),
|
|
("DBL", "德邦快递", 10, "常用快递"),
|
|
]
|
|
|
|
|
|
def seed(tenant_no: str = "zkxw", user_id: str = "d3000000000000000000000000000001") -> None:
|
|
db = SessionLocal()
|
|
created = 0
|
|
skipped = 0
|
|
try:
|
|
for code, name, order_num, remark in EXPRESS_COMPANIES:
|
|
if express_company_svc.express_code_exists(db, code, tenant_no):
|
|
skipped += 1
|
|
continue
|
|
express_company_svc.create_express_company(
|
|
db,
|
|
express_code=code,
|
|
express_name=name,
|
|
tenant_no=tenant_no,
|
|
order_num=order_num,
|
|
remark=remark,
|
|
user_id=user_id,
|
|
)
|
|
created += 1
|
|
print(f"快递公司初始化完成:新增 {created} 条,跳过 {skipped} 条(编码已存在)。")
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
seed()
|