设备增加网络配置,增加编程文件传输接口

This commit is contained in:
胡尧
2025-04-16 17:21:36 +08:00
parent 2100ee9590
commit 9c713c2a37
10 changed files with 311 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import main

View File

@@ -0,0 +1,42 @@
import json
from odoo import http
from odoo.http import request
from odoo.addons.sf_machine_connect.models.ftp_operate import transfer_nc_files
class MainController(http.Controller):
@http.route('/api/manual_download_program', type='json', methods=['POST'], auth='wechat_token', cors='*')
def work_reporting(self, **kwargs):
"""
"""
data = json.loads(request.httprequest.data)
maintenance_equipment_name = data.get('maintenance_equipment_name')
model_id = data.get('model_id')
if not maintenance_equipment_name or not model_id:
return {'code': 400, 'message': '参数错误'}
maintenance_equipment = request.env['maintenance.equipment'].sudo().search([('name', '=', maintenance_equipment_name)], limit=1)
if not maintenance_equipment:
return {'code': 400, 'message': '机床不存在'}
ftp_resconfig = request.env['res.config.settings'].sudo().get_values()
source_ftp_info = {
'host': ftp_resconfig['ftp_host'],
'port': int(ftp_resconfig['ftp_port']),
'username': ftp_resconfig['ftp_user'],
'password': ftp_resconfig['ftp_password']
}
target_ftp_info = {
'host': maintenance_equipment.ftp_host,
'port': int(maintenance_equipment.ftp_port),
'username': maintenance_equipment.ftp_username,
'password': maintenance_equipment.ftp_password
}
# 传输nc文件
if transfer_nc_files(
source_ftp_info,
target_ftp_info,
'/' + str(model_id),
'/home/jikimo/testdir'):
return {'code': 200, 'message': 'success'}
else:
return {'code': 500, 'message': '传输失败'}