fix: 修复定时任务datetime错误和PENDING期号更新逻辑

This commit is contained in:
Mars 2025-07-07 10:42:34 +08:00
parent 5d82328f51
commit 809802e655
2 changed files with 18 additions and 5 deletions

View File

@ -63,7 +63,7 @@ class LotteryScheduler:
db = SessionLocal()
try:
# 判断彩种
weekday = datetime.datetime.now().isoweekday()
weekday = datetime.now().isoweekday()
if weekday == 5:
logger.info("周五休息,不推送推荐")
return
@ -80,7 +80,7 @@ class LotteryScheduler:
title = "你好,帮忙买下双色球。"
dlt_append = False
# 生成batch_id
today = datetime.datetime.now().strftime('%Y%m%d')
today = datetime.now().strftime('%Y%m%d')
batch_id = f"{today}-{random.randint(1000, 9999)}"
# 推荐4注集成预测+智能选号补足)
service = PredictionService(db)

View File

@ -258,7 +258,7 @@ class LotteryUpdater:
def update_bet_issues_by_date(self, lottery_type: str):
"""
根据投注日期更新期号
查找相同日期的投注记录将期号设置为当天开奖的期号
查找投注记录将期号设置为投注日期之后最近的开奖期号
"""
try:
db = self.SessionLocal()
@ -280,16 +280,29 @@ class LotteryUpdater:
# 获取投注日期
bet_date = bet.bet_time.date()
# 查找相同日期的开奖记录
# 查找投注日期之后最近的开奖记录
# 先尝试找投注当天的开奖
draw = db.query(LotteryModel).filter(
LotteryModel.open_time == bet_date).first()
# 如果投注当天没有开奖,找投注日期之后最近的开奖
if not draw:
draw = db.query(LotteryModel).filter(
LotteryModel.open_time > bet_date
).order_by(LotteryModel.open_time.asc()).first()
# 如果还是没找到,找投注日期之前最近的开奖(兜底逻辑)
if not draw:
draw = db.query(LotteryModel).filter(
LotteryModel.open_time <= bet_date
).order_by(LotteryModel.open_time.desc()).first()
if draw:
# 更新投注记录的期号
old_issue = bet.issue
bet.issue = draw.issue
logger.debug(
f"更新投注记录 ID {bet.id}: 期号 {old_issue} -> {draw.issue} (日期匹配: {bet_date})")
f"更新投注记录 ID {bet.id}: 期号 {old_issue} -> {draw.issue} (投注日期: {bet_date}, 开奖日期: {draw.open_time})")
else:
logger.debug(
f"投注记录 ID {bet.id} 的日期 {bet_date} 暂无开奖数据,期号保持 PENDING")