From df53989f22365585be2e49cf9b0d3fba0bb192e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Fri, 25 Apr 2025 14:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BC=A0=E8=BE=93=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jikimo_printing/models/maintenance_printing.py | 2 +- jikimo_work_reporting_api/controllers/main.py | 11 +++++------ sf_machine_connect/models/ftp_operate.py | 8 ++++---- sf_maintenance/models/sf_maintenance.py | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/jikimo_printing/models/maintenance_printing.py b/jikimo_printing/models/maintenance_printing.py index 641c0af4..6a69662f 100644 --- a/jikimo_printing/models/maintenance_printing.py +++ b/jikimo_printing/models/maintenance_printing.py @@ -22,7 +22,7 @@ class MaintenancePrinting(models.Model): # 切换成A4打印机 try: - self.env['jikimo.printing'].print_qr_code(self.id) + self.env['jikimo.printing'].print_qr_code(self.MTcode) except Exception as e: raise UserError(f"打印失败: {str(e)}") diff --git a/jikimo_work_reporting_api/controllers/main.py b/jikimo_work_reporting_api/controllers/main.py index 9bafb01c..c3ea7daa 100644 --- a/jikimo_work_reporting_api/controllers/main.py +++ b/jikimo_work_reporting_api/controllers/main.py @@ -1,7 +1,7 @@ import json from odoo import http from odoo.http import request -from odoo.addons.sf_machine_connect.models.ftp_operate import transfer_nc_files +from odoo.addons.sf_machine_connect.models.ftp_operate import transfer_files from odoo.addons.sf_base.decorators.api_log import api_log class MainController(http.Controller): @@ -18,12 +18,11 @@ class MainController(http.Controller): if not maintenance_equipment_id or not model_id: return {'code': 400, 'message': '参数错误'} try: - maintenance_equipment_id = int(maintenance_equipment_id) model_id = int(model_id) except Exception as e: return {'code': 400, 'message': '参数类型错误'} maintenance_equipment = request.env['maintenance.equipment'].sudo().search( - [('id', '=', maintenance_equipment_id), ('category_id.equipment_type', '=', '机床')], + [('MTcode', '=', maintenance_equipment_id), ('category_id.equipment_type', '=', '机床')], limit=1 ) if not maintenance_equipment: @@ -55,15 +54,15 @@ class MainController(http.Controller): } # 传输nc文件 try: - result = transfer_nc_files( + result = transfer_files( source_ftp_info, target_ftp_info, '/' + str(model_id), '/', match_str=r'^\d*_\d*-' + tool_groups_id.name + r'-\w{2}-all\.nc$' ) - if result: - return {'code': 200, 'message': 'success'} + if len(result) > 0: + return {'code': 200, 'message': '传输成功', 'file_list': result} else: return {'code': 404, 'message': '未找到编程文件'} except Exception as e: diff --git a/sf_machine_connect/models/ftp_operate.py b/sf_machine_connect/models/ftp_operate.py index 8bd5cf52..e8134ab2 100644 --- a/sf_machine_connect/models/ftp_operate.py +++ b/sf_machine_connect/models/ftp_operate.py @@ -133,7 +133,7 @@ class FtpController: -def transfer_nc_files( +def transfer_files( source_ftp_info, target_ftp_info, source_dir, @@ -151,7 +151,7 @@ def transfer_nc_files( target_dir: str, 目标FTP上的目标目录 keep_dir: bool, 是否保持目录结构,默认False """ - trans_status = [False] + transfered_file_list = [] try: # 连接源FTP source_ftp = FtpController( @@ -217,7 +217,7 @@ def transfer_nc_files( with open(temp_path, 'rb') as f: target_ftp.ftp.storbinary(f'STOR {target_path}', f) - trans_status[0] = True + transfered_file_list.append(item) # 删除临时文件 os.remove(temp_path) logging.info(f"已传输文件: {item}") @@ -259,7 +259,7 @@ def transfer_nc_files( traverse_dir(source_dir) logging.info("所有文件传输完成") - return trans_status[0] + return transfered_file_list except Exception as e: logging.error(f"传输过程出错: {str(e)}") diff --git a/sf_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index 1fdd4e3e..2838a0d0 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -845,7 +845,7 @@ class SfMaintenanceEquipment(models.Model): box_size=10, border=4, ) - qr.add_data(record.id) + qr.add_data(record.MTcode) qr.make(fit=True) qr_image = qr.make_image(fill_color="black", back_color="white")