feat(excel):complete design excel

This commit is contained in:
shahzeydyfah
2025-08-05 00:08:40 +03:30
parent 6f6d9ec9da
commit 8b95cd562c
2 changed files with 198 additions and 1 deletions
+173 -1
View File
@@ -6,7 +6,7 @@ import os
from app.config import TaskEnv
from app.models.design_progress import DesignProgressModel, RecordModel, SubRecord, Record, UpdateDesignProgress
from app.models.project import ProjectModel
from app.models.project import ProjectModel, ProjectSts
from core.service.mongo_db import use_collection
import jdatetime
from app.repositories.project import ProjectRepository
@@ -558,12 +558,184 @@ class ExcelRepository():
break
print("code", my_row['code'])
# طراحی دوربین و شبکه
async def addProgressNetworkDesign(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../../excel"))
excel_path = os.path.join(project_root, "network.xlsx")
df = pd.read_excel(excel_path, engine="openpyxl", dtype=str)
df = df.fillna("")
projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None)
for index, row in df.iterrows():
my_row = row.to_dict()
print(f"سطر {index}: {row.to_dict()}")
print("code", my_row['code'])
for p in projects:
if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])):
print('projects', p)
my_project = p
if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "":
progress = DesignProgressModel(
project_id=my_project['_id'],
type=4,
state=my_row['state']
)
progress.init_id().cu_at()
await use_collection("design_progress").insert_one(progress.mongo_dict())
progress_id = progress.id
await self.createRecord(my_row, 'مرتبه اول', 'first_time', progress_id)
break
print("code", my_row['code'])
return True
async def addProgressFazTwo(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../../excel"))
excel_path = os.path.join(project_root, "faz_two.xlsx")
print("Excel file path:", excel_path)
df = pd.read_excel(excel_path, engine="openpyxl", dtype=str)
df = df.fillna("")
projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None)
for index, row in df.iterrows():
my_row = row.to_dict()
print(f"سطر {index}: {row.to_dict()}")
print("code",my_row['code'])
for p in projects:
if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])):
print('projects', p)
my_project = p
progress_id = None
if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "":
progress = DesignProgressModel(
project_id=my_project['_id'],
type=5,
state=my_row['state']
)
progress.init_id().cu_at()
await use_collection("design_progress").insert_one(progress.mongo_dict())
progress_id = progress.id
await self.createRecord(my_row, 'مرتبه اول', 'first_time',progress_id)
if 'second_time/send/date_at' in my_row and my_row['second_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id)
if 'third_time/send/date_at' in my_row and my_row['third_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id)
if 'forth_time/send/date_at' in my_row and my_row['forth_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id)
if 'fifth_time/send/date_at' in my_row and my_row['fifth_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id)
break
print("code", my_row['code'])
return True
async def addProgressMetri(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../../excel"))
excel_path = os.path.join(project_root, "metri.xlsx")
print("Excel file path:", excel_path)
df = pd.read_excel(excel_path, engine="openpyxl", dtype=str)
df = df.fillna("")
projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None)
for index, row in df.iterrows():
my_row = row.to_dict()
print(f"سطر {index}: {row.to_dict()}")
print("code",my_row['code'])
for p in projects:
if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])):
print('projects', p)
my_project = p
progress_id = None
if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "":
progress = DesignProgressModel(
project_id=my_project['_id'],
type=6,
state=my_row['state']
)
progress.init_id().cu_at()
await use_collection("design_progress").insert_one(progress.mongo_dict())
progress_id = progress.id
await self.createRecord(my_row, 'مرتبه اول', 'first_time',progress_id)
if 'second_time/send/date_at' in my_row and my_row['second_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id)
break
print("code", my_row['code'])
return True
async def addProgressTender(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../../excel"))
excel_path = os.path.join(project_root, "tender.xlsx")
print("Excel file path:", excel_path)
df = pd.read_excel(excel_path, engine="openpyxl", dtype=str)
df = df.fillna("")
projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None)
for index, row in df.iterrows():
my_row = row.to_dict()
print(f"سطر {index}: {row.to_dict()}")
print("code",my_row['code'])
for p in projects:
if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])):
print('projects', p)
my_project = p
if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "":
progress = DesignProgressModel(
project_id=my_project['_id'],
type=7,
state=my_row['state']
)
progress.init_id().cu_at()
await use_collection("design_progress").insert_one(progress.mongo_dict())
progress_id = progress.id
await self.createRecord(my_row, 'مرتبه اول', 'first_time',progress_id)
break
print("code", my_row['code'])
return True
async def changeStatus(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../../excel"))
excel_path = os.path.join(project_root, "status.xlsx")
print("Excel file path:", excel_path)
df = pd.read_excel(excel_path, engine="openpyxl", dtype=str)
df = df.fillna("")
projects = await use_collection(TaskEnv.CLN_PROJECT).find({}).to_list(None)
for index, row in df.iterrows():
my_row = row.to_dict()
print(f"سطر {index}: {row.to_dict()}")
print("code",my_row['code'])
for p in projects:
if str(my_row["code"]) in str(p['design']["code"]) and p['counter'] == int(str(my_row["code"])):
print('projects', p)
sts = 2
if my_row["status"] == 'متوقف':
sts = 3
elif my_row["status"] == 'خاتمه یافته':
sts=4
print('sts',sts)
await use_collection('project').update_one({"_id": p["_id"]}, {"$set": {
'design.sts': sts, 'design.reason_stop': my_row["reason_stop"],'design.description':my_row['description']
}})
sts_class = ProjectSts(
project_id=p["_id"],
type='design',
sts=sts,
description=my_row["reason_stop"]
).init_id().cu_at()
await use_collection(TaskEnv.CLN_PROJECT_STS).insert_one(sts_class.mongo_dict())
break
print("code", my_row['code'])
return True
def createDate(self, date):
if '/' in date:
date = date.replace('/', '')
year = int(date[:4])
month = int(date[4:6])
if month == 0:
month = 1
print(month,'month')
day = int(date[6:8])
if day ==0:
day=1
print(day,'day')
jalali_date = jdatetime.date(year, month, day)
gregorian_date = jalali_date.togregorian()
created_at = datetime.datetime.combine(gregorian_date, datetime.time.min)
+25
View File
@@ -64,4 +64,29 @@ def addProgressFazOneUniversity():
def addProgressFazOneAll():
pass
@router.get('/progress/network', tags=_tag_base)
@shrink(repo.addProgressNetworkDesign)
def addProgressNetworkDesign():
pass
@router.get('/progress/faz/two', tags=_tag_base)
@shrink(repo.addProgressFazTwo)
def addProgressFazTwo():
pass
@router.get('/progress/faz/metri', tags=_tag_base)
@shrink(repo.addProgressMetri)
def addProgressMetri():
pass
@router.get('/progress/faz/tender', tags=_tag_base)
@shrink(repo.addProgressTender)
def addProgressTender():
pass
@router.get('/change/design/sts', tags=_tag_base)
@shrink(repo.changeStatus)
def changeStatus():
pass
app.include_router(router)