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