|
@@ -9,13 +9,13 @@ import xlrd
|
|
|
import xlwt
|
|
|
import calendar
|
|
|
|
|
|
-from django.db import transaction
|
|
|
+from django.db import transaction, connection
|
|
|
from django.utils.encoding import escape_uri_path
|
|
|
from django.http import HttpResponse, StreamingHttpResponse
|
|
|
from django.views.generic.base import View
|
|
|
from Model.models import VodBucketModel, CDKcontextModel, Store_Meal, Order_Model, \
|
|
|
UID_Bucket, ExperienceContextModel, Lang, CloudLogModel, UidSetModel, Unused_Uid_Meal, \
|
|
|
- Device_Info, VodHlsModel, UnicomComboOrderInfo, Device_User, AiService
|
|
|
+ Device_Info, DeviceTypeModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.CommonService import CommonService
|
|
@@ -1335,113 +1335,103 @@ class serveManagement(View):
|
|
|
流失预警界面
|
|
|
@param request_dict:
|
|
|
@param response:
|
|
|
+ @param userName:用户名
|
|
|
+ @param uid:设备uid
|
|
|
+ @param grade:预警等级
|
|
|
"""
|
|
|
+ userName = request_dict.get('userName', None)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ grade = request_dict.get('grade', None)
|
|
|
pageNo = request_dict.get('pageNo', None)
|
|
|
pageSize = request_dict.get('pageSize', None)
|
|
|
- use_status = request_dict.get('use_status', None)
|
|
|
- if not all([pageNo, pageSize]):
|
|
|
+ if not all({pageNo, pageSize}):
|
|
|
return response.json(444)
|
|
|
+ # 获取云存套餐信息表内的设备uid
|
|
|
page = int(pageNo)
|
|
|
line = int(pageSize)
|
|
|
- nowTime = int(time.time())
|
|
|
- attrition_list = []
|
|
|
- r = 0
|
|
|
- uid_buncket_qs = UID_Bucket.objects.filter(status=0).values('use_status', 'uid', 'endTime', 'addTime',
|
|
|
- 'use_status').annotate(count=Count('uid')).order_by(
|
|
|
- '-addTime')
|
|
|
- if use_status:
|
|
|
- uid_buncket_qs = uid_buncket_qs.filter(use_status=use_status)
|
|
|
- count = uid_buncket_qs.count()
|
|
|
- uid_buncket_qs = uid_buncket_qs[(page - 1) * line:page * line]
|
|
|
+ para_list = [userName, uid, grade]
|
|
|
+ not_upload_list = []
|
|
|
+ para_count = para_list.count(None)
|
|
|
try:
|
|
|
- for uid_buncket in uid_buncket_qs:
|
|
|
- day = 0
|
|
|
- endTime = uid_buncket['endTime']
|
|
|
- addTime = uid_buncket['addTime']
|
|
|
- start_time = addTime
|
|
|
- start_time = datetime.datetime.fromtimestamp(int(start_time))
|
|
|
- r += 1
|
|
|
- if r > 1:
|
|
|
- nowTime = str(nowTime)
|
|
|
- time_tuple = time.strptime(nowTime, ('%Y-%m-%d %H:%M:%S'))
|
|
|
- nowTime = time.mktime(time_tuple) # 把格式化好的时间转换成时间戳
|
|
|
- nowTime = datetime.datetime.fromtimestamp(int(nowTime))
|
|
|
- time_list = CommonService.cutting_time(start_time, nowTime, 'day')
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid=uid_buncket['uid']).values('uid')
|
|
|
- # 获取自云存开通起没有上传数据天数
|
|
|
- for date in time_list:
|
|
|
- vod_hls_qs = vod_hls_qs.filter(time__gte=date[0], time__lt=date[1])
|
|
|
- if not vod_hls_qs.exists():
|
|
|
- day += 1
|
|
|
- if day > 29:
|
|
|
- break
|
|
|
- day = day
|
|
|
- level = ''
|
|
|
- use_status = uid_buncket['use_status']
|
|
|
- if not use_status == 1:
|
|
|
- level = '八号预警'
|
|
|
+ # 筛选数据
|
|
|
+ cursor = connection.cursor()
|
|
|
+ sql = "SELECT t1.userID_id, du.username, t1.uid, t1.addTime, t1.use_status, t1.`day`, t1.grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day`, t1.grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day`,(CASE WHEN t1.`day` >= '15' AND t1.`day` < '25' THEN '一号预警' WHEN t1.use_status = '1' AND t1.`day` >= '25' THEN '二号预警' WHEN t1.use_status = 2 AND t1.`day` >= '25' THEN '八号预警' ELSE '预警取消' END ) AS grade FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, t1.`day` FROM(SELECT t1.userID_id, t1.uid, t1.addTime, t1.use_status, TIMESTAMPDIFF(DAY,FROM_UNIXTIME(t1.addTime, '%Y-%m-%d' ),DATE_FORMAT( NOW(), '%Y-%m-%d' )) AS 'day' FROM (SELECT di.userID_id, vub.uid, vub.addTime, vub.use_status FROM vod_uid_bucket AS vub, device_info AS di WHERE vub.uid = di.UID AND vub.addTime > '1669824000' GROUP BY di.userID_id) AS t1 WHERE t1.uid NOT IN (SELECT uid FROM uid_cloud_storage_count)) AS t1 WHERE t1.`day`>='15' AND t1.userID_id is NOT NULL) AS t1 ORDER BY t1.userID_id)AS t1 WHERE t1.userID_id NOT IN (SELECT di.userID_id FROM `uid_cloud_storage_count` AS vcsc LEFT JOIN device_info AS di ON vcsc.uid = di.UID WHERE di.userID_id is NOT NULL))AS t1 LEFT JOIN device_user AS du ON t1.userID_id = du.userID"
|
|
|
+ cursor.execute(sql)
|
|
|
+ uid_type_tuple = cursor.fetchall()
|
|
|
+ total = len(uid_type_tuple)
|
|
|
+ cursor.close() # 执行完,关闭
|
|
|
+ connection.close()
|
|
|
+ result_list = []
|
|
|
+ more_list = [] # 多个参数筛查结果
|
|
|
+ new_list = [] # 单独一个参数筛查结果
|
|
|
+ col_names = [desc[0] for desc in cursor.description]
|
|
|
+ for uid_type in uid_type_tuple:
|
|
|
+ uid_dict = dict(zip(col_names, uid_type))
|
|
|
+ result_list.append(uid_dict)
|
|
|
+ if para_count != 2 and para_count != 3: # 两个及以上参数进行筛查
|
|
|
+ if userName and uid and grade == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['uid'] == uid:
|
|
|
+ more_list.append(result)
|
|
|
+ if userName and grade and uid == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ if uid and grade and userName == None:
|
|
|
+ for result in result_list:
|
|
|
+ if result['uid'] == uid and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ if userName and uid and grade:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName and result['uid'] == uid and result['grade'] == grade:
|
|
|
+ more_list.append(result)
|
|
|
+ result_list = more_list[(page - 1) * line:page * line]
|
|
|
+ if para_count == 2: # 一个参数进行筛查
|
|
|
+ if userName:
|
|
|
+ for result in result_list:
|
|
|
+ if result['username'] == userName:
|
|
|
+ new_list.append(result)
|
|
|
+ if uid:
|
|
|
+ for result in result_list:
|
|
|
+ if result['uid'] == uid:
|
|
|
+ new_list.append(result)
|
|
|
+ if grade:
|
|
|
+ for result in result_list:
|
|
|
+ if result['grade'] == grade:
|
|
|
+ new_list.append(result)
|
|
|
+ result_list = new_list[(page - 1) * line:page * line]
|
|
|
+ else:
|
|
|
+ result_list = result_list[(page - 1) * line:page * line]
|
|
|
+ for item in result_list: # 获取账号下的云存设备数量
|
|
|
+ userID_id = item['userID_id']
|
|
|
+ device_info_qs = Device_Info.objects.filter(userID_id=userID_id).annotate(count=Count('UID')).values(
|
|
|
+ 'UID')
|
|
|
+ count = device_info_qs.count()
|
|
|
+ if count == 1 or count == 0:
|
|
|
+ item['device_number'] = count
|
|
|
else:
|
|
|
- # 统计设备目前未上传天数
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid=uid_buncket['uid']).values('uid')
|
|
|
- if 15 <= day < 25:
|
|
|
- if vod_hls_qs.exists():
|
|
|
- level = '取消预警'
|
|
|
+ device_number = 0
|
|
|
+ for device_info in device_info_qs:
|
|
|
+ uid = device_info['UID']
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ucode', 'device_type')
|
|
|
+ ucode = uid_set_qs[0]['ucode'] if uid_set_qs.exists() else ''
|
|
|
+ device_type = uid_set_qs[0]['device_type'] if uid_set_qs.exists() else ''
|
|
|
+ if len(ucode) > 4:
|
|
|
+ number = ucode[-4]
|
|
|
else:
|
|
|
- level = '一号预警'
|
|
|
- if day >= 25:
|
|
|
- if vod_hls_qs.exists():
|
|
|
- level = '取消预警'
|
|
|
- else:
|
|
|
- startTime = uid_buncket['addTime'] # 开始时间
|
|
|
- nowTime = str(nowTime)
|
|
|
- time_tuple = time.strptime(nowTime, ('%Y-%m-%d %H:%M:%S'))
|
|
|
- nowTime = time.mktime(time_tuple) # 把格式化好的时间转换成时间戳
|
|
|
- startTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(startTime)) # 开始时间
|
|
|
- nowTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(nowTime)) # 结束时间
|
|
|
- startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M:%S') # 开始时间
|
|
|
- nowTime = datetime.datetime.strptime(nowTime, '%Y-%m-%d %H:%M:%S') # 结束时间
|
|
|
- day = (nowTime - startTime).days
|
|
|
- level = '二号预警'
|
|
|
- device_user = Device_User.objects.filter(device_info__UID=uid_buncket['uid']).values('username',
|
|
|
- 'userID')
|
|
|
- username = device_user[0]['username'] if device_user.exists() else ''
|
|
|
- userID = device_user[0]['userID'] if device_user.exists() else ''
|
|
|
- order_qs = Order_Model.objects.filter(order_type=0, userID=userID).values('UID').annotate(
|
|
|
- count=Count('UID'))
|
|
|
- # 用户设备购买云存数量
|
|
|
- if not order_qs.exists():
|
|
|
- device_count = 0
|
|
|
- else:
|
|
|
- uid_count = order_qs.count()
|
|
|
- if uid_count == 1:
|
|
|
- device_count = 'N/A'
|
|
|
- else:
|
|
|
- device_count = uid_count
|
|
|
- order_uid_list = [order[uid] for order in order_qs for uid in order]
|
|
|
- vod_hls_qs = VodHlsModel.objects.filter(uid__in=order_uid_list).values('uid')
|
|
|
- # 套餐使用期间是否上传过数据
|
|
|
- if vod_hls_qs.exists():
|
|
|
- other = '有'
|
|
|
- else:
|
|
|
- other = '无'
|
|
|
-
|
|
|
- data = {
|
|
|
- 'userID': userID,
|
|
|
- 'uid': uid_buncket['uid'],
|
|
|
- 'endTime': CommonService.timestamp_to_str(endTime),
|
|
|
- 'addTime': CommonService.timestamp_to_str(addTime),
|
|
|
- 'status': uid_buncket['use_status'],
|
|
|
- 'level': level,
|
|
|
- 'day': day,
|
|
|
- 'other': other,
|
|
|
- 'username': username,
|
|
|
- 'count': device_count,
|
|
|
- }
|
|
|
- attrition_list.append(data)
|
|
|
- test_list = [list for list in attrition_list if list['day'] > 14] # 输出15天及以上的数据
|
|
|
- return response.json(0, {'test_list': test_list, 'total': count})
|
|
|
+ continue
|
|
|
+ device_type_qs = DeviceTypeModel.objects.filter(type=device_type).values('model')
|
|
|
+ model = device_type_qs[0]['model'] if device_type_qs.exists() else ''
|
|
|
+ # 判断设备是否为ipc设备和是否支持云存
|
|
|
+ if model == 2 and number in ['4', '5']:
|
|
|
+ device_number += 1
|
|
|
+ item['device_number'] = device_number
|
|
|
+ item['other_device'] = 0
|
|
|
+ not_upload_list.append(item)
|
|
|
+ return response.json(0, {'result_list': not_upload_list, 'total': total})
|
|
|
except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ meg = '异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e))
|
|
|
+ return response.json(500, meg)
|
|
|
|
|
|
def deactivationPackage(self, userID, request_dict, response):
|
|
|
"""
|