diff --git a/app/models/design_progress.py b/app/models/design_progress.py index 3a7aa4f..e245228 100644 --- a/app/models/design_progress.py +++ b/app/models/design_progress.py @@ -50,7 +50,7 @@ class SubRecord(pydantic.BaseModel): class Record(BaseModel): id: Optional[uuid.UUID] = Field(alias='_id') title: str = Field(description='عنوان در این فیلد قرار میگیرد') - send: SubRecord = Field(description='اطلاعات ارسال در این فیلد ذخیره می شود') + send: Optional[SubRecord] = Field(description='اطلاعات ارسال در این فیلد ذخیره می شود') receive: Optional[SubRecord] = Field(description='اطلاعات دریافت در این فیلد ذخیره می شود') class RecordModel(Record): diff --git a/app/repositories/contract.py b/app/repositories/contract.py index 035bc1a..c587a46 100644 --- a/app/repositories/contract.py +++ b/app/repositories/contract.py @@ -87,6 +87,7 @@ class ContractRepository(BaseRepository): {'$match':query['query']}, {'$group': {"_id": None, 'count': {'$sum': 1},'sum':{"$sum":"$amount"}}} ]).to_list(None) - return count[0] - else: - return [] + print(count) + if len(count)>0: + return count[0] + return [] diff --git a/app/repositories/excel.py b/app/repositories/excel.py index efe1d76..721433a 100644 --- a/app/repositories/excel.py +++ b/app/repositories/excel.py @@ -17,6 +17,7 @@ from app.repositories.monitor_physical_progress import PhysicalProgressRepositor from app.repositories.monitor_rial_progress import RialProgressRepository class ExcelRepository(): + async def addDesignSheet(self): # base_dir = os.path.dirname(os.path.abspath(__file__)) # این یعنی مسیر فایل جاری (مثلاً main.py) # project_root = os.path.abspath(os.path.join(base_dir, "../..")) # رفتن به ریشه پروژه @@ -56,683 +57,745 @@ class ExcelRepository(): return async def addMonitorSheet(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, "projects1.xlsx") - # print("Excel file path:", excel_path) - # df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="نظارت", dtype={'code': str,'date_create_project':str,'date_estimate_complete':str}) - # 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) - # p['monitor'] = {} - # p['monitor']['base_information'] = {"budget" : []} - # p['monitor']['detail'] = {"add_25_percent" : [],"adding" : []} - # p['monitor']['agent'] = {} - # p['monitor']['status_branch'] = {'electricity': False, 'water': False, 'wastewater': False, 'gas': False, 'phone': False} - # if my_row['building_infrastructure'] and pd.notna(row['building_infrastructure']): - # p['design']["building_infrastructure"] = my_row["building_infrastructure"] - # print('a') - # if my_row['land_area'] and pd.notna(row['land_area']): - # p['design']["land_area"] = my_row["land_area"] - # print('a1',my_row['monitor_type']) - # if my_row['monitor_type'] == 'عالیه' : - # print('b1') - # p['monitor']['base_information']['type'] = 39 - # elif my_row['monitor_type'] == 'عالیه و کارگاهی' : - # print('b2') - # p['monitor']['base_information']['type'] = 40 - # else: - # p['monitor']['base_information']['type'] = 42 - # print('a2') - # if my_row['date_create_project'] and pd.notna(row['date_create_project']): - # year = int(my_row['date_create_project'][:4]) - # month = int(my_row['date_create_project'][4:6]) - # day = int(my_row['date_create_project'][6:8]) - # jalali_date = jdatetime.date(year, month, day) - # gregorian_date = jalali_date.togregorian() - # created_at = datetime.datetime.combine(gregorian_date, datetime.time()) - # p['monitor']['detail']['date_create_project'] = created_at - # print('a3') - # if my_row['first_time'] and pd.notna(row['first_time']): - # p['monitor']['detail']["first_time"] = int(my_row["first_time"]) - # print('a4') - # if my_row['extend_time'] and pd.notna(row['extend_time']): - # p['monitor']['detail']["extend_time"] = my_row["extend_time"] - # print('a5') - # # if my_row['date_estimate_complete'] and pd.notna(row['date_estimate_complete']): - # # print('my_row[date_estimate_complete]',my_row['date_estimate_complete']) - # # year_date = int(my_row['date_estimate_complete'][:4]) - # # month_date = int(my_row['date_estimate_complete'][4:6]) - # # day_date = int(my_row['date_estimate_complete'][6:8]) - # # jalali_date_date = jdatetime.date(year_date, month_date, day_date) - # # gregorian_date_date = jalali_date_date.togregorian() - # # estimate = datetime.datetime.combine(gregorian_date_date, datetime.time()) - # # p['monitor']['detail']['date_estimate_complete'] = estimate - # # print('a6') - # if my_row['first_amount'] and pd.notna(row['first_amount']): - # p['monitor']['detail']["first_amount"] = my_row["first_amount"] - # # price = { - # # '_id': uuid.uuid4(), - # # 'project_id': p['_id'], - # # 'first_amount': my_row["first_amount"] - # # } - # # await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) - # print('a7') - # if my_row['add_25_percent'] and pd.notna(row['add_25_percent']): - # p['monitor']['detail']['add_25_percent'].append({"amount": my_row["add_25_percent"]}) - # print('a8') - # if my_row['adding_amount'] and pd.notna(row['adding_amount']): - # p['monitor']['detail']['adding'].append({"amount":my_row["adding_amount"]}) - # print('a9') - # if my_row['workshop_consultant'] and pd.notna(row['workshop_consultant']): - # p['monitor']['agent']['workshop_consultant'] = my_row["workshop_consultant"] - # print('a0') - # if my_row['constractor'] and pd.notna(row['constractor']): - # p['monitor']['agent']['constractor'] = my_row["constractor"] - # print('a00') - # p['has_monitor'] = True - # p['design']['sts'] = 2 - # p['monitor']['sts'] = 2 - # p['monitor']['has_design'] = True - # create_code = ProjectRepository().create_code(ProjectModel(**p)) - # p['monitor']['code'] = 'S'+ create_code - # print('code',p['monitor']['code']) - # if 'date_create_project' in p['monitor']['detail'] and "first_time" in p['monitor']['detail']: - # 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}) + 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, "project1.xlsx") + print("Excel file path:", excel_path) + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="نظارت", dtype={'code': str,'date_create_project':str,'date_estimate_complete':str}) + 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']) + if my_row['code'].startswith("S"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + print('projects',p) + p['monitor'] = {} + p['monitor']['base_information'] = {"budget" : []} + p['monitor']['detail'] = {"add_25_percent" : [],"adding" : []} + p['monitor']['agent'] = {} + p['monitor']['status_branch'] = {'electricity': False, 'water': False, 'wastewater': False, 'gas': False, 'phone': False} + if my_row['building_infrastructure'] and pd.notna(row['building_infrastructure']): + p['design']["building_infrastructure"] = my_row["building_infrastructure"] + print('a') + if my_row['land_area'] and pd.notna(row['land_area']): + p['design']["land_area"] = my_row["land_area"] + print('a1',my_row['monitor_type']) + if my_row['monitor_type'] == 'عالیه' : + print('b1') + p['monitor']['base_information']['type'] = 41 + elif my_row['monitor_type'] == 'عالیه و کارگاهی' : + print('b2') + p['monitor']['base_information']['type'] = 42 + else: + p['monitor']['base_information']['type'] = 43 + print('a2') + if my_row['date_create_project'] and pd.notna(row['date_create_project']): + year = int(my_row['date_create_project'][:4]) + month = int(my_row['date_create_project'][4:6]) + day = int(my_row['date_create_project'][6:8]) + jalali_date = jdatetime.date(year, month, day) + gregorian_date = jalali_date.togregorian() + created_at = datetime.datetime.combine(gregorian_date, datetime.time()) + p['monitor']['detail']['date_create_project'] = created_at + print('a3') + if my_row['first_time'] and pd.notna(row['first_time']): + p['monitor']['detail']["first_time"] = int(my_row["first_time"]) + print('a4') + if my_row['extend_time'] and pd.notna(row['extend_time']): + p['monitor']['detail']["extend_time"] = my_row["extend_time"] + print('a5') + if my_row['date_estimate_complete'] and pd.notna(row['date_estimate_complete']): + print('my_row[date_estimate_complete]',my_row['date_estimate_complete']) + year_date = int(my_row['date_estimate_complete'][:4]) + month_date = int(my_row['date_estimate_complete'][4:6]) + day_date = int(my_row['date_estimate_complete'][6:8]) + jalali_date_date = jdatetime.date(year_date, month_date, day_date) + gregorian_date_date = jalali_date_date.togregorian() + estimate = datetime.datetime.combine(gregorian_date_date, datetime.time()) + p['monitor']['detail']['date_estimate_complete'] = estimate + print('a6') + if my_row['first_amount'] and pd.notna(row['first_amount']): + p['monitor']['detail']["first_amount"] = my_row["first_amount"] + price = { + '_id': uuid.uuid4(), + 'project_id': p['_id'], + 'first_amount': my_row["first_amount"] + } + await use_collection(TaskEnv.CLN_PROJECT_PRICE_REPORT).insert_one(price) + print('a7') + if my_row['add_25_percent'] and pd.notna(row['add_25_percent']): + p['monitor']['detail']['add_25_percent'].append({"amount": my_row["add_25_percent"]}) + print('a8') + # if my_row['adding_amount'] and pd.notna(row['adding_amount']): + # p['monitor']['detail']['adding'].append({"amount":my_row["adding_amount"]}) + # print('a9') + if my_row['workshop_consultant'] and pd.notna(row['workshop_consultant']): + p['monitor']['agent']['workshop_consultant'] = my_row["workshop_consultant"] + print('a0') + if my_row['constractor'] and pd.notna(row['constractor']): + p['monitor']['agent']['constractor'] = my_row["constractor"] + print('a00') + p['has_monitor'] = True + p['design']['sts'] = 2 + p['monitor']['sts'] = 2 + p['monitor']['has_design'] = True + create_code = ProjectRepository().create_code(ProjectModel(**p)) + p['monitor']['code'] = 'S'+ create_code + print('code',p['monitor']['code']) + if 'date_create_project' in p['monitor']['detail'] and "first_time" in p['monitor']['detail']: + 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(row_code)},{"$set":p}) 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 madarek(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") + 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("code",my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time',my_row) : + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if self.if_set('fifth_time',my_row) : + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + if self.if_set('sixth_time',my_row) : + await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id) + if self.if_set('seventh_time', my_row): + await self.createRecord(my_row, 'مرتبه هفتم', 'seventh_time', progress_id) + break + print("code", my_row['code']) return True # faz zero------------------------------------------------------------------------ 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']) + 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']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time',my_row) : + await self.createRecord(my_row, 'مرتبه چهارم', 'forth_time', progress_id) + if self.if_set('fifth_time',my_row) : + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + if self.if_set('sixth_time',my_row) : + await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id) + break + print("code", row_code) return True async def addProgressStudy(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="study", 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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) - # if not progress: - # progress = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'] - # ) - # progress.init_id().cu_at() - # progress = progress.mongo_dict() - # await use_collection("design_progress").insert_one(progress) - # progress_type = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'], - # parent_id=progress['_id'], - # sub_type=2, - # ) - # 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) - # break - # print("code", my_row['code']) + 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="study", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + my_project = p + progress_id = None + # if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=2, + ) + 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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + break + print("code", my_row['code']) return True async def addProgressAlternativeSite(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="alternative_site", 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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) - # if not progress: - # progress = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'] - # ) - # progress.init_id().cu_at() - # progress = progress.mongo_dict() - # await use_collection("design_progress").insert_one(progress) - # progress_type = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'], - # parent_id=progress['_id'], - # sub_type=3, - # ) - # 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) - # break - # print("code", my_row['code']) + 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="alternative_site", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + my_project = p + progress_id = None + # if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=3, + ) + 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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time',my_row) : + await self.createRecord(my_row, 'مرتبه چهارم', 'forth_time', progress_id) + break + print("code", my_row['code']) return True async def addProgressAlternativeArchitecture(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="alternative_architecture", 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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) - # if not progress: - # progress = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'] - # ) - # progress.init_id().cu_at() - # progress = progress.mongo_dict() - # await use_collection("design_progress").insert_one(progress) - # progress_type = DesignProgressModel( - # project_id=my_project['_id'], - # type=2, - # state=my_row['state'], - # parent_id=progress['_id'], - # sub_type=4, - # ) - # 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) - # break - # print("code", my_row['code']) + 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="alternative_architecture", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + my_project = p + progress_id = None + # if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':2}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=2, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=4, + ) + 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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time', my_row): + await self.createRecord(my_row, 'مرتبه چهارم', 'forth_time', progress_id) + if self.if_set('fifth_time',my_row) : + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + break + print("code", my_row['code']) return True async def completeProgressZero(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="alternative_architecture", 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 = await use_collection("design_progress").find_one( - # {'project_id': my_project['_id'], 'type': 2}) - # if progress and 'complete_at' in my_row and my_row['complete_at'] != '': - # print('jjjjjjjjjjjjjjjjjjjj',progress["_id"]) - # c = UpdateDesignProgress(complete_at=my_row['complete_at']) - # await DesignProgressRepository().update(progress["_id"],c) - # break - # print("code", my_row['code']) + 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="alternative_architecture", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + my_project = p + progress = await use_collection("design_progress").find_one( + {'project_id': my_project['_id'], 'type': 2}) + if progress and 'complete_at' in my_row and my_row['complete_at'] != '': + print('jjjjjjjjjjjjjjjjjjjj',progress["_id"]) + date = self.createDate(my_row['complete_at']) + print('cccccccc', date) + c = UpdateDesignProgress(complete_at=date) + await DesignProgressRepository().update(progress["_id"],c) + break + print("code", my_row['code']) return True #---------------------------------------------------------------------------------------- # faz one----------------------------------------------------------------- async def addProgressFazOneArt(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_one.xlsx") - # df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="architecture", 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=3, - # 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=3, - # state=my_row['state'], - # parent_id= progress.id, - # sub_type= 5, - # ) - # 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) - # 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) - # if 'eighth_time/send/date_at' in my_row and my_row['eighth_time/send/date_at'] != "" and progress_id: - # await self.createRecord(my_row, 'مرتبه هشتم', 'eighth_time', progress_id) - # break - # print("code", my_row['code']) + 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_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="architecture", 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("code",my_row['code']) + print("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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=3, + 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=3, + state=my_row['state'], + parent_id= progress.id, + sub_type= 5, + ) + 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 progress_id: + if self.if_set('second_time',my_row) : + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time',my_row) : + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time',my_row) : + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if self.if_set('fifth_time',my_row) : + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + if self.if_set('sixth_time',my_row) : + await self.createRecord(my_row, 'مرتبه ششم', 'sixth_time', progress_id) + if self.if_set('seventh_time', my_row): + await self.createRecord(my_row, 'مرتبه هفتم', 'seventh_time', progress_id) + if self.if_set('eighth_time', my_row): + await self.createRecord(my_row, 'مرتبه هشتم', 'eighth_time', progress_id) + break + print("code", my_row['code']) return True async def addProgressFazOneUniversity(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_one.xlsx") - # df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="university", 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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) - # if not progress: - # progress = DesignProgressModel( - # project_id=my_project['_id'], - # type=3, - # state=my_row['state'] - # ) - # progress.init_id().cu_at() - # progress = progress.mongo_dict() - # await use_collection("design_progress").insert_one(progress) - # progress_type = DesignProgressModel( - # project_id=my_project['_id'], - # type=3, - # state=my_row['state'], - # parent_id=progress['_id'], - # sub_type=6, - # ) - # 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) - # break - # print("code", my_row['code']) + 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_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="university", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + my_project = p + progress_id = None + # if my_row['first_time/send/date_at'] and my_row['first_time/send/date_at'] != "": + progress = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=6, + ) + 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 progress_id: + if self.if_set('second_time', my_row): + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time', my_row): + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time', my_row): + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if self.if_set('fifth_time', my_row): + await self.createRecord(my_row, 'مرتبه پنجم', 'fifth_time', progress_id) + break + print("code", my_row['code']) return True async def addProgressFazOneAll(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_one.xlsx") - # df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="university", 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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) - # if not progress: - # progress = DesignProgressModel( - # project_id=my_project['_id'], - # type=3, - # state=my_row['state'] - # ) - # progress.init_id().cu_at() - # progress = progress.mongo_dict() - # await use_collection("design_progress").insert_one(progress) - # progress_type = DesignProgressModel( - # project_id=my_project['_id'], - # type=3, - # state=my_row['state'], - # parent_id=progress['_id'], - # sub_type=7, - # ) - # 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) - # - # break - # print("code", my_row['code']) + 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_one.xlsx") + df = pd.read_excel(excel_path, engine="openpyxl", sheet_name="all", 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(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 = await use_collection("design_progress").find_one({'project_id':my_project['_id'],'type':3}) + if not progress: + progress = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'] + ) + progress.init_id().cu_at() + progress = progress.mongo_dict() + await use_collection("design_progress").insert_one(progress) + progress_type = DesignProgressModel( + project_id=my_project['_id'], + type=3, + state=my_row['state'], + parent_id=progress['_id'], + sub_type=7, + ) + 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 progress_id: + if self.if_set('second_time', my_row): + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time', my_row): + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + + break + print("code", my_row['code']) return True # طراحی دوربین و شبکه 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']) + 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("code", my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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']) + 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("code",my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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 progress_id: + if self.if_set('second_time', my_row): + await self.createRecord(my_row, 'مرتبه دوم', 'second_time', progress_id) + if self.if_set('third_time', my_row): + await self.createRecord(my_row, 'مرتبه سوم', 'third_time', progress_id) + if self.if_set('forth_time', my_row): + await self.createRecord(my_row, 'مرتبه جهارم', 'forth_time', progress_id) + if self.if_set('fifth_time', my_row): + 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']) + 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("code",my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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 self.if_set('second_time', my_row): + 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']) + 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("code",my_row['code']) + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + 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 changeStatusWithMetri(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() + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + print("code", my_row['code']) + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(row_code)): + await use_collection('project').update_one({"_id": p["_id"]}, {"$set": { + 'design.sts': 4 + }}) + sts_class = ProjectSts( + project_id=p["_id"], + type='design', + sts=4, + ).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 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']) + 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() + if my_row['code'].startswith("D"): + row_code = my_row['code'][1:] + else: + row_code = my_row['code'] + print("code",my_row['code']) + for p in projects: + if str(row_code) in str(p['design']["code"]) and p['counter'] == int(str(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 @@ -780,27 +843,43 @@ class ExcelRepository(): case '12': return 'اسفند' - 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 f'{_time_e}/receive/date_at' in my_row and my_row[f'{_time_e}/receive/date_at'] != "": - print(my_row[f'{_time_e}/receive/date_at']) + + # Helper برای گرفتن تاریخ صحیح یا None + def safe_date(key): + value = my_row.get(key) + return self.createDate(value) if value else None + + # SEND + send_date_key = f'{_time_e}/send/date_at' + send_number_key = f'{_time_e}/send/number' + + if my_row.get(send_date_key) or my_row.get(send_number_key): + send = SubRecord( + date_at=safe_date(send_date_key), + number=my_row.get(send_number_key), + description=None + ) + record.send = send + + # RECEIVE + recv_date_key = f'{_time_e}/receive/date_at' + recv_number_key = f'{_time_e}/receive/number' + + if my_row.get(recv_date_key) or my_row.get(recv_number_key): receive = SubRecord( - date_at=self.createDate(my_row[f'{_time_e}/receive/date_at']), - number=my_row[f'{_time_e}/receive/number'], + date_at=safe_date(recv_date_key), + number=my_row.get(recv_number_key), description=None ) record.receive = receive + record.init_id().cu_at() + print('record1111111111111111',record) await use_collection("design_progress_record").insert_one(record.mongo_dict()) return record @@ -1138,3 +1217,12 @@ class ExcelRepository(): send['avg'] = {} return send + def if_set(self, rank, my_row): + fields = [ + f'{rank}/send/date_at', + f'{rank}/send/number', + f'{rank}/receive/date_at', + f'{rank}/receive/number' + ] + return any(my_row.get(field) not in ("", None) for field in fields) + diff --git a/app/repositories/project.py b/app/repositories/project.py index dc9f0af..0b1fdea 100644 --- a/app/repositories/project.py +++ b/app/repositories/project.py @@ -66,14 +66,14 @@ class ProjectRepository(BaseRepository[ProjectModel]): async def create(self, coding: ProjectModel): coding.counter = 1 - last_project = await use_collection(COLLECTION).find({}).sort("$natural", -1).to_list(None) + last_project = await use_collection(COLLECTION).find({}).sort("counter", -1).to_list(None) if last_project: coding.counter = last_project[0]["counter"] + 1 code = self.create_code(coding) - coding.design.code = 'D' + code + coding.design.code = code coding.init_id().cu_at() if coding.monitor: - coding.monitor.code = 'S' + code + coding.monitor.code = code coding.has_monitor = True await self.create_report_price(coding) if coding.monitor.detail.date_create_project and coding.monitor.detail.first_time: @@ -95,12 +95,12 @@ class ProjectRepository(BaseRepository[ProjectModel]): old_project = ProjectModel(**old_project_dict) if update.monitor and not old_project.monitor: code = self.create_code(update) - update.monitor.code = 'S' + code + update.monitor.code = code if update.design.nature != old_project.design.nature or update.design.type != old_project.design.type: code = self.create_code(update) - update.design.code = 'D' + code + update.design.code = code if update.monitor: - update.monitor.code = 'S' + code + update.monitor.code = code if update.monitor: update.has_monitor = True await self.update_report_price(update) diff --git a/app/urls/excel.py b/app/urls/excel.py index 9dfb247..c0bc647 100644 --- a/app/urls/excel.py +++ b/app/urls/excel.py @@ -18,9 +18,9 @@ def design(): def monitor(): pass -@router.get('/progress1', tags=_tag_base) -@shrink(repo.addProgress1) -def addProgress1(): +@router.get('/progress/madarek', tags=_tag_base) +@shrink(repo.madarek) +def madarek(): pass @router.get('/progress/physical', tags=_tag_base) @@ -89,6 +89,11 @@ def addProgressTender(): def changeStatus(): pass +@router.get('/change/design/metri/sts', tags=_tag_base) +@shrink(repo.changeStatusWithMetri) +def changeStatusWithMetri(): + pass + @router.get('/progress/monitor/physical', tags=_tag_base) @shrink(repo.progressMonitorPhysical) def progressMonitor(): diff --git a/config.yml b/config.yml index 77b555a..43777d2 100644 --- a/config.yml +++ b/config.yml @@ -4,7 +4,7 @@ auth: algorithm: 'HS256' access_token_expire_minutes: 43201 refresh_token_expire_minutes: 43200 - url: 'https://auth.hacoupian.net/v2/auth/validate-token' + url: 'http://pm.khanesaziceco.ir/api/api/me' cache_prefix_key: 'auth_key_' cache_ttl: 360 @@ -68,11 +68,11 @@ database: db: 'omde' limiter_redis: - url: 'redis://192.168.15.76:6379' + url: 'redis://172.16.1.194:6379' db: '' auth_redis: - url: 'redis://192.168.15.231:6379' + url: 'redis://172.16.1.194:6379' db: '1' neo4j: diff --git a/core/utils/auth/__init__.py b/core/utils/auth/__init__.py index 53feea4..16eb440 100644 --- a/core/utils/auth/__init__.py +++ b/core/utils/auth/__init__.py @@ -23,9 +23,8 @@ async def validate_token(_input: ValidateTokenInput): _cache_auth = await redis_get(f'{conf.auth.cache_prefix_key}{_cache_key}', conf.database.get('auth_redis')) if not _cache_auth: client = httpx.AsyncClient() - headers = {'Content-Type': 'application/json', } - - result = await client.request('POST', conf.auth.url, json=_input.dict(), headers=headers) + headers = {'Content-Type': 'application/json', 'Authorization':'Bearer '+_input.token} + result = await client.request('GET', conf.auth.url, json=_input.dict(), headers=headers) export = result.text if 'application/json' in result.headers['content-type']: export = result.json() @@ -35,6 +34,7 @@ async def validate_token(_input: ValidateTokenInput): if 'v2' in conf.auth.url: export = export.get('data') + print(export) await redis_set(f'{conf.auth.cache_prefix_key}{_cache_key}', export, conf.database.get('auth_redis'), ex=conf.auth.cache_ttl) diff --git a/core/utils/auth/model.py b/core/utils/auth/model.py index fb55182..b3eeaef 100644 --- a/core/utils/auth/model.py +++ b/core/utils/auth/model.py @@ -8,12 +8,12 @@ from core.models.base import BaseModel class UserModel(BaseModel): - id: Optional[Union[uuid.UUID, str]] = Field(alias='_id') + id: Optional[Union[uuid.UUID, str, int]] = Field(alias='_id') username: Optional[str] mobile: Optional[str] name: Optional[str] - first_name: Optional[str] - last_name: Optional[str] + fname: Optional[str] + lname: Optional[str] is_su: Optional[bool] unit: Optional[str] avatar: Optional[str]