feat:add monitor sts project
This commit is contained in:
@@ -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