feat:add report
This commit is contained in:
@@ -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]
|
||||||
@@ -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}
|
||||||
@@ -16,3 +16,4 @@ from .financial_pre_payment import *
|
|||||||
from .financial_status import *
|
from .financial_status import *
|
||||||
from .financial_adjust import *
|
from .financial_adjust import *
|
||||||
from .delivery import *
|
from .delivery import *
|
||||||
|
from .report import *
|
||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user