调整设备运行时长

This commit is contained in:
mgw
2024-09-12 15:36:30 +08:00
parent 06c5f65df2
commit eae902ee92

View File

@@ -497,11 +497,11 @@ class Sf_Dashboard_Connect(http.Controller):
# 使用小时和分钟作为键,确保每个小时的数据有独立的键
key = start_time.strftime('%H:%M:%S') # 只取小时:分钟:秒作为键
time_count_dict[key] = len(orders)
order_counts.append({
# order_counts.append()
res['data'][line] = {
'finish_order_nums': time_count_dict,
'plan_order_nums': 28
})
res['data'][line] = order_counts
}
return json.dumps(res)
date_list = get_date_list(begin_time, end_time)
@@ -981,7 +981,7 @@ class Sf_Dashboard_Connect(http.Controller):
# 如果没有图片数据返回404
return request.not_found()
# 设备运行时长
# 设备运行
@http.route('/api/RunningTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
def RunningTime(self, **kw):
"""
@@ -1143,3 +1143,42 @@ class Sf_Dashboard_Connect(http.Controller):
res['data']['all_time_work_rate'] = all_time_work_rate
return json.dumps(res)
# 设备运行时长
@http.route('/api/RunningTimeDetail', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
def RunningTimeDetail(self, **kw):
"""
获取
"""
res = {'status': 1, 'message': '成功', 'data': {}}
# 连接数据库
conn = psycopg2.connect(**db_config)
# 获取请求的机床数据
machine_list = ast.literal_eval(kw['machine_list'])
def fetch_result_as_dict(cursor):
"""辅助函数:将查询结果转为字典"""
columns = [desc[0] for desc in cursor.description]
return dict(zip(columns, cursor.fetchone())) if cursor.rowcount != 0 else None
for item in machine_list:
with conn.cursor() as cur:
cur.execute("""
SELECT * FROM device_data
WHERE device_name = %s
AND device_state != '离线'
ORDER BY time DESC
LIMIT 1;
""", (item,))
last_all_time = 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,
'cut_time': last_all_time['process_time'] if last_all_time['process_time'] is not None else 0,
'run_time': last_all_time['run_time'] if last_all_time['run_time'] is not None else 0 + last_all_time['process_time'] if last_all_time['process_time'] is not None else 0,
'power_on_time': last_all_time['power_on_time'] if last_all_time['power_on_time'] is not None else 0
}
conn.close()
return json.dumps(res)