增加由dashboard调用的接口
This commit is contained in:
1
sf_machine_connect/controllers/__init__.py
Normal file
1
sf_machine_connect/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import controllers
|
||||
98
sf_machine_connect/controllers/controllers.py
Normal file
98
sf_machine_connect/controllers/controllers.py
Normal file
@@ -0,0 +1,98 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import ast
|
||||
import json
|
||||
import logging
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class Sf_Dashboard_Connect(http.Controller):
|
||||
|
||||
@http.route('/api/get_machine_datas/list', type='http', auth='public', methods=['GET', 'POST'], csrf=False,
|
||||
cors="*")
|
||||
def get_machine_datas_list(self, **kw):
|
||||
"""
|
||||
拿到机床数据返回给大屏展示
|
||||
:param kw:
|
||||
:return:
|
||||
"""
|
||||
res = {'status': 1, 'message': '成功', 'data': []}
|
||||
logging.info('前端请求机床数据的参数为:%s' % kw)
|
||||
# tem_list = [
|
||||
# "XT-GNJC-WZZX-X800-Y550-Z550-T24-A5-1", "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-3",
|
||||
# "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-4", "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-5",
|
||||
# "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-6", "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-7",
|
||||
# "XT-GNJC-LSZX-X800-Y550-Z550-T24-A3-8", "XT-GNJC-WZZX-X800-Y550-Z550-T24-A5-2",
|
||||
# "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-9", "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-10",
|
||||
# "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-11", "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-12",
|
||||
# "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-13", "XT-GNJC-GSZG-X600-Y400-Z350-T21-A3-14"
|
||||
# ]
|
||||
try:
|
||||
equipment_obj = request.env['maintenance.equipment'].sudo()
|
||||
# 获取请求的机床数据
|
||||
machine_list = ast.literal_eval(kw['machine_list'])
|
||||
for item in machine_list:
|
||||
machine_data = equipment_obj.search([('code', '=', item)])
|
||||
if machine_data:
|
||||
res['data'].append({
|
||||
'id': machine_data.id,
|
||||
'name': machine_data.name,
|
||||
'code': machine_data.code,
|
||||
'status': machine_data.status,
|
||||
'run_status': machine_data.run_status,
|
||||
'run_time': machine_data.run_time,
|
||||
'system_date': machine_data.system_date,
|
||||
'system_time': machine_data.system_time,
|
||||
'cut_time': machine_data.cut_time,
|
||||
'cut_status': machine_data.cut_status,
|
||||
'program': machine_data.program,
|
||||
'program_name': machine_data.program_name,
|
||||
'program_status': machine_data.program_status,
|
||||
'tool_num': machine_data.tool_num,
|
||||
'machine_power_on_time': machine_data.machine_power_on_time,
|
||||
'product_counts': machine_data.product_counts,
|
||||
'mode': machine_data.mode,
|
||||
'start_time': machine_data.start_time,
|
||||
'end_time': machine_data.end_time,
|
||||
'program_start_time': machine_data.program_start_time,
|
||||
'program_end_time': machine_data.program_end_time,
|
||||
'standby_start_time': machine_data.standby_start_time,
|
||||
'standby_end_time': machine_data.standby_end_time,
|
||||
'offline_start_time': machine_data.offline_start_time,
|
||||
'offline_end_time': machine_data.offline_end_time,
|
||||
'emg_status': machine_data.emg_status,
|
||||
'current_program': machine_data.current_program,
|
||||
'current_program_seq': machine_data.current_program_seq,
|
||||
'x_abs_pos': machine_data.x_abs_pos,
|
||||
'y_abs_pos': machine_data.y_abs_pos,
|
||||
'z_abs_pos': machine_data.z_abs_pos,
|
||||
'feed_speed_set': machine_data.feed_speed_set,
|
||||
'act_feed_speed': machine_data.act_feed_speed,
|
||||
'spindle_speed_set': machine_data.spindle_speed_set,
|
||||
'act_spindle_speed': machine_data.act_spindle_speed,
|
||||
'spindle_load': machine_data.spindle_load,
|
||||
'x_axis_load': machine_data.x_axis_load,
|
||||
'y_axis_load': machine_data.y_axis_load,
|
||||
'z_axis_load': machine_data.z_axis_load,
|
||||
'rapid_feed': machine_data.rapid_feed,
|
||||
'feed_rate': machine_data.feed_rate,
|
||||
'x_mach_coord': machine_data.x_mach_coord,
|
||||
'y_mach_coord': machine_data.y_mach_coord,
|
||||
'z_mach_coord': machine_data.z_mach_coord,
|
||||
'x_rel_coord': machine_data.x_rel_coord,
|
||||
'y_rel_coord': machine_data.y_rel_coord,
|
||||
'z_rel_coord': machine_data.z_rel_coord,
|
||||
'x_dis_coord': machine_data.x_dis_coord,
|
||||
'y_dis_coord': machine_data.y_dis_coord,
|
||||
'z_dis_coord': machine_data.z_dis_coord,
|
||||
'alarm_time': machine_data.alarm_time,
|
||||
'alarm_msg': machine_data.alarm_msg,
|
||||
'clear_time': machine_data.clear_time,
|
||||
})
|
||||
|
||||
return json.JSONEncoder().encode(res)
|
||||
except Exception as e:
|
||||
logging.info('前端请求机床数据失败,原因:%s' % e)
|
||||
res['status'] = -1
|
||||
res['message'] = '前端请求机床数据失败,原因:%s' % e
|
||||
return json.JSONEncoder().encode(res)
|
||||
Reference in New Issue
Block a user