From 047c3b596de914f238adbbeebab62d07c7d0f4ff Mon Sep 17 00:00:00 2001 From: thsrite Date: Wed, 22 Nov 2023 09:21:51 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E6=8F=92=E4=BB=B6=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/downloadhistory_oper.py | 21 +++++++++++++++++++-- app/db/models/downloadhistory.py | 28 +++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/app/db/downloadhistory_oper.py b/app/db/downloadhistory_oper.py index 3f8fc194..d23fbb27 100644 --- a/app/db/downloadhistory_oper.py +++ b/app/db/downloadhistory_oper.py @@ -57,7 +57,14 @@ class DownloadHistoryOper(DbOper): 按fullpath查询下载文件记录 :param fullpath: 数据key """ - return DownloadFiles.get_by_fullpath(self._db, fullpath) + return DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=False) + + def get_files_by_fullpath(self, fullpath: str) -> List[DownloadFiles]: + """ + 按fullpath查询下载文件记录 + :param fullpath: 数据key + """ + return DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=True) def get_files_by_savepath(self, fullpath: str) -> List[DownloadFiles]: """ @@ -78,7 +85,7 @@ class DownloadHistoryOper(DbOper): 按fullpath查询下载文件记录hash :param fullpath: 数据key """ - fileinfo: DownloadFiles = DownloadFiles.get_by_fullpath(self._db, fullpath) + fileinfo: DownloadFiles = DownloadFiles.get_by_fullpath(self._db, fullpath=fullpath, all_files=False) if fileinfo: return fileinfo.download_hash return "" @@ -115,3 +122,13 @@ class DownloadHistoryOper(DbOper): return DownloadHistory.list_by_user_date(db=self._db, date=date, username=username) + + def list_by_date(self, date: str, type: str, tmdbid: str, seasons: str = None) -> List[DownloadHistory]: + """ + 查询某时间之后的下载历史 + """ + return DownloadHistory.list_by_date(db=self._db, + date=date, + type=type, + tmdbid=tmdbid, + seasons=seasons) diff --git a/app/db/models/downloadhistory.py b/app/db/models/downloadhistory.py index c3d091d7..d37ab652 100644 --- a/app/db/models/downloadhistory.py +++ b/app/db/models/downloadhistory.py @@ -123,6 +123,24 @@ class DownloadHistory(Base): DownloadHistory.id.desc()).all() return list(result) + @staticmethod + @db_query + def list_by_date(db: Session, date: str, type: str, tmdbid: str, seasons: str = None): + """ + 查询某时间之后的下载历史 + """ + if seasons: + return db.query(DownloadHistory).filter(DownloadHistory.date > date, + DownloadHistory.type == type, + DownloadHistory.tmdbid == tmdbid, + DownloadHistory.seasons == seasons).order_by( + DownloadHistory.id.desc()).all() + else: + return db.query(DownloadHistory).filter(DownloadHistory.date > date, + DownloadHistory.type == type, + DownloadHistory.tmdbid == tmdbid).order_by( + DownloadHistory.id.desc()).all() + class DownloadFiles(Base): """ @@ -157,9 +175,13 @@ class DownloadFiles(Base): @staticmethod @db_query - def get_by_fullpath(db: Session, fullpath: str): - return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by( - DownloadFiles.id.desc()).first() + def get_by_fullpath(db: Session, fullpath: str, all_files: bool = False): + if not all_files: + return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by( + DownloadFiles.id.desc()).first() + else: + return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).order_by( + DownloadFiles.id.desc()).all() @staticmethod @db_query