diff --git a/handler/car.py b/handler/car.py index 0378bba..1f35374 100644 --- a/handler/car.py +++ b/handler/car.py @@ -17,11 +17,13 @@ def get_list(db: Session = Depends(database), size: int = Query(default=10), keyword: str = Query(default=""), order_by_wrong_rate: bool = Query(default=True)): - logger.logger.info("page => %d, size => %d, keyword => %s", page, size, keyword) + logger.logger.info("page => {}, size => {}, keyword => {}", page, size, keyword) query = db.query(JiaKaoBaoDian) if len(keyword) > 0: - query = query.filter(JiaKaoBaoDian.question.like("%%%s%%" % keyword)) + query = query.filter( + JiaKaoBaoDian.question.like("%%%s%%" % keyword), + JiaKaoBaoDian.illiteracy_explain.like("%%%s%%" % keyword),) if order_by_wrong_rate: query = query.order_by(JiaKaoBaoDian.wrong_rate.desc()) @@ -29,7 +31,7 @@ def get_list(db: Session = Depends(database), offset = (page - 1) * size data = query.offset(offset).limit(size).all() - logger.logger.info("data num %d", len(data)) + logger.logger.info("data num {}", len(data)) return response({ "data": model_list(data), "page": page, diff --git a/main.py b/main.py index c4d2114..b47f710 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import logger import uvicorn from fastapi import FastAPI @@ -9,5 +10,16 @@ app = FastAPI(docs_url="/docs", redoc_url=None) app.include_router(health.router) app.include_router(car.router) + +@app.on_event("startup") +async def startup(): + logger.logger.info("服务启动") + + +@app.on_event("shutdown") +async def shutdown(): + logger.logger.info("服务关闭") + + if __name__ == '__main__': uvicorn.run("main:app", host="0.0.0.0", port=5000, reload=True)