Browse Source

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

guanhailong 2 years ago
parent
commit
8ae8ee09d8

+ 116 - 96
AdminController/UnicomManageController.py

@@ -14,6 +14,7 @@ from Model.models import UnicomDeviceInfo, UnicomCombo, Pay_Type, UnicomComboOrd
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.UnicomObject import UnicomObjeect
 from Object.UnicomObject import UnicomObjeect
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
+from Object.TokenObject import TokenObject
 
 
 
 
 class UnicomManageControllerView(View):
 class UnicomManageControllerView(View):
@@ -30,35 +31,45 @@ class UnicomManageControllerView(View):
 
 
     def validation(self, request_dict, request, operation):
     def validation(self, request_dict, request, operation):
         response = ResponseObject()
         response = ResponseObject()
-        print(request)
-        # 获取套餐详细表
-        if operation == 'get/deta/info':
-            return self.get_unicom_info(request_dict, response)
         # 获取支付类型
         # 获取支付类型
-        elif operation == 'get/pay':
+        if operation == 'get/pay':
             return self.get_pay_type(response)
             return self.get_pay_type(response)
-        # 添加和编辑卡套餐
-        elif operation == 'edit/combo':
-            return self.edit_combo(request_dict, response)
-        # 统计4G套餐
-        elif operation == 'getComboDataList':
-            return self.static_info(request_dict, response)
-        # 删除卡套餐
-        elif operation == 'dele/combo/info':
-            return self.combo_order_info(request_dict, response)
-        # 获取/筛选用户信息
-        elif operation == 'filter/user':
-            return self.get_user_info(request_dict, response)
-        # 充值流量
-        elif operation == 'getFlowPackages':
-            return self.get_flow_packages(request_dict, response)
-        #  获取 / 筛选4G流量卡订单信息
-        elif operation == 'query-order':
-            return self.query_4G_user_order(request_dict, response)
-        elif operation == 'sim-info':
-            return self.get_iccid_info(request_dict, response)
+        # 获取套餐类型
+        elif operation == 'combo/type':
+            return self.get_unicom_combo_type(response)
         else:
         else:
-            return response.json(0)
+            tko = TokenObject(
+                request.META.get('HTTP_AUTHORIZATION'),
+                returntpye='pc')
+            if tko.code != 0:
+                return response.json(tko.code)
+            response.lang = tko.lang
+            userID = tko.userID
+            # 获取套餐详细表
+            if operation == 'get/deta/info':
+                return self.get_unicom_info(request_dict, response)
+            # 添加和编辑卡套餐
+            elif operation == 'edit/combo':
+                return self.edit_combo(request_dict, response)
+            # 统计4G套餐
+            elif operation == 'getComboDataList':
+                return self.static_info(request_dict, response)
+            # 删除卡套餐
+            elif operation == 'dele/combo/info':
+                return self.combo_order_info(request_dict, response)
+            # 获取/筛选用户信息
+            elif operation == 'filter/user':
+                return self.get_user_info(request_dict, response)
+            # 充值流量
+            elif operation == 'getFlowPackages':
+                return self.get_flow_packages(request_dict, response)
+            #  获取/筛选4G流量卡订单信息
+            elif operation == 'query-order':
+                return self.query_4G_user_order(request_dict, response)
+            elif operation == 'sim-info':
+                return self.get_iccid_info(request_dict, response)
+            else:
+                return response.json(404)
 
 
     def get_user_info(self, request_dict, response):
     def get_user_info(self, request_dict, response):
         """
         """
@@ -79,7 +90,6 @@ class UnicomManageControllerView(View):
 
 
         if not all({pageNo, pageSize}):
         if not all({pageNo, pageSize}):
             return response.json(444)
             return response.json(444)
-
         page = int(pageNo)
         page = int(pageNo)
         line = int(pageSize)
         line = int(pageSize)
 
 
@@ -248,21 +258,11 @@ class UnicomManageControllerView(View):
         combo_type = int(combo_type)
         combo_type = int(combo_type)
         is_show = int(is_show)
         is_show = int(is_show)
         sort = int(sort)
         sort = int(sort)
+        nowTime = int(time.time())
 
 
-        if combo_type == 1:
-            combo_type_qs = UnicomCombo.objects.filter(combo_type=1, is_del=False)
-            if combo_type_qs.exists():
-                if combo_id:
-                    combo_id = int(combo_id)
-                    combo_id_qs = combo_type_qs.first().id
-                    if combo_id != combo_id_qs:
-                        return response.json(174)
-                else:
-                    return response.json(174)
-        unicom_combo_qs = UnicomCombo.objects.all()
-
-        try:
-            with transaction.atomic():
+        # 判断是编辑还是添加
+        with transaction.atomic():
+            try:
                 re_data = {
                 re_data = {
                     'combo_name': combo_name,
                     'combo_name': combo_name,
                     'status': status,
                     'status': status,
@@ -276,19 +276,20 @@ class UnicomManageControllerView(View):
                     'is_show': is_show,
                     'is_show': is_show,
                     'virtual_price': virtualPrice,
                     'virtual_price': virtualPrice,
                 }
                 }
-                if unicom_combo_qs.filter(id=combo_id).exists():
-                    re_data['updated_time'] = int(time.time())
-                    UnicomCombo.objects.filter(id=combo_id).update(**re_data)
-                    UnicomCombo.objects.get(id=combo_id).pay_type.set(pay_type)
+                if combo_id:
+                    combo_type_qs = UnicomCombo.objects.filter(id=combo_id)
+                    if not combo_type_qs.exists():
+                        return response.json(173)
+                    re_data['updated_time'] = nowTime
+                    combo_type_qs.filter(id=combo_id).update(**re_data)
+                    combo_type_qs.get(id=combo_id).pay_type.set(pay_type)
                 else:
                 else:
                     re_data['updated_time'] = int(time.time())
                     re_data['updated_time'] = int(time.time())
                     re_data['created_time'] = int(time.time())
                     re_data['created_time'] = int(time.time())
                     UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
                     UnicomCombo.objects.create(**re_data).pay_type.set(pay_type)
                 return response.json(0)
                 return response.json(0)
-
-        except Exception as e:
-            print(repr(e))
-            return response.json(500)
+            except Exception as e:
+                return response.json(500, repr(e))
 
 
     @staticmethod
     @staticmethod
     def get_unicom_info(request_dict, response):
     def get_unicom_info(request_dict, response):
@@ -302,20 +303,22 @@ class UnicomManageControllerView(View):
         pageSize = request_dict.get('pageSize', None)
         pageSize = request_dict.get('pageSize', None)
         if not all([pageNo, pageSize]):
         if not all([pageNo, pageSize]):
             return response.json(444)
             return response.json(444)
+        elif pageNo and pageSize:
+            pass
         page = int(pageNo)
         page = int(pageNo)
         line = int(pageSize)
         line = int(pageSize)
         try:
         try:
             combo_qs = UnicomCombo.objects.filter(is_del=False) \
             combo_qs = UnicomCombo.objects.filter(is_del=False) \
-                           .order_by('sort').values('id', 'status', 'combo_name',
-                                                    'flow_total', 'combo_type',
-                                                    'expiration_days',
-                                                    'expiration_type', 'price', 'is_unlimited',
-                                                    'updated_time', 'created_time',
-                                                    'remark', 'is_show', 'sort', 'virtual_price')[
-                       (page - 1) * line:page * line]
+                .values('id', 'status', 'combo_name',
+                        'flow_total', 'combo_type',
+                        'expiration_days',
+                        'expiration_type', 'price', 'is_unlimited',
+                        'updated_time', 'created_time',
+                        'remark', 'is_show', 'sort', 'virtual_price').order_by('sort')
             if not combo_qs.exists():
             if not combo_qs.exists():
                 return response.json(0, [])
                 return response.json(0, [])
             total = combo_qs.count()
             total = combo_qs.count()
+            combo_qs = combo_qs[(page - 1) * line:page * line]
             combo_list = []
             combo_list = []
             for item in combo_qs:
             for item in combo_qs:
                 # 获取支付方式列表
                 # 获取支付方式列表
@@ -341,7 +344,8 @@ class UnicomManageControllerView(View):
                 })
                 })
             return response.json(0, {'list': combo_list, 'total': total})
             return response.json(0, {'list': combo_list, 'total': total})
         except Exception as e:
         except Exception as e:
-            return response.json(177, repr(e))
+            print(e)
+            return response.json(500, repr(e))
 
 
     @classmethod
     @classmethod
     def get_pay_type(cls, response):
     def get_pay_type(cls, response):
@@ -352,14 +356,26 @@ class UnicomManageControllerView(View):
         """
         """
         pay_type_qs = Pay_Type.objects.all().values('id', 'payment')
         pay_type_qs = Pay_Type.objects.all().values('id', 'payment')
         if not pay_type_qs.exists():
         if not pay_type_qs.exists():
-            return response.json(444)
-        try:
-            pay_type_list = []
-            for pay_type in pay_type_qs:
-                pay_type_list.append(pay_type)
-            return response.json(0, pay_type_list)
-        except Exception as e:
-            return response.json(500, e)
+            return response.json(0, [])
+        pay_type_list = []
+        for pay_type in pay_type_qs:
+            pay_type_list.append(pay_type)
+        return response.json(0, pay_type_list)
+
+    @classmethod
+    def get_unicom_combo_type(cls, response):
+        """
+        获取赠送套餐
+        @param response:
+        @return:
+        """
+        unicom_combo_qs = UnicomCombo.objects.filter(combo_type=2, status=0).values('id', 'combo_name')
+        if not unicom_combo_qs.exists():
+            return response.json(0, [])
+        combo_list = []
+        for combo in unicom_combo_qs:
+            combo_list.append(combo)
+        return response.json(0, combo_list)
 
 
     @classmethod
     @classmethod
     def combo_order_info(cls, request_dict, response):
     def combo_order_info(cls, request_dict, response):
@@ -373,14 +389,11 @@ class UnicomManageControllerView(View):
 
 
         if not combo_id:
         if not combo_id:
             return response.json(444)
             return response.json(444)
-        try:
-            combo_qs = UnicomCombo.objects.filter(id=combo_id)
-            if combo_qs.exists():
-                combo_qs.update(is_del=True)
-            return response.json(0)
-        except Exception as e:
-            print(e)
-            return response.json(500, repr(e))
+        combo_qs = UnicomCombo.objects.filter(id=combo_id)
+        #  只修改默认状态
+        if combo_qs.exists():
+            combo_qs.update(is_del=True)
+        return response.json(0)
 
 
     def static_info(self, request_dict, response):
     def static_info(self, request_dict, response):
         """
         """
@@ -451,7 +464,7 @@ class UnicomManageControllerView(View):
         @comboType request_dict:套餐类型
         @comboType request_dict:套餐类型
         @serialNo request_dict:序列号
         @serialNo request_dict:序列号
         @param response: 响应对象
         @param response: 响应对象
-        @param return:
+        @return:
         """
         """
         userId = request_dict.get('userId', None)
         userId = request_dict.get('userId', None)
         serialNo = request_dict.get('serialNo', None)
         serialNo = request_dict.get('serialNo', None)
@@ -460,36 +473,43 @@ class UnicomManageControllerView(View):
             return response.json(444)
             return response.json(444)
         try:
         try:
             while transaction.atomic():
             while transaction.atomic():
-                combo_info_qs = UnicomCombo.objects.filter(id=comboId, combo_type=2, status=0, is_del=False) \
-                    .values('id', 'combo_name', 'price', 'virtual_price', 'remark', 'combo_type').order_by('sort')
-                if not combo_info_qs.exists():
-                    return response.json(173)
+                combo_info_qs = UnicomCombo.objects.filter(id=comboId, combo_type=2, status=0) \
+                    .values('id', 'combo_name', 'price', 'virtual_price', 'remark', 'combo_type')
                 unicom_device_info_qs = UnicomDeviceInfo.objects.filter(serial_no=serialNo,
                 unicom_device_info_qs = UnicomDeviceInfo.objects.filter(serial_no=serialNo,
                                                                         user_id=userId).values \
                                                                         user_id=userId).values \
-                    ('user_id', 'iccid', 'serial_no')
-                if not unicom_device_info_qs.exists():
+                    ('iccid')
+                if not unicom_device_info_qs.exists() or not combo_info_qs.exists():
                     return response.json(173)
                     return response.json(173)
+                combo_info_qs = combo_info_qs.first()
+                unicom_device_info_qs = unicom_device_info_qs.first()
                 n_time = int(time.time())
                 n_time = int(time.time())
-                icc_id = unicom_device_info_qs[0]['iccid']
-                serial_no = unicom_device_info_qs[0]['serial_no']
-                order_id = CommonService.createOrderID()
-                unicom_combo = UnicomComboView.create_combo_order_info(order_id=order_id, activate_type=1, iccid=icc_id,
+                order_id = CommonService.createOrderID()  # 生成订单号
+                #  赠送套餐下个月生效
+                unicom_combo = UnicomComboView.create_combo_order_info(order_id=order_id, activate_type=1,
+                                                                       iccid=unicom_device_info_qs['iccid'],
                                                                        combo_id=comboId)
                                                                        combo_id=comboId)
                 if unicom_combo is False:
                 if unicom_combo is False:
                     return response.json(178)
                     return response.json(178)
-                # 获取套餐信息
-                combo_info_vo = combo_info_qs[0]
-                c_time = n_time
-                # 根据序列号获取UID
-                uid = CommonService.query_uid_with_serial(serial_no)
                 rank_id, ai_rank_id = UnicomComboView.get_cloud_or_ai_combo()  # 生成订单必须添加该字段
                 rank_id, ai_rank_id = UnicomComboView.get_cloud_or_ai_combo()  # 生成订单必须添加该字段
-                order_dict = {'orderID': order_id, 'UID': uid, 'rank_id': rank_id, 'ai_rank_id': ai_rank_id,
-                              'userID_id': userId, 'desc': combo_info_vo['combo_name'], 'payType': 10,
-                              'payTime': c_time, 'price': combo_info_vo['price'], 'addTime': c_time,
-                              'updTime': c_time, 'status': 1,
-                              'unify_combo_id': str(combo_info_vo['id']), 'order_type': 2,
-                              'store_meal_name': combo_info_vo['combo_name']
-                              }
+                uid = CommonService.query_uid_with_serial(serialNo)  # 获取序列号或UID
+                # 获取套餐信息
+                order_dict = {
+                    'orderID': order_id,
+                    'UID': uid,
+                    'rank_id': rank_id,
+                    'ai_rank_id': ai_rank_id,
+                    'userID_id': userId,
+                    'desc': combo_info_qs['combo_name'],
+                    'payType': 10,
+                    'payTime': n_time,
+                    'price': combo_info_qs['price'],
+                    'addTime': n_time,
+                    'updTime': n_time,
+                    'status': 1,
+                    'unify_combo_id': str(combo_info_qs['id']),
+                    'order_type': 2,
+                    'store_meal_name': combo_info_qs['combo_name']
+                }
                 Order_Model.objects.create(**order_dict)
                 Order_Model.objects.create(**order_dict)
                 return response.json(0)
                 return response.json(0)
         except Exception as e:
         except Exception as e:

+ 6 - 2
Controller/SensorGateway/SmartSocketController.py

@@ -135,6 +135,10 @@ class SmartSocketView(View):
             watt = float(watt)
             watt = float(watt)
             power = float(power)
             power = float(power)
             accumulated_time = int(accumulated_time)
             accumulated_time = int(accumulated_time)
+            #  判断上报数据是否为负数
+            if watt < 0 or power < 0 or accumulated_time < 0:
+                LOGGER.info('{}插座上报负值data:{}'.format(serial_number, request_dict))
+                return response.json(177)
             now_time = int(time.time())
             now_time = int(time.time())
             start_time, end_time = LocalDateTimeUtil.get_today_date(True)
             start_time, end_time = LocalDateTimeUtil.get_today_date(True)
             # 查询当前序列号当天是否有上传过电量统计
             # 查询当前序列号当天是否有上传过电量统计
@@ -221,7 +225,7 @@ class SmartSocketView(View):
         if not device_id:
         if not device_id:
             return False
             return False
         socket_info_qs = SocketInfo.objects.filter(device_id=device_id, type_switch=type_switch)
         socket_info_qs = SocketInfo.objects.filter(device_id=device_id, type_switch=type_switch)
-        LOGGER.info('进入插座电源开关OR倒计时,类型:{}'.format(type_switch))
+        LOGGER.info('{}进入插座电源开关OR倒计时,类型:{}'.format(serial_number, type_switch))
         now_time = int(time.time())
         now_time = int(time.time())
         try:
         try:
             with transaction.atomic():
             with transaction.atomic():
@@ -243,7 +247,7 @@ class SmartSocketView(View):
                 # 发布消息内容
                 # 发布消息内容
                 msg = {'type': 1, 'data': {'deviceSwitch': status}}
                 msg = {'type': 1, 'data': {'deviceSwitch': status}}
                 result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
                 result = CommonService.req_publish_mqtt_msg(serial_number, topic_name, msg)
-                LOGGER.info('智能插座开关设置发布MQTT消息结果{}'.format(result))
+                LOGGER.info('{}智能插座开关设置发布MQTT消息结果{}'.format(serial_number, result))
                 return True
                 return True
         except Exception as e:
         except Exception as e:
             LOGGER.info('智能插座异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             LOGGER.info('智能插座异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))

+ 53 - 39
Controller/TestApi.py

@@ -898,15 +898,21 @@ class testView(View):
             print(e)
             print(e)
             return response.json(500, repr(e))
             return response.json(500, repr(e))
 
 
-    @staticmethod
-    def getSerialNumberInfo(request_dict, response):
+    @classmethod
+    def getSerialNumberInfo(cls, request_dict, response):
         logger = logging.getLogger('info')
         logger = logging.getLogger('info')
         serial_number = request_dict.get('serialNumber', None)
         serial_number = request_dict.get('serialNumber', None)
         if not serial_number:
         if not serial_number:
             return response.json(444)
             return response.json(444)
+        # 返回序列号
         serialNumber = serial_number[:9]
         serialNumber = serial_number[:9]
+        # 查询uid
         serial_number = serial_number[:6]
         serial_number = serial_number[:6]
         try:
         try:
+            company_serial_qs = CompanySerialModel.objects.filter(serial_number=serial_number).values('status')
+            if not company_serial_qs.exists():
+                return response.json(173)
+
             uid_user_message = {
             uid_user_message = {
                 "uid": "",
                 "uid": "",
                 "serialNumber": "",
                 "serialNumber": "",
@@ -920,52 +926,60 @@ class testView(View):
                 "status": "",
                 "status": "",
                 "uid_user_message": uid_user_message
                 "uid_user_message": uid_user_message
             }
             }
-            company_serial_qs = CompanySerialModel.objects.filter(serial_number=serial_number).values('status')
-            if not company_serial_qs.exists():
-                return response.json(173)
-            if company_serial_qs[0]['status'] == 0:
+
+            company_serial_qs = company_serial_qs.first()
+            if company_serial_qs['status'] == 0:
                 return response.json(0, {'contents': '序列号未分配'})
                 return response.json(0, {'contents': '序列号未分配'})
             uid_company_serial_qs = UIDCompanySerialModel.objects.filter(
             uid_company_serial_qs = UIDCompanySerialModel.objects.filter(
                 company_serial__serial_number=serial_number).values('uid__uid', 'uid__status',
                 company_serial__serial_number=serial_number).values('uid__uid', 'uid__status',
                                                                     'company_serial__serial_number')
                                                                     'company_serial__serial_number')
-            if not uid_company_serial_qs.exists() and company_serial_qs[0]['status'] != 0:
-                if company_serial_qs[0]['status'] == 1:
-                    data['status'] = '已分配'
-                if company_serial_qs[0]['status'] == 2:
-                    data['status'] = '绑定uid'
-                if company_serial_qs[0]['status'] == 3:
-                    data['status'] = '已占用'
+            if not uid_company_serial_qs.exists():
+                data['status'] = cls.serial_number_status(company_serial_qs['status'])
                 return response.json(0, data)
                 return response.json(0, data)
-            for uid_company_serial in uid_company_serial_qs:
-                data['uid'] = uid_company_serial['uid__uid']
-                data['serialNumber'] = serialNumber
-                data['status'] = uid_company_serial['uid__status']
-                if company_serial_qs[0]['status'] == 1:
-                    data['status'] = '已分配'
-                if company_serial_qs[0]['status'] == 2:
-                    data['status'] = '绑定uid'
-                if company_serial_qs[0]['status'] == 3:
-                    data['status'] = '已占用'
-                uid = uid_company_serial['uid__uid'] if uid_company_serial['uid__uid'] else ''
-                device_info_qs = Device_Info.objects.filter(UID=uid).values(
-                    'UID',
-                    'serial_number',
-                    'userID_id',
-                    'primaryUserID',
-                    'userID__username')
-                uid_user_message = {
-                    'uid': device_info_qs[0]['UID'] if device_info_qs.exists() else '',
-                    'serialNumber': device_info_qs[0]['serial_number'] if device_info_qs.exists() else '',
-                    'userID': device_info_qs[0]['userID_id'] if device_info_qs.exists() else '',
-                    'username': device_info_qs[0]['userID__username'] if device_info_qs.exists() else '',
-                    'primaryUserID': device_info_qs[0]['primaryUserID'] if device_info_qs.exists() else ''
-                }
-                data['uid_user_message'] = uid_user_message
+            uid_company_serial = uid_company_serial_qs.first()
+            data['uid'] = uid_company_serial['uid__uid']
+            data['serialNumber'] = serialNumber
+            data['status'] = uid_company_serial['uid__status']
+            data['status'] = cls.serial_number_status(company_serial_qs['status'])
+            device_info_qs = Device_Info.objects.filter(UID=data['uid']).values(
+                'UID',
+                'serial_number',
+                'userID_id',
+                'primaryUserID',
+                'userID__username',
+                'data_joined').order_by('-data_joined')
+            if device_info_qs.exists():
+                # 判断主用户是否存在
+                primary_qs = device_info_qs.exclude(primaryUserID='')
+                if primary_qs.exists():
+                    uid_user_message['uid'] = primary_qs['UID'],
+                    uid_user_message['serialNumber'] = primary_qs['serial_number']
+                    uid_user_message['userID'] = primary_qs['userID_id']
+                    uid_user_message['username'] = primary_qs['userID__username']
+                    uid_user_message['primaryUserID'] = primary_qs['primaryUserID']
+                else:
+                    device_info = device_info_qs.first()
+                    uid_user_message['uid'] = device_info['UID']
+                    uid_user_message['serialNumber'] = device_info['serial_number']
+                    uid_user_message['userID'] = device_info['userID_id']
+                    uid_user_message['username'] = device_info['userID__username']
+                    uid_user_message['primaryUserID'] = device_info['primaryUserID']
             return response.json(0, data)
             return response.json(0, data)
         except Exception as e:
         except Exception as e:
-            logger.info('查询异常:{}'.format(e))
+            logger.error('序列号:{}, 查询异常:{}'.format(serial_number, e))
             return response.json(500)
             return response.json(500)
 
 
+    @staticmethod
+    def serial_number_status(status):
+        # 判断序号状态
+        if status == 1:
+            status = '已分配'
+        elif status == 2:
+            status = '绑定uid'
+        elif status == 3:
+            status = '已占用'
+        return status
+
     @classmethod
     @classmethod
     def get_serial_details(cls, request_dict, response, request):
     def get_serial_details(cls, request_dict, response, request):
         """
         """

+ 11 - 23
Controller/UidSetController.py

@@ -11,27 +11,23 @@
 @file: AliPayObject.py
 @file: AliPayObject.py
 @Contact: pzb3076@163.com
 @Contact: pzb3076@163.com
 """
 """
-import threading
 import time
 import time
 import traceback
 import traceback
 
 
 import requests
 import requests
-from django.db.models import Count
-
-from Object.RedisObject import RedisObject
 import simplejson as json
 import simplejson as json
+from django.db import transaction
 from django.utils.decorators import method_decorator
 from django.utils.decorators import method_decorator
 from django.views.decorators.csrf import csrf_exempt
 from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.base import View
 from django.views.generic.base import View
 
 
-from Model.models import UidSetModel, Device_User, Device_Info, UidPushModel, Equipment_Info, UID_Preview, UID_Bucket, \
-    VodHlsModel, Order_Model, OssCrdModel, UidUserModel, UidChannelSetModel, User_Brand, ExperienceContextModel, \
-    StsCrdModel, Unused_Uid_Meal, UIDMainUser, LogModel, CountryModel
+from Model.models import UidSetModel, Device_Info, UidPushModel, Equipment_Info, UID_Preview, UID_Bucket, \
+    VodHlsModel, Order_Model, OssCrdModel, UidUserModel, UidChannelSetModel, ExperienceContextModel, \
+    StsCrdModel, Unused_Uid_Meal, LogModel, CountryModel
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from Service.ModelService import ModelService
 from Service.ModelService import ModelService
-from django.db import transaction
 from Service.VodHlsService import SplitVodHlsObject
 from Service.VodHlsService import SplitVodHlsObject
 
 
 '''
 '''
@@ -107,7 +103,7 @@ class UidSetView(View):
         uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list).values('uid', 'detect_status', 'detect_interval',
         uid_set_qs = UidSetModel.objects.filter(uid__in=uid_list).values('uid', 'detect_status', 'detect_interval',
                                                                          'version', 'ucode', 'p2p_region', 'tz',
                                                                          'version', 'ucode', 'p2p_region', 'tz',
                                                                          'video_code', 'channel', 'cloud_vod')
                                                                          'video_code', 'channel', 'cloud_vod')
-        
+
         if uid_set_qs.exists():
         if uid_set_qs.exists():
             return response.json(0, list(uid_set_qs))
             return response.json(0, list(uid_set_qs))
         else:
         else:
@@ -139,7 +135,7 @@ class UidSetView(View):
                     del_uid = UidSetModel.objects.filter(uid__in=uid)
                     del_uid = UidSetModel.objects.filter(uid__in=uid)
                     if del_uid.exists():
                     if del_uid.exists():
                         del_uid.delete()
                         del_uid.delete()
-                        print ('删除UidSetModel')
+                        print('删除UidSetModel')
                     else:
                     else:
                         val = 1
                         val = 1
                         print('UidSetModel表没有数据')
                         print('UidSetModel表没有数据')
@@ -149,7 +145,7 @@ class UidSetView(View):
                         del_uid.delete()
                         del_uid.delete()
                         # print('删除Equipment_Info')
                         # print('删除Equipment_Info')
                     else:
                     else:
-                        val = val+1
+                        val = val + 1
                         print('Equipment_Info表没有数据')
                         print('Equipment_Info表没有数据')
                 if 'UID_Preview' in id_list:
                 if 'UID_Preview' in id_list:
                     del_uid = UID_Preview.objects.filter(uid__in=uid)
                     del_uid = UID_Preview.objects.filter(uid__in=uid)
@@ -431,6 +427,7 @@ class UidSetView(View):
         end_time = request_dict.get('end_time', None)
         end_time = request_dict.get('end_time', None)
         repeat_day = request_dict.get('repeat_day', None)
         repeat_day = request_dict.get('repeat_day', None)
         direction = request_dict.get('direction', None)
         direction = request_dict.get('direction', None)
+        algorithm_type = int(request_dict.get('algorithmType', 99))
 
 
         if uid and channel:
         if uid and channel:
             channel = int(channel)
             channel = int(channel)
@@ -440,41 +437,32 @@ class UidSetView(View):
                 ucs = {}
                 ucs = {}
                 if enter_voice:
                 if enter_voice:
                     ucs['voice_prompt_enter'] = enter_voice
                     ucs['voice_prompt_enter'] = enter_voice
-
                 if leave_voice:
                 if leave_voice:
                     ucs['voice_prompt_leave'] = leave_voice
                     ucs['voice_prompt_leave'] = leave_voice
-
                 if voice_status:
                 if voice_status:
                     ucs['voice_prompt_status'] = voice_status
                     ucs['voice_prompt_status'] = voice_status
-
                 if intelligent_mute:
                 if intelligent_mute:
                     ucs['voice_prompt_intelligent_mute'] = intelligent_mute
                     ucs['voice_prompt_intelligent_mute'] = intelligent_mute
-
                 if start_x:
                 if start_x:
                     ucs['voice_start_x'] = start_x
                     ucs['voice_start_x'] = start_x
-
                 if start_y:
                 if start_y:
                     ucs['voice_start_y'] = start_y
                     ucs['voice_start_y'] = start_y
-
                 if end_x:
                 if end_x:
                     ucs['voice_end_x'] = end_x
                     ucs['voice_end_x'] = end_x
-
                 if end_y:
                 if end_y:
                     ucs['voice_end_y'] = end_y
                     ucs['voice_end_y'] = end_y
-
                 if start_time:
                 if start_time:
                     ucs['voice_start_time'] = start_time
                     ucs['voice_start_time'] = start_time
-
                 if end_time:
                 if end_time:
                     ucs['voice_end_time'] = end_time
                     ucs['voice_end_time'] = end_time
-
                 if repeat_day:
                 if repeat_day:
                     ucs['voice_repeat_day'] = repeat_day
                     ucs['voice_repeat_day'] = repeat_day
-
                 if direction:
                 if direction:
                     ucs['voice_direction'] = direction
                     ucs['voice_direction'] = direction
+                ucs['algorithm_type'] = algorithm_type
 
 
                 uid_channel_set_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel)
                 uid_channel_set_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel)
+                uid_channel_set_qs = uid_channel_set_qs.filter(algorithm_type=algorithm_type)
                 if not uid_channel_set_qs.exists():
                 if not uid_channel_set_qs.exists():
                     uidObject = UidSetModel.objects.filter(uid=uid)
                     uidObject = UidSetModel.objects.filter(uid=uid)
                     ucs['channel'] = channel
                     ucs['channel'] = channel
@@ -587,4 +575,4 @@ class UidSetView(View):
     #     di_qs = Device_Info.objects.values('area', 'Type').annotate(c=Count('UID', distinct=True)).order_by()
     #     di_qs = Device_Info.objects.values('area', 'Type').annotate(c=Count('UID', distinct=True)).order_by()
     #     for di in di_qs:
     #     for di in di_qs:
     #         print(di)
     #         print(di)
-    #     return response.json(0)
+    #     return response.json(0)

+ 15 - 9
Controller/VoicePromptController.py

@@ -64,9 +64,12 @@ class VoicePromptView(View):
         uid = request_dict.get('uid', None)
         uid = request_dict.get('uid', None)
         channel = request_dict.get('channel', None)
         channel = request_dict.get('channel', None)
         type = request_dict.get('type', None)
         type = request_dict.get('type', None)
+        algorithm_type = int(request_dict.get('algorithmType', 99))
 
 
         if upload_type and uid and channel:
         if upload_type and uid and channel:
-            count = VoicePromptModel.objects.filter(uid=uid, channel=channel, type=type).count()
+            vp_qs = VoicePromptModel.objects.filter(uid=uid, channel=channel, type=type)
+            vp_qs = vp_qs.filter(algorithm_type=algorithm_type)
+            count = vp_qs.count()
             if count >= 3:
             if count >= 3:
                 return response.json(201)
                 return response.json(201)
 
 
@@ -88,6 +91,7 @@ class VoicePromptView(View):
         lang = request_dict.get('lang', '')
         lang = request_dict.get('lang', '')
         uid = request_dict.get('uid', None)
         uid = request_dict.get('uid', None)
         channel = request_dict.get('channel', None)
         channel = request_dict.get('channel', None)
+        algorithm_type = request_dict.get('algorithmType', None)
 
 
         if filename and title and type and uid and channel:
         if filename and title and type and uid and channel:
             voice_prompt = VoicePromptModel()
             voice_prompt = VoicePromptModel()
@@ -99,6 +103,8 @@ class VoicePromptView(View):
             voice_prompt.uid = uid
             voice_prompt.uid = uid
             voice_prompt.channel = channel
             voice_prompt.channel = channel
             voice_prompt.add_time = int(time.time())
             voice_prompt.add_time = int(time.time())
+            if algorithm_type:
+                voice_prompt.algorithm_type = int(algorithm_type)
             voice_prompt.save()
             voice_prompt.save()
 
 
             res = {
             res = {
@@ -145,7 +151,6 @@ class VoicePromptView(View):
         elif ids:
         elif ids:
             voice_qs = VoicePromptModel.objects.filter(id__in=ids.split(','))
             voice_qs = VoicePromptModel.objects.filter(id__in=ids.split(','))
 
 
-
         if not voice_qs.exists():
         if not voice_qs.exists():
             return response.json(14)
             return response.json(14)
 
 
@@ -171,11 +176,16 @@ class VoicePromptView(View):
         lang = request_dict.get('lang', None)
         lang = request_dict.get('lang', None)
         uid = request_dict.get('uid', None)
         uid = request_dict.get('uid', None)
         channel = request_dict.get('channel', None)
         channel = request_dict.get('channel', None)
+        # 个性语音增加算法类型区分默认0兼容老版本
+        algorithm_type = int(request_dict.get('algorithmType', 99))
 
 
         if uid and channel and lang:
         if uid and channel and lang:
-            voice_qs = VoicePromptModel.objects.filter(uid=uid, channel=channel, classification=1)
-            system_qs = VoicePromptModel.objects.filter(classification=0, language=lang, status=1)
-            channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel)
+            voice_qs = VoicePromptModel.objects.filter(uid=uid, channel=channel, classification=1,
+                                                       algorithm_type=algorithm_type)
+            system_qs = VoicePromptModel.objects.filter(classification=0, language=lang, status=1,
+                                                        algorithm_type=algorithm_type)
+            channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid, channel=channel,
+                                                           algorithm_type=algorithm_type)
 
 
             res = {
             res = {
                 'enter_voice': {},
                 'enter_voice': {},
@@ -373,7 +383,3 @@ class VoicePromptView(View):
             return response.json(0)
             return response.json(0)
         else:
         else:
             return response.json(444)
             return response.json(444)
-
-
-
-

+ 6 - 0
Model/models.py

@@ -1451,6 +1451,9 @@ class UidChannelSetModel(models.Model):
     voice_end_time = models.IntegerField(default=0, verbose_name='语音执行的结束时间')
     voice_end_time = models.IntegerField(default=0, verbose_name='语音执行的结束时间')
     voice_repeat_day = models.IntegerField(default=127, verbose_name='语音执行的日期,周几')
     voice_repeat_day = models.IntegerField(default=127, verbose_name='语音执行的日期,周几')
     voice_direction = models.IntegerField(default=0, verbose_name='语音方向。')
     voice_direction = models.IntegerField(default=0, verbose_name='语音方向。')
+    # 0:移动侦测,1:人形检测,2:挥手识别,3:人脸检测,4:异声感知,5:车辆检测,7:宠物检测,6:哭声检测,8:徘徊检测
+    # 9:区域闯入,10:区域闯出,11:长时间无人检测,12:往来检测,13:云相册
+    algorithm_type = models.SmallIntegerField(default=99, verbose_name='关联算法类型')
 
 
     class Meta:
     class Meta:
         db_table = 'uid_channel'
         db_table = 'uid_channel'
@@ -1857,6 +1860,9 @@ class VoicePromptModel(models.Model):
     classification = models.SmallIntegerField(default=1, verbose_name='语音分类。0:系统,1:自定义')
     classification = models.SmallIntegerField(default=1, verbose_name='语音分类。0:系统,1:自定义')
     add_time = models.IntegerField(default=0, verbose_name='添加时间')
     add_time = models.IntegerField(default=0, verbose_name='添加时间')
     uid = models.CharField(max_length=20, default='0', verbose_name='关联设备UID')
     uid = models.CharField(max_length=20, default='0', verbose_name='关联设备UID')
+    # 0:移动侦测,1:人形检测,2:挥手识别,3:人脸检测,4:异声感知,5:车辆检测,7:宠物检测,6:哭声检测,8:徘徊检测
+    # 9:区域闯入,10:区域闯出,11:长时间无人检测,12:往来检测,13:云相册
+    algorithm_type = models.SmallIntegerField(default=99, verbose_name='关联算法类型')
     channel = models.IntegerField(default=0, verbose_name='通道号')
     channel = models.IntegerField(default=0, verbose_name='通道号')
     status = models.SmallIntegerField(default=1, verbose_name='是否启用。0:不启用,1:启用')
     status = models.SmallIntegerField(default=1, verbose_name='是否启用。0:不启用,1:启用')