优化接口,使其易于取值

This commit is contained in:
mgw
2024-08-21 17:44:22 +08:00
parent bae2592587
commit b26919a40d

View File

@@ -376,7 +376,7 @@ class Sf_Dashboard_Connect(http.Controller):
:param kw: :param kw:
:return: :return:
""" """
res = {'status': 1, 'message': '成功', 'data': []} res = {'status': 1, 'message': '成功', 'data': {}}
plan_obj = request.env['sf.production.plan'].sudo() plan_obj = request.env['sf.production.plan'].sudo()
line_list = ast.literal_eval(kw['line_list']) line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"') begin_time_str = kw['begin_time'].strip('"')
@@ -409,24 +409,73 @@ class Sf_Dashboard_Connect(http.Controller):
'date': date.strftime('%Y-%m-%d'), 'date': date.strftime('%Y-%m-%d'),
'order_count': len(orders) 'order_count': len(orders)
}) })
# 外面包一层没什么是包一层不能解决的包一层就能区分了类似于包一层div
# 外面包一层的好处是,可以把多个数据结构打包在一起,方便前端处理
res['data'] = order_counts # date_list_dict = {line: order_counts}
return json.dumps(res)
# # 实时产量 res['data'][line] = order_counts
# @http.route('/api/RealTimeProduct', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") return json.dumps(res)
# def RealTimeProduct(self, **kw):
# """ # 实时产量
# 获取实时产量 @http.route('/api/RealTimeProduct', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
# :param kw: def RealTimeProduct(self, **kw):
# :return: """
# """ 获取实时产量
# :param kw:
# def get_real_time_product(line_list): :return:
# res = {'status': 1, 'message': '成功', 'data': []} """
# plan_obj = request.env['sf.production.plan'].sudo() res = {'status': 1, 'message': '成功', 'data': {}}
# for line in line_list: plan_obj = request.env['sf.production.plan'].sudo()
# plan_data = plan_obj.search([('production_line_id.name', '=', line)]) line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"')
end_time_str = kw['end_time'].strip('"')
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
def get_hourly_intervals(start_time, end_time):
intervals = []
current_time = start_time
while current_time < end_time:
next_hour = current_time + timedelta(hours=1)
intervals.append((current_time, min(next_hour, end_time)))
current_time = next_hour
return intervals
# 当班计划量
for line in line_list:
plan_order_nums = plan_obj.search_count(
[('production_line_id.name', '=', line), ('state', 'not in', ['draft']),
('date_planned_start', '>=', begin_time),
('date_planned_start', '<', end_time)
])
finish_order_nums = plan_obj.search_count(
[('production_line_id.name', '=', line), ('state', 'in', ['finished']),
('date_planned_start', '>=', begin_time),
('date_planned_start', '<', end_time)
])
hourly_intervals = get_hourly_intervals(begin_time, end_time)
production_counts = []
for start, end in hourly_intervals:
orders = plan_obj.search([
('actual_end_time', '>=', start.strftime('%Y-%m-%d %H:%M:%S')),
('actual_end_time', '<', end.strftime('%Y-%m-%d %H:%M:%S')),
('production_line_id.name', '=', line)
])
production_counts.append({
'start_time': start.strftime('%Y-%m-%d %H:%M:%S'),
'end_time': end.strftime('%Y-%m-%d %H:%M:%S'),
'production_count': len(orders)
})
production_counts_dict = {'production_counts': production_counts,
'plan_order_nums': plan_order_nums,
'finish_order_nums': finish_order_nums,
}
res['data'][line] = production_counts_dict
# res['data'].append({line: production_counts})
return json.dumps(res)
# 工单明细 # 工单明细
@http.route('/api/OrderDetail', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") @http.route('/api/OrderDetail', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*")
@@ -437,7 +486,8 @@ class Sf_Dashboard_Connect(http.Controller):
:return: :return:
""" """
res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []} # res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
res = {'status': 1, 'message': '成功', 'data': {}}
plan_obj = request.env['sf.production.plan'].sudo() plan_obj = request.env['sf.production.plan'].sudo()
line_list = ast.literal_eval(kw['line_list']) line_list = ast.literal_eval(kw['line_list'])
begin_time_str = kw['begin_time'].strip('"') begin_time_str = kw['begin_time'].strip('"')
@@ -445,6 +495,9 @@ class Sf_Dashboard_Connect(http.Controller):
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S') begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S') end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
print('line_list: %s' % line_list) print('line_list: %s' % line_list)
not_done_data = []
done_data = []
final_data = {}
for line in line_list: for line in line_list:
# 未完成订单 # 未完成订单
@@ -506,7 +559,7 @@ class Sf_Dashboard_Connect(http.Controller):
'state': state_dict[order.state], 'state': state_dict[order.state],
} }
res['not_done_data'].append(line_dict) not_done_data.append(line_dict)
for finish_order in finish_orders: for finish_order in finish_orders:
blank_name = '' blank_name = ''
@@ -532,6 +585,8 @@ class Sf_Dashboard_Connect(http.Controller):
'finish_time': finish_order.actual_end_time.strftime('%Y-%m-%d %H:%M:%S'), 'finish_time': finish_order.actual_end_time.strftime('%Y-%m-%d %H:%M:%S'),
} }
res['done_data'].append(line_dict) done_data.append(line_dict)
# 开始包一层
res['data'][line] = {'not_done_data': not_done_data, 'done_data': done_data}
return json.dumps(res) return json.dumps(res)