From 41b2cd77272c449f295167782106b8cb92b311cf Mon Sep 17 00:00:00 2001 From: x1ao4 Date: Mon, 15 Sep 2025 01:25:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=80=E8=BF=91=E8=BD=AC?= =?UTF-8?q?=E5=AD=98=E6=96=87=E4=BB=B6=E5=8F=AA=E5=8C=85=E5=90=AB=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E4=BF=A1=E6=81=AF=E6=97=B6=E9=9B=86=E6=95=B0=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=92=8C=E8=BD=AC=E5=AD=98=E8=BF=9B=E5=BA=A6=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复后端 enrich_tasks_with_calendar_meta 函数,增加对只有日期情况的处理 - 修复前端任务列表页面数据加载,确保 episodes 数据和进度映射正确构建 - 解决刷新页面后已转存集数变为0的问题 - 保持向后兼容,不影响包含集数的文件处理 问题:最近转存文件中不包含集数但包含播出日期时,任务列表页面的集数统计和转存进度在刷新后会丢失 解决:完善后端数据处理逻辑,确保前端页面能正确加载和构建所需的数据映射 --- app/run.py | 26 +++++++++++++++++++++++++- app/templates/index.html | 34 ++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/app/run.py b/app/run.py index 5a737f6..56c4878 100644 --- a/app/run.py +++ b/app/run.py @@ -76,7 +76,7 @@ def enrich_tasks_with_calendar_meta(tasks_info: list) -> list: for tid, sn, sname, ecount in rows: season_meta[(int(tid), int(sn))] = {'season_name': sname or '', 'episode_count': int(ecount or 0)} - # 统计“已转存集数”:基于转存记录最新进度构建映射(按任务名) + # 统计"已转存集数":基于转存记录最新进度构建映射(按任务名) transferred_by_task = {} try: rdb = RecordDB() @@ -115,7 +115,31 @@ def enrich_tasks_with_calendar_meta(tasks_info: list) -> list: processed = process_season_episode_info(name_wo_ext, task_name) parsed = extractor.extract_progress_from_latest_file(processed) if parsed and parsed.get('episode_number'): + # 包含集数的情况 transferred_by_task[task_name] = int(parsed['episode_number']) + elif parsed and parsed.get('air_date'): + # 只有日期的情况:通过查询数据库获取对应日期的最大集数 + air_date = parsed['air_date'] + try: + # 查找该任务对应的节目名称 + task_info = next((t for t in tasks_info if (t.get('task_name') or t.get('taskname')) == task_name), None) + if task_info: + show_name = (task_info.get('matched_show_name') or task_info.get('show_name') or '').strip() + if show_name: + # 查询该节目在该日期播出的最大集数 + cur.execute( + """ + SELECT MAX(CAST(episode_number AS INTEGER)) + FROM episodes + WHERE show_name = ? AND air_date = ? + """, + (show_name, air_date) + ) + result = cur.fetchone() + if result and result[0] is not None: + transferred_by_task[task_name] = int(result[0]) + except Exception: + pass rdb.close() except Exception: transferred_by_task = {} diff --git a/app/templates/index.html b/app/templates/index.html index eef4f7a..f45086b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -8925,20 +8925,30 @@ } }); }, - loadTaskLatestInfo() { + async loadTaskLatestInfo() { // 获取所有任务的最新转存信息(包括日期和文件) - axios.get('/task_latest_info') - .then(response => { - if (response.data.success) { - this.taskLatestRecords = response.data.data.latest_records; - this.taskLatestFiles = response.data.data.latest_files; - } else { - console.error('获取任务最新信息失败:', response.data.message); + try { + const response = await axios.get('/task_latest_info'); + if (response.data.success) { + this.taskLatestRecords = response.data.data.latest_records; + this.taskLatestFiles = response.data.data.latest_files; + + // 构建进度映射,确保基于日期的集数统计能正常工作 + this.calendar.progressByTaskName = this.buildProgressByTaskNameFromLatestFiles(this.taskLatestFiles || {}); + this.calendar.progressByShowName = this.buildProgressByShowNameFromTasks(this.calendar.tasks || [], this.calendar.progressByTaskName); + + // 同时加载 episodes 数据,确保基于日期的集数统计能正常工作 + try { + await this.loadCalendarEpisodesLocal(); + } catch (e) { + console.warn('加载 episodes 数据失败:', e); } - }) - .catch(error => { - console.error('获取任务最新信息失败:', error); - }); + } else { + console.error('获取任务最新信息失败:', response.data.message); + } + } catch (error) { + console.error('获取任务最新信息失败:', error); + } }, // 加载任务列表的元数据信息(用于热更新海报和元数据) async loadTasklistMetadata() {