'commit'
This commit is contained in:
@@ -64,19 +64,16 @@ class TeLaiDianService:
|
||||
logger.info(f"仅保存场站基础信息: {station_name}")
|
||||
return True
|
||||
|
||||
async def save_station_data(self, station_name, address, prices):
|
||||
async def save_station_data(self, station_name, address, prices, total_piles=None, free_piles=None, piles_detail=None, parking_info=None):
|
||||
"""
|
||||
保存场站及其价格数据到数据库
|
||||
保存场站全量数据:名称、地址、24小时价格计划、当前状态
|
||||
"""
|
||||
if not prices:
|
||||
return False
|
||||
|
||||
station_hash = self.get_hash(station_name)
|
||||
now = datetime.now()
|
||||
|
||||
# 将价格转换为 24 小时的 schedule 格式 (0-23)
|
||||
# 每个小时存储一个包含多重价格的字典,以记录优惠价、PLUS价和挂牌价
|
||||
station_hash = hashlib.md5(f"{station_name}{address}".encode('utf-8')).hexdigest()
|
||||
|
||||
# 预处理价格:生成 24 小时的价格映射
|
||||
hourly_schedule = [None] * 24
|
||||
|
||||
for p in prices:
|
||||
try:
|
||||
start_parts = p['start'].split(':')
|
||||
@@ -142,9 +139,10 @@ class TeLaiDianService:
|
||||
session=session,
|
||||
id=status_id,
|
||||
station_hash=station_hash,
|
||||
total_piles=None, # 特来电暂时没抓取总桩数
|
||||
free_piles=None,
|
||||
piles_detail_json=None,
|
||||
total_piles=total_piles,
|
||||
free_piles=free_piles,
|
||||
piles_detail_json=piles_detail,
|
||||
parking_info=parking_info,
|
||||
current_price=current_price_info.get('price'),
|
||||
pro_price=current_price_info.get('plus_price'),
|
||||
market_price=current_price_info.get('market_price'),
|
||||
@@ -152,5 +150,5 @@ class TeLaiDianService:
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
logger.info(f"成功保存场站数据: {station_name}")
|
||||
logger.info(f"成功保存场站数据: {station_name} (桩数: {total_piles}, 空闲: {free_piles}, 停车费: {parking_info})")
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user