This commit is contained in:
lhx
2025-11-07 11:47:00 +08:00
3 changed files with 22 additions and 2 deletions

View File

@@ -394,6 +394,7 @@ def get_today_data(request: TodayDataRequest, db: Session = Depends(get_db)):
# account_id = request.account_id # 根据根据实际需求决定是否需要 # account_id = request.account_id # 根据根据实际需求决定是否需要
# 触发定时任务(如果需要传入参数,可在这里添加) # 触发定时任务(如果需要传入参数,可在这里添加)
# from ..utils.scheduler import scheduled_get_max_nyid_by_point_id
# scheduled_get_max_nyid_by_point_id() # scheduled_get_max_nyid_by_point_id()
# 调用服务层获取数据 # 调用服务层获取数据

View File

@@ -13,3 +13,4 @@ class DailyData(Base):
section_id = Column(String(255), nullable=False, comment="所属断面id") section_id = Column(String(255), nullable=False, comment="所属断面id")
remaining = Column(Integer, nullable=False, comment="剩余天数") remaining = Column(Integer, nullable=False, comment="剩余天数")
user_id = Column(Integer, default=1, nullable=False, comment="用户id") user_id = Column(Integer, default=1, nullable=False, comment="用户id")
is_all = Column(Integer, default=1, nullable=False, comment="是否全量数据")

View File

@@ -91,6 +91,20 @@ class TaskScheduler:
name='每日重置账号更新状态' name='每日重置账号更新状态'
) )
logger.info("系统定时任务:每日重置账号更新状态已添加") logger.info("系统定时任务:每日重置账号更新状态已添加")
existing_job = None
existing_job = self.scheduler.get_job("scheduled_get_max_nyid_by_point_id")
if not existing_job:
# 添加每天凌晨1点执行获取max NYID关联数据任务
self.scheduler.add_job(
scheduled_get_max_nyid_by_point_id,
'cron',
id='scheduled_get_max_nyid_by_point_id',
hour=1,
minute=0,
second=0,
name='每日获取max NYID关联数据并创建DailyData记录'
)
logger.info("系统定时任务每日获取max NYID关联数据任务已添加")
except Exception as e: except Exception as e:
logger.error(f"设置系统定时任务失败: {e}") logger.error(f"设置系统定时任务失败: {e}")
@@ -206,6 +220,7 @@ def scheduled_get_max_nyid_by_point_id():
"""定时任务获取max NYID关联数据并批量创建DailyData记录""" """定时任务获取max NYID关联数据并批量创建DailyData记录"""
db: Session = None db: Session = None
try: try:
logger.info("定时任务触发开始获取max NYID关联数据并处理")
# 初始化数据库会话替代接口的Depends依赖 # 初始化数据库会话替代接口的Depends依赖
db = SessionLocal() db = SessionLocal()
logger.info("定时任务开始执行获取max NYID关联数据并处理") logger.info("定时任务开始执行获取max NYID关联数据并处理")
@@ -223,6 +238,7 @@ def scheduled_get_max_nyid_by_point_id():
daily_data = monitor.get_due_data(result) daily_data = monitor.get_due_data(result)
data = daily_data['data'] data = daily_data['data']
error_data = daily_data['error_data'] error_data = daily_data['error_data']
winters = daily_data['winter'] winters = daily_data['winter']
logger.info(f"首次获取数据完成,共{len(result)}条记录") logger.info(f"首次获取数据完成,共{len(result)}条记录")
@@ -238,8 +254,10 @@ def scheduled_get_max_nyid_by_point_id():
# 更新冬休、待处理、错误数据 # 更新冬休、待处理、错误数据
winters = w_list['winter'] winters = w_list['winter']
data.extend(w_list['data']) data.extend(w_list['data'])
# 过期数据一并处理
# data.extend(w_list['error_data'])
error_data.extend(w_list['error_data']) error_data.extend(w_list['error_data'])
data.extend(error_data)
# 4. 初始化服务实例 # 4. 初始化服务实例
level_service = LevelDataService() level_service = LevelDataService()
checkpoint_db = CheckpointService() checkpoint_db = CheckpointService()
@@ -282,7 +300,7 @@ def scheduled_get_max_nyid_by_point_id():
'linecode': d['level_data']['linecode'], 'linecode': d['level_data']['linecode'],
'account_id': d['account_data']['account_id'], 'account_id': d['account_data']['account_id'],
'section_id': d['section_data']['section_id'], 'section_id': d['section_data']['section_id'],
'remaining': d['remaining'], 'remaining': (0-int(d['overdue'])) if 'overdue' in d else d['remaining'],
} }
daily_create_data.append(tem) daily_create_data.append(tem)