diff --git a/jikimo_workorder_exception/controllers/main.py b/jikimo_workorder_exception/controllers/main.py index 6a17f958..03744ff9 100644 --- a/jikimo_workorder_exception/controllers/main.py +++ b/jikimo_workorder_exception/controllers/main.py @@ -21,8 +21,8 @@ class WorkorderExceptionConroller(http.Controller): try: res = {'Succeed': True, 'ErrorCode': 0, 'Error': ''} datas = request.httprequest.data - ret = json.loads(datas)['Datas'] - if not ret.get('RfidCode') or not ret.get('ErrorType'): + ret = json.loads(datas) + if not ret.get('RfidCode') or not ret.get('coding'): res = {'Succeed': False, 'ErrorCode': 400, 'Error': '参数错误'} return json.JSONEncoder().encode(res) @@ -38,7 +38,7 @@ class WorkorderExceptionConroller(http.Controller): # 创建工单异常记录,关联工单 request.env['jikimo.workorder.exception'].sudo().create({ 'workorder_id': workorder.id, - 'exception_code': ret.get('ErrorType'), + 'exception_code': ret.get('coding'), 'exception_content': ret.get('Error', '') }) diff --git a/jikimo_workorder_exception_notify/data/template_data.xml b/jikimo_workorder_exception_notify/data/template_data.xml index 554ef2c2..dec81e71 100644 --- a/jikimo_workorder_exception_notify/data/template_data.xml +++ b/jikimo_workorder_exception_notify/data/template_data.xml @@ -10,7 +10,7 @@ urgent ### 生产线无功能刀具提醒 单号:工单[{{workorder_id.production_id.name}}]({{url}}) -原因:生产线无加工程序用的{{function_tool_name}}名称功能刀具 +原因:生产线无加工程序要用的功能刀具 工单无定位数据提醒 @@ -19,7 +19,7 @@ markdown urgent - ### 生产线无功能刀具提醒 + ### 工单无定位数据提醒 单号:工单[{{workorder_id.production_id.name}}]({{url}}) 原因:无装夹定位测量数据 diff --git a/jikimo_workorder_exception_notify/models/jikimo_workorder_exception.py b/jikimo_workorder_exception_notify/models/jikimo_workorder_exception.py index bbe69ab5..9849f2cd 100644 --- a/jikimo_workorder_exception_notify/models/jikimo_workorder_exception.py +++ b/jikimo_workorder_exception_notify/models/jikimo_workorder_exception.py @@ -34,7 +34,7 @@ class JikimoWorkorderException(models.Model): rec.add_queue('无定位数据') elif rec.exception_code == 'YC0004': # 无FTP文件,调用cloud接口 - data = {'name': rec.workorder_id.programming_no, 'exception_code': 'YC0004'} + data = {'name': rec.workorder_id.production_id.programming_no, 'exception_code': 'YC0004'} configsettings = self.env['res.config.settings'].sudo().get_values() config_header = Common.get_headers(self, configsettings['token'], configsettings['sf_secret_key']) url = '/api/message/workorder_exception' diff --git a/jikimo_workorder_exception_notify/tests/test_jikimo_workorder_exception_notify.py b/jikimo_workorder_exception_notify/tests/test_jikimo_workorder_exception_notify.py index 85d304be..92886ff3 100644 --- a/jikimo_workorder_exception_notify/tests/test_jikimo_workorder_exception_notify.py +++ b/jikimo_workorder_exception_notify/tests/test_jikimo_workorder_exception_notify.py @@ -14,12 +14,25 @@ class TestJikimoWorkorderExceptionNotify(TestJikimoWorkorderExceptionNotifyCommo ('model', '=', 'jikimo.workorder.exception') ])) self.assertTrue(self.env['jikimo.message.template'].search([ - ('name', '=', '加工失败'), + ('name', '=', '工单加工失败提醒'), ('model', '=', 'jikimo.workorder.exception') ])) + def test_create_message_queue_yc0001(self): + exception_record = self.env['jikimo.workorder.exception'].create({ + 'workorder_id': self.workorder.id, + 'exception_code': 'YC0001', + 'exception_content': '无CNC程序' + }) - def test_create_message_queue(self): + message_record = self.env['jikimo.message.queue'].search([ + ('res_id', '=', exception_record.id), + ('model', '=', 'jikimo.workorder.exception'), + ('message_status', '=', 'pending') + ]) + self.assertFalse(message_record) + + def test_create_message_queue_yc0002(self): exception_record = self.env['jikimo.workorder.exception'].create({ 'workorder_id': self.workorder.id, 'exception_code': 'YC0002', @@ -43,7 +56,45 @@ class TestJikimoWorkorderExceptionNotify(TestJikimoWorkorderExceptionNotifyCommo ('message_template_id', '=', message_template.id) ]) self.assertTrue(message_record) + + def test_create_message_queue_yc0003(self): + exception_record = self.env['jikimo.workorder.exception'].create({ + 'workorder_id': self.workorder.id, + 'exception_code': 'YC0003', + 'exception_content': '无定位数据' + }) + + bussiness_node = self.env['jikimo.message.bussiness.node'].search([ + ('name', '=', '无定位数据'), + ('model', '=', 'jikimo.workorder.exception') + ]) + + message_template = self.env['jikimo.message.template'].search([ + ('bussiness_node_id', '=', bussiness_node.id), + ('model', '=', 'jikimo.workorder.exception') + ]) + + message_record = self.env['jikimo.message.queue'].search([ + ('res_id', '=', exception_record.id), + ('model', '=', 'jikimo.workorder.exception'), + ('message_status', '=', 'pending'), + ('message_template_id', '=', message_template.id) + ]) + self.assertTrue(message_record) + def test_create_message_queue_yc0004(self): + exception_record = self.env['jikimo.workorder.exception'].create({ + 'workorder_id': self.workorder.id, + 'exception_code': 'YC0004', + 'exception_content': '无CNC程序' + }) + + message_record = self.env['jikimo.message.queue'].search([ + ('res_id', '=', exception_record.id), + ('model', '=', 'jikimo.workorder.exception'), + ('message_status', '=', 'pending') + ]) + self.assertFalse(message_record) def test_get_message(self): exception_record = self.env['jikimo.workorder.exception'].create({ diff --git a/sf_dlm_management/views/product_template_management_view.xml b/sf_dlm_management/views/product_template_management_view.xml index 8f58b1ad..b1083332 100644 --- a/sf_dlm_management/views/product_template_management_view.xml +++ b/sf_dlm_management/views/product_template_management_view.xml @@ -16,8 +16,8 @@ - - + + = 1000: + continue + alarm_all_time += float(result[0]) + else: + alarm_all_time += 0.0 + + # with conn.cursor() as cur: + # cur.execute(""" + # SELECT * FROM device_data + # WHERE device_name = %s + # AND total_count IS NOT NULL + # ORDER BY time ASC + # LIMIT 1; + # """, (item, )) + # total_count = fetch_result_as_dict(cur) + # 返回数据 res['data'][item] = { 'wait_time': last_all_time['run_time'] if last_all_time['run_time'] is not None else 0, @@ -1343,6 +1373,9 @@ class Sf_Dashboard_Connect(http.Controller): 'alarm_last_24_nums': len(list(set(alarm_last_24_nums))), 'idle_count': idle_count, 'first_online_time': first_online_duration, + 'alarm_all_time': alarm_all_time, + 'alarm_all_nums': len(list(set(alarm_all_nums))) + # 'total_count': total_count['total_count'] if total_count else 0 } conn.close() diff --git a/sf_maintenance/__manifest__.py b/sf_maintenance/__manifest__.py index 595a5d25..88c53ff8 100644 --- a/sf_maintenance/__manifest__.py +++ b/sf_maintenance/__manifest__.py @@ -11,6 +11,7 @@ 'security/group_security.xml', 'security/ir.model.access.csv', 'security/ir_rule_data.xml', + 'data/scheduled_actions.xml', 'views/maintenance_logs_views.xml', 'views/maintenance_equipment_oee_views.xml', 'views/maintenance_views.xml', diff --git a/sf_maintenance/data/scheduled_actions.xml b/sf_maintenance/data/scheduled_actions.xml new file mode 100644 index 00000000..f75b5263 --- /dev/null +++ b/sf_maintenance/data/scheduled_actions.xml @@ -0,0 +1,14 @@ + + + + 设备运行数据 + + code + model.get_running_datas() + 15 + minutes + -1 + + + + diff --git a/sf_maintenance/models/sf_maintenance_oee.py b/sf_maintenance/models/sf_maintenance_oee.py index a88bc27e..0889fdb5 100644 --- a/sf_maintenance/models/sf_maintenance_oee.py +++ b/sf_maintenance/models/sf_maintenance_oee.py @@ -88,6 +88,69 @@ class SfMaintenanceEquipmentOEE(models.Model): begin_time = fields.Date('开始时间') end_time = fields.Date('结束时间') + def get_running_datas(self): + base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + url_time = base_url + '/api/RunningTimeDetail' + cnc_list_obj = self.env['maintenance.equipment'].sudo().search( + [('function_type', '!=', False), ('active', '=', True)]) + machine_list = list(map(lambda x: x.code, cnc_list_obj)) + # print('machine_list: %s' % machine_list) + + data_time = { + "machine_list": str(machine_list) + } + # 发送POST请求 + response_time = requests.post(url_time, json={}, data=data_time) + # print(response_time.json()) + if response_time.status_code == 200: + result_time = response_time.json() + if result_time['status'] == 1: + real_dict = result_time['data'] + for key in real_dict: + # print(key) + equipment_obj = self.env['maintenance.equipment.oee'].sudo().search([('equipment_code', '=', key)]) + if real_dict[key]['power_on_time'] == 0: + equipment_obj.online_time = 0 + equipment_obj.idle_time = 0 + equipment_obj.idle_rate = 0 + equipment_obj.work_rate = 0 + equipment_obj.fault_time = 0 + equipment_obj.fault_rate = 0 + equipment_obj.fault_nums = 0 + equipment_obj.idle_nums = 0 + equipment_obj.work_time = 0 + else: + equipment_obj.online_time = round(convert_to_seconds(real_dict[key]['power_on_time']) / 3600, 2) + equipment_obj.work_time = round(convert_to_seconds(real_dict[key]['cut_time']) / 3600, 2) + equipment_obj.fault_nums = real_dict[key]['alarm_all_nums'] + equipment_obj.idle_nums = real_dict[key]['idle_count'] + equipment_obj.fault_time = round((float(real_dict[key]['alarm_all_time']) if real_dict[key][ + 'alarm_all_time'] else 0) / 3600, 2) + equipment_obj.idle_time = float(equipment_obj.online_time) - float( + equipment_obj.work_time) if equipment_obj.online_time and equipment_obj.work_time else 0 + equipment_obj.idle_rate = round( + float(equipment_obj.idle_time) / ( + float(equipment_obj.online_time) if equipment_obj.online_time else 1) * 100, 2) + equipment_obj.work_rate = round( + float(equipment_obj.work_time) / ( + float(equipment_obj.online_time) if equipment_obj.online_time else 1) * 100, 2) + + equipment_obj.fault_rate = round( + float(equipment_obj.fault_time) / ( + float(equipment_obj.online_time) if equipment_obj.online_time else 1) * 100, 2) + + # 获取当前时间的时间戳 + current_timestamp = datetime.datetime.now().timestamp() + # 机床上线时间段 + first_online_duration = current_timestamp - int(equipment_obj.equipment_id.first_online_time.timestamp()) + + if equipment_obj.online_time: + equipment_obj.offline_time = round((first_online_duration - float(equipment_obj.online_time)) / 3600, 2) + else: + equipment_obj.offline_time = False + # equipment_obj.offline_time = equipment_obj.equipment_id.first_online_time - ( + # float(equipment_obj.online_time) if equipment_obj.online_time else 0) + # 获取日志详情 def get_day_logs(self): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') @@ -150,12 +213,11 @@ class SfMaintenanceEquipmentOEE(models.Model): self.fault_nums = real_dict['alarm_last_24_nums'] self.idle_nums = real_dict['idle_count'] self.work_time = round( - (convert_to_seconds(real_dict['cut_time']) - convert_to_seconds(real_dict['cut_24_time'])) / 3600, + (convert_to_seconds(real_dict['cut_time']) - convert_to_seconds( + real_dict['cut_24_time'])) / 3600, 2) self.offline_time = 24 - (float(self.online_time) if self.online_time else 0) - - if response.status_code == 200: result = response.json() print('============', result) diff --git a/sf_maintenance/views/maintenance_equipment_oee_views.xml b/sf_maintenance/views/maintenance_equipment_oee_views.xml index 98d6dec5..a78408e6 100644 --- a/sf_maintenance/views/maintenance_equipment_oee_views.xml +++ b/sf_maintenance/views/maintenance_equipment_oee_views.xml @@ -79,12 +79,12 @@ - - - -