|
@@ -12,7 +12,7 @@ from Ansjer.config import CRCKey, CONFIG_INFO, CONFIG_TEST, CONFIG_US, \
|
|
|
from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, UIDModel, Device_Info, \
|
|
|
iotdeviceInfoModel, LogModel, UidSetModel, UID_Bucket, \
|
|
|
Unused_Uid_Meal, Order_Model, StsCrdModel, VodHlsModel, ExperienceContextModel, UidUserModel, ExperienceAiModel, \
|
|
|
- AiService, DeviceDomainRegionModel, RegionModel, VPGModel
|
|
|
+ AiService, DeviceDomainRegionModel, RegionModel
|
|
|
from Object.AWS.S3Email import S3Email
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.TokenObject import TokenObject
|
|
@@ -231,7 +231,8 @@ class SerialNumberView(View):
|
|
|
'initStringApp': uid['uid__init_string_app'],
|
|
|
}
|
|
|
return response.json(0, res)
|
|
|
- elif company_serial.status == 3:
|
|
|
+ elif company_serial.status == 3: # 已占用
|
|
|
+ self.log_and_send_email(request, serial, now_time)
|
|
|
return response.json(10042)
|
|
|
except Exception as e:
|
|
|
djangoLogger = logging.getLogger('django')
|
|
@@ -266,6 +267,37 @@ class SerialNumberView(View):
|
|
|
email_content = '{}服{]的uid数量少于{}个,请及时处理'.format(CONFIG_INFO, platform, warning_count)
|
|
|
S3Email().faEmail(email_content, 'servers@ansjer.com')
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def log_and_send_email(request, serial, now_time):
|
|
|
+ """
|
|
|
+ 记录占用操作日志及发送邮件通知
|
|
|
+ @param request:
|
|
|
+ @param serial:
|
|
|
+ @param now_time:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ if CONFIG_INFO == CONFIG_US:
|
|
|
+ # 不为国内ip记录日志
|
|
|
+ ip = CommonService.get_ip_address(request)
|
|
|
+ ip_info = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
+ country_code = ip_info['country_code']
|
|
|
+ if country_code != 'CN':
|
|
|
+ operation = '序列号占用:{}'.format(serial)
|
|
|
+ log_qs = LogModel.objects.filter(operation=operation)
|
|
|
+ if not log_qs.exists():
|
|
|
+ log = {
|
|
|
+ 'ip': ip,
|
|
|
+ 'user_id': 1,
|
|
|
+ 'status': 200,
|
|
|
+ 'time': now_time,
|
|
|
+ 'operation': operation,
|
|
|
+ 'url': 'serialNumber/attachUID',
|
|
|
+ }
|
|
|
+ LogModel.objects.create(**log)
|
|
|
+ # 邮件通知
|
|
|
+ email_content = '国外服发现序列号占用操作: {]'.format(serial)
|
|
|
+ S3Email().faEmail(email_content, 'servers@ansjer.com')
|
|
|
+
|
|
|
def do_get_uid(self, request_dict, response):
|
|
|
serial_number = request_dict.get('serial_number', None)
|
|
|
token = request_dict.get('token', None)
|