Commit 85090e3c by Aeolus

增加list接口分页

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