2023-05-31 14:31:13 +08:00
|
|
|
from fastapi import APIRouter, Depends
|
2023-05-31 11:52:34 +08:00
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
import logger
|
|
|
|
from db.mysql import database
|
2023-05-31 13:50:18 +08:00
|
|
|
from model.car.dto.list import ListDto
|
2023-05-31 11:52:34 +08:00
|
|
|
from orm.jiakaobaodian import JiaKaoBaoDian
|
2023-05-31 21:43:20 +08:00
|
|
|
from utils.common import response, amis_response
|
2023-05-31 11:52:34 +08:00
|
|
|
from utils.model import model_list
|
|
|
|
|
2023-05-31 14:31:13 +08:00
|
|
|
router = APIRouter(tags=["Car"], prefix="/api/car")
|
2023-05-31 11:52:34 +08:00
|
|
|
|
|
|
|
|
2023-05-31 14:02:01 +08:00
|
|
|
@router.post("/list", summary="题目列表")
|
2023-05-31 13:50:18 +08:00
|
|
|
def get_list(dto: ListDto, db: Session = Depends(database)):
|
|
|
|
(page, size, keyword) = (dto.page, dto.size, dto.keyword)
|
|
|
|
order_by_wrong_rate = dto.order_by_wrong_rate
|
2023-05-31 13:20:04 +08:00
|
|
|
logger.logger.info("page => {}, size => {}, keyword => {}", page, size, keyword)
|
2023-05-31 11:52:34 +08:00
|
|
|
|
|
|
|
query = db.query(JiaKaoBaoDian)
|
|
|
|
if len(keyword) > 0:
|
2023-05-31 13:20:04 +08:00
|
|
|
query = query.filter(
|
2023-05-31 13:32:30 +08:00
|
|
|
JiaKaoBaoDian.question.like("%%%s%%" % keyword) |
|
|
|
|
JiaKaoBaoDian.illiteracy_explain.like("%%%s%%" % keyword))
|
2023-05-31 11:52:34 +08:00
|
|
|
if order_by_wrong_rate:
|
|
|
|
query = query.order_by(JiaKaoBaoDian.wrong_rate.desc())
|
|
|
|
|
|
|
|
total = query.count()
|
|
|
|
|
|
|
|
offset = (page - 1) * size
|
|
|
|
data = query.offset(offset).limit(size).all()
|
2023-05-31 13:20:04 +08:00
|
|
|
logger.logger.info("data num {}", len(data))
|
2023-05-31 11:52:34 +08:00
|
|
|
return response({
|
|
|
|
"data": model_list(data),
|
|
|
|
"page": page,
|
|
|
|
"size": size,
|
|
|
|
"total": total
|
|
|
|
})
|
2023-05-31 21:43:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
@router.post("/amis/list", summary="amis 题目列表")
|
|
|
|
def amis_get_list(dto: ListDto, db: Session = Depends(database)):
|
|
|
|
result = get_list(dto, db)['data']
|
|
|
|
|
|
|
|
return amis_response({
|
|
|
|
"rows": result['data'],
|
|
|
|
"page": result['page'],
|
|
|
|
"size": result['size'],
|
|
|
|
"total": result['total']
|
|
|
|
})
|