feat(monitor_physical):add delete
This commit is contained in:
@@ -10,12 +10,12 @@ from core.models.base import BaseModel
|
||||
|
||||
class PhysicalProgressModel(BaseModel):
|
||||
id: Optional[uuid.UUID] = Field(alias='_id')
|
||||
project_id:Optional[uuid.UUID] = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد")
|
||||
project_id:uuid.UUID = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد")
|
||||
program:Optional[float] = Field(description=" برنامه ای")
|
||||
real:Optional[float] = Field(description=" واقعی")
|
||||
medium_progress:Optional[float] = Field(description="متوسط پیشرفت فیزیکی ماهانه از ابتدا تا کنون")
|
||||
deviation:Optional[float] = Field(description="انحراف از برنامه")
|
||||
date_at:Optional[datetime.datetime] = Field(description="تاریخ گزارش پیشرفت")
|
||||
date_at:datetime.datetime = Field(description="تاریخ گزارش پیشرفت")
|
||||
last_month:Optional[float] = Field(description='واقعی ماه اخیر')
|
||||
last_three_month:Optional[float] = Field(description='واقعی ماه اخیر')
|
||||
year:Optional[str]
|
||||
|
||||
@@ -7,7 +7,7 @@ from app.config import TaskEnv
|
||||
from app.models.monito_physical_progress import PhysicalProgressModel, LastRecord
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
from core.utils.crudify import mongo_inserter
|
||||
from core.utils.crudify import mongo_inserter, mongo_soft_deleter
|
||||
from app.repositories.project import ProjectRepository
|
||||
|
||||
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
|
||||
@@ -36,7 +36,6 @@ class PhysicalProgressRepository(BaseRepository):
|
||||
send = {'month': {}, 'three_month': {}, 'before':{}}
|
||||
if _inp.id:
|
||||
find_record = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find_one({"_id":_inp.id})
|
||||
if _inp.id:
|
||||
before = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({
|
||||
'project_id': _inp.project_id,
|
||||
'created_at': {'$lt': find_record['created_at']}}).sort("$natural", -1).to_list(None)
|
||||
@@ -56,6 +55,7 @@ class PhysicalProgressRepository(BaseRepository):
|
||||
{'$match':{'project_id':_inp.project_id, "date_at": {"$lt": _inp.date_at}}},
|
||||
{'$group': {'_id': None, 'avg': {'$avg': "$real"}, 'sum':{'$sum': "$real"}, 'count':{'$sum': 1}}}
|
||||
]).to_list(None)
|
||||
print('avg',_avg)
|
||||
if _avg:
|
||||
send['avg'] = _avg[0]
|
||||
else:
|
||||
@@ -104,6 +104,41 @@ class PhysicalProgressRepository(BaseRepository):
|
||||
else:
|
||||
await use_collection(COLLECTION).update_one({"_id": _i_model.id},{"$set": _update})
|
||||
return res
|
||||
async def delete(self, _id: uuid.UUID):
|
||||
_get = await use_collection(COLLECTION).find_one({"_id": _id})
|
||||
await mongo_soft_deleter(_id, COLLECTION)
|
||||
_get_model = MODEL(**_get)
|
||||
_list = await use_collection(COLLECTION).find({"project_id":_get_model.project_id, "date_at":{"$gt":_get_model.date_at}}).to_list(None)
|
||||
if _list:
|
||||
for i in _list:
|
||||
_i_model = MODEL(**i)
|
||||
_avg = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).aggregate([
|
||||
{'$match': {'project_id': _get_model.project_id, "date_at": {"$lte": _i_model.date_at}}},
|
||||
{'$group': {'_id': None, 'avg': {'$avg': "$real"}}}
|
||||
]).to_list(None)
|
||||
_model = LastRecord(
|
||||
project_id= _i_model.project_id,
|
||||
date_at= _i_model.date_at
|
||||
)
|
||||
_last = await self.last_record(_model)
|
||||
unset = {}
|
||||
if _avg[0]['avg']:
|
||||
_update = {'medium_progress': round(_avg[0]['avg'], 1)}
|
||||
else:
|
||||
_update = {'medium_progress': 0}
|
||||
if _last['month']:
|
||||
_update.update({'last_month':_last['month']['real']})
|
||||
else:
|
||||
unset.update({'last_month': None})
|
||||
if _last['three_month']:
|
||||
_update.update({'last_three_month': _last['three_month']['real']})
|
||||
else:
|
||||
unset.update({'last_three_month': None})
|
||||
if unset:
|
||||
await use_collection(COLLECTION).update_one({"_id": _i_model.id}, {"$set":_update, "$unset":unset})
|
||||
else:
|
||||
await use_collection(COLLECTION).update_one({"_id": _i_model.id},{"$set": _update})
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ def update(_id: UUID, coding: ThisModel = Body(...)):
|
||||
def get(_id: UUID):
|
||||
pass
|
||||
|
||||
# @router.delete('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||
# @shrink(repo.delete)
|
||||
# def delete(_id: UUID):
|
||||
# pass
|
||||
@router.delete('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||
@shrink(repo.delete)
|
||||
def delete(_id: UUID):
|
||||
pass
|
||||
|
||||
@router.post('', response_model=TableEngineExport[ThisModel], tags=_tag_base, description='پیشرفت فیزیکی')
|
||||
@shrink(repo.fetch)
|
||||
|
||||
Reference in New Issue
Block a user