feat:add report
This commit is contained in:
@@ -100,7 +100,7 @@ class Design(pydantic.BaseModel):
|
|||||||
date_send: datetime.datetime = Field(description='تاریخ ابالغ/ارجاع')
|
date_send: datetime.datetime = Field(description='تاریخ ابالغ/ارجاع')
|
||||||
letter: str = Field(description='شماره نامه')
|
letter: str = Field(description='شماره نامه')
|
||||||
land_area:Optional[str] = Field(description="مساحت زمین")
|
land_area:Optional[str] = Field(description="مساحت زمین")
|
||||||
building_infrastructure:Optional[str] = Field(description="زیربنای ساختمان")
|
building_infrastructure:Optional[int] = Field(description="زیربنای ساختمان")
|
||||||
site_area:Optional[str] = Field(description="مساحت محوطه")
|
site_area:Optional[str] = Field(description="مساحت محوطه")
|
||||||
designer:Optional[List[str]] = Field(description="نام طراح")
|
designer:Optional[List[str]] = Field(description="نام طراح")
|
||||||
status_agreement:Optional[str] = Field(description="وضعیت موافقتنامه")
|
status_agreement:Optional[str] = Field(description="وضعیت موافقتنامه")
|
||||||
|
|||||||
@@ -11,4 +11,8 @@ class ReportCountry(pydantic.BaseModel):
|
|||||||
type_id: int = Field(description='کد شناسایی نوع پروژه در این فیلد قرار می گیرد')
|
type_id: int = Field(description='کد شناسایی نوع پروژه در این فیلد قرار می گیرد')
|
||||||
nature_id: int = Field(description='کد شناسایی ماهبت در این فیلد قرار می گیرد')
|
nature_id: int = Field(description='کد شناسایی ماهبت در این فیلد قرار می گیرد')
|
||||||
state: Optional[str]
|
state: Optional[str]
|
||||||
monitor_type: Optional[int]
|
monitor_type: Optional[int]
|
||||||
|
|
||||||
|
class DonutList(pydantic.BaseModel):
|
||||||
|
type: int = Field(description='مقدار وارد شده در گزارش قبل')
|
||||||
|
donut_select: str = Field(description='آیتم دونات انتخاب شده')
|
||||||
+110
-12
@@ -1,7 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from app.config import TaskEnv
|
from app.config import TaskEnv
|
||||||
from app.models.report import StatusReport, ReportCountry
|
from app.models.report import StatusReport, ReportCountry, DonutList
|
||||||
from core.service.mongo_db import use_collection
|
from core.service.mongo_db import use_collection
|
||||||
|
|
||||||
|
|
||||||
@@ -33,17 +33,42 @@ class ReportRepository():
|
|||||||
|
|
||||||
|
|
||||||
async def report_country(self ,_inp: ReportCountry):
|
async def report_country(self ,_inp: ReportCountry):
|
||||||
|
match = {}
|
||||||
if _inp.state:
|
if _inp.state:
|
||||||
count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents(
|
match = {'design.state':_inp.state}
|
||||||
{'design.nature_id':_inp.nature_id,'design.state':_inp.state})
|
if _inp.type_id:
|
||||||
count_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'design.type_id': _inp.type_id,'design.state':_inp.state})
|
match.update({'design.type_id': _inp.type_id})
|
||||||
count_monitor_type = await use_collection(TaskEnv.CLN_PROJECT).count_documents({'monitor.base_information.type': _inp.monitor_type,'design.state':_inp.state})
|
if _inp.nature_id:
|
||||||
else:
|
match.update({'design.nature_id':_inp.nature_id})
|
||||||
count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents(
|
if _inp.monitor_type:
|
||||||
{'design.nature_id': _inp.nature_id})
|
match.update({'monitor.base_information.type': _inp.monitor_type})
|
||||||
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})
|
# count_nature = await use_collection(TaskEnv.CLN_PROJECT).count_documents(
|
||||||
return {'count_nature':count_nature,'count_type':count_type,'count_monitor_type':count_monitor_type}
|
# {'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})
|
||||||
|
|
||||||
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
|
{"$match":match},
|
||||||
|
{'$group': {
|
||||||
|
'_id': "$design.state",
|
||||||
|
'nature_id': {'$addToSet': '$design.nature_id'},
|
||||||
|
'type_id': {'$addToSet': '$design.type_id'},
|
||||||
|
'monitor_type': {'$addToSet': '$monitor.base_information.type'}
|
||||||
|
}},
|
||||||
|
{'$project': {
|
||||||
|
'count_nature_id': {"$size": "$nature_id"},
|
||||||
|
'count_type_id': {"$size": "$type_id"},
|
||||||
|
'count_monitor_type': {"$size": "$monitor_type"},
|
||||||
|
"_id": 1
|
||||||
|
}}
|
||||||
|
]).to_list(None)
|
||||||
|
# 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}
|
||||||
|
return report
|
||||||
|
|
||||||
async def exist_project_state(self):
|
async def exist_project_state(self):
|
||||||
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
@@ -55,4 +80,77 @@ class ReportRepository():
|
|||||||
}
|
}
|
||||||
]).to_list(None)
|
]).to_list(None)
|
||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
||||||
|
async def donut(self,_select:int):
|
||||||
|
report = None
|
||||||
|
if _select == 1:
|
||||||
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
|
{"$group":{"_id":"$design.nature_id",'count':{'$sum':1}}}
|
||||||
|
]).to_list(None)
|
||||||
|
elif _select == 2:
|
||||||
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
|
{
|
||||||
|
"$group": {
|
||||||
|
"_id": {
|
||||||
|
"$cond": [
|
||||||
|
{"$lt": ["$design.building_infrastructure", 1000]}, # Check if a < 10
|
||||||
|
"less_than_1000",
|
||||||
|
{
|
||||||
|
"$cond": [
|
||||||
|
{"$and": [{"$gte": ["$design.building_infrastructure", 1000]}, {"$lt": ["$design.building_infrastructure", 5000]}]}, # Check if 10 <= a < 20
|
||||||
|
"between_1000_and_5000",
|
||||||
|
{
|
||||||
|
"$cond": [
|
||||||
|
{"$and": [{"$gte": ["$design.building_infrastructure", 5000]}, {"$lt": ["$design.building_infrastructure", 15000]}]},
|
||||||
|
"between_5000_and_15000",
|
||||||
|
{
|
||||||
|
"$cond": [
|
||||||
|
{"$and": [{"$gte": ["$design.building_infrastructure", 15000]}, {"$lt": ["$design.building_infrastructure", 30000]}]},
|
||||||
|
"between_15000_and_30000",
|
||||||
|
"greater_than_or_equal_30000" # Otherwise, a >= 30
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"total": {"$sum": 1},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).to_list(None)
|
||||||
|
|
||||||
|
elif _select == 3:
|
||||||
|
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
|
||||||
|
{"$group": {"_id": "$design.type_id", 'count': {'$sum': 1}}}
|
||||||
|
]).to_list(None)
|
||||||
|
return report
|
||||||
|
|
||||||
|
async def list_donut(self,_inp:DonutList):
|
||||||
|
_filter = {'design.nature_id':_inp.donut_select}
|
||||||
|
if _inp.type == 2:
|
||||||
|
if _inp.donut_select == "less_than_1000":
|
||||||
|
_filter = {'design.building_infrastructure': {'$lt': 1000}}
|
||||||
|
elif _inp.donut_select == "between_1000_and_5000":
|
||||||
|
_filter = {'design.building_infrastructure': {'$lt': 5000, "$gte": 1000 }}
|
||||||
|
elif _inp.donut_select == "between_5000_and_15000":
|
||||||
|
_filter = {'design.building_infrastructure': {'$lt': 15000, "$gte": 5000 }}
|
||||||
|
elif _inp.donut_select == "between_15000_and_30000":
|
||||||
|
_filter = {'design.building_infrastructure': {'$lt': 30000, "$gte": 15000 }}
|
||||||
|
else:
|
||||||
|
_filter = {'design.building_infrastructure': {'$gte': 30000}}
|
||||||
|
elif _inp.type == 3 :
|
||||||
|
_filter = {'design.type_id': _inp.donut_select}
|
||||||
|
report = await use_collection(TaskEnv.CLN_PROJECT).find(_filter).to_list(None)
|
||||||
|
|
||||||
|
return report
|
||||||
|
|
||||||
|
async def delay_donut(self):
|
||||||
|
...
|
||||||
|
# await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
|
||||||
|
# {'$group':}
|
||||||
|
# ])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -1,4 +1,4 @@
|
|||||||
from app.models.report import StatusReport, ReportCountry
|
from app.models.report import StatusReport, ReportCountry, DonutList
|
||||||
from app.repositories.report import ReportRepository
|
from app.repositories.report import ReportRepository
|
||||||
from core.app import app
|
from core.app import app
|
||||||
from core.utils.router import generate_router, shrink
|
from core.utils.router import generate_router, shrink
|
||||||
@@ -28,4 +28,14 @@ def report_country(_inp: ReportCountry):
|
|||||||
def exist_project_state():
|
def exist_project_state():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@router.get('/donut/{_select}', tags=_tag_base)
|
||||||
|
@shrink(repo.donut)
|
||||||
|
def donut(_select:int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.post('/list-donut', tags=_tag_base)
|
||||||
|
@shrink(repo.list_donut)
|
||||||
|
def list_donut(_inp: DonutList):
|
||||||
|
pass
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
Reference in New Issue
Block a user