Kaynağa Gözat

优化ip地区信息存储和读写

locky 1 yıl önce
ebeveyn
işleme
1c1aea6a01

+ 8 - 0
AdminController/SerialManageController.py

@@ -50,6 +50,8 @@ class SerialView(View):
                 return self.company_page(request_dict, response)
             if operation == 'number/page':
                 return self.serial_page(request_dict, response)
+            if operation == 'syncSerial':
+                return self.sync_serial(request_dict, response)
             if operation == 'vpg-info/page':
                 return self.vpg_page(request_dict, response)
             if operation == 'uid-info/page':
@@ -189,6 +191,12 @@ class SerialView(View):
             print(e)
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
+    def sync_serial(self, request_dict, response):
+        serial = request_dict.get('serial', None)
+        sync_region = request_dict.get('syncRegion', None)
+        if not all([serial, sync_region]):
+            return response.json(444)
+
     @classmethod
     def vpg_page(cls, request_dict, response):
 

+ 3 - 1
Controller/ShadowController.py

@@ -177,9 +177,11 @@ def update_device_shadow(request):
 
 
 def get_district(ip):
-    ip_addr_qs = IPAddr.objects.filter(ip=ip).values('district')
+    ip_addr_qs = IPAddr.objects.filter(ip=ip).values('district', 'city')
     if ip_addr_qs.exists():
         district = ip_addr_qs[0]['district']
+        if district == '':
+            district = ip_addr_qs[0]['city']
     else:
         ip_qs = IPQuery(ip)
         district = ip_qs.district

+ 6 - 2
Object/IPWeatherObject.py

@@ -41,8 +41,12 @@ class IPQuery:
                 if country_id == 'CN' and city != '':
                     city += '市'
 
-                # ip地址信息存表
-                IPAddr.objects.create(ip=ip, district=district, city=city, region=region, country_code=country_id)
+                # ip地址信息存表或更新
+                ip_addr_qs = IPAddr.objects.filter(ip=ip)
+                if ip_addr_qs.exists():
+                    ip_addr_qs.update(district=district, city=city, region=region, country_code=country_id)
+                else:
+                    IPAddr.objects.create(ip=ip, district=district, city=city, region=region, country_code=country_id)
 
                 # 确定天气城市
                 if district != '':