This commit is contained in:
jinling.yang
2024-08-28 10:28:10 +08:00

View File

@@ -201,7 +201,7 @@ class Sf_Dashboard_Connect(http.Controller):
SELECT time, device_state, program_name SELECT time, device_state, program_name
FROM device_data FROM device_data
WHERE device_name = %s AND time >= %s AND time <= %s WHERE device_name = %s AND time >= %s AND time <= %s
ORDER BY time ASC; ORDER BY time DESC;
''' '''
# 执行SQL命令使用参数绑定 # 执行SQL命令使用参数绑定
cur.execute(sql, (item, begin_time, end_time)) cur.execute(sql, (item, begin_time, end_time))
@@ -308,7 +308,7 @@ class Sf_Dashboard_Connect(http.Controller):
plan_data_total_counts = plan_obj.search_count([('production_line_id.name', '=', line)]) plan_data_total_counts = plan_obj.search_count([('production_line_id.name', '=', line)])
# 工单完成量 # 工单完成量
plan_data_finish_counts = plan_obj.search_count( plan_data_finish_counts = plan_obj.search_count(
[('production_line_id.name', '=', line), ('state', 'not in', ['draft'])]) [('production_line_id.name', '=', line), ('state', 'in', ['finished'])])
# 工单计划量 # 工单计划量
plan_data_plan_counts = plan_obj.search_count( plan_data_plan_counts = plan_obj.search_count(
[('production_line_id.name', '=', line), ('state', 'not in', ['finished'])]) [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])])
@@ -349,7 +349,6 @@ class Sf_Dashboard_Connect(http.Controller):
return json.dumps(res) return json.dumps(res)
# 日完成量统计 # 日完成量统计
class DailyFinishCount(http.Controller):
@http.route('/api/DailyFinishCount', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") @http.route('/api/DailyFinishCount', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
def DailyFinishCount(self, **kw): def DailyFinishCount(self, **kw):
""" """
@@ -382,18 +381,18 @@ class Sf_Dashboard_Connect(http.Controller):
for date in date_list: for date in date_list:
next_day = date + timedelta(days=1) next_day = date + timedelta(days=1)
orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'not in', ['draft']), orders = plan_obj.search([('production_line_id.name', '=', line), ('state', 'in', ['finished']),
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
]) ])
rework_orders = plan_obj.search( rework_orders = plan_obj.search(
[('production_line_id.name', '=', line), ('state', 'in', ['rework']), [('production_line_id.name', '=', line), ('production_id.state', 'in', ['rework']),
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
]) ])
not_passed_orders = plan_obj.search( not_passed_orders = plan_obj.search(
[('production_line_id.name', '=', line), ('state', 'in', ['scrap', 'cancel']), [('production_line_id.name', '=', line), ('production_id.state', 'in', ['scrap', 'cancel']),
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')), (date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00')) (date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
]) ])
@@ -770,10 +769,11 @@ class Sf_Dashboard_Connect(http.Controller):
@http.route('/api/OEEByTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") @http.route('/api/OEEByTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
def OEEByTime(self, **kw): def OEEByTime(self, **kw):
""" """
获取某段时间的oee根据用户指定的时间单位day或hour返回对应的平均值 获取某段时间的OEE根据用户指定的时间单位day或hour返回对应的平均值
如果不传time_unit则默认按天返回并补全没有数据的时间段填充0值。
""" """
res = {'status': 1, 'message': '成功', 'data': {}} res = {'status': 1, 'message': '成功', 'data': {}}
logging.info('前端请求获取某段时间的oee的参数为:%s' % kw) logging.info('前端请求获取某段时间的OEE的参数为:%s' % kw)
# 获取并解析参数 # 获取并解析参数
workcenter_list = ast.literal_eval(kw['workcenter_list']) workcenter_list = ast.literal_eval(kw['workcenter_list'])
@@ -790,8 +790,10 @@ class Sf_Dashboard_Connect(http.Controller):
# 根据时间单位选择不同的时间格式 # 根据时间单位选择不同的时间格式
if time_unit == 'hour': if time_unit == 'hour':
time_format = 'YYYY-MM-DD HH24:00:00' time_format = 'YYYY-MM-DD HH24:00:00'
time_delta = timedelta(hours=1)
else: # 默认为'day' else: # 默认为'day'
time_format = 'YYYY-MM-DD' time_format = 'YYYY-MM-DD'
time_delta = timedelta(days=1)
# 查询并计算OEE平均值 # 查询并计算OEE平均值
oee_data = {} oee_data = {}
@@ -806,7 +808,20 @@ class Sf_Dashboard_Connect(http.Controller):
""", (workcenter, begin_time, end_time)) """, (workcenter, begin_time, end_time))
results = cur.fetchall() results = cur.fetchall()
oee_data[workcenter] = {row[0]: row[1] for row in results} # 初始化当前产线的OEE数据字典
workcenter_oee = {row[0]: row[1] for row in results}
# 补全缺失的时间段
current_time = begin_time
if time_unit != 'hour':
while current_time <= end_time:
time_key = current_time.strftime('%Y-%m-%d')
if time_key not in workcenter_oee:
workcenter_oee[time_key] = 0
current_time += time_delta
# 按时间排序
oee_data[workcenter] = dict(sorted(workcenter_oee.items()))
# 关闭数据库连接 # 关闭数据库连接
cur.close() cur.close()