Commit 85090e3c by Aeolus

增加list接口分页

parent 8adc1df9
......@@ -46,26 +46,31 @@ def rent_list():
if data_type == 0:
start_time, end_time = Helper.getTodayDate()
info = RentService.get_rent_production_info(spot_id, start_time, end_time)
info, total_count = RentService.get_rent_production_info(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify({'error_code': 200, 'error_message': 'Success', 'data': info,
'detail': {'total_income': total_income, 'total_rent': total_rent}})
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
elif data_type == 1:
start_time, end_time = Helper.getYesterdayDate()
info = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify({'error_code': 200, 'error_message': 'Success', 'data': info,
'detail': {'total_income': total_income, 'total_rent': total_rent}})
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
elif data_type == 2:
start_time, end_time = Helper.getSevenDate()
info = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify({'error_code': 200, 'error_message': 'Success', 'data': info,
'detail': {'total_income': total_income, 'total_rent': total_rent}})
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
else:
start_time, end_time = Helper.getMonthDate()
info = RentService.get_not_return_production(spot_id, start_time, end_time)
return jsonify(BASE_RESPONSE(data=info).to_dict())
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, page, limit)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, })
@route_rent.route('/detail', methods=['GET', 'POST'])
......
......@@ -23,6 +23,8 @@ class RentService():
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
......@@ -42,10 +44,10 @@ class RentService():
else:
cur_info['status'] = 0
data.append(cur_info)
return data
return data, total_count
@staticmethod
def get_not_return_production(spot_id, start_time, end_time):
def get_not_return_production(spot_id, start_time, end_time, page, limit):
where = {
Rent.spot_id == spot_id,
Production.is_out == 1,
......@@ -53,8 +55,11 @@ class RentService():
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).all()
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
for info in rent_info:
tmp = {
......@@ -64,17 +69,22 @@ class RentService():
'status': 0
}
data.append(tmp)
return data
return data, total_count
@staticmethod
def get_rent_production_info(spot_id, start_time, end_time):
def get_rent_production_info(spot_id, start_time, end_time, page, limit):
where = {
Rent.spot_id == spot_id,
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).all()
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
for info in rent_info:
cur_info = {}
......@@ -92,7 +102,7 @@ class RentService():
else:
cur_info['status'] = 0
data.append(cur_info)
return data
return data, total_count
@staticmethod
def get_no_production_detail(rent_no):
......
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