|
@@ -5,7 +5,7 @@ from django.http import JsonResponse
|
|
|
|
|
|
from Ansjer.config import SERVER_TYPE, LOGGER
|
|
|
from Model.models import Device_Info, UidSetModel, UID_Preview, VoicePromptModel, UID_Bucket, UidChannelSetModel, \
|
|
|
- AiService, CountryModel, CityInformation
|
|
|
+ AiService, CountryModel, CityInformation, IPAddr
|
|
|
from Object.ETkObject import ETkObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Object.IPWeatherObject import IPQuery
|
|
@@ -75,8 +75,17 @@ def update_device_shadow(request):
|
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid).values('ip')
|
|
|
if uid_set_qs.exists():
|
|
|
if ip != uid_set_qs[0]['ip']:
|
|
|
- ip_qs = IPQuery(ip)
|
|
|
- district = ip_qs.district
|
|
|
+ # 查询ip区级信息
|
|
|
+ ip_addr_qs = IPAddr.objects.filter(ip=ip).values('district')
|
|
|
+ if ip_addr_qs.exists():
|
|
|
+ district = ip_addr_qs[0]['district']
|
|
|
+ else:
|
|
|
+ ip_qs = IPQuery(ip)
|
|
|
+ district = ip_qs.district
|
|
|
+ country_code = ip.country_id
|
|
|
+ # ip地址信息存表
|
|
|
+ IPAddr.objects.create(ip=ip, country_code=country_code, district=district)
|
|
|
+
|
|
|
city_information_qs = CityInformation.objects.filter(district=district).values('city_id')
|
|
|
if city_information_qs.exists():
|
|
|
city_id = city_information_qs[0]['city_id']
|
|
@@ -148,8 +157,17 @@ def update_device_shadow(request):
|
|
|
qs_dict['tb_country'] = country
|
|
|
LOGGER.info('{} qs_dict: {}'.format(uid, qs_dict))
|
|
|
|
|
|
- ip_qs = IPQuery(ip)
|
|
|
- district = ip_qs.district
|
|
|
+ # 查询ip区级信息
|
|
|
+ ip_addr_qs = IPAddr.objects.filter(ip=ip).values('district')
|
|
|
+ if ip_addr_qs.exists():
|
|
|
+ district = ip_addr_qs[0]['district']
|
|
|
+ else:
|
|
|
+ ip_qs = IPQuery(ip)
|
|
|
+ district = ip_qs.district
|
|
|
+ country_code = ip.country_id
|
|
|
+ # ip地址信息存表
|
|
|
+ IPAddr.objects.create(ip=ip, country_code=country_code, district=district)
|
|
|
+
|
|
|
city_information_qs = CityInformation.objects.filter(district=district).values('city_id')
|
|
|
if city_information_qs.exists():
|
|
|
city_id = city_information_qs[0]['city_id']
|