|
@@ -19,11 +19,12 @@ from django.db.models import Q
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import UnicomComboOrderInfo, UnicomCombo, Order_Model, UnicomDeviceInfo, UnicomFlowPush, \
|
|
|
- IotCardUsageHistory, AccessNumberTaskQueue
|
|
|
+ IotCardUsageHistory, AccessNumberTaskQueue, IotCardOrderUsageHistory
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TelecomObject import TelecomObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
|
from Service.TelecomService import TelecomService
|
|
|
|
|
|
logger = logging.getLogger('info')
|
|
@@ -69,6 +70,8 @@ class UnicomComboTaskView(View):
|
|
|
return self.update_device_cycle_flow(response)
|
|
|
elif operation == 'executeAccessTask':
|
|
|
return self.get_access_number_change_task(response)
|
|
|
+ elif operation == 'queryTotalTrafficToday':
|
|
|
+ return self.query_total_traffic_today(response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -613,3 +616,66 @@ class UnicomComboTaskView(View):
|
|
|
continue
|
|
|
except Exception as e:
|
|
|
logger.info('异步变更卡网络状态异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def query_total_traffic_today(response):
|
|
|
+ """
|
|
|
+ 4G订单查询今日总流量消耗
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ asy = threading.Thread(target=UnicomComboTaskView.async_save_today_use_float)
|
|
|
+ asy.start()
|
|
|
+ logger.info('查询4G订单总消耗流量记录')
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def async_save_today_use_float():
|
|
|
+ # 查询正在使用套餐并且大于等于2024年激活 不等于免费测试流量的订单数据
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ yesterday = today - datetime.timedelta(days=1)
|
|
|
+ yesterday = yesterday.strftime('%Y%m%d')
|
|
|
+
|
|
|
+ start_time, end_time = LocalDateTimeUtil.get_start_and_end_time(today.strftime('%Y-%m-%d'), '%Y-%m-%d')
|
|
|
+ o_combo_qs = UnicomComboOrderInfo.objects \
|
|
|
+ .filter(status=1, year__gte=2024, created_time__gte=1714492800, created_time__lt=start_time) \
|
|
|
+ .exclude(combo__combo_type=4) \
|
|
|
+ .values('order_id', 'iccid', 'flow_total_usage')
|
|
|
+ try:
|
|
|
+ unicom_api = UnicomObjeect()
|
|
|
+ if not o_combo_qs.exists():
|
|
|
+ return
|
|
|
+
|
|
|
+ n_time = int(time.time())
|
|
|
+ day = yesterday[-2:]
|
|
|
+ iccid_list = []
|
|
|
+ for item in o_combo_qs:
|
|
|
+ iccid = item['iccid']
|
|
|
+ try:
|
|
|
+ flow = float(unicom_api.get_flow_usage_total(iccid))
|
|
|
+ if flow == 0:
|
|
|
+ continue
|
|
|
+ old_flow = float(item['flow_total_usage'])
|
|
|
+ if flow == old_flow:
|
|
|
+ continue
|
|
|
+ total_usage = Decimal(flow - old_flow).quantize(Decimal('0.00'))
|
|
|
+ iccid_list.append(IotCardOrderUsageHistory(
|
|
|
+ iccid=iccid,
|
|
|
+ order_id=item['order_id'],
|
|
|
+ card_type=1,
|
|
|
+ cycle=int(yesterday), # 将日期转换为整数形式,如202201
|
|
|
+ cycle_date=int(day),
|
|
|
+ total_traffic=total_usage,
|
|
|
+ created_time=n_time,
|
|
|
+ updated_time=n_time
|
|
|
+ ))
|
|
|
+ if len(iccid_list) >= 300:
|
|
|
+ IotCardOrderUsageHistory.objects.bulk_create(iccid_list)
|
|
|
+ iccid_list = []
|
|
|
+ except Exception as e:
|
|
|
+ logger.error(
|
|
|
+ '查询日用量异常iccid{},errLine:{}, errMsg:{}'.format(iccid, e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ if iccid_list:
|
|
|
+ IotCardOrderUsageHistory.objects.bulk_create(iccid_list)
|
|
|
+ except Exception as e:
|
|
|
+ logger.error('统计4G卡日用量异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|