45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
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}
|