Procházet zdrojové kódy

Merge branch 'dev' into lang

lang před 4 roky
rodič
revize
43074323d9

+ 1 - 1
Ansjer/local_settings.py

@@ -76,7 +76,7 @@ WSGI_APPLICATION = 'Ansjer.local_wsgi.application'
 DATABASE_DATA = 'ansjertest'
 SERVER_HOST = '127.0.0.1'
 DATABASES_USER = 'root'
-DATABASES_PASS = '123456'
+DATABASES_PASS = 'mysqlfyzs9wl'
 
 DATABASE_DATA2 = 'ansjerpush'
 SERVER_HOST2 = '127.0.0.1'

+ 9 - 1
Ansjer/urls.py

@@ -12,7 +12,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     ApplicationController, UserExController, CloudStorage, TestApi, UserBrandControllerV2, \
     StatisticsController, Alexa, FAQController, AppLogController, EquipmentVersionLimit, VoicePromptController, \
     CDKController, \
-    DeviceTypeController, CloudTest, Cloudsum, IotCoreController
+    DeviceTypeController, CloudTest, Cloudsum, IotCoreController, OperatingLogs, ProcessInfo
 
 urlpatterns = [
     url(r'^testApi/(?P<operation>.*)$', TestApi.testView.as_view()),
@@ -113,6 +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),
+    url(r'^OTA/checkMaxVersion$', OTAEquipment.checkMaxVersion),
 
     # h获取验证码    # v2接口
     url(r'^v2/account/authcode$', UserController.v2authCodeView.as_view()),
@@ -270,6 +272,12 @@ urlpatterns = [
     #Iot Core
     url(r'iot/(?P<operation>.*)$', IotCoreController.IotCoreView.as_view()),
 
+    # 日志管理系统
+    url(r'^OperatingLogs/(?P<operation>.*)$', OperatingLogs.OperatingLogsView.as_view()),
+    url(r'^ProcessInfo/(?P<operation>.*)$', ProcessInfo.ProcessInfoView.as_view()),
+    url(r'^Cloudsum/(?P<operation>.*)$', Cloudsum.Cloudsum.as_view()),
+
+
     re_path('(?P<path>.*)', LogManager.errorPath),
 
 

+ 69 - 0
Controller/OTAEquipment.py

@@ -685,3 +685,72 @@ def downloadOTAInterfaceV2(request, fullPath, *callback_args, **callback_kwargs)
             return res.json(907)
     else:
         return res.json(444, 'fullPath')
+
+
+@csrf_exempt
+def getDownLoadOTApackUrl(request):
+    # QT获取升级文件的下载链接
+    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)
+    file_path = equipmentVersion[0].filePath
+    if file_path:
+        if file_path.find('static/otapack') != -1:  # 只下载otapack路径下的文件
+            url = SERVER_DOMAIN + 'OTA/downloadsPack/' + file_path  # 复用以前的文件下载方式
+            # SERVER_DOMAIN = 'https://test.dvema.com/'
+            # url = SERVER_DOMAIN + 'OTA/downloadsPack/' + file_path
+            res = {
+                "url": url,
+            }
+            return response.json(0, res)
+        else:
+            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 + 'OTA/downloadsPack/' + file_path
+        res = {
+            "url": url,
+        }
+        return response.json(0, res)
+    else:
+        return response.json(902)

+ 77 - 0
Controller/OperatingLogs.py

@@ -0,0 +1,77 @@
+from django.views import View
+from Object.ResponseObject import ResponseObject
+from Model.models import OperatingLogsModel
+from Controller.ProcessInfo import ProcessInfoView
+from Object.TokenObject import TokenObject
+from Object.LogsObject import LogsObject
+
+class OperatingLogsView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.GET
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.POST
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def validate(self, request_dict, operation):
+        response = LogsObject()
+        # token = request_dict.get('token', None)
+        # tko = TokenObject(token)
+
+        if operation is None:
+            return response.json(444, 'error path')
+        elif operation == 'add_logs':
+            return self.add_logs(request_dict, response)
+        elif operation == 'delete_logs':
+            return self.delete_logs(request_dict, response)
+
+    def add_logs(self, request_dict, response):
+        d = self.get_info(request_dict)
+        if(d['userId'] == ''):
+            return response.json(908)
+        OperatingLogsModel.objects.create(
+            userId=d['userId'],
+            operatingcontent=d['operatingcontent'],
+            operatingtype=d['operatingtype'],
+            is_saveprocessinfo=d['is_saveprocessinfo'],
+            devUid=d['devUid'],
+            userIp=d['userIp'],
+        )
+        if d['is_saveprocessinfo'] == '1':
+            ProcessInfoView.validate(ProcessInfoView(), request_dict, 'add_processinfo')
+        return response.json(0)
+
+    def delete_logs(self, request_dict, response):
+        userId = request_dict.get('userId', None)
+        if userId:
+            OperatingLogsModel.objects.filter(userId=userId).delete()
+            return response.json(0)
+        else:
+            return response.json(444, 'userId is not exist')
+
+
+    def get_info(self, request_dict):
+        userId = request_dict.get('userId', None)
+        operatingcontent = request_dict.get('operatingcontent', None)
+        operatingtype = request_dict.get('operatingtype', None)
+        is_saveprocessinfo = request_dict.get('is_saveprocessinfo', None)
+        devUid = request_dict.get('devUid', None)
+        userIp = request_dict.get('userIp', None)
+        return {
+            'userId': userId,
+            'operatingcontent': operatingcontent,
+            'operatingtype': operatingtype,
+            'is_saveprocessinfo': is_saveprocessinfo,
+            'devUid': devUid,
+            'userIp': userIp,
+        }
+
+
+
+
+

+ 64 - 0
Controller/ProcessInfo.py

@@ -0,0 +1,64 @@
+from django.views import View
+from Object.ResponseObject import ResponseObject
+from Model.models import ProcessInfoLogsModel
+from Object.TokenObject import TokenObject
+from Object.LogsObject import LogsObject
+
+class ProcessInfoView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.GET
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        request_dict = request.POST
+        operation = kwargs.get('operation', None)
+        return self.validate(request_dict, operation)
+
+    def validate(self, request_dict, operation):
+        response = LogsObject()
+        # token = request_dict.get('token', None)
+
+        if operation is None:
+            return response.json(444, 'error path')
+        elif operation == 'add_processinfo':
+            return self.add_processinfo(request_dict, response)
+        elif operation == 'delete_processinfo':
+            return self.delete_processinfo(request_dict, response)
+
+    def add_processinfo(self, request_dict, response):
+        d = self.get_info(request_dict)
+        if(d['userId'] == ''):
+            return response.json(908)
+        ProcessInfoLogsModel.objects.create(
+            userId=d['userId'],
+            devUid=d['devUid'],
+            operatingcontent=d['operatingcontent'],
+        )
+        return response.json(0)
+
+    def delete_processinfo(self, request_dict, response):
+        userId = request_dict.get('userId', None)
+        if userId:
+            ProcessInfoLogsModel.objects.filter(userId=userId).delete()
+            return response.json(0)
+        else:
+            return response.json(444, 'userId is not exist')
+
+    def get_info(self, request_dict):
+        devUid = request_dict.get('devUid', None)
+        operatingcontent = request_dict.get('operatingcontent', None)
+        operatingtime = request_dict.get('operatingtime', None)
+        userId = request_dict.get('userId', None)
+        return {
+            'devUid': devUid,
+            'operatingcontent': operatingcontent,
+            'operatingtime': operatingtime,
+            'userId': userId,
+        }
+
+
+
+

+ 2 - 1
Controller/VoicePromptController.py

@@ -29,9 +29,9 @@ class VoicePromptView(View):
 
     def validate(self, request_dict, operation):
         token = request_dict.get('token', None)
+        print(token)
         lang = request_dict.get('lang', None)
         response = ResponseObject(lang=lang)
-
         token = TokenObject(token)
         if token.code != 0:
             return response.json(token.code)
@@ -309,6 +309,7 @@ class VoicePromptView(View):
             return response.json(444)
 
         voice_qs = VoicePromptModel.objects.filter(classification=0, type=type)
+        print(voice_qs)
         res = {
             'count': 0
         }

+ 29 - 0
Model/models.py

@@ -1209,3 +1209,32 @@ class DeviceTypeModel(models.Model):
         db_table = 'device_type'
         verbose_name = '设备类型表'
         verbose_name_plural = verbose_name
+
+
+class OperatingLogsModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    userId = models.CharField(blank=False, max_length=32, db_index=True, verbose_name=u'操作人')
+    operatingtime = models.DateTimeField(blank=True, verbose_name=u'操作时间', auto_now=True)
+    operatingcontent = models.TextField(blank=True, default='', verbose_name=u'操作内容')
+    operatingtype = models.CharField(blank=True, verbose_name=u'操作类型', max_length=32)
+    is_saveprocessinfo = models.SmallIntegerField(default=1, verbose_name=u'是否保存过程信息。1:保存,2:不保存')
+    devUid = models.CharField(default='', blank=True, max_length=32, verbose_name=u'设备ID')
+    userIp = models.CharField(blank=True, max_length=20, default='', verbose_name=u'用户ip')
+
+    class Meta:
+        db_table = 'operating_logs'
+        verbose_name = '操作数据表'
+        verbose_name_plural = verbose_name
+
+
+class ProcessInfoLogsModel(models.Model):
+    id = models.AutoField(primary_key=True)
+    userId = models.CharField(blank=False, max_length=32, db_index=True, verbose_name=u'操作人')
+    devUid = models.CharField(default='', blank=True, max_length=32, verbose_name=u'设备ID')
+    operatingcontent = models.TextField(blank=True, default='', verbose_name=u'操作内容')
+    operatingtime = models.DateTimeField(blank=True, verbose_name=u'操作时间', auto_now=True)
+
+    class Meta:
+        db_table = 'processinfo_logs'
+        verbose_name = '过程信息表'
+        verbose_name_plural = verbose_name

+ 210 - 0
Object/LogsObject.py

@@ -0,0 +1,210 @@
+from django.shortcuts import HttpResponse
+import simplejson as json
+
+
+class LogsObject(object):
+    def __init__(self, lang='en'):
+        self.lang = lang
+
+    def data(self, code, res={}):
+        data_en = {
+            0: 'Success',
+            5: 'Please try again one minute later!',
+            10: res,
+            12: 'You are not the primary user of the device!',
+            14: 'Device is not belong to you',
+            15: 'Device has been bound',
+            16: 'WeChat has been bound, please log in and unbind using WeChat',
+            17: 'No email or mobile phone login',
+            44: 'System error! Can not send email',
+            48: 'System object error!',
+            89: 'Already send the code, please check it or get it again after 10m',
+            90: 'please check code or get it again after 1m',
+            99: 'Mail doesn\'t exist!',
+            100: 'Phone format error!',
+            101: 'Phone already existed!',
+            102: 'Phone doesn\'t exist!',
+            103: 'Mail already existed!',
+            104: 'Account doesn\'t exist!',
+            105: 'Email format error!',
+            107: 'The username not conform to the rules!',
+            109: 'The password not conform to the rules!',
+            110: 'user doesn\'t activated',
+            111: 'Error password',
+            112: 'Fingerprint login is not turned on',
+            119: 'The qr code has expired',
+            120: 'The code has expired',
+            121: 'The verification code is wrong!',
+            173: 'Data does not exists!',
+            174: 'Data already exists!',
+            176: 'Delete error',
+            177: 'Update error',
+            178: 'ADD error',
+            179: 'Nickname repeated',
+            201: 'You can only add 3 custom voice at most',
+            306: 'The link has expired!',
+            309: 'Please ReLogin! errmsg token',
+            404: 'You don not have permission to access this!',
+            414: 'Please confirm the request url!',
+            424: 'Database Error !',
+            444: 'Wrong parameters!',
+            474: 'System Maintaining!',
+            475: 'App Version too low, please upgrade!',
+            500: 'Query Database Error:',
+            700: 'Upload file error',
+            701: 'The file does not exist!',
+            711: 'Do not downgrade',
+            712: 'Area needs to be consistent',
+            713: 'Storage rules cannot be changed during the validity period',
+            717: 'Authorization expires',
+            800: 'Order does not exist',
+            801: 'The refund amount cannot be greater than the order price',
+            802: 'The order has been completed and cannot be cancelled',
+            804: 'Refund, please do not repeat the operation',
+            900: 'There is no information about this version!',
+            901: 'Getting URL failure!',
+            902: 'No update!',
+            903: 'Error filename',
+            904: 'Version does not support this feature!',
+            906: 'Cause of file operation error',
+            907: 'The download file does not exist!',
+            908: 'userId cannot be empty',
+            10001: 'Customer number, customer confidentiality error',
+            10002: 'Check your configuration: no customer number, customer confidentiality',
+            10003: 'The authorization code does not exist. Please reauthorize',
+            10004: 'The request method is incorrect. Please contact the developer',
+            10005: 'Wrong configuration, wrong customer number',
+            10006: 'Configuration error. The path value is incorrect',
+            10007: 'This device is not an experience package and cannot be reset',
+            10008: 'The user does not have this device and cannot transfer',
+            10009: 'The user already owns the device and cannot transfer it',
+            10010: 'Devices that are not under the same account cannot be transferred',
+            10011: 'Receiving transfer device does not exist and cannot be transferred',
+            10012: 'Experience packages cannot be transferred',
+            10013: 'Original equipment package has expired and cannot be transferred',
+            10014: 'Accept transfer of equipment packages that have not expired and cannot be transferred',
+            10015: 'Shared devices cannot be transferred',
+            10030: 'No purchase of cloud storage',
+            10031: 'The cloud storage has expired',
+            10032: 'The switched cloud storage package ID cannot be the same as the one in use',
+            10033: 'The primary user of the device cannot purchase it',
+            10034: 'Non device primary users cannot view cloud storage',
+            10035: 'Non device primary users cannot experience cloud storage',
+            10036: 'Non device primary users cannot exchange for cloud storage',
+            10037: 'Non device primary user cannot transfer device',
+            10038: 'Non device primary user cannot transfer packages',
+            10039: 'Activation code has been used',
+            10040: 'Invalid activation code'
+        }
+        data_cn = {
+            0: '成功',
+            5: '请一分钟后再尝试',
+            10: res,
+            12: '非设备主用户',
+            14: '设备不属于您',
+            15: '设备已被绑定',
+            16: '微信已被绑定,请使用微信登录并解绑',
+            17: '未绑定邮箱或者手机登录方式',
+            44: '系统错误!无法发送电子邮件',
+            48: '系统对象错误',
+            89: '已发验证码,请检测或10分钟后重新获取。',
+            90: '请检测或1分钟后重新获取。',
+            99: '邮箱不存在!',
+            100: '手机格式错误!',
+            101: '手机已存在!',
+            102: '手机不存在!',
+            103: '邮箱已存在!',
+            104: '账户不存在!',
+            105: '邮箱格式错误!',
+            107: '用户名格式不符合!',
+            109: '密码格式不符合!',
+            110: '用户未激活!',
+            111: '密码不正确!',
+            112: '未开通指纹登录',
+            119: '二维码过期',
+            120: '验证码过期',
+            121: '验证码错了!',
+            173: '数据不存在!',
+            174: '数据已存在!',
+            176: '删除错误',
+            177: '更新错误',
+            178: '增加错误',
+            179: '名称不能重复',
+            201: '最多只能添加3条自定义语音',
+            306: '链接已超过有效期!',
+            309: '请重新登录!',
+            404: '您没有访问的权限!',
+            414: '请确认请求url!',
+            424: '数据库错误!',
+            444: '参数错误!',
+            474: '系统维护中!',
+            475: '版本过低,请升级程序!',
+            500: '查询数据库错误!',
+            700: '上传文件错误',
+            701: '文件不存在',
+            711: '不可降级',
+            712: '区域不一致',
+            713: '有效期内不可更改存储规则',
+            717: '授权过期',
+            800: '订单不存在',
+            801: '退款金额不能大于订单价格',
+            802: '订单已完成,不能撤销',
+            804: '订单已退款,请勿重复操作',
+            900: '版本信息不存在',
+            901: '获取链接失败',
+            902: '无更新!',
+            903: '文件名不符合!',
+            904: '版本不支持本功能!',
+            906: '文件操作错误',
+            907: '文件不存在!',
+            908: '用户id不能为空',
+            10001: '客户编号,客户机密错误',
+            10002: '检查您的配置:没有客户编号,客户机密',
+            10003: '授权码不存在,请重新授权',
+            10004: '请求方法不正确。请联系开发者',
+            10005: '配置错误,客户编号这个值是错误的',
+            10006: '配置错误,路径这个值是错误的',
+            10007: '此设备不是体验套餐,无法重置',
+            10008: '用户没有此设备,无法转移',
+            10009: '用户已拥有此设备,无法转移',
+            10010: '不是同一账户下的设备,无法转移',
+            10011: '接受转移设备不存在,无法转移',
+            10012: '体验套餐无法转移',
+            10013: '原设备套餐已过期,无法转移',
+            10014: '接受转移设备套餐未过期,无法转移',
+            10015: '分享的设备无法转移',
+            10030: '未购买云存',
+            10031: '云存已过期',
+            10032: '切换的云存套餐ID不能与正在使用中的相同',
+            10033: '非设备主用户无法购买',
+            10034: '非设备主用户无法查看云存',
+            10035: '非设备主用户无法体验云存',
+            10036: '非设备主用户无法兑换云存',
+            10037: '非设备主用户无法转移设备',
+            10038: '非设备主用户无法转移套餐',
+            10039: '激活码已被使用过',
+            10040: '无效激活码'
+        }
+        if self.lang == 'cn':
+            msg = data_cn
+        elif self.lang == 'zh-Hans':
+            msg = data_cn
+        elif self.lang == 'zh-Hant':
+            msg = data_cn
+        else:
+            msg = data_en
+        try:
+            message = msg[code]
+        except Exception as e:
+            message = '系统错误,code不存在'
+        print(self.lang == 'cn')
+        print(msg)
+        return {'result_code': code, 'reason': message, 'result': res, 'error_code': code}
+
+    def formal(self, code, res={}):
+        formal_data = self.data(code, res)
+        return json.dumps(formal_data, ensure_ascii=False)
+
+    def json(self, code, res={}):
+        result = self.formal(code, res)
+        return HttpResponse(result)