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
+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='آیتم دونات انتخاب شده')
+58 -5
View File
@@ -175,7 +175,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
return True return True
async def list_project_design(self): 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 return project
async def list_project_monitor(self): async def list_project_monitor(self):
@@ -231,25 +240,69 @@ class ProjectRepository(BaseRepository[ProjectModel]):
return projects 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]: 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), query_class=use_collection(self.COLLECTION),
soft_deleted=True, soft_deleted=True,
model=self.MODEL, model=self.MODEL,
search_cols=['design.title'], search_cols=['design.title'],
extra_filter=[{'sts': 2}], extra_filter=extra_filter,
inputs=_input.te) \ inputs=_input.te) \
.to_dict() .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]: 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), query_class=use_collection(self.COLLECTION),
soft_deleted=True, soft_deleted=True,
model=self.MODEL, model=self.MODEL,
search_cols=['design.title'], search_cols=['design.title'],
extra_filter=[{'sts': 1}], extra_filter=extra_filter,
inputs=_input.te) \ inputs=_input.te) \
.to_dict() .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): async def get_all(self):
url = 'http://api.khanesaziceco.ir/api/api/project/table' 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.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)
+7 -3
View File
@@ -10,7 +10,8 @@ from .utils.Models import TableEngineExport
class NewTableEngine: class NewTableEngine:
def __init__(self, query_class, model, inputs, mode, engine: AbstractEngine, extra_filter, 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.model = model
self.query_class = query_class self.query_class = query_class
self.mode = mode self.mode = mode
@@ -29,6 +30,7 @@ class NewTableEngine:
self.search_cols = search_cols self.search_cols = search_cols
self.unselect = unselect self.unselect = unselect
self.return_query = return_query self.return_query = return_query
self.collation = collation
self.engine = engine(self) self.engine = engine(self)
@staticmethod @staticmethod
@@ -38,10 +40,12 @@ class NewTableEngine:
mode: WorkingMode = WorkingMode.Development, mode: WorkingMode = WorkingMode.Development,
extra_filter=None, extra_filter=None,
soft_deleted=False, 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, 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, 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 @staticmethod
def mssql(query_class, model, inputs, mode: WorkingMode = WorkingMode.Development, extra_filter=None, 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.soft_deleted = table_engine.soft_deleted
self.unselect = table_engine.unselect self.unselect = table_engine.unselect
self.return_query = table_engine.return_query self.return_query = table_engine.return_query
self.collation = {'locale': 'fa'}
@abc.abstractmethod @abc.abstractmethod
def exe(self): def exe(self):
+4
View File
@@ -54,6 +54,10 @@ class MongoEngine(AbstractEngineClass):
else: else:
tmp = tmp.sort(sort_by) 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: if self.input.e and self.input.e.ot:
res = await tmp.to_list(None) res = await tmp.to_list(None)
self.input.e.d = await self.generate_output(res) self.input.e.d = await self.generate_output(res)