Browse Source

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJServer

locky 3 năm trước cách đây
mục cha
commit
1a1980f420

+ 4 - 1
AdminController/SurveysManageController.py

@@ -286,6 +286,8 @@ class SurveysView(View):
             cursor.execute(sql, [1, 0, ])
             cloud_count = cursor.fetchall()
             total = len(cloud_count)
+            readCount = SurveysUserLog.objects.count()
+            unreadCount = total - readCount
             sql += 'order by ca.created_time DESC,orderID DESC LIMIT %s,%s '
             cursor.execute(sql, [1, 0, ((page - 1) * size), size, ])
             data_obj = cursor.fetchall()
@@ -313,7 +315,8 @@ class SurveysView(View):
                     tMap.update({"createdTime": ''})
                     tMap.update({"isUpgrade": 0})
                 result_list.append(tMap)
-            return response.json(0, {'list': result_list, 'total': total})
+            return response.json(0, {'list': result_list, 'total': total, 'readCount': readCount,
+                                     'unreadCount': unreadCount})
         except Exception as e:
             print(e)
             return response.json(500, repr(e))

+ 1 - 1
Ansjer/test/postest.py

@@ -20,7 +20,7 @@ data['appBundleId'] = 'com.ansjer.zccloud_ab'
 data['tz'] = '+08.00'
 data['uid'] = 'HLK7EJ2VYLNHHUMG111A'
 data['status'] = '1'
-data['m_code'] = 'AN02000025070000001207.zccloud_ab'
+data['m_code'] = 'AN025070000001207.zccloud_ab'
 data['token'] = 'local'
 data['lang'] = 'cn'
 data['app_type'] = '2'

+ 5 - 1
Ansjer/urls.py

@@ -21,6 +21,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     DetectControllerV2, ShadowController, TestDetectController, PcInfo, PctestController, DeviceDebug, PaymentCycle, \
     DeviceLogController, CouponController, AiController
 from Controller.Surveys import CloudStorageController
+from Controller.Cron import CronDelDataController
 from AdminController import UserManageController, RoleController, MenuController, TestServeController, \
     ServeManagementController, LogManagementController, DeviceManagementController, VersionManagementController, \
     AiServeController, SurveysManageController
@@ -166,7 +167,7 @@ urlpatterns = [
     url(r'^deviceShadow/update$', ShadowController.update_device_shadow),
     url(r'^deviceShadow/generateUTK$', ShadowController.generate_utk),
     url(r'^test/notify/push$', TestDetectController.NotificationView.as_view()),
-    url(r'^eq/del$', EquipmentInfo.deleteExpireEquipmentInfo),
+
     # 新增
     url(r'^cloudVod/(?P<operation>.*)$', CloudVod.CloudVodView.as_view()),
     url(r'^meal/(?P<operation>.*)$', MealManage.MealView.as_view()),
@@ -392,6 +393,9 @@ urlpatterns = [
     url(r'surveys/(?P<operation>.*)', SurveysManageController.SurveysView.as_view()),
     # 后台界面接口 -----------------------------------------------------
 
+    # 定时删除任务接口
+    url(r'^cron/(?P<operation>.*)', CronDelDataController.CronDelDataView.as_view()),
+
     re_path('(?P<path>.*)', LogManager.errorPath),
 
 ]

+ 29 - 17
Controller/CloudStorage.py

@@ -905,8 +905,11 @@ class CloudStorageView(View):
 
                     order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
                     datetime = time.strftime("%Y-%m-%d", time.localtime())
-                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的'+UID+'设备在'+datetime+'已成功购买云存套餐', 'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
-                    self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
+                    # 如果存在序列号,消息提示用序列号
+                    device_name = CommonService.query_serial_with_uid(uid=UID)
+
+                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的'+device_name+'设备在'+datetime+'已成功购买云存套餐', 'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
+                    self.do_vod_msg_Notice(device_name, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
                     red_url = "{SERVER_DOMAIN_SSL}web/paid2/success.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
                     if lang != 'cn':
                         red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_success.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
@@ -1049,11 +1052,14 @@ class CloudStorageView(View):
 
                 order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
                 datetime = time.strftime("%Y-%m-%d", time.localtime())
-                sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
-                                     'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on ' + time.strftime(
+                # 如果存在序列号,消息提示用序列号
+                device_name = CommonService.query_serial_with_uid(uid=UID)
+
+                sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功购买云存套餐',
+                                     'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
                                          "%b %dth,%Y", time.localtime())]
 
-                self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
+                self.do_vod_msg_Notice(device_name, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
 
                 # return response.json(0)
                 red_url = "{SERVER_DOMAIN_SSL}web/paid2/success.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
@@ -1175,10 +1181,13 @@ class CloudStorageView(View):
 
                     order_qs.update(status=1, updTime=nowTime, uid_bucket_id=uid_bucket_id, promotion_rule_id=promotion_rule_id)
                     datetime = time.strftime("%Y-%m-%d", time.localtime())
-                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + UID + '设备在' + datetime + '已成功购买云存套餐',
-                                         'Dear customer,you already subscribed the cloud storage package successfully for device ' + UID + ' on ' + time.strftime(
+                    # 如果存在序列号,消息提示用序列号
+                    device_name = CommonService.query_serial_with_uid(uid=UID)
+
+                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功购买云存套餐',
+                                         'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
                                              "%b %dth,%Y", time.localtime())]
-                    self.do_vod_msg_Notice(UID, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
+                    self.do_vod_msg_Notice(device_name, channel, userid, lang, sys_msg_text_list, 'SMS_219738485')
                     redisObj.del_data(key=orderID + 'do_notify')
                     return HttpResponse("<xml>\
                       <return_code><![CDATA[SUCCESS]]></return_code>\
@@ -1518,11 +1527,12 @@ class CloudStorageView(View):
                 #     UIDMainUser.objects.create(**uid_main_dict)
                 sms = 'SMS_219738485'
                 datetime = time.strftime("%Y-%m-%d", time.localtime())
-                sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + uid + '设备在' + datetime + '已成功购买云存套餐',
-                                     'Dear customer,you already subscribed the cloud storage package successfully for device ' + uid + ' on ' + time.strftime(
+                # 如果存在序列号,消息提示用序列号
+                device_name = CommonService.query_serial_with_uid(uid=uid)
+                sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功购买云存套餐',
+                                     'Dear customer,you already subscribed the cloud storage package successfully for device ' + device_name + ' on ' + time.strftime(
                                          "%b %dth,%Y", time.localtime())]
 
-                # return response.json(0)
                 returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
                 if pay_type == 10:
                     ExperienceContextModel.objects.create(
@@ -1532,8 +1542,8 @@ class CloudStorageView(View):
                     )
                     returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=10&lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
                     datetime = time.strftime("%Y-%m-%d", time.localtime())
-                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + uid + '设备在' + datetime + '已成功开通云存体验套餐',
-                                         'Dear customer,you already subscribed the free trial cloud storage service successfully for device ' + uid + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
+                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功开通云存体验套餐',
+                                         'Dear customer,you already subscribed the free trial cloud storage service successfully for device ' + device_name + ' on '+ time.strftime("%b %dth,%Y", time.localtime())]
                     sms = 'SMS_222870823'
                 if pay_type == 11:
                     update_dict = {}
@@ -1543,8 +1553,8 @@ class CloudStorageView(View):
                     returnurl = "{SERVER_DOMAIN_SSL}cloudstorage/payOK?paytype=11&lang={lang}".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL,lang=lang)
 
                     datetime = time.strftime("%Y-%m-%d", time.localtime())
-                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + uid + '设备在' + datetime + '已成功兑换云存套餐',
-                                         'Dear customer, you already redeemed for the cloud storage package successfully for device ' +uid +' on '+time.strftime("%b %dth,%Y", time.localtime())]
+                    sys_msg_text_list = ['温馨提示:尊敬的客户,您的' + device_name + '设备在' + datetime + '已成功兑换云存套餐',
+                                         'Dear customer, you already redeemed for the cloud storage package successfully for device ' +device_name +' on '+time.strftime("%b %dth,%Y", time.localtime())]
                     sms = 'SMS_219748439'
 
                 self.do_vod_msg_Notice(uid, channel, userID, lang, sys_msg_text_list, sms)
@@ -1790,10 +1800,12 @@ class CloudStorageView(View):
         for ub in list:
             for oo in oqlist:
                 if ub['id'] == oo['uid_bucket_id']:
+                    # 如果存在序列号,消息提示用序列号
+                    device_name = CommonService.query_serial_with_uid(uid=ub['uid'])
                     if ub['bucket__area'] == 'cn':
-                        sys_msg_text = "温馨提示:尊敬的客户,您" + ub['uid'] + "设备的云存套餐将在" + time.strftime("%Y-%m-%d", time.localtime(ub['endTime'])) + "到期"
+                        sys_msg_text = "温馨提示:尊敬的客户,您" + device_name + "设备的云存套餐将在" + time.strftime("%Y-%m-%d", time.localtime(ub['endTime'])) + "到期"
                     else:
-                        sys_msg_text = 'Dear customer,the cloud storage package for your device '+ub['uid']+' will expire on '+time.strftime('%m-%d-%y',time.localtme(ub['endTime']))
+                        sys_msg_text = 'Dear customer,the cloud storage package for your device '+device_name+' will expire on '+time.strftime('%m-%d-%y',time.localtime(ub['endTime']))
                     uq_list.append(SysMsgModel(
                         userID_id=oo['userID_id'],
                         addTime=now_time,

+ 67 - 0
Controller/Cron/CronDelDataController.py

@@ -0,0 +1,67 @@
+#!/usr/bin/python3.6
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2022 #
+# @Time    : 2022/4/1 11:27
+# @Author  : ming
+# @Email   : zhangdongming@asj6.wecom.work
+# @File    : CronDelDataController.py
+# @Software: PyCharm
+import time
+
+from django.db import connection, connections
+from django.views import View
+
+from Object.ResponseObject import ResponseObject
+from Object.utils import LocalDateTimeUtil
+
+
+class CronDelDataView(View):
+    def get(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.GET, request, operation)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        return self.validation(request.POST, request, operation)
+
+    def validation(self, request_dict, request, operation):
+        response = ResponseObject()
+        if operation == 'access-log/del':   # 定时删除访问接口数据
+            return self.del_access_log(response)
+        elif operation == 'push-info/del':  # 定时删除推送数据
+            return self.del_push_info(response)
+        else:
+            return response.json(404)
+
+    @staticmethod
+    def del_access_log(response):
+        try:
+            cursor = connection.cursor()
+            # 删除一个月前的数据
+            last_month = LocalDateTimeUtil.get_last_month()
+            sql = 'DELETE FROM access_log WHERE time < %s limit %s'
+            cursor.execute(sql, [last_month, 10000])
+            # 关闭游标
+            cursor.close()
+            connection.close()
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, repr(e))
+
+    @staticmethod
+    def del_push_info(response):
+        nowTime = int(time.time())
+        cursor = connections['mysql02'].cursor()
+        try:
+            for i in range(5):
+                # 删除7天前的数据
+                sql = "DELETE FROM `equipment_info` WHERE addTime<={} LIMIT 10000".format(nowTime - 3600 * 24 * 7)
+                cursor.execute(sql)
+            # 关闭游标
+            cursor.close()
+            return response.json(0)
+        except Exception as e:
+            return response.json(500, repr(e))

+ 0 - 17
Controller/EquipmentInfo.py

@@ -290,23 +290,6 @@ class EquipmentInfo(View):
 use information_schema;
 select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='Ansjer81';
 '''
-# 定时删除推送数据
-def deleteExpireEquipmentInfo(request):
-    response = ResponseObject()
-    import time
-    nowTime = int(time.time())
-    cursor = connections['mysql02'].cursor()
-    try:
-        for i in range(5):
-            # 删除7天前的数据
-            sql = "DELETE FROM `equipment_info` WHERE addTime<={} LIMIT 10000".format(nowTime - 3600 * 24 * 7)
-            cursor.execute(sql)
-        # 关闭游标
-        cursor.close()
-        return response.json(0)
-    except Exception as e:
-        return response.json(500, repr(e))
-
 
 # 按季度删除访问日志
 def deleteExpireEquipmentInfoById(request):

+ 1 - 1
Object/AWS/ElasticTranscoder.py

@@ -34,7 +34,7 @@ class ElasticTranscoder:
             Outputs=[
                 {
                     'Key': OutputKey,
-                    'PresetId': '1351620000001-200010',
+                    'PresetId': '13516001-200010',
                     'SegmentDuration': '2',
                 }
             ]

+ 16 - 2
Object/utils/LocalDateTimeUtil.py

@@ -27,8 +27,10 @@ def get_last_first_date_and_last_date(n):
 def get_today_date(timestamp=False):
     """
     返回当天开始时间和结束时间
-    :param timestamp 是否返回时间戳
-    :returns: zero_today ,last_today
+    Args:
+        timestamp 是否返回时间戳
+    returns:
+        zero_today ,last_today
     """
 
     now = datetime.datetime.now()
@@ -42,6 +44,18 @@ def get_today_date(timestamp=False):
     return zero_today, last_today
 
 
+def get_last_month():
+    """
+    获取前一个月时间
+    returns:
+        last_month_date
+    """
+    today = datetime.date.today()  # 1. 获取「今天」
+    last_month = today.replace(month=today.month - 1)  # 2.获取前一个月
+    last_month_date = last_month.strftime("%Y-%m-%d %H:%M:%S")
+    return last_month_date
+
+
 if __name__ == "__main__":
     start_time, end_time = get_today_date(True)
     print('--- start_time = {} end_time = {}'.format(start_time, end_time))

+ 10 - 1
Service/CommonService.py

@@ -16,7 +16,7 @@ from Ansjer.config import BASE_DIR, UNICODE_ASCII_CHARACTER_SET, SERVER_DOMAIN_S
 import OpenSSL.crypto as ct
 from base64 import encodebytes
 from Controller.CheckUserData import RandomStr
-from Model.models import iotdeviceInfoModel
+from Model.models import iotdeviceInfoModel, Device_Info
 from Service.ModelService import ModelService
 
 
@@ -542,3 +542,12 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
         pay_failed_url = "{}web/paid2/{}".format(SERVER_DOMAIN_SSL, file_name)
         return pay_failed_url
 
+    # 根据uid查询序列号,存在则返回序列号,否则返uid
+    @staticmethod
+    def query_serial_with_uid(uid):
+        device_info_qs = Device_Info.objects.filter(UID=uid)
+        if device_info_qs.exists():
+            serial_number = device_info_qs[0]['serial_number']
+            if serial_number:
+                return serial_number
+        return uid

+ 11 - 11
Service/DeviceOperation.py

@@ -31,7 +31,7 @@ class DeviceOperation:
             "0x10019": 'LOG_TYPE_MANUAL_SNAP_FAIL',  # 手动抓图失败
 
             # setup 系统配置
-            "0x20000": 'LOG_TYPE_CONFIG',
+            "0x": 'LOG_TYPE_CONFIG',
             "0x20001": 'LOG_TYPE_CHGE_VIDEO_FORMAT',  # 改变视频制式
             "0x20002": 'LOG_TYPE_CHGE_VGA_RESOLUTION',  # 改变显示器分辨率
             "0x20003": 'LOG_TYPE_CHGE_LANGUAGE',  # 调整语言
@@ -136,14 +136,14 @@ class DeviceOperation:
             "0x100009": 'LOG_TYPE_UNLOCK_PICTURE',  # 解锁图片
 
             # 查看信息(Check Infomantion)
-            "0x200000": 'LOG_TYPE_VIEW_INFO',  # 查看系统信息
-            "0x200001": 'LOG_TYPE_VIEW_SYSTEM',  # 查看系统信息
-            "0x200002": 'LOG_TYPE_VIEW_EVENT',  # 查看事件
-            "0x200003": 'LOG_TYPE_VIEW_LOG',  # 查看日志
-            "0x200004": 'LOG_TYPE_VIEW_NETWORK',  # 查看网络状态
-            "0x200005": 'LOG_TYPE_VIEW_ONLINE_USER',  # 查看在线用户
-            "0x200006": 'LOG_TYPE_VIEW_EXPORT_LOG',  # 导出日志
-            "0x200007": 'LOG_TYPE_VIEW_EXPORT_EVENT',  # 导出事件
+            "0x0": 'LOG_TYPE_VIEW_INFO',  # 查看系统信息
+            "0x1": 'LOG_TYPE_VIEW_SYSTEM',  # 查看系统信息
+            "0x2": 'LOG_TYPE_VIEW_EVENT',  # 查看事件
+            "0x3": 'LOG_TYPE_VIEW_LOG',  # 查看日志
+            "0x4": 'LOG_TYPE_VIEW_NETWORK',  # 查看网络状态
+            "0x5": 'LOG_TYPE_VIEW_ONLINE_USER',  # 查看在线用户
+            "0x6": 'LOG_TYPE_VIEW_EXPORT_LOG',  # 导出日志
+            "0x7": 'LOG_TYPE_VIEW_EXPORT_EVENT',  # 导出事件
 
             # 异常信息(Error)
             "0x400000": 'LOG_TYPE_ERROR_INFO',  # 网络地址冲突
@@ -178,11 +178,11 @@ class DeviceOperation:
     def getODla(search_class):
         data = {
             'Operation': ['0x10000', '0x10019'], #操作
-            'Setup': ['0x20000', '0x20048'], #系统配置
+            'Setup': ['0x', '0x20048'], #系统配置
             'Playback': ['0x40000', '0x40008'], #录像回放
             'Backup': ['0x80000', '0x80004'], #数据备份
             'Search': ['0x100001', '0x100009'], #录像检索
-            'Check Infomantion': ['0x200000', '0x200007'], #查看信息
+            'Check Infomantion': ['0x0', '0x7'], #查看信息
             'Error': ['0x400000', '0x40000C'], #异常信息
             'Event': ['0x800000', '0x800010'], #事件信息
         }