feat: 单独查询项目已花费的金额以及预算余额
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
from decimal import Decimal
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
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.model.ReimburseModel import ReimburseService
|
||||||
from app.utils.db_utils import AsyncSessionDep
|
from app.utils.db_utils import AsyncSessionDep
|
||||||
|
|
||||||
@@ -18,23 +13,4 @@ def add_approve_route(app: FastAPI):
|
|||||||
session=session,
|
session=session,
|
||||||
row_dict={"id": reimburse_id}
|
row_dict={"id": reimburse_id}
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
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']]
|
|
||||||
# 剩余金额
|
|
||||||
dict_item['balance'] = Decimal(dict_item['budget']) - Decimal(dict_item['spent'])
|
|
||||||
|
|
||||||
return project_dict_list
|
|
||||||
|
|||||||
Reference in New Issue
Block a user