feat: 单独查询项目已花费的金额
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
from decimal import Decimal
|
||||
from typing import List
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.model.ApproveModel import ApproveService, ApproveModel
|
||||
from app.model.ProjectModel import ProjectModel, ProjectService
|
||||
from app.model.ReimburseModel import ReimburseService
|
||||
from app.utils.db_utils import AsyncSessionDep
|
||||
|
||||
|
||||
def add_approve_route(app: FastAPI):
|
||||
# 提交报销单接口
|
||||
@app.post('/submit_reimburse')
|
||||
@@ -15,3 +19,18 @@ def add_approve_route(app: FastAPI):
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
@app.post('/query_spent')
|
||||
async def query_spent(session: AsyncSessionDep, proj_id_list: List[str]):
|
||||
result = {item: Decimal(0) for item in proj_id_list}
|
||||
approve_cls_list = (await session.execute(ApproveService.select_cls().where(ApproveModel.proj_id.in_(proj_id_list)))).scalars().all()
|
||||
for approve_item in approve_cls_list:
|
||||
if approve_item.status == 'approved':
|
||||
result[approve_item.proj_id] += Decimal(approve_item.amount)
|
||||
|
||||
project_cls_list = (await session.execute(ProjectService.select_cls().where(ProjectModel.id.in_(proj_id_list)))).scalars().all()
|
||||
project_dict_list = [item.model_dump() for item in project_cls_list]
|
||||
for dict_item in project_dict_list:
|
||||
dict_item['spent'] = result[dict_item['id']]
|
||||
|
||||
return project_dict_list
|
||||
|
||||
Reference in New Issue
Block a user