接口优化
This commit is contained in:
@@ -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'])])
|
||||||
@@ -770,10 +770,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 +791,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 +809,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()
|
||||||
|
|||||||
Reference in New Issue
Block a user