|
@@ -57,6 +57,8 @@ class UnicomComboTaskView(View):
|
|
|
return response.json(0)
|
|
|
elif operation == 'queryFlowUsedHistory':
|
|
|
return self.query_flow_used_history(response)
|
|
|
+ elif operation == 'queryFlowCache':
|
|
|
+ return self.query_flow_cache(response)
|
|
|
|
|
|
@classmethod
|
|
|
def check_activate_combo(cls, request_dict, response):
|
|
@@ -117,10 +119,23 @@ class UnicomComboTaskView(View):
|
|
|
"""
|
|
|
logger.info('--->进入监控流量使用情况')
|
|
|
try:
|
|
|
- unicom_api = UnicomObjeect()
|
|
|
combo_order_qs = UnicomComboOrderInfo.objects.filter(status=1, is_del=False, combo__is_unlimited=0).values()
|
|
|
if not combo_order_qs.exists():
|
|
|
return response.json(0)
|
|
|
+ asy = threading.Thread(target=UnicomComboTaskView.async_monitoring_flow, args=(combo_order_qs,))
|
|
|
+ asy.start()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('出错了~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(177, repr(e))
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def async_monitoring_flow(cls, combo_order_qs):
|
|
|
+ """
|
|
|
+ 异步检测流量使用详情
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ unicom_api = UnicomObjeect()
|
|
|
today = datetime.datetime.today()
|
|
|
year = today.year
|
|
|
month = today.month
|
|
@@ -162,11 +177,8 @@ class UnicomComboTaskView(View):
|
|
|
if not activate_status:
|
|
|
# 停用
|
|
|
unicom_api.change_device_to_disable(iccid)
|
|
|
-
|
|
|
- return response.json(0)
|
|
|
except Exception as e:
|
|
|
- logger.info('出错了~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return response.json(177, repr(e))
|
|
|
+ logger.info('异步~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
def flow_warning_push(app_user_id, serial_no, combo_order_id, flow_total, flow_usage):
|
|
@@ -390,3 +402,23 @@ class UnicomComboTaskView(View):
|
|
|
# 批量创建IotCardUsageHistory对象
|
|
|
if iot_card_list:
|
|
|
IotCardUsageHistory.objects.bulk_create(iot_card_list)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def query_flow_cache(cls, response):
|
|
|
+ """
|
|
|
+ 查询流量缓存永久的将设置过期时间为10分钟
|
|
|
+ """
|
|
|
+ redis = RedisObject()
|
|
|
+ try:
|
|
|
+ res = redis.get_keys('ASJ:UNICOM:FLOW:*')
|
|
|
+ keys = [key.decode() for key in res]
|
|
|
+ # 进行进一步的处理或打印
|
|
|
+ for key in keys:
|
|
|
+ ttl = redis.get_ttl(key)
|
|
|
+ if ttl == -1:
|
|
|
+ logger.info('iccidFlow:{}'.format(key))
|
|
|
+ redis.CONN.expire(key, 60 * 10)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('出错了~次月激活套餐异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(177, repr(e))
|