feat: 单独查询项目已花费的金额

This commit is contained in:
martsforever
2025-08-24 01:29:31 +08:00
parent ad09b6ad81
commit 75f8d94d02
3 changed files with 25 additions and 5 deletions
+20 -1
View File
@@ -1,9 +1,13 @@
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
def add_approve_route(app: FastAPI): def add_approve_route(app: FastAPI):
# 提交报销单接口 # 提交报销单接口
@app.post('/submit_reimburse') @app.post('/submit_reimburse')
@@ -15,3 +19,18 @@ def add_approve_route(app: FastAPI):
) )
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']]
return project_dict_list
+1 -1
View File
@@ -41,7 +41,7 @@ class ApproveModel(PublicApproveModel, table=True):
pass pass
ApproveProjService = create_model_service( ApproveService = create_model_service(
Cls=ApproveModel, Cls=ApproveModel,
custom_query=lambda: select(ApproveModel) custom_query=lambda: select(ApproveModel)
.options( .options(
+4 -3
View File
@@ -5,6 +5,7 @@ from langchain_core.runnables import RunnableLambda
from langserve import add_routes from langserve import add_routes
from app.config.env import env from app.config.env import env
from app.controller.add_approve_route import add_approve_route
from app.controller.add_langgraph_approve_route import add_langgraph_approve_route from app.controller.add_langgraph_approve_route import add_langgraph_approve_route
from app.controller.add_langgraph_chat_route import add_langgraph_chat_route from app.controller.add_langgraph_chat_route import add_langgraph_chat_route
from app.controller.add_langgraph_route import add_langgraph_route from app.controller.add_langgraph_route import add_langgraph_route
@@ -18,7 +19,7 @@ from app.controller.test_sqlmodel import add_test_sqlmodel_route
from app.controller.test_sync import add_test_sync_route from app.controller.test_sync import add_test_sync_route
from app.controller.translate_controller import add_translate_route from app.controller.translate_controller import add_translate_route
from app.create_app import create_app from app.create_app import create_app
from app.model.ApproveModel import ApproveProjService from app.model.ApproveModel import ApproveService
from app.model.LgApprove import LgApproveService from app.model.LgApprove import LgApproveService
from app.model.LgChat import LgChatService from app.model.LgChat import LgChatService
from app.model.LgMessage import LgMessageService from app.model.LgMessage import LgMessageService
@@ -52,7 +53,7 @@ add_langgraph_route(app)
add_lg_approve_route(app) add_lg_approve_route(app)
add_langgraph_approve_route(app) add_langgraph_approve_route(app)
add_langgraph_chat_route(app) add_langgraph_chat_route(app)
add_approve_route(app)
@app.get("/get_env") @app.get("/get_env")
async def test(): async def test():
@@ -94,7 +95,7 @@ RelProjUserService.add_route(app=app, path="/rel_proj_user")
ReimburseService.add_route(app=app, path="/reimburse") ReimburseService.add_route(app=app, path="/reimburse")
ReimburseTravelService.add_route(app=app, path="/reimburse_travel") ReimburseTravelService.add_route(app=app, path="/reimburse_travel")
ReimburseOtherService.add_route(app=app, path="/reimburse_other") ReimburseOtherService.add_route(app=app, path="/reimburse_other")
ApproveProjService.add_route(app=app, path="/approve") ApproveService.add_route(app=app, path="/approve")
if __name__ == "__main__": if __name__ == "__main__":
run_uvicorn() run_uvicorn()