增加部件、图片列表拉取操作

This commit is contained in:
Voge1imkafig 2025-07-07 18:05:03 +08:00
parent fca9473657
commit 614c277dae
7 changed files with 126 additions and 61 deletions

View File

@ -15,7 +15,10 @@ from tools.get_pictures import (
get_picture_nums,find_image,collect_defect_data get_picture_nums,find_image,collect_defect_data
) )
from tools.Get_Json import get_project_info,get_jizu_info,get_jizu_shigong_info,get_weather from tools.Get_Json import (get_project_info,get_jizu_info,
get_jizu_shigong_info,get_weather,
get_picture)
import asyncio import asyncio
@ -121,11 +124,11 @@ async def generate_report(base_info, baogao_info):
cover_date = "time" cover_date = "time"
TITLE_OF_REPORT = "companyencode" TITLE_OF_REPORT = "companyencode"
jiegou_xuhao = 'num' jiegou_xuhao = 'num'
turbine_id = base_info['turbine_id']
jizu_data = get_jizu_info(base_info['turbine_id']) jizu_data = get_jizu_info(turbine_id)
project_data = get_project_info(jizu_data['projectId']) project_data = get_project_info(jizu_data['projectId'])
shigong_data = get_jizu_shigong_info(base_info['turbine_id']) shigong_data = get_jizu_shigong_info(turbine_id)
print(shigong_data)
try: try:
fengchang_name = project_data['farmName'] fengchang_name = project_data['farmName']
Yi_company = project_data['inspectionUnit'] Yi_company = project_data['inspectionUnit']
@ -144,26 +147,45 @@ async def generate_report(base_info, baogao_info):
try: try:
baogao_date = datetime.datetime.now().strftime("%Y年%m月%d%H:%M") #现在的时间 baogao_date = datetime.datetime.now().strftime("%Y年%m月%d%H:%M") #现在的时间
#数据库拉取信息
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"]) #天气
#前端信息 #前端信息
baogao_info = merge_info(baogao_info, DEFAULT_BAOGAO_INFO) baogao_info = merge_info(baogao_info, DEFAULT_BAOGAO_INFO)
key_words= re.compile('|'.join(map(re.escape, baogao_info['key_words'].split(',')))) key_words= re.compile('|'.join(map(re.escape, baogao_info['key_words'].split(','))))
shengcheng_dir = baogao_info['shengcheng_dir'] shengcheng_dir = baogao_info['shengcheng_dir']
muban_dir = baogao_info['muban_dir'] muban_dir = baogao_info['muban_dir']
project_number = baogao_info['jizu_type']
baogao_type = baogao_info['baogao_type']
if muban_dir == "" or shengcheng_dir == "": if muban_dir == "" or shengcheng_dir == "":
print("未配置图片/生成路径/总图片路径,请检查配置") print("未配置模板/生成路径,请检查配置")
return 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)
date_year_month = get_year_month(baogao_date) 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'] Jiancha_renyuan = baogao_info['jiancha_renyuan']
shebei_peizhi = baogao_info['shebei_peizhi'] shebei_peizhi = baogao_info['shebei_peizhi']
shigong_fangan = baogao_info['shigong_fangan'] shigong_fangan = baogao_info['shigong_fangan']

View File

@ -3,3 +3,5 @@ GETPROJECTINFO = "/project/detail/{projectId}"
GETJIZUINFO = "/turbine/detail/{turbineId}" GETJIZUINFO = "/turbine/detail/{turbineId}"
GETSHIGONGINFO = "/t-construction/list" GETSHIGONGINFO = "/t-construction/list"
GETWEATHERINFO = "/weather-type/{weatherCode}" GETWEATHERINFO = "/weather-type/{weatherCode}"
GETPICTURELIST = "/image/list"
GETPARTLIST = "/part/list"

View File

@ -2,7 +2,7 @@ import requests
import json import json
from tools.API import * from tools.API import *
def get_data(url, data_type="data", params=None): def get_data(url : str, data_type : str = "data", params : dict = None ) -> dict:
headers = { headers = {
"content_type": "application/x-www-form-urlencoded" "content_type": "application/x-www-form-urlencoded"
} }
@ -11,7 +11,7 @@ def get_data(url, data_type="data", params=None):
if response.status_code == 200: if response.status_code == 200:
data = json.loads(response.text) data = json.loads(response.text)
print(f"获取到数据:{data}") print(f"获取到数据:{data}")
return data.get(data_type) return data[data_type]
else: else:
print(f"请求数据失败,状态码:{response.status_code}") print(f"请求数据失败,状态码:{response.status_code}")
return None return None
@ -19,15 +19,15 @@ def get_data(url, data_type="data", params=None):
print(f"请求数据失败,异常:{e}") print(f"请求数据失败,异常:{e}")
return None return None
def get_project_info(projectId): def get_project_info(projectId : str) -> dict:
projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId) projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId)
return get_data(projecturl, "data") return get_data(projecturl, "data")
def get_jizu_info(turbineId): def get_jizu_info(turbineId : str) -> dict:
jizuurl = DTURL + GETJIZUINFO.format(turbineId=turbineId) jizuurl = DTURL + GETJIZUINFO.format(turbineId=turbineId)
return get_data(jizuurl, "data") return get_data(jizuurl, "data")
def get_jizu_shigong_info(turbineId): def get_jizu_shigong_info(turbineId : str) -> dict:
jizuurl = DTURL + GETSHIGONGINFO jizuurl = DTURL + GETSHIGONGINFO
params = { params = {
"rows": { "rows": {
@ -37,6 +37,73 @@ def get_jizu_shigong_info(turbineId):
result = get_data(jizuurl, "rows", params) result = get_data(jizuurl, "rows", params)
return result[0] if result else None return result[0] if result else None
def get_weather(weatherid): def get_weather(weatherid : str) -> dict:
weatherurl = DTURL + GETWEATHERINFO.format(weatherCode=weatherid) weatherurl = DTURL + GETWEATHERINFO.format(weatherCode=weatherid)
return get_data(weatherurl, "data") return get_data(weatherurl, "data")
def get_part_list(turbineId : str) -> dict:
parturl = DTURL + GETPARTLIST
params = {
"turbineId" : turbineId
}
result = get_data(parturl, params = params)
result = [item["partId"] for item in result]
print(f"获取到部件{result}")
return result
def get_picture(turbineId : str):
"""获取对应机组所有图片
Args:
turbineId (str): 机组ID
Return:
list: 包含所有图片信息的列表(按部件分list)
[
[
{
"imageId": "字符串",
"imageName": "字符串",
"imagePath": "字符串",
"partId": "字符串",
"partName": "字符串",
"imageResolution": "字符串",
"focalDistance": "字符串/None",
"shootingTime": "字符串/None",
"cameraManufacturer": "字符串/None",
"cameraModel": "字符串/None",
"weather": "字符串/None",
"weatherLabel": "字符串/None",
"humidness": "数值/None",
"temperature": "字符串/None",
"windLevel": "数值/None",
"shootingMethod": "字符串/None",
"shootingMethodLabel": "字符串/None",
"shootingDistance": "数值/None",
"collectorName": "字符串/None",
"imageType": "None",
"imageTypeLabel": "None",
"audioList": "None",
"gps": "字符串/None"
},
...
],
[
{
// 相同结构的字典对象
},
...
]
]
"""
picturerul = DTURL + GETPICTURELIST
part_list = get_part_list(turbineId)
result = []
for part_id in part_list:
params = {
"partId" : part_id,
}
result.append(get_data(picturerul, params = params))
return result

View File

@ -15,17 +15,20 @@
DEFAULT_BAOGAO_INFO = { DEFAULT_BAOGAO_INFO = {
#目录 #目录
'picture_dir': "", #图片存放地址 为了报告美观希望总的汇总图片数量为3的倍数
'shengcheng_dir': "", #报告生成的路径 'shengcheng_dir': "", #报告生成的路径
'muban_dir': "", #文档模板存放路径 'muban_dir': "", #文档模板存放路径
'total_picture_dir': "", #用于生成略缩图的路径
"dianxing_enum" : "TYPICAL",
"quexian_enum" : "DEFECT",
"waibu_enum" : "out_work",
"neibu_enum" : "in_work",
"fanglei_enum" : "lightning-protection-work",
"if_waibu" : True,
"if_neibu" : True,
"if_fanglei" : True,
'key_words': '缺,损,裂,脱,污', #关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化 'key_words': '缺,损,裂,脱,污', #关键字,用于汇总图的名字包含缺陷时标红,匹配逻辑为正则匹配单个字则为红 后续可优化
#当前检查报告基本内容
'jizu_type': 'H3-08#', #检查的机组编号
'jiancha_date': '2021年12月10日 9.00', #检查叶片日期 注意空格分开 小时分钟间隔为.
'baogao_date': '2021年12月10日 9.00', #生成报告时间 注意空格分开
'baogao_type': "风力发电机组叶片检查报告", #报告类型
#检查方案 #检查方案
'beizhu': '', 'beizhu': '',
'renyuan_peizhi': '''2人主检飞手1人副检抄表1人 'renyuan_peizhi': '''2人主检飞手1人副检抄表1人
@ -45,35 +48,6 @@ DEFAULT_BAOGAO_INFO = {
1大疆无人机1台M350rtkM300rtkM30TM30精灵4PRO2大疆精灵4PRO+索尼A7R2机身+索尼200-600mm镜头/适马150-600mm镜头 1大疆无人机1台M350rtkM300rtkM30TM30精灵4PRO2大疆精灵4PRO+索尼A7R2机身+索尼200-600mm镜头/适马150-600mm镜头
1人工检查照明设备2套视频记录手机2台含氧量监测仪1台电动扳手2套卷尺1个2爬壁机器人检查无人作业校车+视频图传1套照明设备2套含氧量监测仪1台电动扳手2套卷尺1个''', 1人工检查照明设备2套视频记录手机2台含氧量监测仪1台电动扳手2套卷尺1个2爬壁机器人检查无人作业校车+视频图传1套照明设备2套含氧量监测仪1台电动扳手2套卷尺1个''',
'jiancha_renyuan': '张三', 'jiancha_renyuan': '张三',
#检查信息
'waibu_jiancha': 'True', #是否包含外部检查
'neibu_jiancha': 'True', #是否包含内部检查
'fanglei_jiancha': 'True', #是否包含防雷检查 #注:防雷检测占不存放缺陷图
'jiancha_location': '叶片外部外观', #检查内容文字
'jiancha_fangshi': '作业无人机近距离外观检查', #检查方式文字
'yepian_changjia': '株洲时代新材料科技股份有限公司', #叶片厂家信息
#报告处理信息
'yezhu_renyuan': '李四', #业主(人员)
'changjia_renyuan': '王五', #厂家(人员)
'date_process': '生成报告人员', #数据处理人员 吴总希望获取前端用户执行生成人员为这个人
'baogao_bianzhi': '生成报告人员', #报告编制人员 吴总希望获取前端用户执行生成人员为这个人
'baogao_shenghe': '待填写(人员)', #报告审核人员
'shenghe_date': '待填写(日期)', #报告审核日期
#检查情况汇总表(文字信息) 前端根据是否包含对应部分检查自行确定检查内容,这里默认全部包含
'Y1_jiancha_neirong': '''1.叶片前缘、后缘、PS面、SS面
2.叶片内部导雷卡腹板透光人孔盖版叶根盖板...
3.轮毂至塔基导通内部导线线阻外部导线线阻...''',
'Y2_jiancha_neirong': '''1.叶片前缘、后缘、PS面、SS面
2.叶片内部导雷卡腹板透光人孔盖版叶根盖板...
3.轮毂至塔基导通内部导线线阻外部导线线阻...''',
'Y3_jiancha_neirong': '''1.叶片前缘、后缘、PS面、SS面
2.叶片内部导雷卡腹板透光人孔盖版叶根盖板...
3.轮毂至塔基导通内部导线线阻外部导线线阻...''',
#报告总结
'baogao_zongjie': '''1、因海上风电叶片运行环境恶劣、空气盐碱度高叶片前缘合模缝区域及PS面迎风面涂层易受腐蚀建议定期观察维护。
2经无人机近距离外观检查发现H3-08#机位Y200220AF叶片PS面距叶根20m处发现一处裂纹损伤长度轴向3m该缺陷经我方判定为严重缺陷建议尽快结安排对该机组停机并结合其他检查手段如人工打磨进一步勘查并决定维修处置方案防止风险进一步升级。
3经无人机近距离外观检查未发现H3-08#机位Y200249AF、Y200250AF叶片有明显影响机组正常运行的外部缺陷。
''', #报告总结文字
} }
DEFAULT_BASE_INFO = { #项目基本信息 DEFAULT_BASE_INFO = { #项目基本信息