fix:last record
This commit is contained in:
@@ -2,6 +2,7 @@ import datetime
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
import pydantic
|
||||
from pydantic import Field
|
||||
|
||||
from core.models.base import BaseModel
|
||||
@@ -18,3 +19,8 @@ class PhysicalProgressModel(BaseModel):
|
||||
last_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
||||
last_three_month:Optional[int] = Field(description='واقعی ماه اخیر')
|
||||
|
||||
class LastRecord(pydantic.BaseModel):
|
||||
project_id:Optional[uuid.UUID] = Field(description="کد شناسایی پروژه در این فیلد قرار می گیرد")
|
||||
date_at:Optional[datetime.datetime] = Field(description='تاریخ وارد شده')
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import uuid
|
||||
import datetime
|
||||
|
||||
from app.config import TaskEnv
|
||||
from app.models.monito_physical_progress import PhysicalProgressModel
|
||||
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
|
||||
@@ -9,18 +10,37 @@ from app.repositories.project import ProjectRepository
|
||||
|
||||
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
|
||||
MODEL = PhysicalProgressModel
|
||||
|
||||
|
||||
class PhysicalProgressRepository(BaseRepository):
|
||||
def __init__(self):
|
||||
super().__init__(collection=TaskEnv.CLN_MONITOR_PYSICAL, model=PhysicalProgressModel)
|
||||
|
||||
async def last_record(self,project_id:uuid.UUID):
|
||||
last = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({'project_id':project_id}).sort("$natural", -1).to_list(None)
|
||||
async def search_last(self, connection: str, _inp: LastRecord, first: int, last: int):
|
||||
m_first = _inp.date_at - datetime.timedelta(days=first)
|
||||
print(m_first)
|
||||
m_end = _inp.date_at - datetime.timedelta(days=last)
|
||||
print(m_end)
|
||||
last = await use_collection(connection).find({
|
||||
'project_id': _inp.project_id,
|
||||
'date_at': {'$gte': m_first, '$lte': m_end}
|
||||
}).sort("$natural", -1).to_list(None)
|
||||
if last:
|
||||
return last[0]
|
||||
else:
|
||||
return {}
|
||||
|
||||
async def create(self,_inp:MODEL):
|
||||
create = await mongo_inserter(_inp,COLLECTION,getter=self.get)
|
||||
async def last_record(self, _inp: LastRecord):
|
||||
send = {'month': {}, 'three_month': {}}
|
||||
last = await self.search_last(TaskEnv.CLN_MONITOR_PYSICAL, _inp, 35, 25)
|
||||
if last:
|
||||
send['month'] = last
|
||||
three_month = await self.search_last(TaskEnv.CLN_MONITOR_PYSICAL, _inp, 95, 85)
|
||||
if three_month:
|
||||
send['three_month'] = three_month
|
||||
return send
|
||||
|
||||
async def create(self, _inp: MODEL):
|
||||
create = await mongo_inserter(_inp, COLLECTION, getter=self.get)
|
||||
await ProjectRepository().set_sts_two_for_monitor(_inp.project_id)
|
||||
return create
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from app.config import TaskEnv
|
||||
from app.models.monito_physical_progress import LastRecord
|
||||
from app.models.monitor_rial_progress import RialProgressModel
|
||||
from app.repositories.monitor_physical_progress import PhysicalProgressRepository
|
||||
from app.repositories.project import ProjectRepository
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
@@ -12,12 +14,9 @@ class RialProgressRepository(BaseRepository):
|
||||
def __init__(self):
|
||||
super().__init__(collection=TaskEnv.CLN_MONITOR_RIAL, model=RialProgressModel)
|
||||
|
||||
async def last_record(self, project_id:uuid.UUID):
|
||||
last = await use_collection(TaskEnv.CLN_MONITOR_RIAL).find({'project_id':project_id}).sort("$natural", -1).to_list(None)
|
||||
if last:
|
||||
return last[0]
|
||||
else:
|
||||
return {}
|
||||
async def last_record(self, _inp: LastRecord):
|
||||
last = await PhysicalProgressRepository().search_last(TaskEnv.CLN_MONITOR_RIAL, _inp, 35, 25)
|
||||
return last
|
||||
|
||||
async def create(self,_inp:RialProgressModel):
|
||||
create = await mongo_inserter(_inp,TaskEnv.CLN_MONITOR_RIAL,getter=self.get)
|
||||
|
||||
@@ -2,7 +2,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import Body
|
||||
|
||||
from app.models.monito_physical_progress import PhysicalProgressModel
|
||||
from app.models.monito_physical_progress import PhysicalProgressModel, LastRecord
|
||||
from app.repositories.monitor_physical_progress import PhysicalProgressRepository
|
||||
from core.app import app
|
||||
from core.utils.router import generate_router, shrink
|
||||
@@ -19,9 +19,9 @@ repo = PhysicalProgressRepository()
|
||||
def create(coding: ThisModel = Body(...)):
|
||||
pass
|
||||
|
||||
@router.post('/last/{project_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت فیزیکی')
|
||||
@router.post('/last', response_model=list[dict], tags=_tag_base, description='پیشرفت فیزیکی')
|
||||
@shrink(repo.last_record)
|
||||
def last_record(project_id:UUID):
|
||||
def last_record(last:LastRecord):
|
||||
pass
|
||||
|
||||
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت فیزیکی')
|
||||
|
||||
@@ -2,6 +2,7 @@ from uuid import UUID
|
||||
|
||||
from fastapi import Body
|
||||
|
||||
from app.models.monito_physical_progress import LastRecord
|
||||
from app.models.monitor_rial_progress import RialProgressModel
|
||||
from app.repositories.monitor_rial_progress import RialProgressRepository
|
||||
from core.app import app
|
||||
@@ -19,9 +20,9 @@ repo = RialProgressRepository()
|
||||
def create(coding: ThisModel = Body(...)):
|
||||
pass
|
||||
|
||||
@router.post('/last/{project_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
||||
@router.post('/last', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
||||
@shrink(repo.last_record)
|
||||
def last_record(project_id:UUID):
|
||||
def last_record(last:LastRecord):
|
||||
pass
|
||||
|
||||
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base, description='پیشرفت ریالی')
|
||||
|
||||
Reference in New Issue
Block a user