From 2438ee0f6afa354d4425c24126d97510417d855e Mon Sep 17 00:00:00 2001 From: shahzeydyfah Date: Thu, 31 Jul 2025 23:32:55 +0330 Subject: [PATCH] feat(excel):add takmil madarek --- app/repositories/excel.py | 122 +++++++++++++++++++++++++++++++++++++- app/urls/excel.py | 5 ++ 2 files changed, 126 insertions(+), 1 deletion(-) diff --git a/app/repositories/excel.py b/app/repositories/excel.py index 85646c1..efa1ca2 100644 --- a/app/repositories/excel.py +++ b/app/repositories/excel.py @@ -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 \ No newline at end of file + 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 diff --git a/app/urls/excel.py b/app/urls/excel.py index fef63b3..451176f 100644 --- a/app/urls/excel.py +++ b/app/urls/excel.py @@ -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) \ No newline at end of file