From eec79d7d3e6ccc70c5deaeee149f246c56f0e2f9 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Thu, 5 Sep 2024 10:30:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=BAurl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 5168173e..6e661f46 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -15,7 +15,7 @@ db_config = { "user": "postgres", "password": "postgres", "port": "5432", - "host": "172.16.10.98" + "host": "172.16.10.113" } @@ -162,7 +162,8 @@ class Sf_Dashboard_Connect(http.Controller): 'first_online_duration': first_online_duration, # 停机时间:关机时间 - 运行时间 # 停机时长:关机时间 - 初次上线时间 - 'img': f'data:image/png;base64,{machine_data.machine_tool_picture.decode("utf-8")}', + # 'img': f'data:image/png;base64,{machine_data.machine_tool_picture.decode("utf-8")}', + 'img': f'https://xt.sf.jikimo.com/equipment/get_image/{machine_data.id}', 'equipment_type': machine_data.category_id.name, }) @@ -843,3 +844,21 @@ class Sf_Dashboard_Connect(http.Controller): # 返回数据 res['data'] = oee_data return json.dumps(res) + + @http.route(['/equipment/get_image/'], type='http', auth="public", website=True) + def get_image(self, record_id, **kwargs): + # 获取模型中的记录 + record = request.env['maintenance.equipment'].sudo().browse(record_id) + + # 获取图片字段的数据 + image_data_base64 = record.machine_tool_picture + + if image_data_base64: + # 将Base64解码为二进制数据 + image_data_binary = base64.b64decode(image_data_base64) + + # 返回图片数据,并设置正确的Content-Type + return request.make_response(image_data_binary, headers=[('Content-Type', 'image/png')]) + else: + # 如果没有图片数据,返回404 + return request.not_found()