diff --git a/app/models/report.py b/app/models/report.py index b455b47..bc7e92f 100644 --- a/app/models/report.py +++ b/app/models/report.py @@ -1,4 +1,5 @@ -from typing import Optional +import uuid +from typing import Optional, Literal import pydantic from pydantic import Field @@ -16,6 +17,10 @@ class ReportCountry(pydantic.BaseModel): state: Optional[str] monitor_type: Optional[int] +class DelayDonutDetail(pydantic.BaseModel): + project_id:uuid.UUID + select:Literal['financial','force_major','technical'] + class DonutList(pydantic.BaseModel): type: int = Field(description='مقدار وارد شده در گزارش قبل') donut_select: str = Field(description='آیتم دونات انتخاب شده') \ No newline at end of file diff --git a/app/repositories/report.py b/app/repositories/report.py index 8f5e352..cac2cc1 100644 --- a/app/repositories/report.py +++ b/app/repositories/report.py @@ -1,7 +1,7 @@ import uuid from app.config import TaskEnv -from app.models.report import StatusReport, ReportCountry, DonutList +from app.models.report import StatusReport, ReportCountry, DonutList, DelayDonutDetail from core.service.mongo_db import use_collection @@ -159,8 +159,9 @@ class ReportRepository(): return report - async def delay_donut(self): + async def delay_donut(self, project_id:uuid.UUID): report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([ + {"$match":{'project_id':project_id}}, {'$group': {"_id": None, "total_financial": {"$sum": "$financial.total"}, "total_force_major": {"$sum": "$force_major.total"}, "total_technical": {"$sum": "$technical.total"}, @@ -169,6 +170,31 @@ class ReportRepository(): }} ]).to_list(None) return report + async def delay_donut_detail(self, _inp:DelayDonutDetail): + _group = {} + if _inp.select == 'financial': + _group = {"_id": None, "total_status": {"$sum": "$financial.status"}, + "total_prepayment": {"$sum": "$financial.prepayment"}, + "total_modification": {"$sum": "$financial.modification"}, + "total_good_job": {"$sum": "$financial.good_job"}, + } + elif _inp.select == 'force_major': + _group = {"_id": None, "total_force_event": {"$sum": "$force_major.force_event"}, + "total_material": {"$sum": "$force_major.material"}, + "total_rules": {"$sum": "$force_major.rules"}, + "total_define_indicators": {"$sum": "$force_major.define_indicators"}, + } + elif _inp.select == 'technical': + _group = {"_id": None, "total_map_technical": {"$sum": "$technical.map_technical"}, + "total_permit": {"$sum": "$technical.permit"}, + "total_purchase": {"$sum": "$technical.purchase"}, + "total_suspense": {"$sum": "$technical.suspense"}, + } + report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([ + {"$match": {'project_id': _inp.project_id}}, + {'$group': _group} + ]).to_list(None) + return report async def list_delay_donut(self, _select: str): get_list = [] diff --git a/app/urls/report.py b/app/urls/report.py index 17e0dbb..c6be88a 100644 --- a/app/urls/report.py +++ b/app/urls/report.py @@ -1,4 +1,8 @@ -from app.models.report import StatusReport, ReportCountry, DonutList +import uuid + +from fastapi import Body + +from app.models.report import StatusReport, ReportCountry, DonutList, DelayDonutDetail from app.repositories.report import ReportRepository from core.app import app from core.utils.router import generate_router, shrink @@ -17,23 +21,28 @@ def project_status_design(_inp: StatusReport): #نقشه:وضعیت های نظارت @router.post('/monitor/sts', tags=_tag_base) @shrink(repo.project_status_monitor) -def project_status_monitor(_inp: StatusReport): +def project_status_monitor(_inp: StatusReport = Body(...)): pass @router.post('/country', tags=_tag_base) @shrink(repo.report_country) -def report_country(_inp: ReportCountry): +def report_country(_inp: ReportCountry = Body(...)): pass # نمایش تعداد پروژه ها در هر شهر بر اساس فیلترهای انتخاب شده @router.post('/exist_state', tags=_tag_base) @shrink(repo.exist_project_state) -def exist_project_state(_inp: StatusReport): +def exist_project_state(_inp: StatusReport = Body(...)): pass - -@router.get('/donut/delay', tags=_tag_base) +#نمودار تاخیرات بر اساس پروژه انتخاب شده +@router.get('/donut/delay/{project_id}', tags=_tag_base) @shrink(repo.delay_donut) -def delay_donut(): +def delay_donut(project_id:uuid.UUID): + pass +#وقتی روی نمودار تاخیرات کلیک کرد جزئیات را بهش نمایش بده +@router.post('/donut/delay/detail', tags=_tag_base) +@shrink(repo.delay_donut_detail) +def delay_donut_detail(_inp: DelayDonutDetail = Body(...)): pass @router.get('/donut/delay/percent', tags=_tag_base)