547 lines
24 KiB
Python
547 lines
24 KiB
Python
# 文档处理工具
|
||
from tools.document_tools import (
|
||
create_document, add_documents,add_table_and_replace,
|
||
add_table_to_document,process_images_table,
|
||
)
|
||
|
||
# 内容处理工具
|
||
from tools.content_tools import (
|
||
add_picture,split_table_by_row_content,
|
||
search_and_replace,add_picture_to_table
|
||
)
|
||
|
||
from tools.get_pictures import (
|
||
make_Thumbnail,resize_and_reduce_quality,
|
||
get_picture_nums,find_image,collect_defect_data,
|
||
process_picture_data
|
||
)
|
||
|
||
from tools.Get_Json import (get_project_info,get_jizu_info,
|
||
get_jizu_shigong_info,get_weather,
|
||
get_picture)
|
||
|
||
|
||
import asyncio
|
||
|
||
from core.tables import fill_tables
|
||
|
||
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 : '十二'}
|
||
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'
|
||
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)
|
||
try:
|
||
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']
|
||
except Exception as e:
|
||
print(f"数据库的项目-机组基本信息获取失败:{e}")
|
||
return
|
||
|
||
try:
|
||
baogao_date = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M") #现在的时间
|
||
|
||
|
||
#前端信息
|
||
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']
|
||
muban_dir = baogao_info['muban_dir']
|
||
if muban_dir == "" or shengcheng_dir == "":
|
||
print("未配置模板/生成路径,请检查配置")
|
||
return
|
||
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']
|
||
|
||
dianxing_type = baogao_info['dianxing_enum']
|
||
|
||
|
||
#数据库拉取信息
|
||
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"]) #天气
|
||
#拉取图片数据
|
||
picture_data = get_picture(turbine_id)
|
||
#获取缺陷图列表和典型图列表
|
||
defect_pictures, typical_pictures = process_picture_data(picture_data, image_source_to_find)
|
||
#处理图片数据
|
||
|
||
|
||
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']
|
||
|
||
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")
|
||
|
||
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
|
||
|
||
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)}检测内容"
|
||
|
||
#创建文档、添加封面
|
||
print(await create_document(output_dir))
|
||
print(add_documents(output_dir, cover_dirs[0]))
|
||
print(await add_picture(output_dir, cover_dirs[1]))
|
||
print(add_documents(output_dir, cover_dirs[2]))
|
||
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, 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_date, date_year_month))
|
||
print(await search_and_replace(output_dir, 'bianzhi', baogao_bianzhi))
|
||
print(await search_and_replace(output_dir, 'shenghe', baogao_shenghe))
|
||
print(await search_and_replace(output_dir, 'mianzhe_shengming', mianzhe_shengming))
|
||
|
||
total_table_num = 0
|
||
#项目概况表
|
||
print("开始添加项目概况表")
|
||
XIANG_MU_GAI_KUANG = os.path.join(muban_dir,"xiangmugaikuo.docx")
|
||
print(f"查找模板,找到模板:{XIANG_MU_GAI_KUANG}")
|
||
project_location = fengchang_location
|
||
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[0][1] = fengchang_name
|
||
#XIANGMU_GAIKUO[0][3]=XIANGMU_GAIKUO[0][4] = "盐城市滨海县"
|
||
XIANGMU_GAIKUO[0][3] = 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[4][1] = jizu_xinghao
|
||
XIANGMU_GAIKUO[4][4] = xiangmuguige
|
||
print("建立表结构完毕,开始插入模板")
|
||
#添加项目概况表
|
||
print(f"输出路径:{output_dir},模板路径:{XIANG_MU_GAI_KUANG},插入数据:{XIANGMU_GAIKUO}")
|
||
output_doc, message = await add_table_to_document(output_dir, XIANG_MU_GAI_KUANG,5,5,total_table_num,XIANGMU_GAIKUO)
|
||
print(message)
|
||
print("模板插入完毕,开始替换内容")
|
||
total_table_num += 1
|
||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
head_num += 1
|
||
|
||
#检查方案描述
|
||
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,
|
||
'beizhu' : beizhu,
|
||
'num' : num_to_chinese[head_num],
|
||
}
|
||
print(await add_table_and_replace(output_dir, FANGAN_JIANCHA_DIR, 0, list_to_replace))
|
||
print(split_table_by_row_content(output_dir, output_dir, total_table_num))
|
||
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[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[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)#添加图片
|
||
# else:
|
||
# print('传入了总图片路径,获取图片数量')
|
||
# Thumbnail_Picture = await make_Thumbnail(total_picture_dir, Picture_dir)#添加图片
|
||
# normal_picture_num = get_picture_nums(total_picture_dir)
|
||
# JIANCHA_XINGXI42 = tatong_image_path
|
||
#新建检查信息表
|
||
output_doc, message = await add_table_to_document(output_dir, JIANCHA_XINGXI_DIR,9,4,total_table_num ,JIANCHA_XINGXI,False)
|
||
print(message)
|
||
# print(await add_picture_to_table(output_doc, output_dir, 4, 2, JIANCHA_XINGXI42, total_table_num , 1.18))
|
||
# #添加略缩图片
|
||
# print(await add_picture_to_table(output_doc, output_dir, 8, 0, Thumbnail_Picture, total_table_num))
|
||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
head_num += 1
|
||
total_table_num += 1
|
||
|
||
#添加成果递交表
|
||
|
||
CHENGGUO_DIJIAO_DIR = os.path.join(muban_dir,"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] = yezhu_renyuan
|
||
CHENGGUO_DIJIAO[2][1] = Jiancha_date.split(' ')[0]
|
||
CHENGGUO_DIJIAO[3][1] = data_process
|
||
CHENGGUO_DIJIAO[4][1] = baogao_bianzhi
|
||
CHENGGUO_DIJIAO[5][1] = baogao_shenghe
|
||
CHENGGUO_DIJIAO[1][3] = changjia_renyuan
|
||
CHENGGUO_DIJIAO[2][3] = Jiancha_date.split(' ')[1]
|
||
CHENGGUO_DIJIAO[3][3] = baogao_date.split(' ')[0]
|
||
CHENGGUO_DIJIAO[4][3] = baogao_date.split(' ')[0]
|
||
CHENGGUO_DIJIAO[5][3] = shenghe_date.split(' ')[0]
|
||
|
||
output_doc, message = await add_table_to_document(output_dir, CHENGGUO_DIJIAO_DIR,5,5,total_table_num,CHENGGUO_DIJIAO,True,0.04)
|
||
print(message)
|
||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
head_num += 1
|
||
total_table_num += 1
|
||
|
||
# #检查情况汇总表(文字信息)
|
||
# try:
|
||
# search_file_list = []
|
||
# if ifwaibu:
|
||
# search_file_list.append("外缺陷图")
|
||
# if ifneibu:
|
||
# search_file_list.append("内缺陷图")
|
||
# Y1_quexian_num, Y1_quexian_dict = collect_defect_data(Y1, Picture_dir, ifwaibu, ifneibu, search_file_list)
|
||
# Y2_quexian_num, Y2_quexian_dict = collect_defect_data(Y2, Picture_dir, ifwaibu, ifneibu, search_file_list)
|
||
# Y3_quexian_num, Y3_quexian_dict = collect_defect_data(Y3, Picture_dir, ifwaibu, ifneibu, search_file_list)
|
||
# weak_num_Y1 = f"{Y1}共发现缺陷{Y1_quexian_num}处"
|
||
# weak_num_Y2 = f"{Y2}共发现缺陷{Y2_quexian_num}处"
|
||
# weak_num_Y3 = f"{Y3}共发现缺陷{Y3_quexian_num}处"
|
||
# except Exception as e:
|
||
# print(f"缺陷图获取失败:{e}")
|
||
# return
|
||
|
||
# #添加检查情况汇总表
|
||
# JIANCHA_HUIZONG_DIR = os.path.join(muban_dir,"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] = Y1_jiancha
|
||
# JIANCHA_HUIZONG[2][1] = Y2_jiancha
|
||
# JIANCHA_HUIZONG[3][1] = Y3_jiancha
|
||
# JIANCHA_HUIZONG[1][2] = "/n".join([f"{i+1}.{name}" for i, (name, path) in enumerate(Y1_quexian_dict.items())]) if Y1_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
|
||
# JIANCHA_HUIZONG[2][2] = "/n".join([f"{i+1}.{name}" for i, (name, path) in enumerate(Y2_quexian_dict.items())]) if Y2_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
|
||
# JIANCHA_HUIZONG[3][2] = "/n".join([f"{i+1}.{name}" for i, (name, path) in enumerate(Y3_quexian_dict.items())]) if Y3_quexian_num else '未发现明显影响风力发电机组正常运行的缺陷'
|
||
# output_doc, message = await add_table_to_document(output_dir, JIANCHA_HUIZONG_DIR,4,3,total_table_num,JIANCHA_HUIZONG,False,ALIGMENT='LEFT')
|
||
# print(message)
|
||
# print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
# total_table_num += 1
|
||
# head_num += 1
|
||
|
||
# #主要部位图片展示表/检查内容表
|
||
# search_file_list = ["外汇总","内汇总","防汇总"]
|
||
# picture_Y1_num, Y1_dict = collect_defect_data(Y1, Picture_dir, ifwaibu, ifneibu, search_file_list, iffanglei)
|
||
# picture_Y2_num, Y2_dict = collect_defect_data(Y2, Picture_dir, ifwaibu, ifneibu, search_file_list, iffanglei)
|
||
# picture_Y3_num, Y3_dict = collect_defect_data(Y3, Picture_dir, ifwaibu, ifneibu, search_file_list, iffanglei)
|
||
# print(f"图片、文字数量:{picture_Y1_num} {picture_Y2_num} {picture_Y3_num}")
|
||
# JIANCHA_NEIRONG_TOTAL_NUM = picture_Y1_num+ picture_Y2_num + picture_Y3_num
|
||
# col ,row = 3, 0
|
||
# JIANCHA_NEIRONG_PICTURES_TABLE = os.path.join(muban_dir,"check2.docx")
|
||
# JIANCHA_NEIRONG_Y1_DIR = os.path.join(muban_dir,"check_content.docx")
|
||
# JIANCHA_NEIRONG_Y1 = list(list("" for _ in range(3)) for j in range(1))
|
||
# JIANCHA_NEIRONG_Y1[0][0] = f"叶片1:{Y1}检查内容"
|
||
# print(f"Y1标题内容:{JIANCHA_NEIRONG_Y1}")
|
||
# JIANCHA_NEIRONG_Y2_DIR = os.path.join(muban_dir,"check3.docx")
|
||
# JIANCHA_NEIRONG_Y2 = list(list("" for _ in range(3)) for j in range(1))
|
||
# JIANCHA_NEIRONG_Y2[0][0] = f"叶片2:{Y2}检查内容"
|
||
# print(f"Y2标题内容:{JIANCHA_NEIRONG_Y2}")
|
||
# JIANCHA_NEIRONG_Y3_DIR = os.path.join(muban_dir,"check3.docx")
|
||
# JIANCHA_NEIRONG_Y3 = list(list("" for _ in range(3)) for j in range(1))
|
||
# JIANCHA_NEIRONG_Y3[0][0] = f"叶片3:{Y3}检查内容"
|
||
# print(f"Y3标题内容:{JIANCHA_NEIRONG_Y3}")
|
||
# print(f"当前表格序号为 {total_table_num}")
|
||
# print(key_words)
|
||
# output_doc, message = await add_table_to_document(output_dir, JIANCHA_NEIRONG_Y1_DIR,1,3,total_table_num,JIANCHA_NEIRONG_Y1,True, 1)
|
||
# print(message)
|
||
# total_table_num += 1
|
||
|
||
# total_table_num = await process_images_table(Y1_dict, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
|
||
|
||
# output_doc, message = await 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_images_table(Y2_dict, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
|
||
|
||
# output_doc, message = await 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_images_table(Y3_dict, output_dir, total_table_num, JIANCHA_NEIRONG_PICTURES_TABLE, key_words)
|
||
# print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
# head_num += 1
|
||
|
||
# #缺陷详情
|
||
# QUEXIAN_XIANGQING_DIR = os.path.join(muban_dir,"check_check.docx")
|
||
# QUEXIAN_XIANGQING_TITLE_DIR = os.path.join(muban_dir,"check_check_title.docx")
|
||
|
||
# Y_tables = [Y1_quexian_dict,Y2_quexian_dict,Y3_quexian_dict]
|
||
# 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_dict) in enumerate(zip(table_lists, Y_tables)):
|
||
# for image_name, 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]),Y1)
|
||
# Y2_TABLES, Y2_TABLES_PICTURES = fill_tables(table_lists[1],4,5,len(table_lists[1]),Y2)
|
||
# Y3_TABLES, Y3_TABLES_PICTURES = fill_tables(table_lists[2],4,5,len(table_lists[2]),Y3)
|
||
# print(add_documents(output_dir, QUEXIAN_XIANGQING_TITLE_DIR))
|
||
# print(await 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)
|
||
|
||
|
||
#总结
|
||
ZONG_JIE_DIR = os.path.join(muban_dir,"result.docx")
|
||
ZONG_JIE_BEFORE = "result"
|
||
ZONG_JIE = baogao_info['baogao_zongjie']
|
||
print(add_documents(output_dir, ZONG_JIE_DIR))
|
||
print(await search_and_replace(output_dir, ZONG_JIE_BEFORE, ZONG_JIE))
|
||
print(await search_and_replace(output_dir, 'company_yi', Yi_company))
|
||
print(await search_and_replace(output_dir, 'baogao_date', baogao_date.split(' ')[0]))
|
||
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
|
||
|
||
def main():
|
||
json_data1 = {
|
||
"turbine_id" : "183463dbf40d9278549a76b82b175dd9",
|
||
}
|
||
|
||
json_data2 = {
|
||
'shengcheng_dir': r".\output",
|
||
'muban_dir': r".\muban",
|
||
}
|
||
asyncio.run(generate_report(json_data1,json_data2))
|
||
print('文档生成完毕')
|
||
if __name__ == '__main__':
|
||
main() |