Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/test'

locky 3 anni fa
parent
commit
1547a0d7b0

+ 212 - 1
AdminController/VersionManagementController.py

@@ -4,13 +4,14 @@ import os
 import hashlib
 import time
 
+from django.db import transaction
 from django.views.generic.base import View
 
 from Ansjer.config import BASE_DIR
-from Model.models import Equipment_Version, App_Info, AppSetModel
 from Object.TokenObject import TokenObject
 from Object.ResponseObject import ResponseObject
 from Service.CommonService import CommonService
+from Model.models import Equipment_Version, App_Info, AppSetModel, App_Colophon
 
 
 class VersionManagement(View):
@@ -53,6 +54,14 @@ class VersionManagement(View):
                 return self.getAppSet(request_dict, response)
             elif operation == 'editAppSet':
                 return self.editAppSet(request_dict, response)
+            elif operation == 'getAppRecordList':
+                return self.getAppRecordList(request_dict, response)
+            elif operation == 'getAppBundleIdList':
+                return self.getAppBundleIdList(request_dict, response)
+            elif operation == 'addOrEditAppRecord':
+                return self.addOrEditAppRecord(request_dict, response)
+            elif operation == 'deleteAppRecord':
+                return self.deleteAppRecord(request_dict, response)
             else:
                 return response.json(404)
 
@@ -304,3 +313,205 @@ class VersionManagement(View):
         except Exception as e:
             print(e)
             return response.json(500, repr(e))
+
+    def getAppRecordList_1(self, request_dict, response):
+        app_type = request_dict.get('app_type', 'IOS')
+        pageNo = request_dict.get('pageNo', None)
+        pageSize = request_dict.get('pageSize', None)
+
+        if not all([pageNo, pageSize]):
+            return response.json(444)
+
+        page = int(pageNo)
+        line = int(pageSize)
+
+        try:
+            if app_type:
+                if app_type == 'IOS':
+                    app_type = 1
+                elif app_type == '安卓':
+                    app_type = 2
+                else:
+                    app_type = 3
+            app_colophon_qs = App_Colophon.objects.filter(app_id__app_type=app_type).order_by('app_id').values_list('app_id__appBundleId', flat=True).distinct()
+            if not app_colophon_qs.exists():
+                return response.json(173)
+            total = app_colophon_qs.count()
+            app_colophon_list = list(app_colophon_qs[(page - 1) * line:page * line])
+            app_info_qs = App_Colophon.objects.filter(app_id__appBundleId__in=app_colophon_list).\
+                values("id", "lang", "newApp_version", "content","version_time", "app_id__appBundleId", "app_id__appName", "app_id__app_type")
+            app_info_list = list(app_info_qs)
+            data_dict = {}
+            # 组装数据
+            for app_info in app_info_list:
+                for app_colophon in app_colophon_list:
+                    if app_colophon not in data_dict.keys():
+                        data_dict[app_colophon] = []
+                    if app_colophon == app_info['app_id__appBundleId']:
+                        data_dict[app_colophon].append(app_info)
+
+            for k, v in enumerate(data_dict):
+                new = sorted(data_dict[v], key=lambda x: x['id'], reverse=True)
+                data_dict[v] = new
+
+            res = {
+                'data_dict': data_dict,
+                'total': total
+            }
+            return response.json(0, res)
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))
+
+    def getAppRecordList(self, request_dict, response):
+        app_type = request_dict.get('appType', 'IOS')
+        queryVersion = request_dict.get('queryVersion', None)
+        queryAppBundleId = request_dict.get('queryAppBundleId', None)
+        pageNo = request_dict.get('pageNo', None)
+        pageSize = request_dict.get('pageSize', None)
+
+        if not all([pageNo, pageSize]):
+            return response.json(444)
+
+        page = int(pageNo)
+        line = int(pageSize)
+
+        try:
+            if app_type == 'IOS':
+                app_type = 1
+            elif app_type == '安卓':
+                app_type = 2
+            else:
+                app_type = 3
+            app_colophon_qs = App_Colophon.objects.filter(app_id__app_type=app_type).order_by('app_id').values_list('app_id__appBundleId', flat=True).distinct()
+            if not app_colophon_qs.exists():
+                return response.json(173)
+            total = app_colophon_qs.count()
+            app_colophon_list = list(app_colophon_qs[(page - 1) * line:page * line])
+            app_info_qs = App_Colophon.objects.filter(app_id__appBundleId__in=app_colophon_list).\
+                values("id", "lang", "newApp_version", "content", "version_time", "app_id__appBundleId", "app_id__appName", "app_id__app_type")
+            app_info_list = list(app_info_qs)
+            app_record_list = []    # 响应的app record数据
+            appBundleId_list = []   # 记录已添加过的appBundleId
+            # 组装数据
+            for app_info in app_info_list:
+                version = app_info['lang'] + app_info['newApp_version']
+                if app_info['app_id__appBundleId'] not in appBundleId_list:
+                    appBundleId_list.append(app_info['app_id__appBundleId'])
+                    newApp_version_list = [[app_info['lang'], app_info['newApp_version']]]
+                    app_record_dict = {
+                        'app_id__appBundleId': app_info['app_id__appBundleId'],
+                        'app_id__appName': app_info['app_id__appName'],
+                        'app_id__app_type': app_info['app_id__app_type'],
+                        'version': version,
+                        'newApp_version_list': newApp_version_list,
+                        'id': app_info['id'],
+                        'content': app_info['content'],
+                        'version_time': time.strftime("%Y-%m-%d", time.localtime(app_info['version_time'])),
+                    }
+                    if queryVersion and queryVersion == version and queryAppBundleId == app_info['app_id__appBundleId']:
+                        app_record_dict['id'] = app_info['id']
+                        app_record_dict['content'] = app_info['content']
+                        app_record_dict['version_time'] = time.strftime("%Y-%m-%d", time.localtime(app_info['version_time']))
+
+                    app_record_list.append(app_record_dict)
+                else:
+                    index = appBundleId_list.index(app_info['app_id__appBundleId'])
+                    newApp_version_list = [app_info['lang'], app_info['newApp_version']]
+
+                    if queryVersion and queryVersion == version and queryAppBundleId == app_info['app_id__appBundleId']:
+                        app_record_dict['id'] = app_info['id']
+                        app_record_dict['content'] = app_info['content']
+                        app_record_dict['version_time'] = time.strftime("%Y-%m-%d", time.localtime(app_info['version_time']))
+                        app_record_dict['version'] = version
+                        app_record_dict['newApp_version_list'].insert(0, newApp_version_list)
+                    else:
+                        app_record_list[index]['newApp_version_list'].append(newApp_version_list)
+
+            res = {
+                'app_record_list': app_record_list,
+                'total': total
+            }
+            return response.json(0, res)
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))
+
+    def getAppBundleIdList(self, request_dict, response):
+        print('request_dict:', request_dict)
+        app_type = request_dict.get('appType', 'IOS')
+
+        try:
+            if app_type == 'IOS':
+                app_type = 1
+            elif app_type == '安卓':
+                app_type = 2
+            else:
+                app_type = 3
+            app_info_qs = App_Info.objects.filter(app_type=app_type).values('id', 'appBundleId')
+            appBundleIdList = list(app_info_qs)
+            return response.json(0, {'appBundleIdList': appBundleIdList})
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))
+
+    def addOrEditAppRecord(self, request_dict, response):
+        print('request_dict:', request_dict)
+        appBundleId = request_dict.get('app_id__appBundleId', None)
+        newApp_version = request_dict.get('version', None)
+        version_time = request_dict.get('version_time', None)
+        cn_content = request_dict.get('cnContent', None)
+        en_content = request_dict.get('enContent', None)
+        content = request_dict.get('content', None)
+        app_colophon_id = request_dict.get('id', None)
+
+        if not all([appBundleId, newApp_version, version_time]):
+            return response.json(444)
+
+        try:
+            version_time = int(time.mktime(time.strptime(version_time, '%Y-%m-%d')))  # 字符串转时间戳
+            if app_colophon_id:     # 编辑
+                # 编辑获取的版本信息前两位为语言
+                lang = newApp_version[:2]
+                newApp_version = newApp_version[2:]
+                App_Colophon.objects.filter(id=app_colophon_id).update(lang=lang, newApp_version=newApp_version,
+                                                                       content=content, version_time=version_time)
+            else:   # 添加
+                app_info_qs = App_Info.objects.filter(appBundleId=appBundleId).values('id')
+                if not app_info_qs.exists():
+                    return response.json(173)
+
+                data_dict = {
+                    'app_id_id': app_info_qs[0]['id'],
+                    'newApp_version': newApp_version,
+                    'version_time': version_time,
+                    'lang': 'cn',
+                    'content': cn_content,
+                }
+                with transaction.atomic():
+                    # 创建中文内容数据
+                    App_Colophon.objects.create(**data_dict)
+                    # 创建英文内容数据
+                    data_dict['lang'] = 'en'
+                    data_dict['content'] = en_content
+                    App_Colophon.objects.create(**data_dict)
+            return response.json(0)
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))
+
+    def deleteAppRecord(self, request_dict, response):
+        print('request_dict:', request_dict)
+        app_colophon_id = request_dict.get('app_colophon_id', None)
+
+        try:
+            if not app_colophon_id:
+                return response.json(444)
+            app_colophon_qs = App_Colophon.objects.filter(id=app_colophon_id)
+            if not app_colophon_qs.exists():
+                return response.json(173)
+            app_colophon_qs.delete()
+            return response.json(0)
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))

+ 20 - 0
Controller/IotCoreController.py

@@ -59,6 +59,8 @@ class IotCoreView(View):
 
             if operation == 'clearIotCerm':
                 return self.clear_Iot_Cerm(request_dict, response)
+            elif operation == 'getIotInfo':
+                return self.getIotInfo(request_dict, response)
             else:
                 return response.json(404)
 
@@ -330,3 +332,21 @@ class IotCoreView(View):
         MSG['arn'] = arn
         MSG['region_name'] = region_name
         return MSG
+
+    def getIotInfo(self, request_dict, response):
+        # 获取IoT数据
+        serial_number = request_dict.get('serial_number', None)
+        if not serial_number:
+            return response.json(444)
+
+        try:
+            serial_number = serial_number[0:6]
+            iot_info_qs = iotdeviceInfoModel.objects.filter(serial_number=serial_number).values('endpoint', 'token_iot_number')
+            if not iot_info_qs.exists():
+                return response.json(173)
+            endpoint = iot_info_qs[0]['endpoint']
+            token_iot_number = iot_info_qs[0]['token_iot_number']
+            res = {'endpoint': endpoint, 'token_iot_number': token_iot_number}
+            return response.json(0, res)
+        except Exception as e:
+            return response.json(500, repr(e))