|
@@ -1,5 +1,6 @@
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
|
|
+import threading
|
|
import time
|
|
import time
|
|
|
|
|
|
import requests
|
|
import requests
|
|
@@ -11,7 +12,8 @@ from Ansjer.config import CRCKey, CONFIG_INFO, CONFIG_TEST, CONFIG_US, \
|
|
from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, UIDModel, Device_Info, \
|
|
from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, UIDModel, Device_Info, \
|
|
iotdeviceInfoModel, LogModel, UidSetModel, UID_Bucket, \
|
|
iotdeviceInfoModel, LogModel, UidSetModel, UID_Bucket, \
|
|
Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, UidUserModel, ExperienceAiModel, \
|
|
Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, UidUserModel, ExperienceAiModel, \
|
|
- AiService, DeviceDomainRegionModel, RegionModel
|
|
|
|
|
|
+ AiService, DeviceDomainRegionModel, RegionModel, VPGModel
|
|
|
|
+from Object.AWS.S3Email import S3Email
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.uidManageResponseObject import uidManageResponseObject
|
|
from Object.uidManageResponseObject import uidManageResponseObject
|
|
@@ -201,9 +203,13 @@ class SerialNumberView(View):
|
|
'operation': '序列号{}绑定uid: {}'.format(serial, uid.uid),
|
|
'operation': '序列号{}绑定uid: {}'.format(serial, uid.uid),
|
|
}
|
|
}
|
|
LogModel.objects.create(**log)
|
|
LogModel.objects.create(**log)
|
|
- if CONFIG_INFO != CONFIG_TEST: # 不为测试服,则序列号写入redis列表
|
|
|
|
- redisObj.rpush(USED_SERIAL_REDIS_LIST, serial)
|
|
|
|
redisObj.del_data(key=key)
|
|
redisObj.del_data(key=key)
|
|
|
|
+
|
|
|
|
+ # 处理序列号状态和计算剩余uid数量线程
|
|
|
|
+ thread = threading.Thread(target=self.rpush_serial_and_count_uid, args=(serial, p2p_type,
|
|
|
|
+ redisObj))
|
|
|
|
+ thread.start()
|
|
|
|
+
|
|
return response.json(0, res)
|
|
return response.json(0, res)
|
|
return response.json(5)
|
|
return response.json(5)
|
|
elif company_serial.status == 2: # 返回uid
|
|
elif company_serial.status == 2: # 返回uid
|
|
@@ -231,6 +237,36 @@ class SerialNumberView(View):
|
|
djangoLogger.exception(repr(e))
|
|
djangoLogger.exception(repr(e))
|
|
return response.json(176, str(e))
|
|
return response.json(176, str(e))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def rpush_serial_and_count_uid(serial, p2p_type, redis_obj):
|
|
|
|
+ """
|
|
|
|
+ 处理序列号状态和计算剩余uid数量线程
|
|
|
|
+ @param serial: 序列号
|
|
|
|
+ @param p2p_type: p2p类型
|
|
|
|
+ @param redis_obj: redis对象
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ # 测试服不处理
|
|
|
|
+ if CONFIG_INFO != CONFIG_TEST:
|
|
|
|
+ redis_obj.rpush(USED_SERIAL_REDIS_LIST, serial)
|
|
|
|
+ vpg_qs = VPGModel.objects.filter()
|
|
|
|
+ if vpg_qs.exists():
|
|
|
|
+ p2p_type = int(p2p_type)
|
|
|
|
+ platform = '尚云' if p2p_type == 1 else 'tutk'
|
|
|
|
+ vpg_id = 1
|
|
|
|
+ if CONFIG_INFO == 'us':
|
|
|
|
+ vpg_id = 3
|
|
|
|
+ elif CONFIG_INFO == 'eur':
|
|
|
|
+ vpg_id = 4
|
|
|
|
+
|
|
|
|
+ for vpg in vpg_qs:
|
|
|
|
+ unused_uid_count = UIDModel.objects.filter(vpg_id=vpg_id, status=0, p2p_type=p2p_type).count()
|
|
|
|
+ # 判断剩余uid数量
|
|
|
|
+ warning_count = 2000
|
|
|
|
+ if unused_uid_count < warning_count:
|
|
|
|
+ email_content = '{}服{]的uid数量少于{}个,请及时处理'.format(CONFIG_INFO, platform, warning_count)
|
|
|
|
+ S3Email().faEmail(email_content, 'servers@ansjer.com')
|
|
|
|
+
|
|
def do_get_uid(self, request_dict, response):
|
|
def do_get_uid(self, request_dict, response):
|
|
serial_number = request_dict.get('serial_number', None)
|
|
serial_number = request_dict.get('serial_number', None)
|
|
token = request_dict.get('token', None)
|
|
token = request_dict.get('token', None)
|