Sfoglia il codice sorgente

添加updateUserCountry用于定时统计任务调用

tanghongbin 4 anni fa
parent
commit
d98ea2de06
2 ha cambiato i file con 24 aggiunte e 0 eliminazioni
  1. 2 0
      Ansjer/urls.py
  2. 22 0
      Controller/UserController.py

+ 2 - 0
Ansjer/urls.py

@@ -235,6 +235,8 @@ urlpatterns = [
 
     # 本地登录接口
     url(r'^local/(?P<operation>.*)$', UserController.LocalUserView.as_view()),
+    url(r'^account/updateUserCountry', UserController.updateUserCountry),
+
 
     # app 设备消息模板
     # 路由加参数参考

+ 22 - 0
Controller/UserController.py

@@ -3627,3 +3627,25 @@ def delete_local_account(username):
         if user.is_local:
             user.delete()
             Device_Info.objects.filter(userID__userID=user.userID).delete()
+
+
+def updateUserCountry(request):
+    country_ip_qs = CountryIPModel.objects.filter()
+    if country_ip_qs.exists():
+        country_ip_qs = country_ip_qs[0: 1000]
+        ids = []
+        redisObject = RedisObject(db=6)
+        for country_ip in country_ip_qs:
+            key = 'ip_country_{ip}'.format(ip=country_ip.ip)
+            data = redisObject.get_data(key=key)
+            if data:
+                country = data
+            else:
+                country = CommonService.getAddr(country_ip.ip)
+                redisObject.set_data(key=key, val=country, expire=3600)
+
+            UserExModel.objects.filter(id=country_ip.user_ex_id).update(country=country)
+            ids.append(country_ip.id)
+        CountryIPModel.objects.filter(id__in=tuple(ids)).delete()
+    response = ResponseObject()
+    return response.json(0)