143 lines
8.8 KiB
Python
143 lines
8.8 KiB
Python
import datetime
|
|
import uuid
|
|
|
|
import pandas as pd
|
|
import os
|
|
|
|
from app.config import TaskEnv
|
|
from app.models.project import ProjectModel
|
|
from core.service.mongo_db import use_collection
|
|
import jdatetime
|
|
from app.repositories.project import ProjectRepository
|
|
|
|
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 |