Report_Generate_Server/Dt_report.py

576 lines
29 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 文档处理工具
from tools.document_tools import (
create_document, add_documents,add_table_and_replace,
add_table_to_document,add_dynamic_table,
process_server_images_table,add_header,change_heading
)
# 内容处理工具
from tools.content_tools import (
add_picture,split_table_by_row_content,
search_and_replace,add_heading
)
from tools.get_pictures import (
process_picture_data,get_records_with_pic
)
from tools.Get_Json import (
get_project_info,get_jizu_info,
get_jizu_shigong_info,get_defect_detail,
get_part_picture,get_yepian_xiangqing,
check_pic_url,get_full_picture_url,
get_defect_record_list
)
from tools.dataproccess import (
caculate_work_days,get_year_month,
merge_info,get_defect_str,
safe_get,get_resource_path,merge_dicts
)
from core.tables import fill_tables
from tools.defines import *
import os, re, datetime
async def generate_dt_report(base_info, baogao_info):
#获取模板编号、模板名称
num_to_chinese = {1 : '', 2 : '', 3 : '', 4 : '', 5 : '', 6 : '', 7 : '', 8 : '', 9 : '', 10 : '', 11 : '十一', 12 : '十二'}
cover_encode = "encode"
cover_project = "project"
baogao_name1 = "baogaoname1"
baogao_name2 = "baogaoname2"
company_name_yi = "company_name_yi"
cover_date = "time"
TITLE_OF_REPORT = "companyencode"
jiegou_xuhao = 'num'
print(f"获取到参数:基本信息:{base_info}\n\n报告信息:{baogao_info}")
try:
base_info = merge_info(base_info, DEFAULT_BASE_INFO)
turbine_id = base_info['turbine_id']
jizu_data = get_jizu_info(turbine_id)
project_data = get_project_info(jizu_data['projectId'])
shigong_data = get_jizu_shigong_info(turbine_id)
fengchang_name = project_data['farmName']
Yi_company = project_data['inspectionUnit']
yi_fuzeren = project_data['inspectionContact']
yi_phone = project_data['inspectionPhone']
fengchang_location = project_data['farmAddress']
Jia_company = project_data['client']
jia_fuzeren = project_data['clientContact']
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']
cover_url = project_data['coverUrl']
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)
key_words= re.compile('|'.join(map(re.escape, baogao_info['key_words'].split(',')))) #关键字
shengcheng_dir = baogao_info['shengcheng_dir'] #路径
if shengcheng_dir == "":
print("未配置生成路径,请检查配置")
return
if_waibu = baogao_info["if_waibu"]
if_neibu = baogao_info["if_neibu"]
if_fanglei = baogao_info["if_fanglei"]
quexian_type = baogao_info['quexian_enum']
dianxing_type = baogao_info['dianxing_enum']
other_type = baogao_info["other_enum"]
jiancha_renyuan = baogao_info['jiancha_renyuan'] #检查人员,目前是从命令行参数获取,需要完善
check_date = baogao_info['check_date']
if check_date == None:
check_date = "未获取"
baogao_bianzhi = baogao_info["userName"]
baogao_shenghe = baogao_info["baogaoCheck"]
Jiancha_date = baogao_info["check_date"]
data_processor = baogao_info["data_processor"]
coverurl = baogao_info["coverurl"]
#数据库拉取信息
# Jiancha_date = shigong_data["startTime"].replace("T", " ") #检查日期
# image_count = shigong_data['imageCount'] #从施工方案获取的图片数量,待定!!!
# temperature = shigong_data['temperature'] #温度
# wind_speed = shigong_data['windSpeed'] #风速
# weather = get_weather(shigong_data["weatherCode"]) #天气 不从此接口获取,待定!!!
#拉取部件、图片数据
part_data, picture_data1, picture_data2, Yepians = get_part_picture(turbine_id)
picture_data = merge_dicts(picture_data1, picture_data2)
print(Yepians)
Y1_info = get_yepian_xiangqing(Yepians[0]["partId"])
Y_Code = [yepian["partCode"] for yepian in Yepians]
partManufacturer = Y1_info["partManufacturer"]
print(f"找到叶片号{Y_Code},厂商{partManufacturer}")
image_source_to_find = []
baogao_label = []
renyuan_peizhi = []
gongzuo_neirong = []
shigong_fangan = []
shebei_peizhi = []
beizhu = []
jiancha = []
neirong = []
neirong2 = []
#获取对应枚举字段
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) + f"{len(Y_Code)}支叶片的前缘、后缘、迎风面、背风面。")
neirong2.append("前缘、后缘、迎风面、背风面。")
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) + f"{len(Y_Code)}支叶片的内部导雷卡、腹板、透光、人孔盖版、叶根盖板...")
neirong2.append("内部导雷卡、腹板、透光、人孔盖版、叶根盖板...")
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"轮毂至塔基导通、内部导线线阻、外部导线线阻...")
neirong2.append("轮毂至塔基导通、内部导线线阻、外部导线线阻...")
#获取缺陷图列表和典型图列表
filtered_picture_data, total_picture_num = process_picture_data(picture_data, image_source_to_find)
#获取所有缺陷记录
defect_records = get_defect_record_list()
#获取缺陷记录中对应图片的记录
defect_records_with_pic, error_pic_with_no_record = get_records_with_pic(defect_records, filtered_picture_data, quexian_type)
if len(error_pic_with_no_record) > 0:
print(f"!!!有部分缺陷图片没有对应的缺陷记录,将不会生成这些图片的缺陷表:{error_pic_with_no_record} ")
print(f"对应缺陷图的缺陷记录列表:{defect_records_with_pic}")
except Exception as e:
print(f"报告基本信息获取失败:{e}")
return
#检查参数合法性
if not if_fanglei or not if_neibu or not if_waibu:
print("请至少选择一种检查项目")
return
if not os.path.exists(shengcheng_dir):
print(f"生成路径{shengcheng_dir}不存在")
return
output_doc = None
head_num = 1
###封面创建###
cover_dirs = [get_resource_path("muban/fengmian1.docx"),get_resource_path("muban/fengmian.jpg"),get_resource_path("muban/fengmian2.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):
if version != 1:
output_dir = output_dir.replace(f"{version - 1}",f"{version}")
else:
output_dir = output_dir.replace("",f"{version}")
version += 1
mianzhe_shengming = f"本报告仅涵盖{''.join(baogao_label)}检测内容"
print(await create_document(output_dir))
change_heading(output_dir, "Heading 1", DT_EADING_1_CONFIG)
if baogao_info["if_docx_fengmian"] :
#创建文档、添加封面
print(add_documents(output_dir, cover_dirs[0]))
if check_pic_url(coverurl): #手动导入封面图片测试用
print(add_picture(output_dir, get_full_picture_url(coverurl), width = 6.41, height = 4))
elif check_pic_url(cover_url):
print(add_picture(output_dir, get_full_picture_url(cover_url), width = 6.41, height = 4))
else:
print(add_picture(output_dir, cover_dirs[1]))
print(add_documents(output_dir, cover_dirs[2]))
print("封面创建成功")
#YYYY年MM月DD日 HH:MM:SS
#更改文档信息
print(search_and_replace(output_dir, TITLE_OF_REPORT, jizu_bianhao))
print(search_and_replace(output_dir, baogao_name1, baogao_name))
print(search_and_replace(output_dir, company_name_yi, Yi_company))
print(search_and_replace(output_dir, cover_project, fengchang_name))
print(search_and_replace(output_dir, cover_encode, jizu_bianhao))
print(search_and_replace(output_dir, cover_date, date_year_month))
print(search_and_replace(output_dir, 'bianzhi', baogao_bianzhi))
print(search_and_replace(output_dir, 'shenghe', baogao_shenghe))
print(search_and_replace(output_dir, 'mianzhe_shengming', mianzhe_shengming))
add_header(output_dir, TEMPLATE_HEADER.DT_HEADER.ENUM)
total_table_num = 0
if baogao_info["if_docx_project_overview"]:
#项目概况表
print("开始添加项目概况表")
XIANG_MU_GAI_KUANG = get_resource_path("muban/xiangmugaikuo.docx")
print(f"查找模板,找到模板:{XIANG_MU_GAI_KUANG}")
project_location = fengchang_location
company_name_jia = Jia_company
fuzeren = yi_fuzeren
phone_fuzeren = yi_phone
xiangmuguige = jizu_num
Yi_company = Yi_company
XIANGMU_GAIKUO = list(list("" for i in range(6)) for j in range(5))
XIANGMU_GAIKUO[0][1] = fengchang_name
XIANGMU_GAIKUO[0][4] = project_location
XIANGMU_GAIKUO[1][1] = company_name_jia
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][3] = xiangmuguige
XIANGMU_GAIKUO[4][5] = gongqi
print("建立表结构完毕,开始插入模板")
#添加项目概况表
print(f"输出路径:{output_dir},模板路径:{XIANG_MU_GAI_KUANG},插入数据:{XIANGMU_GAIKUO}")
print(add_heading(output_dir, f"一、项目概括", 1))
output_doc, message = add_table_to_document(output_dir, XIANG_MU_GAI_KUANG,5,5,total_table_num,XIANGMU_GAIKUO, if_para=False)
print(message)
print("模板插入完毕,开始替换内容")
total_table_num += 1
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
print(search_and_replace(output_dir, TITLE_OF_REPORT, jizu_bianhao))
print(search_and_replace(output_dir, baogao_name2, baogao_name))
head_num += 1
if baogao_info['if_docx_inspection_method']:
#检查方案描述
FANGAN_JIANCHA_DIR = get_resource_path("muban/checkmethod.docx")
list_to_replace = {
'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],
}
print(add_heading(output_dir, f"二、检查方案", 1))
print(add_table_and_replace(output_dir, FANGAN_JIANCHA_DIR, 0, list_to_replace, no_para=True))
print(split_table_by_row_content(output_dir, output_dir, total_table_num))
total_table_num += 1
head_num += 1
if baogao_info['if_docx_inspection_info']:
#检查信息
JIANCHA_XINGXI_DIR = get_resource_path("muban/checkinfo.docx")
JIANCHA_XINGXI = list(list("" for i in range(4)) for j in range(9))
JIANCHA_XINGXI[0][1] = jiancha_renyuan
try:
JIANCHA_XINGXI[1][1] = Jiancha_date.split('T')[0]
except:
JIANCHA_XINGXI[1][1] = "格式不对或无数据"
JIANCHA_XINGXI[1][3] = jizu_bianhao
JIANCHA_XINGXI[2][1] = "风力发电机组" + baogao_name
JIANCHA_XINGXI[2][3] = "".join(jiancha)
JIANCHA_XINGXI[3][2] = partManufacturer
JIANCHA_XINGXI[4][1] = '叶片型号:' + jizu_xinghao
JIANCHA_XINGXI[5][1] = Y_Code[0] if len(Y_Code) > 0 else ""
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"检查,采集叶片图片{total_picture_num}张,内容覆盖" + ";".join(_ for _ in neirong)
#新建检查信息表
print(add_heading(output_dir, f"三、检查信息", 1))
output_doc, message = add_table_to_document(output_dir, JIANCHA_XINGXI_DIR,9,4,total_table_num ,JIANCHA_XINGXI,False,if_para=False)
print(message)
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
head_num += 1
total_table_num += 1
if baogao_info['if_docx_chengguo_sub']:
# 添加成果递交表
CHENGGUO_DIJIAO_DIR = get_resource_path("muban/chengguo_sub.docx")
CHENGGUO_DIJIAO = list(list("" for i in range(4)) for j in range(6))
CHENGGUO_DIJIAO[0][1] = jiancha_renyuan
CHENGGUO_DIJIAO[1][1] = jia_fuzeren
try:
CHENGGUO_DIJIAO[2][1] = Jiancha_date.split('T')[0]
except:
CHENGGUO_DIJIAO[2][1] = "格式不对或无数据"
CHENGGUO_DIJIAO[3][1] = data_processor
CHENGGUO_DIJIAO[4][1] = baogao_bianzhi
CHENGGUO_DIJIAO[5][1] = baogao_shenghe
try:
CHENGGUO_DIJIAO[2][3] = Jiancha_date.split('T')[1]
except:
CHENGGUO_DIJIAO[2][3] = "格式不对或无数据"
CHENGGUO_DIJIAO[3][3] = baogao_date.split(' ')[0]
CHENGGUO_DIJIAO[4][3] = baogao_date.split(' ')[0]
CHENGGUO_DIJIAO[5][3] = "未审核"
print(add_heading(output_dir, f"四、成果递交", 1))
output_doc, message = add_table_to_document(output_dir, CHENGGUO_DIJIAO_DIR,5,5,total_table_num,CHENGGUO_DIJIAO,True,0.04,if_para=False)
print(message)
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
head_num += 1
total_table_num += 1
if baogao_info['if_docx_inspection_text'] and if_waibu:
#检查情况汇总表(文字信息)
try:
#获取缺陷信息
"""
需要获取:
Y1、Y2、Y3叶片的缺陷数量缺陷字典{描述:图片路径}
和数据库连接需要的新增异常处理:
目前逻辑为找到图片后找缺陷类型的图片通过图片id查找对应缺陷记录
如果没有找到,要返回对应异常,即已选出(标注)缺陷图,但未填写对应缺陷信息的异常返回。
最后将无异常的图片入队缺陷字典(同数量),有异常的图片再另存。
"""
Y1_quexian_list = []
Y2_quexian_list = []
Y3_quexian_list = []
Y1_quexian_list = defect_records_with_pic["叶片1"]["DEFECT"] if "叶片1" in defect_records_with_pic else {}
Y2_quexian_list = defect_records_with_pic["叶片2"]["DEFECT"] if "叶片2" in defect_records_with_pic else {}
Y3_quexian_list = defect_records_with_pic["叶片3"]["DEFECT"] if "叶片3" in defect_records_with_pic else {}
Y1_quexian_num = len(Y1_quexian_list)
Y2_quexian_num = len(Y2_quexian_list)
Y3_quexian_num = len(Y3_quexian_list)
no_defect_found = "未发现明显缺陷"
weak_num_Y1 = f"{Y_Code[0] if len(Y_Code) > 0 else ''}叶片" + f"共发现缺陷{Y1_quexian_num}" if Y1_quexian_num > 0 else no_defect_found
weak_num_Y2 = f"{Y_Code[1] if len(Y_Code) > 1 else ''}叶片" + f"共发现缺陷{Y2_quexian_num}" if Y1_quexian_num > 0 else no_defect_found
weak_num_Y3 = f"{Y_Code[2] if len(Y_Code) > 2 else ''}叶片" + f"共发现缺陷{Y3_quexian_num}" if Y1_quexian_num > 0 else no_defect_found
except Exception as e:
print(f"缺陷图获取失败:{e}")
return
#添加检查情况汇总表
JIANCHA_HUIZONG_DIR = get_resource_path("muban/total_check.docx")
JIANCHA_HUIZONG = list(list("" for i in range(3)) for j in range(4))
JIANCHA_HUIZONG[1][0] = weak_num_Y1
JIANCHA_HUIZONG[2][0] = weak_num_Y2
JIANCHA_HUIZONG[3][0] = weak_num_Y3
JIANCHA_HUIZONG[1][1] = "\n".join(neirong2)
JIANCHA_HUIZONG[2][1] = "\n".join(neirong2)
JIANCHA_HUIZONG[3][1] = "\n".join(neirong2)
JIANCHA_HUIZONG[1][2] = "\n".join([f"{i+1}.{s}" for i, s in enumerate(get_defect_str(Y1_quexian_list))]) if Y1_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
JIANCHA_HUIZONG[2][2] = "\n".join([f"{i+1}.{s}" for i, s in enumerate(get_defect_str(Y2_quexian_list))]) if Y2_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
JIANCHA_HUIZONG[3][2] = "\n".join([f"{i+1}.{s}" for i, s in enumerate(get_defect_str(Y3_quexian_list))]) if Y3_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
print(add_heading(output_dir, f"五、检查情况汇总 ", 1))
output_doc, message = add_table_to_document(output_dir, JIANCHA_HUIZONG_DIR,4,3,total_table_num,JIANCHA_HUIZONG,False,ALIGMENT='LEFT', if_para=False)
print(message)
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
total_table_num += 1
head_num += 1
if baogao_info['if_docx_inspection_picture']:
#主要部位图片展示表/检查内容表
#获取典型图信息
try:
Y1_list = safe_get(filtered_picture_data, "叶片1", dianxing_type, default=[])
Y2_list = safe_get(filtered_picture_data, "叶片2", dianxing_type, default=[])
Y3_list = safe_get(filtered_picture_data, "叶片3", dianxing_type, default=[])
picture_Y1_num = len(Y1_list)
picture_Y2_num = len(Y2_list)
picture_Y3_num = len(Y3_list)
except Exception as e:
print(f"获取缺陷图失败:{e}")
print(f"图片、文字数量:{picture_Y1_num} {picture_Y2_num} {picture_Y3_num}")
JIANCHA_NEIRONG_TOTAL_NUM = picture_Y1_num+ picture_Y2_num + picture_Y3_num
if JIANCHA_NEIRONG_TOTAL_NUM <= 0:
print("无典型图片数据,无法生成典型图表")
else:
print(add_heading(output_dir, f"六、检查内容", 1))
col ,row = 3, 0
JIANCHA_NEIRONG_PICTURES_TABLE = get_resource_path("muban/check2.docx")
JIANCHA_NEIRONG_Y1_DIR = get_resource_path("muban/check_content.docx")
JIANCHA_NEIRONG_Y1 = list(list("" for _ in range(3)) for j in range(1))
Y1_code = Y_Code[0] if len(Y_Code) > 0 else ""
Y2_code = Y_Code[1] if len(Y_Code) > 1 else ""
Y3_code = Y_Code[2] if len(Y_Code) > 2 else ""
JIANCHA_NEIRONG_Y1[0][0] = f"叶片1{Y1_code}检查内容"
print(f"Y1标题内容{JIANCHA_NEIRONG_Y1}")
JIANCHA_NEIRONG_Y2_DIR = get_resource_path("muban/check3.docx")
JIANCHA_NEIRONG_Y2 = list(list("" for _ in range(3)) for j in range(1))
JIANCHA_NEIRONG_Y2[0][0] = f"叶片2{Y2_code}检查内容"
print(f"Y2标题内容{JIANCHA_NEIRONG_Y2}")
JIANCHA_NEIRONG_Y3_DIR = get_resource_path("muban/check3.docx")
JIANCHA_NEIRONG_Y3 = list(list("" for _ in range(3)) for j in range(1))
JIANCHA_NEIRONG_Y3[0][0] = f"叶片3{Y3_code}检查内容"
print(f"Y3标题内容{JIANCHA_NEIRONG_Y3}")
print(f"当前表格序号为 {total_table_num}")
print(key_words)
output_doc, message = add_table_to_document(output_dir, JIANCHA_NEIRONG_Y1_DIR,1,3,total_table_num,JIANCHA_NEIRONG_Y1,True, 1,if_para=False)
print(message)
total_table_num += 1
total_table_num = await process_server_images_table(Y1_list, image_source_to_find, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
output_doc, message = add_table_to_document(output_dir, JIANCHA_NEIRONG_Y2_DIR,1,3,total_table_num,JIANCHA_NEIRONG_Y2,True, 1)
print(message)
total_table_num += 1
total_table_num = await process_server_images_table(Y2_list, image_source_to_find, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
output_doc, message = add_table_to_document(output_dir, JIANCHA_NEIRONG_Y3_DIR,1,3,total_table_num,JIANCHA_NEIRONG_Y3,True, 1)
print(message)
total_table_num += 1
total_table_num = await process_server_images_table(Y3_list, image_source_to_find, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
head_num += 1
if baogao_info['if_docx_defect_picture'] and if_waibu:
# #缺陷详情
QUEXIAN_XIANGQING_DIR = get_resource_path("muban/check_check.docx")
QUEXIAN_XIANGQING_TITLE_DIR = get_resource_path("muban/check_check_title.docx")
Y_tables = [Y1_quexian_list,Y2_quexian_list,Y3_quexian_list]
Y1_table_list = []
Y2_table_list = []
Y3_table_list = []
table_lists = [Y1_table_list, Y2_table_list, Y3_table_list]
for i, (table_list, Y_lists) in enumerate(zip(table_lists, Y_tables)):
for Y_list in Y_lists:
image_defect_record = Y_list["record"]
image_path = Y_list["imagePath"]
image_defect_record = get_defect_detail(image_defect_record["defectId"])
# 从imagedefectrecord中获取各个字段
defect_type = image_defect_record.get('defectTypeLabel', '未知缺陷类型')
defect_location = f"{image_defect_record.get('partName', '')}{image_defect_record.get('defectPosition', '')}"
# 使用axial和chordwise作为缺陷尺寸信息
axial = image_defect_record.get('axial', '')
chordwise = image_defect_record.get('chordwise', '')
defect_size = f"轴向:{axial} 弦向:{chordwise}" if axial or chordwise else ''
visibility = "暂无此项"
urgency = "暂无此项"
severity = image_defect_record.get('defectLevelLabel', '未知严重等级')
repair_suggestion = image_defect_record.get('repairIdea', '无维修建议')
print(f"获取第{i + 1}个叶片的缺陷图: {image_path}")
table_list.append({
"QueXianLeiXing": defect_type,
"QueXianWeiZhi": defect_location,
"QueXianChiCun": defect_size,
"WeiZongDengJi": severity,
"Tupian_Dir": get_full_picture_url(image_path) if check_pic_url(image_path) else None,
"visibility": visibility,
"urgency": urgency,
"repair_suggestion": repair_suggestion, # 新增维修建议字段
})
# for i, (table_list, Y_dict) in enumerate(zip(table_lists, Y_tables)):
# for image_defect_record, image_path in Y_dict.items():
# # 从图片名解析各个字段
# parts = image_name.split('_')
# if len(parts) >= 8: # 确保有7个部分
# defect_type = parts[1]
# defect_location = parts[2]
# defect_size = parts[3]
# visibility = parts[4]
# urgency = parts[5]
# severity = parts[6]
# repair_suggestion = parts[7]
# print(f"获取第{i+1}个叶片的缺陷图: {image_path}")
# table_list.append({
# "QueXianLeiXing": defect_type,
# "QueXianWeiZhi": defect_location,
# "QueXianChiCun": defect_size,
# "WeiZongDengJi": severity,
# "Tupian_Dir": image_path,
# "visibility": visibility,
# "urgency": urgency,
# "repair_suggestion": repair_suggestion.split('.')[0], # 新增维修建议字段
# })
# else:
# table_list.append({
# "QueXianLeiXing": "图片命名有误",
# "QueXianWeiZhi": "图片命名有误",
# "QueXianChiCun": "图片命名有误",
# "WeiZongDengJi": "图片命名有误",
# "Tupian_Dir": image_path,
# "visibility": "图片命名有误",
# "urgency": "图片命名有误",
# "repair_suggestion": "图片命名有误", # 新增维修建议字段
# })
Y1_TABLES, Y1_TABLES_PICTURES = fill_tables(table_lists[0],4,5,len(table_lists[0]),Y_Code[0] if len(Y_Code) > 0 else "")
Y2_TABLES, Y2_TABLES_PICTURES = fill_tables(table_lists[1],4,5,len(table_lists[1]),Y_Code[1] if len(Y_Code) > 1 else "")
Y3_TABLES, Y3_TABLES_PICTURES = fill_tables(table_lists[2],4,5,len(table_lists[2]),Y_Code[2] if len(Y_Code) > 2 else "")
print(add_documents(output_dir, QUEXIAN_XIANGQING_TITLE_DIR))
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
head_num += 1
table_num = 0
Xu_Hao = 0
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y1_TABLES,QUEXIAN_XIANGQING_DIR,Y1_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y2_TABLES,QUEXIAN_XIANGQING_DIR,Y2_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
total_table_num,table_num,Xu_Hao = await add_dynamic_table(output_doc,output_dir,table_num,Y3_TABLES,QUEXIAN_XIANGQING_DIR,Y3_TABLES_PICTURES,4,5,total_table_num,False,xuhao=Xu_Hao)
if baogao_info['if_docx_conclusion']:
#总结
ZONG_JIE_DIR = get_resource_path("muban/result.docx")
ZONG_JIE_BEFORE = "result"
ZONG_JIE = baogao_info['conclusion']
print(add_documents(output_dir, ZONG_JIE_DIR))
print(search_and_replace(output_dir, ZONG_JIE_BEFORE, ZONG_JIE))
print(search_and_replace(output_dir, 'company_yi', Yi_company))
print(search_and_replace(output_dir, 'baogao_date', baogao_date.split(' ')[0]))
print(search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))