Commit a5d23ca1 by Aeolus

用户使用时长分析接口修改

parent 4ced67f9
......@@ -81,9 +81,33 @@ def user_rent_number():
def user_rent_time():
json_data = request.get_json()
spot_id = json_data['spot_id'] if 'spot_id' in json_data else 0
return_data = [0, 0, 0]
move_spot_ids = {16: 50, 42: 51, 48: 49}
sql_spot_id = spot_id
while True:
tmp_data = []
sql = """
select count(1) as number from(SELECT id FROM production
where spot_id ='{spot_id}' and total >0 and return_time is not null and time_to_sec(timediff(return_time, created_at))<3600) as rs
union all
select count(1) as number from(SELECT id FROM production
where spot_id ='{spot_id}' and total >0 and return_time is not null and time_to_sec(timediff(return_time, created_at))>3600 and time_to_sec(timediff(return_time, created_at))<=7200) as rs
union all
select count(1) as number from(SELECT id FROM production
where spot_id ='{spot_id}' and total >0 and return_time is not null and time_to_sec(timediff(return_time, created_at))<7200) as rs;
""".format(spot_id=spot_id)
result = db.session.execute(sql).fetchall()
if result:
for i in result:
tmp_data.append(i.number)
for i in range(3):
return_data[i] += tmp_data[i]
if not move_spot_ids.get(sql_spot_id, None):
break
else:
sql_spot_id = move_spot_ids[sql_spot_id]
rent_time_info = ReportService.get_customer_rent_time(spot_id)
return jsonify(BASE_RESPONSE(data=rent_time_info).to_dict())
return jsonify(BASE_RESPONSE(data=return_data).to_dict())
@route_report.route('/income_chart', methods=['GET', 'POST'])
......@@ -154,16 +178,15 @@ def get_machine_rent_number():
""".format(sql_spot_id, datetime.datetime.now().strftime("%Y-%m-%d"))
result = db.session.execute(sql).fetchall()
if result:
for i in result:
if machines.get(str(i.id), None):
machines[str(i.id)][1] += i.number
if result:
if not move_spot_ids.get(sql_spot_id, None):
break
else:
sql_spot_id = move_spot_ids[sql_spot_id]
data = list(machines.values())
print(data)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': data})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment