Compare commits

..
3 Commits
Author SHA1 Message Date
shahzeydyfah ee3a5025c1 fix(report):add change 2026-10-03 22:29:07 +03:30
shahzeydyfah 0cbf543940 fix(project):sort 2026-09-13 21:53:35 +03:30
shahzeydyfah b74b0067a6 fix(project):filter sts in monitor or design 2026-09-13 21:25:06 +03:30
7 changed files with 200 additions and 25 deletions
+5 -1
View File
@@ -22,10 +22,14 @@ class DelayDonutDetail(pydantic.BaseModel):
project_id:uuid.UUID
select:Literal['financial','force_major','technical']
class DonutReport(pydantic.BaseModel):
only_current: bool = Field(default=False, description='فقط پروژه‌های نظارت جاری؛ مقدار false برای همه پروژه‌های نظارت')
class DonutList(pydantic.BaseModel):
type: int = Field(description='مقدار وارد شده در گزارش قبل')
donut_select: str = Field(description='آیتم دونات انتخاب شده')
class PhysicalMonth(pydantic.BaseModel):
from_date:datetime.datetime
to_date:datetime.datetime
to_date:datetime.datetime
+58 -5
View File
@@ -175,7 +175,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
return True
async def list_project_design(self):
project = await use_collection(COLLECTION).find({'monitor': {"$exists": 0}}).to_list(None)
project = await use_collection(COLLECTION).find({
'$or': [
{'has_monitor': False},
{'monitor': {'$exists': 0}},
{
'has_monitor': True,
'monitor.has_design': True
}
]
}).to_list(None)
return project
async def list_project_monitor(self):
@@ -231,25 +240,69 @@ class ProjectRepository(BaseRepository[ProjectModel]):
return projects
@staticmethod
def _has_design_sts_filter(te_input) -> bool:
if not te_input:
return False
f_list = getattr(te_input, 'f', None) if not isinstance(te_input, dict) else te_input.get('f')
if not f_list:
return False
for scope in f_list:
items = scope.get('items', []) if isinstance(scope, dict) else getattr(scope, 'items', [])
if items:
for item in items:
col = item.get('col') if isinstance(item, dict) else getattr(item, 'col', '')
if col == 'design.sts':
return True
return False
async def fetch_delete(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
return await NewTableEngine.mongo(
extra_filter = [{'sts': 2}]
if self._has_design_sts_filter(_input.te if _input else None):
extra_filter.append({
'$or': [
{'has_monitor': False},
{'monitor': {'$exists': False}},
{'has_monitor': True, 'monitor.has_design': True}
]
})
result = await NewTableEngine.mongo(
query_class=use_collection(self.COLLECTION),
soft_deleted=True,
model=self.MODEL,
search_cols=['design.title'],
extra_filter=[{'sts': 2}],
extra_filter=extra_filter,
inputs=_input.te) \
.to_dict()
if result and result.rows:
for row in result.rows:
if row.monitor and row.monitor.has_design is False:
row.design.sts = None
return result
async def fetch(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
return await NewTableEngine.mongo(
extra_filter = [{'sts': 1}]
if self._has_design_sts_filter(_input.te if _input else None):
extra_filter.append({
'$or': [
{'has_monitor': False},
{'monitor': {'$exists': False}},
{'has_monitor': True, 'monitor.has_design': True}
]
})
result = await NewTableEngine.mongo(
query_class=use_collection(self.COLLECTION),
soft_deleted=True,
model=self.MODEL,
search_cols=['design.title'],
extra_filter=[{'sts': 1}],
extra_filter=extra_filter,
inputs=_input.te) \
.to_dict()
if result and result.rows:
for row in result.rows:
if row.monitor and row.monitor.has_design is False:
row.design.sts = None
return result
async def get_all(self):
url = 'http://api.khanesaziceco.ir/api/api/project/table'
+111 -12
View File
@@ -3,7 +3,7 @@ from datetime import time
from app.config import TaskEnv
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
@@ -150,6 +150,64 @@ class ReportRepository():
]).to_list(None)
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):
_filter = None
if _inp.type == 1:
@@ -230,6 +288,13 @@ class ReportRepository():
async def categorize_deviation(self):
report = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).aggregate(
[{"$match": {"deviation": {"$exists": True, "$ne": None}}},
{"$lookup": {
"from": TaskEnv.CLN_PROJECT,
"localField": "project_id",
"foreignField": "_id",
"as": "project"
}},
{"$match": {"project.monitor.sts": 2}},
{"$group": {
"_id": {
"$cond": [
@@ -267,6 +332,28 @@ class ReportRepository():
]).to_list(None)
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):
get_list = []
_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": {
"_id": {
@@ -440,22 +536,18 @@ class ReportRepository():
}
}
]).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
async def design_progress_status(self):
result = await use_collection("design_progress").aggregate([
{'$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":
{'_id': '$type',
'count': {'$sum': 1},
@@ -468,6 +560,13 @@ class ReportRepository():
async def design_progress_status_state(self):
result = await use_collection("design_progress").aggregate([
{'$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":
{'_id': {'state':"$state",'type':'$type'},
'count': {'$sum': 1},
+14 -4
View File
@@ -2,7 +2,7 @@ import uuid
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 core.app import app
from core.utils.router import generate_router, shrink
@@ -62,15 +62,25 @@ def sum_add_time_end_project():
@shrink(repo.delay_donut_all)
def delay_donut_all():
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)
@shrink(repo.list_delay_donut)
def list_delay_donut(_select):
pass
#تفکیک پروژه ها بر حسب زیربنا و تفکیک ماهیت پروژه و تفکیک بر حسب نوع پروژه
@router.get('/donut/{_select}', tags=_tag_base)
@router.post('/donut/{_select}', tags=_tag_base)
@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
@router.post('/list-donut', tags=_tag_base)
@@ -145,4 +155,4 @@ def get_extra_project(project_id: uuid.UUID):
def design_chart(project_id: uuid.UUID):
pass
app.include_router(router)
app.include_router(router)
+7 -3
View File
@@ -10,7 +10,8 @@ from .utils.Models import TableEngineExport
class NewTableEngine:
def __init__(self, query_class, model, inputs, mode, engine: AbstractEngine, extra_filter,
default_sort_by, joins, search_cols, options=None, soft_deleted=False, unselect={}, return_query=False):
default_sort_by, joins, search_cols, options=None, soft_deleted=False, unselect={}, return_query=False,
collation={'locale': 'fa'}):
self.model = model
self.query_class = query_class
self.mode = mode
@@ -29,6 +30,7 @@ class NewTableEngine:
self.search_cols = search_cols
self.unselect = unselect
self.return_query = return_query
self.collation = collation
self.engine = engine(self)
@staticmethod
@@ -38,10 +40,12 @@ class NewTableEngine:
mode: WorkingMode = WorkingMode.Development,
extra_filter=None,
soft_deleted=False,
default_sort_by=None, joins=None, search_cols=[] ,unselect={}, return_query=False):
default_sort_by=None, joins=None, search_cols=[] ,unselect={}, return_query=False,
collation={'locale': 'fa'}):
return NewTableEngine(query_class, model, inputs, mode, engine=MongoEngine, extra_filter=extra_filter,
default_sort_by=default_sort_by, joins=joins, search_cols=search_cols,
soft_deleted=soft_deleted,unselect=unselect, return_query=return_query)
soft_deleted=soft_deleted,unselect=unselect, return_query=return_query,
collation=collation)
@staticmethod
def mssql(query_class, model, inputs, mode: WorkingMode = WorkingMode.Development, extra_filter=None,
+1
View File
@@ -17,6 +17,7 @@ class AbstractEngineClass(abc.ABC):
self.soft_deleted = table_engine.soft_deleted
self.unselect = table_engine.unselect
self.return_query = table_engine.return_query
self.collation = {'locale': 'fa'}
@abc.abstractmethod
def exe(self):
+4
View File
@@ -54,6 +54,10 @@ class MongoEngine(AbstractEngineClass):
else:
tmp = tmp.sort(sort_by)
is_natural = isinstance(sort_by, dict) and sort_by.get('key_or_list') == '$natural'
if getattr(self, 'collation', None) and not is_natural:
tmp = tmp.collation(self.collation)
if self.input.e and self.input.e.ot:
res = await tmp.to_list(None)
self.input.e.d = await self.generate_output(res)