|
@@ -32,6 +32,8 @@ class UnicomDataView(View):
|
|
|
return response.json(token_code)
|
|
|
if operation == 'getFlowInfo': # 查询流量使用情况
|
|
|
return self.get_flow_info(request_dict, response)
|
|
|
+ elif operation == 'getMonthlyFlowInfo': # 查询流量使用情况
|
|
|
+ return self.get_monthly_flow_info(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -102,20 +104,18 @@ class UnicomDataView(View):
|
|
|
total_flow = 0
|
|
|
for item in iccid_qs:
|
|
|
item['flow_total_usage'] = 0
|
|
|
- item['flow_info'] = []
|
|
|
key = 'monthly' + item['iccid']
|
|
|
user_qs = UnicomDeviceInfo.objects.filter(iccid=item['iccid']).values('user_id')
|
|
|
item['user_id'] = user_qs[0]['user_id'] if user_qs.exists() else ''
|
|
|
if year and month:
|
|
|
file = year + '-' + month
|
|
|
- flow = redis_obj.get_hash_data(key, file)
|
|
|
+ flow = redis_obj.get_hash_data(key, file)[0]
|
|
|
+ flow = flow.decode() if flow else 0
|
|
|
item['flow_total_usage'] = flow
|
|
|
- item['flow_info'].append({file: flow})
|
|
|
else:
|
|
|
flow_dict = redis_obj.get_all_hash_data(key)
|
|
|
for k, v in flow_dict.items():
|
|
|
item['flow_total_usage'] += float(v)
|
|
|
- item['flow_info'].append({k.decode(): float(v)})
|
|
|
iccid_list.append(item)
|
|
|
total_flow += float(item['flow_total_usage'])
|
|
|
res = {
|
|
@@ -128,3 +128,39 @@ class UnicomDataView(View):
|
|
|
return response.json(444)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def get_monthly_flow_info(cls, request_dict, response):
|
|
|
+ """
|
|
|
+ 查询月度流量使用情况
|
|
|
+ @param request_dict: 请求数据
|
|
|
+ @request_dict year: 年
|
|
|
+ @request_dict month: 月
|
|
|
+ @request_dict iccid: 卡号
|
|
|
+ @param response:响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ iccid = request_dict.get('iccid', None)
|
|
|
+ year = request_dict.get('year', None)
|
|
|
+ month = request_dict.get('month', None)
|
|
|
+ redis_obj = RedisObject()
|
|
|
+ data_list = []
|
|
|
+ if not iccid:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ key = 'monthly' + iccid
|
|
|
+ if year and month:
|
|
|
+ file = year + '-' + month
|
|
|
+ flow = redis_obj.get_hash_data(key, file)
|
|
|
+ flow = flow.decode() if flow else 0
|
|
|
+ data_list.append({file: flow})
|
|
|
+ else:
|
|
|
+ flow_dict = redis_obj.get_all_hash_data(key)
|
|
|
+ for k, v in flow_dict.items():
|
|
|
+ data_list.append({k.decode(): float(v)})
|
|
|
+ res = {
|
|
|
+ 'list': data_list,
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|