diff --git a/app/models/report.py b/app/models/report.py new file mode 100644 index 0000000..d51773d --- /dev/null +++ b/app/models/report.py @@ -0,0 +1,14 @@ +from typing import Optional + +import pydantic +from pydantic import Field + + +class StatusReport(pydantic.BaseModel): + state: Optional[str] + +class ReportCountry(pydantic.BaseModel): + type_id: int = Field(description='کد شناسایی نوع پروژه در این فیلد قرار می گیرد') + nature_id: int = Field(description='کد شناسایی ماهبت در این فیلد قرار می گیرد') + state: Optional[str] + monitor_type: Optional[int] \ No newline at end of file diff --git a/app/repositories/report.py b/app/repositories/report.py new file mode 100644 index 0000000..690208c --- /dev/null +++ b/app/repositories/report.py @@ -0,0 +1,44 @@ +from app.config import TaskEnv +from app.models.report import StatusReport, ReportCountry +from core.service.mongo_db import use_collection + + +class ReportRepository(): + async def project_status(self, _inp: StatusReport,type): + if _inp.state: + match = {f'{type}.sts': {'$exists': 1}, 'design.state':_inp.state} + + else: + match = {f'{type}.sts': {'$exists': 1}} + report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([ + { + "$match": match + }, + { + '$group': { + '_id': f"${type}.sts", + 'count': {'$sum': 1} + } + } + ]).to_list(None) + return report + + async def project_status_design(self, _inp: StatusReport): + return await self.project_status(_inp, 'design') + + async def project_status_monitor(self, _inp: StatusReport): + return await self.project_status(_inp, 'monitor') + + + async def report_country(self ,_inp: ReportCountry): + if _inp.state: + count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents( + {'design.nature_id':_inp.nature_id,'design.state':_inp.state}) + count_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'design.type_id': _inp.type_id,'design.state':_inp.state}) + count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type,'design.state':_inp.state}) + else: + count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents( + {'design.nature_id': _inp.nature_id}) + count_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'design.type_id':_inp.type_id}) + count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type}) + return {'count_nature':count_nature,'count_type':count_type,'count_monitor_type':count_monitor_type} diff --git a/app/urls/__init__.py b/app/urls/__init__.py index 97c8cc5..bcef09e 100644 --- a/app/urls/__init__.py +++ b/app/urls/__init__.py @@ -15,4 +15,5 @@ from .monitor_secondary import * from .financial_pre_payment import * from .financial_status import * from .financial_adjust import * -from .delivery import * \ No newline at end of file +from .delivery import * +from .report import * \ No newline at end of file diff --git a/app/urls/report.py b/app/urls/report.py new file mode 100644 index 0000000..36ab6ea --- /dev/null +++ b/app/urls/report.py @@ -0,0 +1,26 @@ +from app.models.report import StatusReport, ReportCountry +from app.repositories.report import ReportRepository +from core.app import app +from core.utils.router import generate_router, shrink + +router_base_url = 'report' +_tag_base = [router_base_url] +router = generate_router(router_base_url, auth_dependencies=False, version='v2') +repo = ReportRepository() + +@router.post('/design/sts', tags=_tag_base) +@shrink(repo.project_status_design) +def project_status_design(_inp: StatusReport): + pass + +@router.post('/monitor/sts', tags=_tag_base) +@shrink(repo.project_status_monitor) +def project_status_monitor(_inp: StatusReport): + pass + +@router.post('/country', tags=_tag_base) +@shrink(repo.report_country) +def report_country(_inp: ReportCountry): + pass + +app.include_router(router) \ No newline at end of file