diff --git a/Generate_Report.py b/Generate_Report.py index fd42563..692aea6 100644 --- a/Generate_Report.py +++ b/Generate_Report.py @@ -16,10 +16,16 @@ from tools.get_pictures import ( process_picture_data ) -from tools.Get_Json import (get_project_info,get_jizu_info, - get_jizu_shigong_info,get_weather, - get_picture) +from tools.Get_Json import ( + get_project_info,get_jizu_info, + get_jizu_shigong_info,get_weather, + get_part_picture +) +from tools.dataproccess import ( + caculate_work_days,add_dynamic_table, + get_year_month,merge_info, +) import asyncio @@ -29,91 +35,6 @@ from tools.defines import * import os, re, datetime from pathlib import Path -async def add_dynamic_table(output_doc, output_dir, table_num, TABLES, JIANCHA_XIANGQING_DIR, PICTURES, row, col, i, FLAG, xuhao): - """创建动态表 - - Args: - output_doc (Document): 文档对象 - output_dir (str): 输出目录 - table_num (int): 表格序号 - TABLES (list): 表格数据 - JIANCHA_XIANGQING_DIR (str): 检查详情表目录 - PICTURES (dict): 图片数据字典,键为表索引,值为图片路径列表 - row (int): 行数 - col (int): 列数 - i (int): 表格序号 - FLAG: 其他标志 - - Returns: - tuple: (i, table_num) 更新后的表格序号和表格数量 - """ - for table_idx, Table in enumerate(TABLES): - print(Table) - output_doc, message = await add_table_to_document(output_dir, JIANCHA_XIANGQING_DIR, row, col, i, Table, FLAG) - print(message) - - # 获取当前表格对应的图片 - current_table_pictures = PICTURES.get(table_idx, []) - print(f"开始处理图片列表: {current_table_pictures}") - - for picturedir in current_table_pictures: - try: - print(f"添加 {picturedir} {type(picturedir)}到表格{table_idx}") - resize_and_reduce_quality(picturedir, picturedir) - await add_picture_to_table(output_doc, output_dir, 4, 0, picturedir, i, 4.7232) - except Exception as e: - print(f"添加图片失败:{e}") - - print(await search_and_replace(output_dir, 'tupian_xuhao', f'{xuhao}')) - table_num += 1 - i += 1 - xuhao += 1 - return i, table_num, xuhao - -def get_year_month(date): - """根据格式化date字符串获取年月 'date': '二〇二一年十二月十日 9:00' - - Args: date (str): 日期字符串 - - Returns: 年月字符串 '二〇二一年十二月' - """ - unit_map = {'1' : '一', '2' : '二', '3' : '三', '4' : '四', '5' : '五', '6' : '六', '7' : '七', '8' : '八', '9' : '九', '0' : '〇'} - unit_map_month = {1 : '一', 2 : '二', 3 : '三', 4 : '四', 5 : '五', 6 : '六', 7 : '七', 8 : '八', 9 : '九', 10 : '十', 11 : '十一', 12 : '十二'} - year = date.split('年')[0] - month = date.split('年')[1].split('月')[0] - year = ''.join([unit_map[i] for i in year]) - month = unit_map_month[int(month)] - return f"{year}年{month}月" - -def merge_info(frontend_info, default_info): - """ - 合并前端传入的 info 和默认 info - 规则:如果前端传入的值为空(None 或空字符串),则使用默认值 - - Args: - frontend_info: 前端传入的字典 - default_info: 默认的完整字典 - Returns: - 合并后的完整字典 - """ - if not isinstance(frontend_info, dict) or frontend_info is None: - return default_info.copy() - - merged_info = {} - - for key, default_value in default_info.items(): - # 获取前端传入的值 - frontend_value = frontend_info.get(key) - - # 判断前端值是否为空(None 或空字符串) - if frontend_value is None or frontend_value == "": - merged_info[key] = default_value - else: - merged_info[key] = frontend_value - - return merged_info - - async def generate_report(base_info, baogao_info): #获取模板编号、模板名称 num_to_chinese = {1 : '一', 2 : '二', 3 : '三', 4 : '四', 5 : '五', 6 : '六', 7 : '七', 8 : '八', 9 : '九', 10 : '十', 11 : '十一', 12 : '十二'} @@ -130,6 +51,7 @@ async def generate_report(base_info, baogao_info): jizu_data = get_jizu_info(turbine_id) project_data = get_project_info(jizu_data['projectId']) shigong_data = get_jizu_shigong_info(turbine_id) + try: fengchang_name = project_data['farmName'] Yi_company = project_data['inspectionUnit'] @@ -141,13 +63,18 @@ async def generate_report(base_info, baogao_info): jia_phone = project_data['clientPhone'] jizu_num = project_data['scale'] jizu_xinghao = project_data['turbineModel'] + project_name = project_data['projectName'] + jizu_bianhao = jizu_data["turbineName"] + start_date = project_data['startDate'] + end_date = project_data['endDate'] + gongqi = caculate_work_days(start_date, end_date) except Exception as e: print(f"数据库的项目-机组基本信息获取失败:{e}") return try: baogao_date = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M") #现在的时间 - + date_year_month = get_year_month(baogao_date) #前端信息 baogao_info = merge_info(baogao_info, DEFAULT_BAOGAO_INFO) @@ -160,14 +87,6 @@ async def generate_report(base_info, baogao_info): if_waibu = baogao_info["if_waibu"] if_neibu = baogao_info["if_neibu"] if_fanglei = baogao_info["if_fanglei"] - image_source_to_find = [] - #获取对应枚举字段 - if if_waibu: - image_source_to_find.append(baogao_info['waibu_enum']) - if if_neibu: - image_source_to_find.append(baogao_info['neibu_enum']) - if if_fanglei: - image_source_to_find.append(baogao_info['fanglei_enum']) quexian_type = baogao_info['quexian_enum'] @@ -176,58 +95,100 @@ async def generate_report(base_info, baogao_info): #数据库拉取信息 Jiancha_date = shigong_data["startTime"].replace("T", " ") #检查日期 - image_count = shigong_data['imageCount'] #从施工方案获取的图片数量,待定 + image_count = shigong_data['imageCount'] #从施工方案获取的图片数量,待定!!! temperature = shigong_data['temperature'] #温度 wind_speed = shigong_data['windSpeed'] #风速 - weather = get_weather(shigong_data["weatherCode"]) #天气 - #拉取图片数据 - picture_data = get_picture(turbine_id) + weather = get_weather(shigong_data["weatherCode"]) #天气 不从此接口获取,待定!!! + + #拉取部件、图片数据 + part_data, picture_data = get_part_picture(turbine_id) + + #获取叶片信息 + print(part_data) + Yepians = [] + yepian_to_find = ["叶片1","叶片2","叶片3"] + #依次获取叶片1,2,3的信息(未考虑多个同叶片的信息情况,正常情况下不会发生) + for name in yepian_to_find: + # 找到第一个匹配的部件并添加到列表中 + for part in part_data: + if part['partName'] == name: + Yepians.append(part) + print(Yepians) + print(f"找到叶片号{[yepian["partCode"] for yepian in Yepians]}") + Y_Code = [yepian["partCode"] for yepian in Yepians] + + image_source_to_find = [] + baogao_label = [] + renyuan_peizhi = [] + gongzuo_neirong = [] + shigong_fangan = [] + shebei_peizhi = [] + beizhu = [] + jiancha = [] + neirong = [] + #获取对应枚举字段 + if if_waibu: + baogao_label.append("外观") + image_source_to_find.append(baogao_info['waibu_enum']) + if baogao_info["shigong_fangan"] == "None": + print("未传入施工方案,使用已有枚举") + renyuan_peizhi.append(SHIGONG_FANGAN_ENUM.WAIBU.RENYUAN_PEIZHI) + gongzuo_neirong.append(SHIGONG_FANGAN_ENUM.WAIBU.GONGZUO_NEIRONG) + shebei_peizhi.append(SHIGONG_FANGAN_ENUM.WAIBU.SHEBEI_PEIZHI) + shigong_fangan.append(SHIGONG_FANGAN_ENUM.WAIBU.SHIGONG_FANGAN) + else: + pass #待添加如果从平台传入枚举,但目前没必要,如果这种枚举标准信息库有更好的优化则可以实现 + jiancha.append("无人机近距离外观检查") + neirong.append(f"、".join(Y_Code) + "三支叶片的前缘、后缘、迎风面、背风面。") + if if_neibu: + baogao_label.append("内部") + image_source_to_find.append(baogao_info['neibu_enum']) + if baogao_info["shigong_fangan"] == "None": + renyuan_peizhi.append(SHIGONG_FANGAN_ENUM.NEIBU.RENYUAN_PEIZHI) + gongzuo_neirong.append(SHIGONG_FANGAN_ENUM.NEIBU.GONGZUO_NEIRONG) + shebei_peizhi.append(SHIGONG_FANGAN_ENUM.NEIBU.SHEBEI_PEIZHI) + shigong_fangan.append(SHIGONG_FANGAN_ENUM.NEIBU.SHIGONG_FANGAN) + else: + pass + jiancha.append("人工内部拍摄") + neirong.append(f"、".join(Y_Code) + "三支叶片的内部导雷卡、腹板、透光、人孔盖版、叶根盖板...") + if if_fanglei: + baogao_label.append("防雷") + image_source_to_find.append(baogao_info['fanglei_enum']) + if baogao_info["shigong_fangan"] == "None": + renyuan_peizhi.append(SHIGONG_FANGAN_ENUM.FANGLEI.YEPIAN.RENYUAN_PEIZHI) + gongzuo_neirong.append(SHIGONG_FANGAN_ENUM.FANGLEI.YEPIAN.GONGZUO_NEIRONG) + shebei_peizhi.append(SHIGONG_FANGAN_ENUM.FANGLEI.YEPIAN.SHEBEI_PEIZHI) + shigong_fangan.append(SHIGONG_FANGAN_ENUM.FANGLEI.YEPIAN.SHIGONG_FANGAN) + else: + pass + jiancha.append("人工防雷") + neirong.append(f"轮毂至塔基导通、内部导线线阻、外部导线线阻...") + #获取缺陷图列表和典型图列表 - defect_pictures, typical_pictures = process_picture_data(picture_data, image_source_to_find) - #处理图片数据 + defect_pictures, typical_pictures = process_picture_data(picture_data, image_source_to_find, quexian_type, dianxing_type) + print(f"\n\n\n缺陷图片列表:{defect_pictures}\n\n\n典型图片列表:{typical_pictures}\n\n\n") + + #处理图片数据待完成,图片绑定施工后 + defect_pictures_id = [pic for pic in defect_pictures] - date_year_month = get_year_month(baogao_date) - - project_number = baogao_info['jizu_type'] - baogao_type = baogao_info['baogao_type'] - Jiancha_renyuan = baogao_info['jiancha_renyuan'] - shebei_peizhi = baogao_info['shebei_peizhi'] - shigong_fangan = baogao_info['shigong_fangan'] - renyuan_peizhi = baogao_info['renyuan_peizhi'] - gongzuo_neirong = baogao_info['gongzuo_neirong'] - beizhu = baogao_info['beizhu'] - - Jiancha_location = baogao_info['jiancha_location'] - Jiancha_fangshi = baogao_info['jiancha_fangshi'] - Changjia = baogao_info['yepian_changjia'] - - yezhu_renyuan = baogao_info['yezhu_renyuan'] - changjia_renyuan = baogao_info['changjia_renyuan'] - data_process = baogao_info['date_process'] - baogao_bianzhi = baogao_info['baogao_bianzhi'] - baogao_shenghe = baogao_info['baogao_shenghe'] - shenghe_date = baogao_info['shenghe_date'] - - Y1_jiancha = baogao_info['Y1_jiancha_neirong'] - Y2_jiancha = baogao_info['Y2_jiancha_neirong'] - Y3_jiancha = baogao_info['Y3_jiancha_neirong'] + baogao_bianzhi = baogao_info["userName"] + baogao_shenghe = baogao_info["baogaoCheck"] except Exception as e: print(f"报告基本信息获取失败:{e}") return normal_picture_num = 0 - Y1 = "t" - Y2 = "t" - Y3 = "t" output_doc = None head_num = 1 ###封面创建### cover_dirs = [os.path.join(muban_dir,"fengmian1.docx"),os.path.join(muban_dir,"fengmian.jpg"),os.path.join(muban_dir,"fengmian2.docx")] #输出目录 - output_dir = os.path.normpath(f"{shengcheng_dir}/{fengchang_name}项目{baogao_type}{project_number}{baogao_date.split(' ')[0]}版.docx") + baogao_name = "叶片" + "、".join(baogao_label) + output_dir = os.path.normpath(f"{shengcheng_dir}/{project_name}项目{baogao_name}{jizu_bianhao}{baogao_date.split(' ')[0]}版.docx") version = 1 while os.path.exists(output_dir): @@ -237,19 +198,7 @@ async def generate_report(base_info, baogao_info): output_dir = output_dir.replace("版",f"版{version}") version += 1 - ifwaibu = baogao_info['waibu_jiancha'] - ifneibu = baogao_info['neibu_jiancha'] - iffanglei = baogao_info['fanglei_jiancha'] - parts = [] - if ifwaibu: - parts.append("叶片外观") - if ifneibu: - parts.append("叶片内部") - if iffanglei: - parts.append("叶片防雷") - if not parts: - print("前端未指定检查内容") - mianzhe_shengming = f"本报告仅涵盖{'、'.join(parts)}检测内容" + mianzhe_shengming = f"本报告仅涵盖{'、'.join(baogao_label)}检测内容" #创建文档、添加封面 print(await create_document(output_dir)) @@ -259,12 +208,12 @@ async def generate_report(base_info, baogao_info): print("封面创建成功") #更改文档信息 - print(await search_and_replace(output_dir, TITLE_OF_REPORT, project_number)) - print(await search_and_replace(output_dir, baogao_name1, baogao_type)) - print(await search_and_replace(output_dir, baogao_name2, baogao_type)) + print(await search_and_replace(output_dir, TITLE_OF_REPORT, jizu_bianhao)) + print(await search_and_replace(output_dir, baogao_name1, baogao_name)) + print(await search_and_replace(output_dir, baogao_name2, baogao_name)) print(await search_and_replace(output_dir, company_name_yi, Yi_company)) print(await search_and_replace(output_dir, cover_project, fengchang_name)) - print(await search_and_replace(output_dir, cover_encode, project_number)) + print(await search_and_replace(output_dir, cover_encode, jizu_bianhao)) print(await search_and_replace(output_dir, cover_date, date_year_month)) print(await search_and_replace(output_dir, 'bianzhi', baogao_bianzhi)) print(await search_and_replace(output_dir, 'shenghe', baogao_shenghe)) @@ -279,20 +228,22 @@ async def generate_report(base_info, baogao_info): company_name_jia = Jia_company fuzeren = yi_fuzeren phone_fuzeren = yi_phone - jizu_bianhao = project_number xiangmuguige = jizu_num Yi_company = Yi_company - XIANGMU_GAIKUO = list(list("" for i in range(5)) for j in range(5)) + XIANGMU_GAIKUO = list(list("" for i in range(6)) for j in range(5)) XIANGMU_GAIKUO[0][1] = fengchang_name #XIANGMU_GAIKUO[0][3]=XIANGMU_GAIKUO[0][4] = "盐城市滨海县" - XIANGMU_GAIKUO[0][3] = project_location + XIANGMU_GAIKUO[0][4] = project_location #XIANGMU_GAIKUO[1][1]=XIANGMU_GAIKUO[2,1]=XIANGMU_GAIKUO[3,1] = "国家电投集团滨海风力发电有限公司" XIANGMU_GAIKUO[1][1] = company_name_jia - XIANGMU_GAIKUO[1][3] = Yi_company - XIANGMU_GAIKUO[2][3] = fuzeren - XIANGMU_GAIKUO[3][4] = phone_fuzeren + XIANGMU_GAIKUO[1][4] = Yi_company + XIANGMU_GAIKUO[2][1] = jia_fuzeren + XIANGMU_GAIKUO[2][4] = fuzeren + XIANGMU_GAIKUO[3][2] = jia_phone + XIANGMU_GAIKUO[3][5] = phone_fuzeren XIANGMU_GAIKUO[4][1] = jizu_xinghao - XIANGMU_GAIKUO[4][4] = xiangmuguige + XIANGMU_GAIKUO[4][3] = xiangmuguige + XIANGMU_GAIKUO[4][5] = gongqi print("建立表结构完毕,开始插入模板") #添加项目概况表 print(f"输出路径:{output_dir},模板路径:{XIANG_MU_GAI_KUANG},插入数据:{XIANGMU_GAIKUO}") @@ -306,10 +257,10 @@ async def generate_report(base_info, baogao_info): #检查方案描述 FANGAN_JIANCHA_DIR = os.path.join(muban_dir,"checkmethod.docx") list_to_replace = { - 'renyuan_peizhi' : renyuan_peizhi, - 'shebei_peizhi' : shebei_peizhi, - 'shigong_fangan' : shigong_fangan, - 'gongzuo_neirong' : gongzuo_neirong, + 'renyuan_peizhi' : "\n".join(renyuan_peizhi), + 'shebei_peizhi' : "\n".join(shebei_peizhi), + 'shigong_fangan' : "\n".join(shigong_fangan), + 'gongzuo_neirong' : "\n".join(gongzuo_neirong), 'beizhu' : beizhu, 'num' : num_to_chinese[head_num], } @@ -318,30 +269,19 @@ async def generate_report(base_info, baogao_info): total_table_num += 1 head_num += 1 - jiancha = [] - neirong = [] - if ifwaibu: - jiancha.append("无人机外部高精度飞行") - neirong.append(f"{Y1}、{Y2}、{Y3}三支叶片的前缘、后缘、迎风面、背风面。") - if ifneibu: - jiancha.append("人工内部拍摄") - neirong.append(f"{Y1}、{Y2}、{Y3}三支叶片的内部导雷卡、腹板、透光、人孔盖版、叶根盖板...") - if iffanglei: - jiancha.append("人工防雷") - neirong.append(f"轮毂至塔基导通、内部导线线阻、外部导线线阻...") JIANCHA_XINGXI_DIR = os.path.join(muban_dir,"checkinfo.docx") JIANCHA_XINGXI = list(list("" for i in range(4)) for j in range(9)) - JIANCHA_XINGXI[0][1] = Jiancha_renyuan + JIANCHA_XINGXI[0][1] = "" JIANCHA_XINGXI[1][1] = Jiancha_date.split(' ')[0] - JIANCHA_XINGXI[1][3] = project_number - JIANCHA_XINGXI[2][1] = Jiancha_location - JIANCHA_XINGXI[2][3] = Jiancha_fangshi - JIANCHA_XINGXI[3][2] = Changjia - JIANCHA_XINGXI[4][1] = '机组编号:' + project_number + '机组' - JIANCHA_XINGXI[5][1] = Y1 - JIANCHA_XINGXI[6][1] = Y2 - JIANCHA_XINGXI[7][1] = Y3 + JIANCHA_XINGXI[1][3] = jizu_bianhao + JIANCHA_XINGXI[2][1] = "风力发电机组" + baogao_name + JIANCHA_XINGXI[2][3] = "、".join(jiancha) + JIANCHA_XINGXI[3][2] = ""#需要使用查看叶片详情接口获取,待完成 + JIANCHA_XINGXI[4][1] = '机组编号:' + jizu_bianhao+ '机组' + JIANCHA_XINGXI[5][1] = Y_Code[0] + JIANCHA_XINGXI[6][1] = Y_Code[1] if len(Y_Code) > 1 else "" + JIANCHA_XINGXI[7][1] = Y_Code[2] if len(Y_Code) > 2 else "" JIANCHA_XINGXI[8][0] = "本次" + "、".join(_ for _ in jiancha) + f"检查,采集叶片图片{normal_picture_num}张,内容覆盖" + ";".join(_ for _ in neirong) # if total_picture_dir == "": # Thumbnail_Picture = await make_Thumbnail(Picture_dir, Picture_dir)#添加图片 @@ -540,6 +480,44 @@ def main(): json_data2 = { 'shengcheng_dir': r".\output", 'muban_dir': r".\muban", + # "shigong_fangan_enum" : { #可能放入标准信息库?但不论如何,修改了这个枚举的话,报告生成逻辑也要修改,待优化! + # "SHIGONG_FANGAN_ENUM": { + # "WAIBU": { + # "GONGZUO_NEIRONG": "无人机叶片外观巡检", + # "RENYUAN_PEIZHI": "1人;主检飞手1人", + # "SHEBEI_PEIZHI": "1、大疆无人机1台(M350rtk,M300rtk,M30T,M30,精灵4PRO)2、大疆精灵4PRO+索尼A7R2机身+索尼200-600mm镜头/适马150-600mm镜头", + # "SHIGONG_FANGAN": None + # }, + # "NEIBU": { + # "GONGZUO_NEIRONG": "叶片内部检查", + # "RENYUAN_PEIZHI": "2人;轮毂作业检查2人", + # "SHEBEI_PEIZHI": "1、人工检查:照明设备2套,视频记录手机2台,含氧量监测仪1台,电动扳手2套,卷尺1个。2、爬壁机器人检查:无人作业校车+视频图传1套,照明设备2套,含氧量监测仪1台,电动扳手2套,卷尺1个。", + # "SHIGONG_FANGAN": None + # }, + # "FANGLEI": { + # "YEPIAN": { + # "GONGZUO_NEIRONG": "无人机叶片防雷导通测试", + # "RENYUAN_PEIZHI": "2人;主检飞手1人,副检抄表1人", + # "SHEBEI_PEIZHI": "1四轴电阻无人机1套,电子微欧计1台,视频记录手机1台", + # "SHIGONG_FANGAN": None + # }, + # "DIAOLAN": { + # "GONGZUO_NEIRONG": "无人吊篮叶片导通测试(含机舱设备、)", + # "RENYUAN_PEIZHI": "3人,轮毂机舱作业1人,揽风绳作业1人,无人设备操作员及抄表1人", + # "SHEBEI_PEIZHI": "无人吊篮系统1套(爬绳器+接触平台)、电子微欧计1套,视频记录手机1台,对讲机2台", + # "SHIGONG_FANGAN": None + # }, + # "SHESHI": { + # "GONGZUO_NEIRONG": "风机基础、办公楼、变电站防雷接地检测及浪涌保护器测试", + # "RENYUAN_PEIZHI": "1人;抄表人员1人,检测人员1人,监护1人。", + # "SHEBEI_PEIZHI": "接地电阻测试仪1套、SPD测试仪1套、对讲机2个、", + # "SHIGONG_FANGAN": None + # }, + # "FEISHOURENYUAN_PEIZHI": "1人;主检飞手1人", + # "LUNGUZUOYERENYUAN_PEIZHI": "2人;轮毂作业检查2人" + # } + # } + # }, } asyncio.run(generate_report(json_data1,json_data2)) print('文档生成完毕') diff --git a/muban/xiangmugaikuo.docx b/muban/xiangmugaikuo.docx index ee39cf2..5662b94 100644 Binary files a/muban/xiangmugaikuo.docx and b/muban/xiangmugaikuo.docx differ diff --git a/output/三峡能源阿城万兴风电场防雷通道检测项目项目叶片外观、内部、防雷一期012号2025年07月08日版3.docx b/output/三峡能源阿城万兴风电场防雷通道检测项目项目叶片外观、内部、防雷一期012号2025年07月08日版3.docx new file mode 100644 index 0000000..eb657f2 Binary files /dev/null and b/output/三峡能源阿城万兴风电场防雷通道检测项目项目叶片外观、内部、防雷一期012号2025年07月08日版3.docx differ diff --git a/tools/Get_Json.py b/tools/Get_Json.py index 7334787..0b55c19 100644 --- a/tools/Get_Json.py +++ b/tools/Get_Json.py @@ -47,18 +47,19 @@ def get_part_list(turbineId : str) -> dict: "turbineId" : turbineId } result = get_data(parturl, params = params) - result = [item["partId"] for item in result] print(f"获取到部件{result}") - return result + return result, [item["partId"] for item in result] -def get_picture(turbineId : str) -> list[dict]: +def get_part_picture(turbineId : str) -> tuple[list[dict], list[dict]]: """获取对应机组所有图片 Args: turbineId (str): 机组ID Return: + list: 包含所有对应机组的部件信息的列表 + list: 包含所有图片信息的列表(按部件分list) [ { @@ -90,7 +91,7 @@ def get_picture(turbineId : str) -> list[dict]: ] """ picturerul = DTURL + GETPICTURELIST - part_list = get_part_list(turbineId) + part_data, part_list = get_part_list(turbineId) result = [] for part_id in part_list: params = { @@ -99,7 +100,7 @@ def get_picture(turbineId : str) -> list[dict]: for images in get_data(picturerul, params = params): result.append(images) print(f"图片数据获取成功:{result}") - return result + return part_data, result def find_defect_record(defect_pictures : list[dict]): """查找缺陷图片的缺陷记录 diff --git a/tools/__pycache__/API.cpython-313.pyc b/tools/__pycache__/API.cpython-313.pyc index 275947e..23f7340 100644 Binary files a/tools/__pycache__/API.cpython-313.pyc and b/tools/__pycache__/API.cpython-313.pyc differ diff --git a/tools/__pycache__/Get_Json.cpython-313.pyc b/tools/__pycache__/Get_Json.cpython-313.pyc index f884804..0a79772 100644 Binary files a/tools/__pycache__/Get_Json.cpython-313.pyc and b/tools/__pycache__/Get_Json.cpython-313.pyc differ diff --git a/tools/__pycache__/dataproccess.cpython-313.pyc b/tools/__pycache__/dataproccess.cpython-313.pyc new file mode 100644 index 0000000..9bfc738 Binary files /dev/null and b/tools/__pycache__/dataproccess.cpython-313.pyc differ diff --git a/tools/__pycache__/defines.cpython-313.pyc b/tools/__pycache__/defines.cpython-313.pyc index 3bbad01..f98d6dc 100644 Binary files a/tools/__pycache__/defines.cpython-313.pyc and b/tools/__pycache__/defines.cpython-313.pyc differ diff --git a/tools/__pycache__/get_pictures.cpython-313.pyc b/tools/__pycache__/get_pictures.cpython-313.pyc index 1fe9702..ab09f33 100644 Binary files a/tools/__pycache__/get_pictures.cpython-313.pyc and b/tools/__pycache__/get_pictures.cpython-313.pyc differ diff --git a/tools/dataproccess.py b/tools/dataproccess.py new file mode 100644 index 0000000..cb37f1f --- /dev/null +++ b/tools/dataproccess.py @@ -0,0 +1,106 @@ +from tools.content_tools import add_picture_to_table +from tools.document_tools import add_table_to_document,search_and_replace +from tools.get_pictures import resize_and_reduce_quality + +def caculate_work_days(start_date : str, end_date : str) -> str: + """根据起止日期计算工期 + + Args: + start_date (str): 格式: yyyy-mm-ddThh:mm:ss + end_date (str): 格式: yyyy-mm-ddThh:mm:ss + + Returns: + str: 计算出来的总工期,单位为天 + """ + import datetime + if start_date == None or end_date == None: + return f"开始时间{start_date} ---- 结束时间{end_date} 日期格式错误" + + start_date = datetime.datetime.strptime(start_date, '%Y-%m-%dT%H:%M:%S') + end_date = datetime.datetime.strptime(end_date, '%Y-%m-%dT%H:%M:%S') + + return (end_date - start_date).days + +async def add_dynamic_table(output_doc, output_dir, table_num, TABLES, JIANCHA_XIANGQING_DIR, PICTURES, row, col, i, FLAG, xuhao): + """创建动态表 + + Args: + output_doc (Document): 文档对象 + output_dir (str): 输出目录 + table_num (int): 表格序号 + TABLES (list): 表格数据 + JIANCHA_XIANGQING_DIR (str): 检查详情表目录 + PICTURES (dict): 图片数据字典,键为表索引,值为图片路径列表 + row (int): 行数 + col (int): 列数 + i (int): 表格序号 + FLAG: 其他标志 + + Returns: + tuple: (i, table_num) 更新后的表格序号和表格数量 + """ + for table_idx, Table in enumerate(TABLES): + print(Table) + output_doc, message = await add_table_to_document(output_dir, JIANCHA_XIANGQING_DIR, row, col, i, Table, FLAG) + print(message) + + # 获取当前表格对应的图片 + current_table_pictures = PICTURES.get(table_idx, []) + print(f"开始处理图片列表: {current_table_pictures}") + + for picturedir in current_table_pictures: + try: + print(f"添加 {picturedir} {type(picturedir)}到表格{table_idx}") + resize_and_reduce_quality(picturedir, picturedir) + await add_picture_to_table(output_doc, output_dir, 4, 0, picturedir, i, 4.7232) + except Exception as e: + print(f"添加图片失败:{e}") + + print(await search_and_replace(output_dir, 'tupian_xuhao', f'{xuhao}')) + table_num += 1 + i += 1 + xuhao += 1 + return i, table_num, xuhao + +def get_year_month(date): + """根据格式化date字符串获取年月 'date': '二〇二一年十二月十日 9:00' + + Args: date (str): 日期字符串 + + Returns: 年月字符串 '二〇二一年十二月' + """ + unit_map = {'1' : '一', '2' : '二', '3' : '三', '4' : '四', '5' : '五', '6' : '六', '7' : '七', '8' : '八', '9' : '九', '0' : '〇'} + unit_map_month = {1 : '一', 2 : '二', 3 : '三', 4 : '四', 5 : '五', 6 : '六', 7 : '七', 8 : '八', 9 : '九', 10 : '十', 11 : '十一', 12 : '十二'} + year = date.split('年')[0] + month = date.split('年')[1].split('月')[0] + year = ''.join([unit_map[i] for i in year]) + month = unit_map_month[int(month)] + return f"{year}年{month}月" + +def merge_info(frontend_info, default_info): + """ + 合并前端传入的 info 和默认 info + 规则:如果前端传入的值为空(None 或空字符串),则使用默认值 + + Args: + frontend_info: 前端传入的字典 + default_info: 默认的完整字典 + Returns: + 合并后的完整字典 + """ + if not isinstance(frontend_info, dict) or frontend_info is None: + return default_info.copy() + + merged_info = {} + + for key, default_value in default_info.items(): + # 获取前端传入的值 + frontend_value = frontend_info.get(key) + + # 判断前端值是否为空(None 或空字符串) + if frontend_value is None or frontend_value == "": + merged_info[key] = default_value + else: + merged_info[key] = frontend_value + + return merged_info \ No newline at end of file diff --git a/tools/defines.py b/tools/defines.py index ae59823..a8303ea 100644 --- a/tools/defines.py +++ b/tools/defines.py @@ -26,30 +26,49 @@ DEFAULT_BAOGAO_INFO = { "if_waibu" : True, "if_neibu" : True, "if_fanglei" : True, - + "userName" : "admin", + "baogaoCheck" : "未审核", 'key_words': '缺,损,裂,脱,污', #关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化 - #检查方案 - 'beizhu': '无', - 'renyuan_peizhi': '''2人;主检飞手1人,副检抄表1人 -3人,轮毂机舱作业1人,揽风绳作业1人,无人设备操作员及抄表1人 -1人;抄表人员1人,检测人员1人,监护1人。 -1人;主检飞手1人 -2人;轮毂作业检查2人''', - 'gongzuo_neirong': '''无人机叶片防雷导通测 -无人吊篮叶片导通测试(含机舱设备、) -风机基础、办公楼、变电站防雷接地检测及浪涌保护器测试 -无人机叶片外观巡检 -叶片内部检查''', - 'shigong_fangan': '无', - 'shebei_peizhi': '''1四轴电阻无人机1套,电子微欧计1台,视频记录手机1台 -无人吊篮系统1套(爬绳器+接触平台)、电子微欧计1套,视频记录手机1台,对讲机2台 -接地电阻测试仪1套、SPD测试仪1套、对讲机2个、 -1、大疆无人机1台(M350rtk,M300rtk,M30T,M30,精灵4PRO)2、大疆精灵4PRO+索尼A7R2机身+索尼200-600mm镜头/适马150-600mm镜头 -1、人工检查:照明设备2套,视频记录手机2台,含氧量监测仪1台,电动扳手2套,卷尺1个。2、爬壁机器人检查:无人作业校车+视频图传1套,照明设备2套,含氧量监测仪1台,电动扳手2套,卷尺1个。''', + "shigong_fangan" : "None", 'jiancha_renyuan': '张三', } - + +class JIANCHA_ENUM : + class WAIBU: + PART = "无人机外部高精度飞行" + #NEIRONG = + +class SHIGONG_FANGAN_ENUM : + class WAIBU: + GONGZUO_NEIRONG = "无人机叶片外观巡检" + RENYUAN_PEIZHI = "1人;主检飞手1人" + SHEBEI_PEIZHI = "1、大疆无人机1台(M350rtk,M300rtk,M30T,M30,精灵4PRO)2、大疆精灵4PRO+索尼A7R2机身+索尼200-600mm镜头/适马150-600mm镜头" + SHIGONG_FANGAN = "" + class NEIBU: + GONGZUO_NEIRONG = "叶片内部检查" + RENYUAN_PEIZHI = "2人;轮毂作业检查2人" + SHEBEI_PEIZHI = "1、人工检查:照明设备2套,视频记录手机2台,含氧量监测仪1台,电动扳手2套,卷尺1个。2、爬壁机器人检查:无人作业校车+视频图传1套,照明设备2套,含氧量监测仪1台,电动扳手2套,卷尺1个。" + SHIGONG_FANGAN = "" + class FANGLEI: + class YEPIAN: + GONGZUO_NEIRONG = "无人机叶片防雷导通测试" + RENYUAN_PEIZHI = "2人;主检飞手1人,副检抄表1人" + SHEBEI_PEIZHI = "1四轴电阻无人机1套,电子微欧计1台,视频记录手机1台" + SHIGONG_FANGAN = "" + class DIAOLAN: + GONGZUO_NEIRONG = "无人吊篮叶片导通测试(含机舱设备、)" + RENYUAN_PEIZHI = "3人,轮毂机舱作业1人,揽风绳作业1人,无人设备操作员及抄表1人" + SHEBEI_PEIZHI = "无人吊篮系统1套(爬绳器+接触平台)、电子微欧计1套,视频记录手机1台,对讲机2台" + SHIGONG_FANGAN = "" + class SHESHI: + GONGZUO_NEIRONG = "风机基础、办公楼、变电站防雷接地检测及浪涌保护器测试" + RENYUAN_PEIZHI = "1人;抄表人员1人,检测人员1人,监护1人。" + SHEBEI_PEIZHI = "接地电阻测试仪1套、SPD测试仪1套、对讲机2个、" + SHIGONG_FANGAN = "" + FEISHOURENYUAN_PEIZHI = "1人;主检飞手1人" + LUNGUZUOYERENYUAN_PEIZHI = "2人;轮毂作业检查2人" + DEFAULT_BASE_INFO = { #项目基本信息 #项目概况 'jituan_jianxie': '甲方集团', @@ -83,15 +102,15 @@ oneproject = { "auditorId": "ca37c4337df8673a5c045b6c25acf74a", "qualityOfficerId": "862e027910c2562d2b67d88ec33d77ba", "projectManagerId": "fbaa9e0aecf2ce287138c38a4b654085", - "constructionTeamLeaderId": None, + "constructionTeamLeaderId": "", "status": 0, - "startDate": None, - "endDate": None, - "constructorName": None, + "startDate": "", + "endDate": "", + "constructorName": "", "auditorName": "李四", "qualityOfficerName": "辛奇", "projectManagerName": "张三", - "constructionTeamLeaderName": None, + "constructionTeamLeaderName": "", "statusLabel": "待施工" }, "msg": "", @@ -147,4 +166,3 @@ yepian = { "code": 200, "success": True } - diff --git a/tools/get_pictures.py b/tools/get_pictures.py index d77594b..5497237 100644 --- a/tools/get_pictures.py +++ b/tools/get_pictures.py @@ -246,8 +246,8 @@ def process_picture_data(picture_data : list[dict], dianxing_type (str): 典型类型枚举值 Returns: tuple( - defct_pictures, 缺陷图列表 - dianxing_pictures 典型图列表 + defct_pictures, 缺陷图列表 + dianxing_pictures 典型图列表 ) """ #过滤目标来源的图片数据