71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
|
|
"""美国物流价格数据访问类"""
|
||
|
|
import pandas as pd
|
||
|
|
from typing import Dict, List, Optional
|
||
|
|
from dataaccess.base_dao import BaseDAO
|
||
|
|
|
||
|
|
|
||
|
|
class USPriceDAO(BaseDAO):
|
||
|
|
"""美国物流价格数据访问"""
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__("us_logistics_price")
|
||
|
|
|
||
|
|
def get_all_companies(self) -> List[str]:
|
||
|
|
"""获取所有美国物流公司"""
|
||
|
|
df = self.get_all()
|
||
|
|
if df.empty:
|
||
|
|
return []
|
||
|
|
return df["company"].unique().tolist()
|
||
|
|
|
||
|
|
def get_company_price(self, company: str) -> pd.DataFrame:
|
||
|
|
"""获取指定物流公司的价格数据"""
|
||
|
|
return self.get_by_condition({"company": company})
|
||
|
|
|
||
|
|
def get_company_config(self, company: str) -> Dict:
|
||
|
|
"""获取物流公司配置信息"""
|
||
|
|
df = self.get_by_condition({"company": company})
|
||
|
|
if df.empty:
|
||
|
|
return {}
|
||
|
|
|
||
|
|
config = {}
|
||
|
|
for _, row in df.iterrows():
|
||
|
|
key = row.get("config_key")
|
||
|
|
value = row.get("config_value")
|
||
|
|
if key:
|
||
|
|
config[key] = value
|
||
|
|
|
||
|
|
return config
|
||
|
|
|
||
|
|
|
||
|
|
class USPostcodeDAO(BaseDAO):
|
||
|
|
"""美国邮编分区数据访问"""
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__("us_postcode_zone")
|
||
|
|
|
||
|
|
def get_zone(self, postcode: str, port: str = "west") -> Optional[str]:
|
||
|
|
"""根据邮编获取分区"""
|
||
|
|
postcode_5 = postcode[:5]
|
||
|
|
df = self.get_by_condition({"postcode": postcode_5, "port": port})
|
||
|
|
|
||
|
|
if df.empty:
|
||
|
|
return None
|
||
|
|
|
||
|
|
return df.iloc[0].get("zone")
|
||
|
|
|
||
|
|
def get_remote_type(self, postcode: str) -> int:
|
||
|
|
"""获取偏远类型: 0-非偏远, 1-偏远, 2-超偏远, 3-超超偏远"""
|
||
|
|
postcode_5 = postcode[:5]
|
||
|
|
df = self.get_by_condition({"postcode": postcode_5})
|
||
|
|
|
||
|
|
if df.empty:
|
||
|
|
return 0
|
||
|
|
|
||
|
|
return int(df.iloc[0].get("remote_type", 0))
|
||
|
|
|
||
|
|
def is_contiguous(self, postcode: str) -> bool:
|
||
|
|
"""判断是否在本土范围内"""
|
||
|
|
postcode_5 = postcode[:5]
|
||
|
|
df = self.get_by_condition({"postcode": postcode_5})
|
||
|
|
return not df.empty
|