fix:design progress
This commit is contained in:
@@ -12,16 +12,17 @@ from core.service.mongo_db import use_collection
|
||||
from core.utils.crudify import mongo_soft_deleter
|
||||
|
||||
COLLECTION = "design_progress"
|
||||
|
||||
|
||||
class DesignProgressRepository(BaseRepository[CreateDesignProgress]):
|
||||
def __int__(self):
|
||||
super().__init__(collection=COLLECTION, model=CreateDesignProgress)
|
||||
|
||||
|
||||
async def create(self,_inp:CreateDesignProgress):
|
||||
async def create(self, _inp: CreateDesignProgress):
|
||||
exist = await use_collection(COLLECTION).find_one({
|
||||
"project_id":_inp.project_id,
|
||||
"type":_inp.type,
|
||||
"sub_type":_inp.sub_type
|
||||
"project_id": _inp.project_id,
|
||||
"type": _inp.type,
|
||||
"sub_type": _inp.sub_type
|
||||
})
|
||||
if not exist:
|
||||
progress = DesignProgressModel(
|
||||
@@ -39,23 +40,25 @@ class DesignProgressRepository(BaseRepository[CreateDesignProgress]):
|
||||
)
|
||||
return await self.get(get_record)
|
||||
|
||||
async def get(self,get_record:GetRecord):
|
||||
progress = await use_collection(COLLECTION).find_one({"project_id":get_record.project_id,"type":get_record.type,"sub_type":get_record.sub_type})
|
||||
async def get(self, get_record: GetRecord):
|
||||
progress = await use_collection(COLLECTION).find_one(
|
||||
{"project_id": get_record.project_id, "type": get_record.type, "sub_type": get_record.sub_type})
|
||||
if progress:
|
||||
progress['records'] = await use_collection('design_progress_record').find({"design_progress_id":progress["_id"]}).to_list(None)
|
||||
progress['records'] = await use_collection('design_progress_record').find(
|
||||
{"design_progress_id": progress["_id"]}).to_list(None)
|
||||
return progress
|
||||
|
||||
async def update(self, _id: UUID, _inp: UpdateDesignProgress):
|
||||
design_progress = await use_collection(COLLECTION).find_one({"_id":_id})
|
||||
design_progress = await use_collection(COLLECTION).find_one({"_id": _id})
|
||||
design_progress = DesignProgressModel(**design_progress)
|
||||
records = await use_collection('design_progress_record').find_one(
|
||||
{"design_progress_id": _id})
|
||||
start_at = records['send']['date_at']
|
||||
await use_collection(COLLECTION).update_one({"_id":_id},{"$set": {
|
||||
"start_at":start_at,"complete_at":_inp.complete_at
|
||||
await use_collection(COLLECTION).update_one({"_id": _id}, {"$set": {
|
||||
"start_at": start_at, "complete_at": _inp.complete_at
|
||||
}})
|
||||
if design_progress.type == 1:
|
||||
await use_collection('project').update_one({"_id":design_progress.project_id},{"$set":{"sts":2}})
|
||||
await use_collection('project').update_one({"_id": design_progress.project_id}, {"$set": {"sts": 2}})
|
||||
elif design_progress.type == 7:
|
||||
await use_collection('project').update_one({"_id": design_progress.project_id}, {"$set": {"sts": 4}})
|
||||
get_record = GetRecord(
|
||||
@@ -64,45 +67,44 @@ class DesignProgressRepository(BaseRepository[CreateDesignProgress]):
|
||||
sub_type=design_progress.sub_type
|
||||
)
|
||||
return await self.get(get_record)
|
||||
async def check_complete(self,get_record:GetRecord):
|
||||
result ={
|
||||
"exist":False
|
||||
|
||||
async def check_complete(self, get_record: GetRecord):
|
||||
result = {
|
||||
"exist": False
|
||||
}
|
||||
if get_record.type :
|
||||
if get_record.type:
|
||||
if get_record.type > 1:
|
||||
progress = await use_collection(COLLECTION).find_one(
|
||||
{"project_id": get_record.project_id, "type": int(get_record.type) - 1,
|
||||
"completed_at": {"$exists": 1}})
|
||||
"completed_at": {"$exists": 1},"sub_type":{"$exists":0}})
|
||||
if not progress:
|
||||
return {"exist":True,"detail":'before type not complete'}
|
||||
return {"exist": True, "detail": 'before type not complete'}
|
||||
if get_record.type < 7:
|
||||
progress = await use_collection(COLLECTION).find(
|
||||
{"project_id": get_record.project_id, "type": int(get_record.type)+1}).to_list(None)
|
||||
{"project_id": get_record.project_id, "type": int(get_record.type) + 1}).to_list(None)
|
||||
if progress:
|
||||
ids = [i["_id"] for i in progress]
|
||||
records = await use_collection('design_progress_record').find_one(
|
||||
{"design_progress_id": {"$in":ids}})
|
||||
{"design_progress_id": {"$in": ids}})
|
||||
if records:
|
||||
return {"exist":True,"detail":"next record is exist"}
|
||||
return {"exist": True, "detail": "next record is exist"}
|
||||
|
||||
return result
|
||||
|
||||
async def check_create_complete(self,get_record:GetRecord):
|
||||
async def check_create_complete(self, get_record: GetRecord):
|
||||
result = False
|
||||
if get_record.type and get_record.type >1:
|
||||
if get_record.type and get_record.type > 1:
|
||||
progress = await use_collection(COLLECTION).find(
|
||||
{"project_id": get_record.project_id, "type": int(get_record.type)+1}).to_list(None)
|
||||
{"project_id": get_record.project_id, "type": int(get_record.type) + 1}).to_list(None)
|
||||
if progress:
|
||||
ids = [i["_id"] for i in progress]
|
||||
records = await use_collection('design_progress_record').find_one(
|
||||
{"design_progress_id": {"$in":ids}})
|
||||
{"design_progress_id": {"$in": ids}})
|
||||
if records:
|
||||
result=True
|
||||
result = True
|
||||
return result
|
||||
|
||||
|
||||
class DesignProgressRecordRepository(BaseRepository[RecordModel]):
|
||||
def __int__(self):
|
||||
super().__init__(collection='design_progress_record', model=RecordModel)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user