fix(report):add change

This commit is contained in:
shahzeydyfah
2026-10-03 22:29:07 +03:30
parent 0cbf543940
commit ee3a5025c1
3 changed files with 130 additions and 17 deletions
+4
View File
@@ -22,6 +22,10 @@ class DelayDonutDetail(pydantic.BaseModel):
project_id:uuid.UUID project_id:uuid.UUID
select:Literal['financial','force_major','technical'] select:Literal['financial','force_major','technical']
class DonutReport(pydantic.BaseModel):
only_current: bool = Field(default=False, description='فقط پروژه‌های نظارت جاری؛ مقدار false برای همه پروژه‌های نظارت')
class DonutList(pydantic.BaseModel): class DonutList(pydantic.BaseModel):
type: int = Field(description='مقدار وارد شده در گزارش قبل') type: int = Field(description='مقدار وارد شده در گزارش قبل')
donut_select: str = Field(description='آیتم دونات انتخاب شده') donut_select: str = Field(description='آیتم دونات انتخاب شده')
+111 -12
View File
@@ -3,7 +3,7 @@ from datetime import time
from app.config import TaskEnv from app.config import TaskEnv
from app.models.project import ProjectPriceReport from app.models.project import ProjectPriceReport
from app.models.report import StatusReport, ReportCountry, DonutList, DelayDonutDetail, PhysicalMonth from app.models.report import StatusReport, ReportCountry, DonutList, DonutReport, DelayDonutDetail, PhysicalMonth
from core.service.mongo_db import use_collection from core.service.mongo_db import use_collection
@@ -150,6 +150,64 @@ class ReportRepository():
]).to_list(None) ]).to_list(None)
return report return report
async def donut_v2(self, _select: int, _inp: DonutReport):
project_filter = {"has_monitor": True}
if _inp.only_current:
project_filter["monitor.sts"] = 2
report = None
if _select == 1:
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
{"$match": project_filter},
{"$group": {"_id": "$design.nature_id", 'count': {'$sum': 1}}}
]).to_list(None)
elif _select == 2:
report = await use_collection(TaskEnv.CLN_PROJECT).aggregate([
{"$match": project_filter},
{
"$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([
{"$match": project_filter},
{"$group": {"_id": "$design.type_id", 'count': {'$sum': 1}}}
]).to_list(None)
return report
async def list_donut(self, _inp: DonutList): async def list_donut(self, _inp: DonutList):
_filter = None _filter = None
if _inp.type == 1: if _inp.type == 1:
@@ -230,6 +288,13 @@ class ReportRepository():
async def categorize_deviation(self): async def categorize_deviation(self):
report = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).aggregate( report = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).aggregate(
[{"$match": {"deviation": {"$exists": True, "$ne": None}}}, [{"$match": {"deviation": {"$exists": True, "$ne": None}}},
{"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}},
{"$match": {"project.monitor.sts": 2}},
{"$group": { {"$group": {
"_id": { "_id": {
"$cond": [ "$cond": [
@@ -267,6 +332,28 @@ class ReportRepository():
]).to_list(None) ]).to_list(None)
return report return report
async def delay_donut_all_v2(self, _inp: DonutReport):
project_filter = {"project.has_monitor": True}
if _inp.only_current:
project_filter["project.monitor.sts"] = 2
report = await use_collection(TaskEnv.CLN_BILL_DELAY).aggregate([
{"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}},
{"$match": project_filter},
{'$group': {"_id": None, "total_financial": {"$sum": "$financial.total"},
"total_force_major": {"$sum": "$force_major.total"},
"total_technical": {"$sum": "$technical.total"},
"total_extra_new_work": {"$sum": "$extra_new_work"},
"total_other": {"$sum": "$other"},
}}
]).to_list(None)
return report
async def list_delay_donut(self, _select: str): async def list_delay_donut(self, _select: str):
get_list = [] get_list = []
_map = {'1': 'financial.total', '2': 'force_major.total', '3': 'technical.total', '4': 'extra_new_work', _map = {'1': 'financial.total', '2': 'force_major.total', '3': 'technical.total', '4': 'extra_new_work',
@@ -420,6 +507,15 @@ class ReportRepository():
} }
} }
}, },
{
"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}
},
{"$match": {"project.monitor.sts": 2}},
{ {
"$group": { "$group": {
"_id": { "_id": {
@@ -440,22 +536,18 @@ class ReportRepository():
} }
} }
]).to_list(None) ]).to_list(None)
# result = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).aggregate([
# {"$match":{"date_at":{"$lte":to_date,"$gte":from_date}}},
# {
# "$sort": {'date_at': -1}
# },
# {"$group":
# {'_id': {"year": "$year", "month": "$month"},
# 'avg': {'$avg': "$real"}},
# }
# ]).to_list(None)
return result return result
async def design_progress_status(self): async def design_progress_status(self):
result = await use_collection("design_progress").aggregate([ result = await use_collection("design_progress").aggregate([
{'$match':{'complete_at':{"$exists":0},'parent_id':{"$exists":0}}}, {'$match':{'complete_at':{"$exists":0},'parent_id':{"$exists":0}}},
{"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}},
{"$match": {"project.design.sts": 2}},
{"$group": {"$group":
{'_id': '$type', {'_id': '$type',
'count': {'$sum': 1}, 'count': {'$sum': 1},
@@ -468,6 +560,13 @@ class ReportRepository():
async def design_progress_status_state(self): async def design_progress_status_state(self):
result = await use_collection("design_progress").aggregate([ result = await use_collection("design_progress").aggregate([
{'$match':{'complete_at':{"$exists":0},'parent_id':{"$exists":0}}}, {'$match':{'complete_at':{"$exists":0},'parent_id':{"$exists":0}}},
{"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}},
{"$match": {"project.design.sts": 2}},
{"$group": {"$group":
{'_id': {'state':"$state",'type':'$type'}, {'_id': {'state':"$state",'type':'$type'},
'count': {'$sum': 1}, 'count': {'$sum': 1},
+13 -3
View File
@@ -2,7 +2,7 @@ import uuid
from fastapi import Body from fastapi import Body
from app.models.report import StatusReport, ReportCountry, DonutList, DelayDonutDetail, PhysicalMonth from app.models.report import StatusReport, ReportCountry, DonutList, DonutReport, DelayDonutDetail, PhysicalMonth
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
@@ -62,15 +62,25 @@ def sum_add_time_end_project():
@shrink(repo.delay_donut_all) @shrink(repo.delay_donut_all)
def delay_donut_all(): def delay_donut_all():
pass pass
@router.post('/donut-v2/delay/all', tags=_tag_base)
@shrink(repo.delay_donut_all_v2)
def delay_donut_all_v2(_inp: DonutReport = Body(...)):
pass
#لیست پروژه ها را نمایش میده #لیست پروژه ها را نمایش میده
@router.get('/donut/delay/{_select}', tags=_tag_base) @router.get('/donut/delay/{_select}', tags=_tag_base)
@shrink(repo.list_delay_donut) @shrink(repo.list_delay_donut)
def list_delay_donut(_select): def list_delay_donut(_select):
pass pass
#تفکیک پروژه ها بر حسب زیربنا و تفکیک ماهیت پروژه و تفکیک بر حسب نوع پروژه #تفکیک پروژه ها بر حسب زیربنا و تفکیک ماهیت پروژه و تفکیک بر حسب نوع پروژه
@router.get('/donut/{_select}', tags=_tag_base) @router.post('/donut/{_select}', tags=_tag_base)
@shrink(repo.donut) @shrink(repo.donut)
def donut(_select:int): def donut(_select: int, _inp: DonutReport = Body(...)):
pass
@router.post('/donut-v2/{_select}', tags=_tag_base)
@shrink(repo.donut_v2)
def donut_v2(_select: int, _inp: DonutReport = Body(...)):
pass pass
@router.post('/list-donut', tags=_tag_base) @router.post('/list-donut', tags=_tag_base)