add progress project model, repository
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
import datetime
|
||||||
|
import uuid
|
||||||
|
from typing import Optional, Literal, List
|
||||||
|
|
||||||
|
import pydantic
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
|
from core.models.base import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class DesignProgressModel(BaseModel):
|
||||||
|
id: Optional[uuid.UUID] = Field(alias='_id')
|
||||||
|
start_at: Optional[datetime.datetime] = Field(description='تاریخ اولین درخواست در این فیلد قرار می گیرد')
|
||||||
|
project_id: uuid.UUID = Field(description='کد شناسایی پروژه در این فیلد ذخیره می شود')
|
||||||
|
complete_at: Optional[datetime.datetime] = Field(description='تاریخ تکمیل مدارک')
|
||||||
|
user_complete: Optional[int] = Field(description='کاربری که اطلاعات را تکمیل می کند در این فیلد قرار می گیرد')
|
||||||
|
type: Literal[1, 2, 3, 4, 5, 6, 7] = Field(description="""
|
||||||
|
1 تکمیل مدارک و مستندات
|
||||||
|
.2 فاز صفر
|
||||||
|
.3 فاز یک
|
||||||
|
.4 طراحی شبکه و دوربین و برق اضطراری
|
||||||
|
.5 فاز دو
|
||||||
|
.6 متر برآورد
|
||||||
|
.7 اسناد مناقصه
|
||||||
|
""")
|
||||||
|
parent_id: Optional[uuid.UUID] = Field(description='زیر مجموعه کدام نوع اصلی است')
|
||||||
|
sub_type: Optional[Literal[1, 2, 3, 4, 5, 6, 7]] = Field(description="""
|
||||||
|
1. برنامه فیزیکی
|
||||||
|
2. گزارش فاز صفر کلیه رشته ها
|
||||||
|
3. آلترناتیک لکه گذاری جا نمایی در سایت
|
||||||
|
4. آلترناتیک لکه گذاری معماری طبقات
|
||||||
|
5. فاز یک معماری
|
||||||
|
6.تائید دانشگاه علوم پزشکی
|
||||||
|
7.گزارش های کلیه رشته ها
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
class SubRecord(pydantic.BaseModel):
|
||||||
|
date_at: datetime.datetime = Field(description='تاریخ در این فیلد ذخیره می شود')
|
||||||
|
number: str = Field(description='شماره نامه در این فیلد ذخیره می شود')
|
||||||
|
description: str = Field(description='توضیحات در این فیلد ذخیره می شود')
|
||||||
|
|
||||||
|
class Record(BaseModel):
|
||||||
|
id: Optional[uuid.UUID] = Field(alias='_id')
|
||||||
|
title: str = Field(description='عنوان در این فیلد قرار میگیرد')
|
||||||
|
send: SubRecord = Field(description='اطلاعات ارسال در این فیلد ذخیره می شود')
|
||||||
|
receive: Optional[SubRecord] = Field(description='اطلاعات دریافت در این فیلد ذخیره می شود')
|
||||||
|
|
||||||
|
class RecordModel(Record):
|
||||||
|
design_progress_id: uuid.UUID = Field(description='کد شناسایی فیلد پیشرفت طراحی در این فیلد قرار می گیرد')
|
||||||
|
|
||||||
|
class CreateDesignProgress(DesignProgressModel):
|
||||||
|
records:Optional[List[Record]]=Field(description='لیست رکوردها د این فیلد قرار میگیرد')
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import datetime
|
||||||
|
import uuid
|
||||||
|
from typing import Literal, Optional, List
|
||||||
|
|
||||||
|
import pydantic
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
|
from core.models.base import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class SubRecord(pydantic.BaseModel):
|
||||||
|
date_at: datetime.datetime = Field(description='تاریخ در این فیلد ذخیره می شود')
|
||||||
|
number: str = Field(description='شماره نامه در این فیلد ذخیره می شود')
|
||||||
|
description: str = Field(description='توضیحات در این فیلد ذخیره می شود')
|
||||||
|
|
||||||
|
|
||||||
|
class Record(pydantic.BaseModel):
|
||||||
|
send: SubRecord = Field(description='اطلاعات ارسال در این فیلد ذخیره می شود')
|
||||||
|
receive: Optional[SubRecord] = Field(description='اطلاعات دریافت در این فیلد ذخیره می شود')
|
||||||
|
|
||||||
|
|
||||||
|
class CompleteDocument(BaseModel):
|
||||||
|
start_at:Optional[datetime.datetime] = Field(description='تاریخ اولین درخواست در این فیلد قرار می گیرد')
|
||||||
|
project_id: uuid.UUID = Field(description='کد شناسایی پروژه در این فیلد ذخیره می شود')
|
||||||
|
complete_at: Optional[datetime.datetime] = Field(description='تاریخ تکمیل مدارک')
|
||||||
|
user_complete: Optional[int] = Field(description='کاربری که اطلاعات را تکمیل می کند در این فیلد قرار می گیرد')
|
||||||
|
records: Optional[List[Record]] = Field(description='رکوردهای ارسال و دریافت در این فیلد قرار می گیرد')
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import copy
|
||||||
|
import uuid
|
||||||
|
from typing import List
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from app.models.design_progress import DesignProgressModel, CreateDesignProgress, RecordModel
|
||||||
|
from core.repositories.base import BaseRepository
|
||||||
|
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)
|
||||||
|
def create_progress_model(self,_inp:CreateDesignProgress)->DesignProgressModel:
|
||||||
|
if _inp.complete_at:
|
||||||
|
_inp.start_at = _inp.records[0].send.date_at
|
||||||
|
progress = DesignProgressModel(
|
||||||
|
project_id=_inp.project_id,
|
||||||
|
type=_inp.type,
|
||||||
|
parent_id=_inp.parent_id,
|
||||||
|
sub_type=_inp.sub_type,
|
||||||
|
start_at= _inp.start_at,
|
||||||
|
complete_at= _inp.complete_at
|
||||||
|
)
|
||||||
|
progress.init_id().cu_at()
|
||||||
|
return progress
|
||||||
|
def create_record(self,_inp:CreateDesignProgress,_id:uuid.UUID=None):
|
||||||
|
records = []
|
||||||
|
for record in _inp.records:
|
||||||
|
save_record = RecordModel(
|
||||||
|
design_progress_id=_id,
|
||||||
|
title=record.title,
|
||||||
|
send=record.send,
|
||||||
|
receive=record.receive
|
||||||
|
).init_id().cu_at()
|
||||||
|
records.append(save_record.mongo_dict())
|
||||||
|
return records
|
||||||
|
async def create(self,create:CreateDesignProgress):
|
||||||
|
progress = self.create_progress_model(create)
|
||||||
|
await use_collection(COLLECTION).insert_one(progress.mongo_dict())
|
||||||
|
if create.records:
|
||||||
|
records = self.create_record(create)
|
||||||
|
await use_collection('design_progress_record').insert_many(records)
|
||||||
|
return self.get(progress.id)
|
||||||
|
|
||||||
|
async def get(self, _id: UUID):
|
||||||
|
progress = await use_collection(COLLECTION).find_one({"_id":_id})
|
||||||
|
progress['records'] = await use_collection('design_progress_record').find({"design_progress_id":_id}).to_list(None)
|
||||||
|
return progress
|
||||||
|
|
||||||
|
async def update(self, _id: UUID, update: CreateDesignProgress):
|
||||||
|
progress = self.create_progress_model(update)
|
||||||
|
await use_collection(COLLECTION).update_one({"_id":_id},{"$set":progress.mongo_dict()})
|
||||||
|
if update.records:
|
||||||
|
before_records = await use_collection('design_progress_record').distinct("_id",{"design_progress_id":_id})
|
||||||
|
update_records = []
|
||||||
|
update_record_ids = []
|
||||||
|
create_records = []
|
||||||
|
delete_records = list(before_records).copy()
|
||||||
|
for record in update.records:
|
||||||
|
if record.id:
|
||||||
|
save_record = RecordModel(
|
||||||
|
design_progress_id=_id,
|
||||||
|
title=record.title,
|
||||||
|
send=record.send,
|
||||||
|
receive=record.receive
|
||||||
|
).u_at()
|
||||||
|
update_records.append(save_record.mongo_dict())
|
||||||
|
update_record_ids.append(record.id)
|
||||||
|
delete_records.remove(record.id)
|
||||||
|
else:
|
||||||
|
save_record = RecordModel(
|
||||||
|
design_progress_id=_id,
|
||||||
|
title=record.title,
|
||||||
|
send=record.send,
|
||||||
|
receive=record.receive
|
||||||
|
).init_id().cu_at()
|
||||||
|
create_records.append(save_record.mongo_dict())
|
||||||
|
if update_records:
|
||||||
|
await use_collection('design_progress_record').update_many({"_id":{"$in":update_record_ids}},{"$set":update_records})
|
||||||
|
if create_records:
|
||||||
|
await use_collection('design_progress_record').insert_many(create_records)
|
||||||
|
if delete_records:
|
||||||
|
await mongo_soft_deleter({"_id":{"$in":delete_records}},'design_progress_record')
|
||||||
|
return self.get(progress.id)
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,6 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
|||||||
|
|
||||||
|
|
||||||
async def create(self,coding:ProjectModel):
|
async def create(self,coding:ProjectModel):
|
||||||
print("11111111111111111")
|
|
||||||
coding.counter = 1
|
coding.counter = 1
|
||||||
last_project = await use_collection(COLLECTION).find({}).sort("$natural",-1).to_list(None)
|
last_project = await use_collection(COLLECTION).find({}).sort("$natural",-1).to_list(None)
|
||||||
if last_project:
|
if last_project:
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
from .project import *
|
from .project import *
|
||||||
from .grand_project import *
|
from .grand_project import *
|
||||||
|
from .design_progress import *
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from fastapi import Body
|
||||||
|
|
||||||
|
from app.models.design_progress import DesignProgressModel, CreateDesignProgress
|
||||||
|
from app.repositories.design_progress import DesignProgressRepository
|
||||||
|
from core.app import app
|
||||||
|
from core.utils.router import generate_router, shrink
|
||||||
|
from core.utils.table_engine import TableEngineExport, TableEngineRequestType
|
||||||
|
|
||||||
|
ThisModel = CreateDesignProgress
|
||||||
|
router_base_url = 'design_progress'
|
||||||
|
_tag_base = [router_base_url]
|
||||||
|
router = generate_router(router_base_url, auth_dependencies=False, version='v2')
|
||||||
|
|
||||||
|
|
||||||
|
repo = DesignProgressRepository(collection='design_progress')
|
||||||
|
|
||||||
|
@router.post('/create', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.create)
|
||||||
|
def create(coding: ThisModel = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@router.put('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.update)
|
||||||
|
def update(_id: UUID, coding: ThisModel = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete('/{_id}', response_model=bool, tags=_tag_base)
|
||||||
|
@shrink(repo.delete)
|
||||||
|
def delete(_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@router.get('/{_id}', response_model=ThisModel, tags=_tag_base)
|
||||||
|
@shrink(repo.get)
|
||||||
|
def get(_id: UUID):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@router.post('', response_model=TableEngineExport[ThisModel], tags=_tag_base)
|
||||||
|
@shrink(repo.fetch)
|
||||||
|
def fetch(body: TableEngineRequestType = Body(...)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
app.include_router(router)
|
||||||
Reference in New Issue
Block a user