766 lines
47 KiB
Python
766 lines
47 KiB
Python
import datetime
|
|
import uuid
|
|
|
|
import pandas as pd
|
|
import os
|
|
|
|
from app.config import TaskEnv
|
|
from app.models.design_progress import DesignProgressModel, RecordModel, SubRecord, Record, UpdateDesignProgress
|
|
from app.models.project import ProjectModel, ProjectSts
|
|
from core.service.mongo_db import use_collection
|
|
import jdatetime
|
|
from app.repositories.project import ProjectRepository
|
|
from app.repositories.design_progress import DesignProgressRepository
|
|
|
|
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, "../..")) # رفتن به ریشه پروژه
|
|
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_send':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)
|
|
if my_row['letter'] and pd.notna(row['letter']):
|
|
p['design']["letter"] = my_row["letter"]
|
|
if my_row['date_send'] and pd.notna(row['date_send']):
|
|
year = int(my_row['date_send'][:4])
|
|
month = int(my_row['date_send'][4:6])
|
|
day = int(my_row['date_send'][6:8])
|
|
jalali_date = jdatetime.date(year, month, day)
|
|
gregorian_date = jalali_date.togregorian()
|
|
created_at = datetime.datetime.combine(gregorian_date, datetime.time())
|
|
p['design']['date_send'] = created_at
|
|
if my_row['land_area'] and pd.notna(row['land_area']):
|
|
p['design']["land_area"] = my_row["land_area"]
|
|
if my_row['building_infrastructure'] and pd.notna(row['building_infrastructure']):
|
|
p['design']["building_infrastructure"] = my_row["building_infrastructure"]
|
|
if my_row['site_area'] and pd.notna(row['site_area']):
|
|
p['design']["site_area"] = my_row["site_area"]
|
|
if my_row['designer'] and pd.notna(row['designer']):
|
|
p['design']["designer"] = [my_row["designer"]]
|
|
p['design']["sts"] = 2
|
|
|
|
await use_collection(TaskEnv.CLN_PROJECT).update_one({'counter':int(my_row["code"])},{"$set":{'design':p['design']}})
|
|
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})
|
|
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'])
|
|
|
|
# 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'])
|
|
|
|
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'])
|
|
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'])
|
|
|
|
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'])
|
|
|
|
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'])
|
|
#----------------------------------------------------------------------------------------
|
|
# 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'])
|
|
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'])
|
|
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'])
|
|
# طراحی دوربین و شبکه
|
|
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)
|
|
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 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'])
|
|
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
|