feat:add monitor sts project
This commit is contained in:
@@ -4,6 +4,8 @@ from app.config import TaskEnv
|
||||
from app.models.monito_physical_progress import PhysicalProgressModel
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
from core.utils.crudify import mongo_inserter
|
||||
from app.repositories.project import ProjectRepository
|
||||
|
||||
COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL
|
||||
MODEL = PhysicalProgressModel
|
||||
@@ -16,4 +18,9 @@ class PhysicalProgressRepository(BaseRepository):
|
||||
if last:
|
||||
return last[0]
|
||||
else:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
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
|
||||
|
||||
@@ -2,8 +2,11 @@ import uuid
|
||||
|
||||
from app.config import TaskEnv
|
||||
from app.models.monitor_rial_progress import RialProgressModel
|
||||
from app.repositories.project import ProjectRepository
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
from core.utils.crudify import mongo_inserter
|
||||
|
||||
|
||||
class RialProgressRepository(BaseRepository):
|
||||
def __init__(self):
|
||||
@@ -14,4 +17,9 @@ class RialProgressRepository(BaseRepository):
|
||||
if last:
|
||||
return last[0]
|
||||
else:
|
||||
return {}
|
||||
return {}
|
||||
|
||||
async def create(self,_inp:RialProgressModel):
|
||||
create = await mongo_inserter(_inp,TaskEnv.CLN_MONITOR_RIAL,getter=self.get)
|
||||
await ProjectRepository().set_sts_two_for_monitor(_inp.project_id)
|
||||
return create
|
||||
@@ -1,8 +1,10 @@
|
||||
import uuid
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.models.project import ProjectModel, UpdateSts
|
||||
from app.config import TaskEnv
|
||||
from app.models.project import ProjectModel, UpdateSts, ProjectSts
|
||||
from core.repositories.base import BaseRepository
|
||||
from core.service.mongo_db import use_collection
|
||||
|
||||
@@ -56,7 +58,30 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
await use_collection(COLLECTION).update_one({"_id":_id},{"$set":{
|
||||
'design.sts':update.sts,'design.reason_stop':update.reason_stop
|
||||
}})
|
||||
return True
|
||||
sts_class = ProjectSts(
|
||||
project_id= _id,
|
||||
type = 'design',
|
||||
sts= update.sts,
|
||||
description= update.reason_stop
|
||||
).init_id().cu_at()
|
||||
await use_collection(TaskEnv.CLN_PROJECT_STS).insert_one(sts_class.mongo_dict())
|
||||
return await self.get(_id)
|
||||
|
||||
async def update_monitor_sts(self, _id: UUID, update: UpdateSts):
|
||||
old_project = await use_collection(COLLECTION).find_one({"_id":_id})
|
||||
if not old_project:
|
||||
raise HTTPException(status_code=400,detail='این پروژه وجود ندارد')
|
||||
await use_collection(COLLECTION).update_one({"_id":_id},{"$set":{
|
||||
'monitor.sts':update.sts,'monitor.reason_sts':update.reason_stop
|
||||
}})
|
||||
sts_class = ProjectSts(
|
||||
project_id= _id,
|
||||
type = 'monitor',
|
||||
sts= update.sts,
|
||||
description= update.reason_stop
|
||||
).init_id().cu_at()
|
||||
await use_collection(TaskEnv.CLN_PROJECT_STS).insert_one(sts_class.mongo_dict())
|
||||
return await self.get(_id)
|
||||
|
||||
async def delete(self, _id: UUID):
|
||||
old_project = await use_collection(COLLECTION).find_one({"_id":_id})
|
||||
@@ -74,4 +99,35 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
|
||||
async def list_project_monitor(self):
|
||||
project = await use_collection(COLLECTION).find({'monitor':{"$exists":1}}).to_list(None)
|
||||
return project
|
||||
return project
|
||||
|
||||
async def list_sts_design(self,_id:uuid.UUID):
|
||||
sts_project = await use_collection(TaskEnv.CLN_PROJECT_STS).find({
|
||||
"project_id":_id,
|
||||
"type":"design"
|
||||
}).to_list(None)
|
||||
return sts_project
|
||||
|
||||
async def list_sts_monitor(self,_id:uuid.UUID):
|
||||
sts_project = await use_collection(TaskEnv.CLN_PROJECT_STS).find({
|
||||
"project_id":_id,
|
||||
"type":"monitor"
|
||||
}).to_list(None)
|
||||
return sts_project
|
||||
|
||||
async def set_sts_two_for_monitor(self,project_id:uuid.UUID):
|
||||
project = await use_collection(TaskEnv.CLN_PROJECT).find_one({"_id": project_id})
|
||||
if not ('sts' in project['monitor'] and project['monitor']['sts'] > 1):
|
||||
await use_collection(TaskEnv.CLN_PROJECT).update_one(
|
||||
{'_id': project_id},
|
||||
{"$set":{"monitor.sts": 2}})
|
||||
|
||||
sts_class = ProjectSts(
|
||||
project_id=project_id,
|
||||
type='monitor',
|
||||
sts=2
|
||||
).init_id().cu_at()
|
||||
await use_collection(TaskEnv.CLN_PROJECT_STS).insert_one(sts_class.mongo_dict())
|
||||
|
||||
|
||||
return True
|
||||
Reference in New Issue
Block a user