feat:历史记录按目录模糊匹配
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func
|
from sqlalchemy import Column, Integer, String, Sequence, Boolean, func, or_
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from app.db import db_query, db_update, Base
|
from app.db import db_query, db_update, Base
|
||||||
@ -50,26 +50,33 @@ class TransferHistory(Base):
|
|||||||
@db_query
|
@db_query
|
||||||
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30, status: bool = None):
|
def list_by_title(db: Session, title: str, page: int = 1, count: int = 30, status: bool = None):
|
||||||
if status is not None:
|
if status is not None:
|
||||||
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%'),
|
result = db.query(TransferHistory).filter(
|
||||||
TransferHistory.status == status).order_by(
|
TransferHistory.status == status
|
||||||
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
).order_by(
|
||||||
count).all()
|
TransferHistory.date.desc()
|
||||||
|
).offset((page - 1) * count).limit(count).all()
|
||||||
else:
|
else:
|
||||||
result = db.query(TransferHistory).filter(TransferHistory.title.like(f'%{title}%')).order_by(
|
result = db.query(TransferHistory).filter(or_(
|
||||||
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
TransferHistory.src.like(f'%{title}%'),
|
||||||
count).all()
|
TransferHistory.dest.like(f'%{title}%'),
|
||||||
|
)).order_by(
|
||||||
|
TransferHistory.date.desc()
|
||||||
|
).offset((page - 1) * count).limit(count).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
def list_by_page(db: Session, page: int = 1, count: int = 30, status: bool = None):
|
def list_by_page(db: Session, page: int = 1, count: int = 30, status: bool = None):
|
||||||
if status is not None:
|
if status is not None:
|
||||||
result = db.query(TransferHistory).filter(TransferHistory.status == status).order_by(
|
result = db.query(TransferHistory).filter(
|
||||||
TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
TransferHistory.status == status
|
||||||
count).all()
|
).order_by(
|
||||||
|
TransferHistory.date.desc()
|
||||||
|
).offset((page - 1) * count).limit(count).all()
|
||||||
else:
|
else:
|
||||||
result = db.query(TransferHistory).order_by(TransferHistory.date.desc()).offset((page - 1) * count).limit(
|
result = db.query(TransferHistory).order_by(
|
||||||
count).all()
|
TransferHistory.date.desc()
|
||||||
|
).offset((page - 1) * count).limit(count).all()
|
||||||
return list(result)
|
return list(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -113,10 +120,12 @@ class TransferHistory(Base):
|
|||||||
@db_query
|
@db_query
|
||||||
def count_by_title(db: Session, title: str, status: bool = None):
|
def count_by_title(db: Session, title: str, status: bool = None):
|
||||||
if status is not None:
|
if status is not None:
|
||||||
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%'),
|
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.status == status).first()[0]
|
||||||
TransferHistory.status == status).first()[0]
|
|
||||||
else:
|
else:
|
||||||
return db.query(func.count(TransferHistory.id)).filter(TransferHistory.title.like(f'%{title}%')).first()[0]
|
return db.query(func.count(TransferHistory.id)).filter(or_(
|
||||||
|
TransferHistory.src.like(f'%{title}%'),
|
||||||
|
TransferHistory.dest.like(f'%{title}%')
|
||||||
|
)).first()[0]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_query
|
@db_query
|
||||||
|
Reference in New Issue
Block a user