Przeglądaj źródła

添加OTA升级条件限制

tanghongbin 4 lat temu
rodzic
commit
4ae00579f7
4 zmienionych plików z 165 dodań i 8 usunięć
  1. 2 1
      Ansjer/urls.py
  2. 110 0
      Controller/EquipmentVersionLimit.py
  3. 38 7
      Controller/OTAEquipment.py
  4. 15 0
      Model/models.py

+ 2 - 1
Ansjer/urls.py

@@ -10,7 +10,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     StsOssController, UIDPreview, OssCrd, SysMsg, UidUser, EquipmentManagerV2, EquipmentManagerV3, PushDeploy, \
     StsOssController, UIDPreview, OssCrd, SysMsg, UidUser, EquipmentManagerV2, EquipmentManagerV3, PushDeploy, \
     AppSetController, \
     AppSetController, \
     ApplicationController, UserExController, CloudStorage, TestApi, UserBrandControllerV2, \
     ApplicationController, UserExController, CloudStorage, TestApi, UserBrandControllerV2, \
-    StatisticsController, Alexa, FAQController, AppLogController
+    StatisticsController, Alexa, FAQController, AppLogController, EquipmentVersionLimit
 
 
 urlpatterns = [
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -234,6 +234,7 @@ urlpatterns = [
     # 本地登录接口
     # 本地登录接口
     url(r'^local/(?P<operation>.*)$', UserController.LocalUserView.as_view()),
     url(r'^local/(?P<operation>.*)$', UserController.LocalUserView.as_view()),
     url(r'^account/updateUserCountry', UserController.updateUserCountry),
     url(r'^account/updateUserCountry', UserController.updateUserCountry),
+    url(r'^equipmentVersionLimit/(?P<operation>.*)$', EquipmentVersionLimit.EquipmentVersionLimitView.as_view()),
 
 
     # 订阅邮件
     # 订阅邮件
     url(r'^account/subscribe$', UserController.SubscribeEmailView.as_view()),
     url(r'^account/subscribe$', UserController.SubscribeEmailView.as_view()),

+ 110 - 0
Controller/EquipmentVersionLimit.py

@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import time
+
+from django.views import View
+
+from Model.models import EquipmentVersionLimitModel, UidSetModel
+from Object.RedisObject import RedisObject
+from Object.ResponseObject import ResponseObject
+from Object.TokenObject import TokenObject
+
+
+class EquipmentVersionLimitView(View):
+
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation', None)
+        request_dict = request.GET
+        return self.validate(request_dict, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation', None)
+        request_dict = request.POST
+        return self.validate(request_dict, operation)
+
+    def validate(self, request_dict, operation):
+        token = request_dict.get('token', None)
+        token = TokenObject(token)
+        print('ind')
+        response = ResponseObject()
+        if token.code != 0:
+            return response.json(token.code)
+
+        if operation == 'add':
+            return self.do_add(request_dict, response)
+        elif operation == 'update':
+            return self.do_update(request_dict, response)
+        elif operation == 'delete':
+            return self.do_delete(request_dict, response)
+        elif operation == 'uid':
+            return self.do_query(request_dict, response)
+        else:
+            return response.json(404)
+
+    def do_add(self, request_dict, response):
+        type = request_dict.get('type', None)
+        content = request_dict.get('content', None)
+        eid = request_dict.get('eid', None)
+
+        if type and content and eid:
+            now_time = int(time.time())
+            data = EquipmentVersionLimitModel()
+            data.type = type
+            data.content = content
+            data.equipment_version_id = eid
+            data.status = 1
+            data.add_time = now_time
+            data.update_time = now_time
+            data.save()
+            return response.json(0)
+        else:
+            return response.json(444)
+
+    def do_update(self, request_dict, response):
+        print('in ')
+        id = request_dict.get('id', None)
+        content = request_dict.get('content', None)
+        status = request_dict.get('status', None)
+
+        if id is None:
+            return response.json(444)
+
+        update = {}
+        if content:
+            update['content'] = content
+
+        if status:
+            update['status'] = status
+
+        evl_qs = EquipmentVersionLimitModel.objects.filter(id=id)
+        if evl_qs.exists():
+            eid = evl_qs[0].equipment_version_id
+            evl_qs.update(**update)
+            redisObject = RedisObject()
+            redisObject.del_data(key='limit_{eid}'.format(eid=eid))
+        return response.json(0)
+
+    def do_delete(self, request_dict, response):
+        id = request_dict.get('id', None)
+
+        if id is None:
+            return response.json(0)
+
+        evl_qs = EquipmentVersionLimitModel.objects.filter(id=id)
+        if evl_qs.exists():
+            eid = evl_qs[0].equipment_version_id
+            redisObject = RedisObject()
+            redisObject.del_data(key='limit_{eid}'.format(eid=eid))
+            evl_qs.delete()
+        return response.json(0)
+
+    def do_query(self, request_dict, response):
+        uid_qs = UidSetModel.objects.filter()[0:5000].values('uid')
+        data = []
+        for uid in uid_qs:
+            data.append(uid['uid'])
+            data.append(uid['uid'])
+            data.append(uid['uid'])
+        return response.json(0, data)

+ 38 - 7
Controller/OTAEquipment.py

@@ -14,8 +14,9 @@ from django.views.generic import TemplateView
 from Ansjer.config import BASE_DIR
 from Ansjer.config import BASE_DIR
 from Ansjer.config import SERVER_DOMAIN
 from Ansjer.config import SERVER_DOMAIN
 from Ansjer.config import SERVER_TYPE
 from Ansjer.config import SERVER_TYPE
-from Model.models import Device_User
+from Model.models import Device_User, EquipmentVersionLimitModel, CountryIPModel
 from Model.models import Equipment_Version
 from Model.models import Equipment_Version
+from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
 from Object.UrlTokenObject import UrlTokenObject
 from Object.UrlTokenObject import UrlTokenObject
@@ -476,8 +477,9 @@ def getNewVerInterface(request):
     token = request_dict.get('token', None)
     token = request_dict.get('token', None)
     lang = request_dict.get('lang', None)
     lang = request_dict.get('lang', None)
     now_ver = request_dict.get('ver', None)
     now_ver = request_dict.get('ver', None)
+    uid = request_dict.get('uid', None)
     if not code or not now_ver:
     if not code or not now_ver:
-        return response.json(902, {'param':'code,ver'})
+        return response.json(902, {'param': 'code,ver'})
         # return response.json(444, 'code,ver')
         # return response.json(444, 'code,ver')
     tko = TokenObject(token)
     tko = TokenObject(token)
     response.lang = tko.lang
     response.lang = tko.lang
@@ -490,9 +492,38 @@ def getNewVerInterface(request):
         equipmentValid = Equipment_Version.objects.filter(code=code, status=1, lang='en').order_by(
         equipmentValid = Equipment_Version.objects.filter(code=code, status=1, lang='en').order_by(
             '-data_joined')
             '-data_joined')
 
 
-    print(equipmentValid)
     if equipmentValid.exists():
     if equipmentValid.exists():
         equipment = equipmentValid[0]
         equipment = equipmentValid[0]
+        redisObject = RedisObject(db=3)
+        key = 'limit_{eid}'.format(eid=equipment.eid)
+
+        evl_qs = redisObject.get_data(key=key)
+        if evl_qs:
+            evl_qs = json.loads(evl_qs)
+        else:
+            evl_qs = EquipmentVersionLimitModel.objects.filter(equipment_version_id=equipment.eid, status=1).values()
+            if evl_qs.exists():
+                redisObject.set_data(key=key, val=json.dumps(list(evl_qs.values())), expire=600)
+        if evl_qs and len(evl_qs) > 0:
+            evl = evl_qs[0]
+            if evl['type'] == 1:  # uid限制
+                uids = json.loads(evl['content'])
+                if not uids.__contains__(uid):
+                    return response.json(902)
+            elif evl['type'] == 2:  # user限制
+                users = json.loads(evl['content'])
+                if not users.__contains__(tko.userID):
+                    return response.json(902)
+            elif evl['type'] == 3:  # 国家地区限制
+                countries = json.loads(evl['content'])
+                country_ip_qs = CountryIPModel.objects.filter(user_ex__userID=tko.userID)
+                if country_ip_qs.exists():
+                    country = country_ip_qs[0].country
+                else:
+                    country = CommonService.getAddr(CommonService.get_ip_address(request))
+                if not countries.__contains__(country):
+                    return response.json(902)
+
         file_path = equipment.filePath
         file_path = equipment.filePath
         ver = equipment.softwareVersion
         ver = equipment.softwareVersion
         max_ver = equipment.max_ver
         max_ver = equipment.max_ver
@@ -507,10 +538,10 @@ def getNewVerInterface(request):
             #     url = SERVER_DOMAIN + 'dlotapack/' + file_path
             #     url = SERVER_DOMAIN + 'dlotapack/' + file_path
             # else:
             # else:
             #     这里调用国内服务器进行下载,防止下载bug
             #     这里调用国内服务器进行下载,防止下载bug
-                # if code == '18E201200CA' or code == '18E201200CZ':
-                #     url = 'http://www.zositech.xyz/dlotapack/' + file_path
-                # else:
-                #     url = SERVER_DOMAIN + 'dlotapack/' + file_path
+            # if code == '18E201200CA' or code == '18E201200CZ':
+            #     url = 'http://www.zositech.xyz/dlotapack/' + file_path
+            # else:
+            #     url = SERVER_DOMAIN + 'dlotapack/' + file_path
             return response.json(0, {
             return response.json(0, {
                 'ver': ver,
                 'ver': ver,
                 'url': url,
                 'url': url,

+ 15 - 0
Model/models.py

@@ -1009,4 +1009,19 @@ class CountryIPModel(models.Model):
     class Meta:
     class Meta:
         db_table = 'country_ip'
         db_table = 'country_ip'
         verbose_name = 'ip-国家统计表'
         verbose_name = 'ip-国家统计表'
+        verbose_name_plural = verbose_name
+
+
+class EquipmentVersionLimitModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    type = models.SmallIntegerField(default=0, verbose_name='限制类型')
+    content = models.TextField(default='', verbose_name='限制内容')
+    equipment_version = models.ForeignKey(Equipment_Version, to_field='eid', on_delete=models.CASCADE, verbose_name='关联设备版本信息id')
+    status = models.SmallIntegerField(default=0, verbose_name='是否启用。0:不启用,1:启用')
+    add_time = models.IntegerField(default=0, verbose_name='添加时间')
+    update_time = models.IntegerField(default=0, verbose_name='更新时间')
+
+    class Meta:
+        db_table = 'equipment_version_limit'
+        verbose_name = '设备版本信息限制表'
         verbose_name_plural = verbose_name
         verbose_name_plural = verbose_name