Browse Source

ota检查更新

locky 4 years ago
parent
commit
071d3fd18a
2 changed files with 42 additions and 7 deletions
  1. 2 1
      Ansjer/urls.py
  2. 40 6
      Controller/OTAEquipment.py

+ 2 - 1
Ansjer/urls.py

@@ -113,7 +113,8 @@ urlpatterns = [
     url(r'^OTA/uploadsPack$', OTAEquipment.uploadOTAInterfaceView.as_view()),
     url(r'^OTA/downloadsPack/(?P<fullPath>[0-9\w/.\-]+)', OTAEquipment.downloadOTAInterface),
     url(r'^dlotapack/(?P<fullPath>[0-9\w/.\-]+)', OTAEquipment.downloadOTAInterfaceV2),
-    url(r'^OTA/getDownLoadOTApackUrl$', OTAEquipment.getDownLoadOTApackUrl),    # ota升级接口
+    url(r'^OTA/getDownLoadOTApackUrl$', OTAEquipment.getDownLoadOTApackUrl),
+    url(r'^OTA/checkMaxVersion$', OTAEquipment.checkMaxVersion),
 
     # h获取验证码    # v2接口
     url(r'^v2/account/authcode$', UserController.v2authCodeView.as_view()),

+ 40 - 6
Controller/OTAEquipment.py

@@ -689,17 +689,16 @@ def downloadOTAInterfaceV2(request, fullPath, *callback_args, **callback_kwargs)
 
 @csrf_exempt
 def getDownLoadOTApackUrl(request):
-    # 获取升级文件的下载链接
+    # QT获取升级文件的下载链接
     response = ResponseObject()
-    request.encoding = 'utf-8'
     if request.method == "POST":
-        deviceType = request.POST.get('deviceType', None)
-        version = request.POST.get('version', None)
+        request_dict = request.POST
     elif request.method == "GET":
-        deviceType = request.GET.get('deviceType', None)
-        version = request.GET.get('version', None)
+        request_dict = request.GET
     else:
         return response.json(444)
+    deviceType = request_dict.get('deviceType', None)
+    version = request_dict.get('version', None)
     if not deviceType or not version:
         return response.json(444, 'deviceType or version')
     equipmentVersion = Equipment_Version.objects.filter(mci=deviceType, version=version)
@@ -720,3 +719,38 @@ def getDownLoadOTApackUrl(request):
             return response.json(901)
     else:
         return response.json(901)
+
+
+@csrf_exempt
+def checkMaxVersion(request):
+    # QT检查ota设备软件版本是否为最新版本
+    response = ResponseObject()
+    if request.method == "POST":
+        request_dict = request.POST
+    elif request.method == "GET":
+        request_dict = request.GET
+    else:
+        return response.json(444)
+    deviceType = request_dict.get('deviceType', None)
+    version = request_dict.get('version', None) # 设备版本:当前版本+设备规格代码
+    if not deviceType or not version:
+        return response.json(444, 'deviceType or version')
+    equipmentVersion = Equipment_Version.objects.filter(mci=deviceType, version=version)
+    # 判断是否有该版本存在
+    if not equipmentVersion.exists():
+        return response.json(907)
+    # now_version = version[:version.rindex('.')]
+    # code = version[version.rindex('.')+1:]
+
+    file_path = equipmentVersion[0].filePath
+    softwareVersion = equipmentVersion[0].softwareVersion
+    max_version = equipmentVersion[0].max_ver
+    if softwareVersion < max_version:
+        # 当前版本小于最大版本,返回文件下载链接
+        url = SERVER_DOMAIN + 'downloadsPack/' + file_path
+        res = {
+            "url": url,
+        }
+        return response.json(0, res)
+    else:
+        return response.json(902)