feat(excel):add takmil madarek

This commit is contained in:
shahzeydyfah
2025-07-31 23:32:55 +03:30
parent cf05ea14b4
commit 2438ee0f6a
2 changed files with 126 additions and 1 deletions
+121 -1
View File
@@ -5,6 +5,7 @@ import pandas as pd
import os
from app.config import TaskEnv
from app.models.design_progress import DesignProgressModel, RecordModel, SubRecord, Record
from app.models.project import ProjectModel
from core.service.mongo_db import use_collection
import jdatetime
@@ -140,4 +141,123 @@ class ExcelRepository():
p['date_delay'] = ProjectRepository().creat_date_delay(ProjectModel(**p))
print('date_delay',p['date_delay'])
await use_collection(TaskEnv.CLN_PROJECT).update_one({'counter':int(my_row["code"])},{"$set":p})
return
return
async def addProgress1(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../.."))
excel_path = os.path.join(project_root, "takmil_madarek.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=1,
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)
if 'sixth_time/send/date_at' in my_row and my_row['sixth_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id)
if 'seventh_time/send/date_at' in my_row and my_row['seventh_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه هفتم', 'seventh_time', progress_id)
break
print("code", my_row['code'])
async def addProgressPhysical(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.abspath(os.path.join(base_dir, "../.."))
excel_path = os.path.join(project_root, "faz_zero.xlsx")
df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="physical", 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=2,
state=my_row['state']
)
progress.init_id().cu_at()
await use_collection("design_progress").insert_one(progress.mongo_dict())
progress_type = DesignProgressModel(
project_id=my_project['_id'],
type=2,
state=my_row['state'],
parent_id= progress.id,
sub_type= 1,
)
progress_type.init_id().cu_at()
await use_collection("design_progress").insert_one(progress_type.mongo_dict())
progress_id = progress_type.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)
if 'sixth_time/send/date_at' in my_row and my_row['sixth_time/send/date_at'] != "" and progress_id:
await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id)
break
print("code", my_row['code'])
def createDate(self, date):
year = int(date[:4])
month = int(date[4:6])
day = int(date[6:8])
jalali_date = jdatetime.date(year, month, day)
gregorian_date = jalali_date.togregorian()
created_at = datetime.datetime.combine(gregorian_date, datetime.time())
return created_at
async def createRecord(self, my_row, _time_f, _time_e, progress_id):
send = SubRecord(
date_at=self.createDate(my_row[f'{_time_e}/send/date_at']),
number=my_row[f'{_time_e}/send/number'],
description=None
)
record = RecordModel(
design_progress_id=progress_id,
title=_time_f,
send=send,
)
if my_row[f'{_time_e}/receive/date_at'] and my_row[f'{_time_e}/receive/date_at'] != "":
receive = SubRecord(
date_at=self.createDate(my_row[f'{_time_e}/receive/date_at']),
number=my_row[f'{_time_e}/receive/number'],
description=None
)
record.receive = receive
record.init_id().cu_at()
await use_collection("design_progress_record").insert_one(record.mongo_dict())
return record
+5
View File
@@ -18,4 +18,9 @@ def design():
def monitor():
pass
@router.get('/progress1', tags=_tag_base)
@shrink(repo.addProgress1)
def addProgress1():
pass
app.include_router(router)