示例#1
0
    def scn_queryData_data(self,
                           headers=None,
                           id=None,
                           res_accurate=False,
                           business_exception=False):
        # TODO: 请确定参数并完成参数注释

        # 参数化
        # if func_param is None: func_param = gen_bnsData.xxx()

        # 发送业务请求
        res_json = self.bns_queryData_data(
            headers=headers,
            id=id,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:订单查询")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:订单查询")
示例#2
0
 def retry(*args, **kwargs):
     # 重试次数
     for _ in range(times):
         try:
             return func(*args, **kwargs)
         except DefinedBusinessException:
             time.sleep(wait_time)
     raise DefinedBusinessException("这个api连续多次执行失败:{}".format(func))
示例#3
0
    def scn_node_addThirdPartner(self, headers=None, parentAreaCode=None, partnerName=None, res_accurate=False,
                                 business_exception=False):
        """
        添加三级合作方
        :param headers:
        :param parentAreaCode:上级区域编码
        :param partnerName: 合作方名称
        :param res_accurate:
        :param business_exception:
        :return:
        """

        # 参数化
        if partnerName is None: partnerName = gen_bnsData.random_node_thirdPartnerName()

        # 发送业务请求
        res_json = self.bns_node_addThirdPartner(headers=headers,
                                                 parentAreaCode=parentAreaCode,
                                                 partnerName=partnerName, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode")
        areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId")
        areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType")
        name = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.name")
        parentAreaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.parentAreaCode")
        nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel")

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                return areaCode

            # 全部信息返回
            info_dict = dict()
            if areaCode is not None: info_dict.setdefault('areaCode', areaCode)
            if areaId is not None: info_dict.setdefault('areaId', areaId)
            if areaType is not None: info_dict.setdefault('areaType', areaType)
            if name is not None: info_dict.setdefault('name', name)
            if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode)
            if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加三级合作方")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加三级合作方")
示例#4
0
    def scn_node_addCollect(self, headers=None, parentAreaCode=None, nodeName=None, collectTypeId=None,
                            skipTime=None, skipType=None, res_accurate=False, business_exception=False):
        """
        添加汇总节点
        :param headers:
        :param parentAreaCode: 上级区域编码
        :param nodeName: 节点名称
        :param collectTypeId: 汇总节点类型
        :param skipTime: 门店去重时间
        :param skipType:去重时间类型(-1表示自定义,0表示门店去重时间)
        :param res_accurate:
        :param business_exception:
        :return:
        """

        # 参数化
        if nodeName is None: nodeName = gen_bnsData.random_node_collectNodeName()
        if collectTypeId is None: collectTypeId = 1
        if skipType is None: skipType = 0

        # 发送业务请求
        res_json = self.bns_node_addCollect(headers=headers,
                                            parentAreaCode=parentAreaCode,
                                            nodeName=nodeName,
                                            collectTypeId=collectTypeId,
                                            skipTime=skipTime,
                                            skipType=skipType, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]
        areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode")
        areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId")
        areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType")
        parentAreaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.parentAreaCode")
        nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel")
        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                return areaCode

            # 全部信息返回
            info_dict = dict()
            # TODO: 请确认,是否需要接收其他必要信息, 如添加后产生的唯一性标识信息
            if areaCode is not None: info_dict.setdefault('areaCode', areaCode)
            if areaId is not None: info_dict.setdefault('areaId', areaId)
            if areaType is not None: info_dict.setdefault('areaType', areaType)
            if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel)
            if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode)
            if nodeName is not None: info_dict.setdefault('nodeName', nodeName)
            if collectTypeId is not None: info_dict.setdefault('collectTypeId', collectTypeId)
            if skipTime is not None: info_dict.setdefault('skipTime', skipTime)
            if skipType is not None: info_dict.setdefault('skipType', skipType)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加汇总子节点")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加汇总子节点")
示例#5
0
    def scn_node_addLogic(self, headers=None, parentAreaCode=None, nodeName=None, logicTypeId=None,
                          skipTime=None, skipType=None, res_accurate=False, business_exception=False):
        '''

        :param headers:
        :param parentAreaCode: 添加节点的上级节点编码
        :param nodeName: 添加节点的名称
        :param logicTypeId: 数据处理逻辑类型id
        :param skipTime: 门店去重时间(秒)
        :param skipType: 去重时间类型(-1表示自定义,0表示门店去重时间)
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        if nodeName is None: nodeName = gen_bnsData.random_node_nodeName()
        #skipType为0时为取门店去重时间,即skipTime取门店去重时间
        if skipType is None: skipType = 0

        # 发送业务请求
        res_json = self.bns_node_addLogic(headers=headers,
                                          parentAreaCode=parentAreaCode,
                                          nodeName=nodeName,
                                          logicTypeId=logicTypeId,
                                          skipTime=skipTime,
                                          skipType=skipType, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId")
            areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode")
            areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType")
            nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel")
            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            if areaId is not None: info_dict.setdefault('areaId', areaId)
            if areaCode is not None: info_dict.setdefault('areaCode', areaCode)
            if areaType is not None: info_dict.setdefault('areaType', areaType)
            if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel)
            if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode)
            if nodeName is not None: info_dict.setdefault('nodeName', nodeName)
            if logicTypeId is not None: info_dict.setdefault('logicTypeId', logicTypeId)
            if skipTime is not None: info_dict.setdefault('skipTime', skipTime)
            if skipType is not None: info_dict.setdefault('skipType', skipType)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加抓拍子节点")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加抓拍子节点")
示例#6
0
    def scn_node_addBrand(self, parentAreaCode=None,headers=None,  brandName=None, ageGroups=None, res_accurate=False, business_exception=False):
        """
        添加品牌节点
        :param parentAreaCode:上级区域编码
        :param headers:
        :param brandName:品牌名称
        :param ageGroups: 年龄分组,例:[(0,2),(3,5),(5,90)]
        :param res_accurate:
        :param business_exception:
        :return:
        """

        # 参数化
        if brandName is None: brandName = gen_bnsData.random_node_brandName()
        if ageGroups is None: ageGroups = [(0,90)]

        # 发送业务请求
        res_json = self.bns_node_addBrand(headers=headers,
										parentAreaCode=parentAreaCode,
										brandName=brandName,
                                        ageGroups=ageGroups)

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            # 收集响应信息:输入信息或返回信息中提取
            areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId")
            areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode")
            areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType")
            nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel")

            # 精确返回的内容
            if res_accurate:
                return areaCode

            # 全部信息返回
            info_dict = dict()
            if areaId is not None: info_dict.setdefault('areaId', areaId)
            if areaCode is not None: info_dict.setdefault('areaCode', areaCode)
            if areaType is not None: info_dict.setdefault('areaType', areaType)
            if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel)
            if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode)
            if brandName is not None: info_dict.setdefault('brandName', brandName)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加品牌")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加品牌")
示例#7
0
    def scn_snap_list(self, headers=None, areaCodesList=None, deviceCode=None, deviceType=None, startAgeInit=None, endAgeInit=None, startDateTime=None, endDateTime=None, faceId=None, memberFaceId=None, sexInit=None, snapType=None, userStatus=None, userType=None, pageNo=None, pageSize=None, res_accurate=False, business_exception=False,expected_value=None):
        '''
        功能:抓拍列表查询
        :param headers:
        :param areaCodesList: 节点编码
        :param deviceCode: 设备编码
        :param deviceType: 设备类型
        :param startAgeInit: 开始年龄
        :param endAgeInit: 结束年龄
        :param startDateTime: 开始时间
        :param endDateTime: 结束时间
        :param faceId: 人脸ID
        :param sexInit: 性别,男:0,女:1
        :param snapType: 抓拍类型,0:人脸;3:头肩;5:无特征人脸;6:低质量
        :param userStatus: 客流方向,0:无状态;1:店外徘徊;2:进店;3:店内徘徊;4:出店
        :param userType: 客户类型, 0:普通客户;1:会员,2:店员
        :param pageNo: 页码
        :param pageSize:每页条数
        :param res_accurate:
        :param business_exception:
        :return:
        '''
        
        # 参数化
        if startDateTime is None: startDateTime = gen_bnsData.random_snap_startDateTime()
        if endDateTime is None: endDateTime = gen_bnsData.random_snap_endDateTime()
        if pageNo is None: pageNo = 1
        if pageSize is None: pageSize = 20

        # 发送业务请求
        res_json = self.bns_snap_list(headers=headers,
										areaCodesList=areaCodesList,
										deviceCode=deviceCode,
										deviceType=deviceType,
										startAgeInit=startAgeInit,
										endAgeInit=endAgeInit,
										startDateTime=startDateTime,
										endDateTime=endDateTime,
										faceId=faceId,
										sexInit=sexInit,
										snapType=snapType,
										userStatus=userStatus,
										userType=userType,
										pageNo=pageNo,
										pageSize=pageSize,)
        
        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json
            
        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]
        
        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                return JsonHelper.parseJson_by_objectpath(res_json, "count($.response_data.data.list)")

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")
        
        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:抓拍列表查询")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:抓拍列表查询")
示例#8
0
    def scn_operateUser_add_techSupport(self,
                                        headers=None,
                                        userName=None,
                                        userPhone=None,
                                        res_accurate=False,
                                        business_exception=False):
        '''
        功能:运营用户里添加一个技术支持
        :param headers:
        :param userName: 用户姓名
        :param userPhone: 手机号
        :param areaCodesList: 权限对应作用节点
        :return:
        '''

        # 参数化
        if userName is None:
            userName = gen_bnsData.random_operateUser_userName()
        if userPhone is None:
            userPhone = gen_bnsData.random_operateUser_userPhone()
        roleId = 2
        areaCodesList = ["0000"]

        # 发送业务请求
        res_json = self.bns_operateUser_add(
            headers=headers,
            userName=userName,
            userPhone=userPhone,
            roleId=roleId,
            areaCodesList=areaCodesList,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            userInfo = self.bns_operateUser_list(userInfo=userPhone)
            userId = JsonHelper.parseJson_by_objectpath(userInfo,
                                                        "$..*[@.id]",
                                                        res_firstOne=True)
            # 获取密码并修改为默认密码Dj123456
            password_by_md5 = get_md5Password_from_mysql_in_mall(userPhone)
            ScnApi(username=userPhone,
                   password=password_by_md5).scn_operateUser_modifyPassword()
            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            info_dict.setdefault('userId', userId)
            if userName is not None: info_dict.setdefault('userName', userName)
            if userPhone is not None:
                info_dict.setdefault('userPhone', userPhone)
            if roleId is not None: info_dict.setdefault('roleId', roleId)
            if areaCodesList is not None:
                info_dict.setdefault('areaCodesList', areaCodesList)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加运营用户")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加运营用户")
示例#9
0
    def scn_node_addShop(self, headers=None, parentAreaCode=None, shopName=None, province=None, city=None,
                         district=None, clerkSim=None, clerkSimType=None, customerSim=None, customerSimType=None,
                         groupId=None, repeatDate=None, skipTime=None, trailSkipTime=None, res_accurate=False,
                         business_exception=False):
        '''

        :param headers:
        :param parentAreaCode: 添加门店的上级节点区域编码
        :param shopName: 添加门店的名称
        :param province: 省
        :param city: 市
        :param district: 县/区
        :param clerkSim: 店员相似度阈值
        :param clerkSimType: 店员相似度选择(-1表示自定义,0表示低,1表示中,2表示高)
        :param customerSim: 顾客相似度阈值
        :param customerSimType: 顾客相似度选择(-1表示自定义,0表示低,1表示中,2表示高)
        :param groupId: 门店分组编码
        :param repeatDate: 回头客范围(天)
        :param skipTime: 门店去重时间(秒)
        :param trailSkipTime: 门店轨迹去重时间(秒)
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        if shopName is None: shopName = gen_bnsData.random_node_shopName()
        if province is None or city is None or district is None:
            province, city, district = gen_bnsData.get_random_addNode_mallAddr()
        if clerkSimType is None: clerkSimType = 1
        if customerSimType is None: customerSimType = 1
        if repeatDate is None: repeatDate = 30
        if skipTime is None: skipTime = 3600
        if trailSkipTime is None: trailSkipTime = 3600
        if shopName is None: shopName = gen_bnsData.random_node_shopName()

        # 发送业务请求
        res_json = self.bns_node_addShop(headers=headers,
                                         parentAreaCode=parentAreaCode,
                                         shopName=shopName,
                                         province=province,
                                         city=city,
                                         district=district,
                                         clerkSim=clerkSim,
                                         clerkSimType=clerkSimType,
                                         customerSim=customerSim,
                                         customerSimType=customerSimType,
                                         groupId=groupId,
                                         repeatDate=repeatDate,
                                         skipTime=skipTime,
                                         trailSkipTime=trailSkipTime, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
            5013
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            areaId = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaId")
            areaCode = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaCode")
            areaType = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.areaType")
            nodeLevel = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.data.nodeLevel")
            if res_accurate:
                return areaCode

            # 全部信息返回
            info_dict = dict()
            if areaId is not None: info_dict.setdefault('areaId', areaId)
            if areaCode is not None: info_dict.setdefault('areaCode', areaCode)
            if areaType is not None: info_dict.setdefault('areaType', areaType)
            if nodeLevel is not None: info_dict.setdefault('nodeLevel', nodeLevel)
            if parentAreaCode is not None: info_dict.setdefault('parentAreaCode', parentAreaCode)
            if shopName is not None: info_dict.setdefault('shopName', shopName)
            if clerkSim is not None: info_dict.setdefault('clerkSim', clerkSim)
            if clerkSimType is not None: info_dict.setdefault('clerkSimType', clerkSimType)
            if customerSim is not None: info_dict.setdefault('customerSim', customerSim)
            if customerSimType is not None: info_dict.setdefault('customerSimType', customerSimType)
            if groupId is not None: info_dict.setdefault('groupId', groupId)
            if repeatDate is not None: info_dict.setdefault('repeatDate', repeatDate)
            if skipTime is not None: info_dict.setdefault('skipTime', skipTime)
            if trailSkipTime is not None: info_dict.setdefault('trailSkipTime', trailSkipTime)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加门店")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加门店")
示例#10
0
    def scn_device_add(self,
                       mallAreaCode,
                       deviceCodeOrBar,
                       areaCodesList,
                       headers=None,
                       deviceName=None,
                       res_accurate=False,
                       business_exception=False):
        '''
        :param headers:
        :param deviceCodeOrBar: 设备编码/条码
        :param deviceName: 设备名称
        :param areaCodesList: 挂载节点(区域编码为列表形式)
        :return:
        '''

        self.set_headers("areaCode", "mallAreaCode")
        # 参数化
        if deviceName is None:
            deviceName = gen_bnsData.random_device_deviceName()

        # 发送业务请求
        res_json = self.bns_device_add(
            mallAreaCode=mallAreaCode,
            headers=headers,
            deviceCodeOrBar=deviceCodeOrBar,
            deviceName=deviceName,
            areaCodesList=areaCodesList,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            if deviceCodeOrBar is not None:
                info_dict.setdefault('deviceCodeOrBar', deviceCodeOrBar)
            if deviceName is not None:
                info_dict.setdefault('deviceName', deviceName)
            if areaCodesList is not None:
                info_dict.setdefault('areaCodesList', areaCodesList)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:绑定设备")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:绑定设备")
示例#11
0
    def scn_iotUser_add_techSupoort(self,
                                    headers=None,
                                    userEmail=None,
                                    userName=None,
                                    userPhone=None,
                                    res_accurate=False,
                                    business_exception=False):
        '''
        功能:IOT添加一个技术支持人员
        :param headers:
        :param userEmail: 邮箱
        :param userName: 姓名
        :param userPhone: 手机号
        :return:
        '''

        # 参数化
        if userEmail is None:
            userEmail = gen_bnsData.random_iotUser_userEmail()
        if userName is None: userName = gen_bnsData.random_iotUser_userName()
        if userPhone is None:
            userPhone = gen_bnsData.random_iotUser_userPhone()
        roleIdsList = [3]

        # 发送业务请求
        res_json = self.bns_iotUser_add(
            headers=headers,
            userEmail=userEmail,
            userName=userName,
            userPhone=userPhone,
            roleIdsList=roleIdsList,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            userId = JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data.data.userId")
            # 获取密码
            password_by_md5 = get_md5Password_from_mysql_in_iot(userPhone)
            # 精确返回的内容
            if res_accurate:
                return userPhone

            # 全部信息返回
            info_dict = dict()
            info_dict.setdefault('userId', userId)
            info_dict.setdefault('userPassword', password_by_md5)
            if userEmail is not None:
                info_dict.setdefault('userEmail', userEmail)
            if userName is not None: info_dict.setdefault('userName', userName)
            if userPhone is not None:
                info_dict.setdefault('userPhone', userPhone)
            if roleIdsList is not None:
                info_dict.setdefault('roleIdsList', roleIdsList)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:添加员工")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:添加员工")
示例#12
0
    def scn_memberlevel_add(self,
                            brandCode,
                            brandId,
                            headers=None,
                            levelName=None,
                            res_accurate=False,
                            business_exception=False):
        '''

        :param headers:
        :param brandCode: 品牌编码
        :param brandId: 品牌id
        :param levelName: 会员级别名称
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        if levelName is None:
            levelName = gen_bnsData.random_memberlevel_levelName()

        # 发送业务请求
        res_json = self.bns_memberlevel_add(
            headers=headers,
            brandCode=brandCode,
            brandId=brandId,
            levelName=levelName,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            if brandCode is not None:
                info_dict.setdefault('brandCode', brandCode)
            if brandId is not None: info_dict.setdefault('brandId', brandId)
            if levelName is not None:
                info_dict.setdefault('levelName', levelName)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:新增会员级别")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:新增会员级别")
示例#13
0
    def scn_operateUser_changeUserRole(self,
                                       headers=None,
                                       userId=None,
                                       res_accurate=False,
                                       business_exception=False):
        '''

        :param headers:
        :param userId: 账户权限对应的用户ID
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        res = self.bns_operateUser_getUserRoleList()
        userId_list = JsonHelper.parseJson_by_objectpath(res, "$..*['id']")
        if userId is None: userId = userId_list[0]

        # 发送业务请求
        res_json = self.bns_operateUser_changeUserRole(
            headers=headers,
            userId=userId,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:切换账户权限角色")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:切换账户权限角色")
示例#14
0
    def scn_node_list(self, headers=None, parentAreaCode=None, name=None, nodeLevel=None, pageNo=None, pageSize=None,
                      res_accurate=False, business_exception=False):
        """
        获取抓拍列表
        :param headers:
        :param parentAreaCode: 上级节点编码
        :param name: 节点名称
        :param nodeLevel: 节点等级
        :param pageNo: 页码
        :param pageSize: 每页展示数量
        :param res_accurate:
        :param business_exception:
        :return:
        """
        # 参数化
        if pageNo is None: pageNo = 1
        if pageSize is None: pageSize = 10

        # 发送业务请求
        res_json = self.bns_node_list(headers=headers,
                                      parentAreaCode=parentAreaCode,
                                      name=name,
                                      nodeLevel=nodeLevel,
                                      pageNo=pageNo,
                                      pageSize=pageSize, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:区域列表")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:区域列表")
示例#15
0
    def scn_device_auth(self,
                        deviceCode,
                        data=None,
                        headers=None,
                        res_accurate=False,
                        business_exception=False):
        '''

        :param headers:
        :param deviceCode: 设备编码
        :param data: 数据加密
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        deviceCode = deviceCode

        json_dict = {
            "equno": deviceCode,
            "time": TimeHelper.get_time_from_timestamp(),
            "randCode": StringHelper.random_string(16)
        }

        publicKey = utils.get_publicKey_from_mysql(deviceCode)
        # RSA加密方法
        rsa = utils.RSA()

        data = rsa.rsa_pubkey_encrypt(publicKey, json.dumps(json_dict))

        # 发送业务请求
        res_json = self.bns_device_auth(
            headers=headers,
            deviceCode=deviceCode,
            data=data,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.resultCode")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            data = JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data.data")
            res = rsa.rsa_pubkey_decrypt(publicKey, data)  # 解密接口返回的信息

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = json.loads(res)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:设备鉴权")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:设备鉴权")
示例#16
0
    def scn_node_treeGroup(self, headers=None, parentAreaCode=None, areaType=None, expandAll=None,
                           includeParentNode=None, name=None, nodeLevel=None, provinceCity=None, res_accurate=False,
                           business_exception=False):
        """
        获取节点树(带节点分组)
        :param headers:
        :param parentAreaCode:上级区域编码
        :param areaType: 节点类型
        :param expandAll: 是否展开所有节点,可选
        :param includeParentNode: 是否包含父级节点,可选,默认不包含
        :param name: 节点名称
        :param nodeLevel: 区域级别
        :param provinceCity: 区域位置-省市
        :param res_accurate:
        :param business_exception:
        :return:
        """

        # 参数化
        # if func_param is None: func_param = gen_bnsData.xxx()

        # 发送业务请求
        res_json = self.bns_node_treeGroup(headers=headers,
                                           parentAreaCode=parentAreaCode,
                                           areaType=areaType,
                                           expandAll=expandAll,
                                           includeParentNode=includeParentNode,
                                           name=name,
                                           nodeLevel=nodeLevel,
                                           provinceCity=provinceCity, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:节点树")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:节点树")
示例#17
0
    def scn_employee_add(self,
                         mallareaCode,
                         faceId,
                         imagePath,
                         headers=None,
                         employeename=None,
                         phoneNo=None,
                         sex=None,
                         age=None,
                         remark=None,
                         res_accurate=False,
                         business_exception=False):
        '''

        :param headers:
        :param mallareaCode: 门店编码
        :param employeename: 店员姓名
        :param phoneNo: 手机号码
        :param faceId: 人脸faceId
        :param imagePath: 图片路径
        :param sex: 性别
        :param age: 年龄
        :param remark: 备注
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        if employeename is None:
            employeename = gen_bnsData.random_employee_employeename()
        if phoneNo is None: phoneNo = StringHelper.get_random_phoneno()
        if remark is None: remark = gen_bnsData.random_employee_remark()

        # 发送业务请求
        res_json = self.bns_employee_add(
            headers=headers,
            mallareaCode=mallareaCode,
            employeename=employeename,
            phoneNo=phoneNo,
            faceId=faceId,
            imagePath=imagePath,
            sex=sex,
            age=age,
            remark=remark,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            if mallareaCode is not None:
                info_dict.setdefault('mallareaCode', mallareaCode)
            if employeename is not None:
                info_dict.setdefault('employeename', employeename)
            if phoneNo is not None: info_dict.setdefault('phoneNo', phoneNo)
            if faceId is not None: info_dict.setdefault('faceId', faceId)
            if imagePath is not None:
                info_dict.setdefault('imagePath', imagePath)
            if sex is not None: info_dict.setdefault('sex', sex)
            if age is not None: info_dict.setdefault('age', age)
            if remark is not None: info_dict.setdefault('remark', remark)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:新增店员")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:新增店员")
示例#18
0
    def scn_publicDevice_add(self, headers=None, deviceType=None, manufacturerType=None, deviceCode=None,
                          deviceBarCode=None, hardwareVersion=None, lensType=None, res_accurate=False,
                          business_exception=False):

        # 参数化: 默认是店计瑞为,编码长度14,条码长度10
        if deviceType is None: deviceType = 0
        if manufacturerType is None: manufacturerType = 0
        if deviceCode is None: deviceCode = gen_bnsData.random_publicDevice_deviceCode(14)
        if deviceBarCode is None: deviceBarCode = gen_bnsData.random_publicDevice_deviceBarCode(10)
        if hardwareVersion is None: hardwareVersion = gen_bnsData.random_publicDevice_hardwareVersion()
        if lensType is None: lensType = gen_bnsData.random_publicDevice_lensType()

        # 发送业务请求
        res_json = self.bns_publicDevice_add(headers=headers,
                                          deviceType=deviceType,
                                          manufacturerType=manufacturerType,
                                          deviceCode=deviceCode,
                                          deviceBarCode=deviceBarCode,
                                          hardwareVersion=hardwareVersion,
                                          lensType=lensType, )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数
            list_info = self.bns_publicDevice_list(pageNo=1, pageSize=20, deviceCode=deviceCode)
            enale = JsonHelper.parseJson_by_objectpath(list_info, "$..*[@.enable]", res_firstOne=True)
            deviceRegDatetime = JsonHelper.parseJson_by_objectpath(list_info, "$..*[@.createTime]", res_firstOne=True)

            # 精确返回的内容
            if res_accurate:
                pass

            # 全部信息返回
            info_dict = dict()
            if enale is not None: info_dict.setdefault('enale', enale)
            if deviceRegDatetime is not None: info_dict.setdefault('deviceRegDatetime', deviceRegDatetime)
            if deviceType is not None: info_dict.setdefault('deviceType', deviceType)
            if manufacturerType is not None: info_dict.setdefault('manufacturerType', manufacturerType)
            if deviceCode is not None: info_dict.setdefault('deviceCode', deviceCode)
            if deviceBarCode is not None: info_dict.setdefault('deviceBarCode', deviceBarCode)
            if hardwareVersion is not None: info_dict.setdefault('hardwareVersion', hardwareVersion)
            if lensType is not None: info_dict.setdefault('lensType', lensType)
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:公共服务注册设备")

            return JsonHelper.parseJson_by_objectpath(res_json, "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:公共服务注册设备")
示例#19
0
    def scn_operateUser_modifyPassword(self,
                                       headers=None,
                                       oldPasswordMd5=None,
                                       newPassword=None,
                                       res_accurate=False,
                                       business_exception=False):
        '''
        功能:修改密码
        :param headers:
        :param oldPasswordMd5: 旧密码,MD5值
        :param newPassword: 新密码
        :param res_accurate:
        :param business_exception:
        :return:
        '''

        # 参数化
        if oldPasswordMd5 is None:
            oldPasswordMd5 = self.password

        if newPassword is None:
            newPassword = self.SET_DEFAULT_PASSWORD

        # 发送业务请求
        res_json = self.bns_operateUser_modifyPassword(
            headers=headers,
            oldPasswordMd5=oldPasswordMd5,
            newPassword=newPassword,
        )

        # 定义一个http状态码的白名单, 如果状态码不在白名单中,则直接返回
        white_list = [200, 201]
        # 获取当前请求的http状态码
        http_code = JsonHelper.parseJson_by_objectpath(res_json,
                                                       "$.response_code")
        # 如果请求返回的状态码不是期望的http状态码, 则直接返回该状态码
        if http_code not in white_list:
            return res_json

        # 提取业务码
        actually_business_code = JsonHelper.parseJson_by_objectpath(
            res_json, "$.response_data.code")
        # 异常码集合
        exception_list = [
            # 400004,   # 设备类型不合法
        ]

        # 正常业务状态码下, 函数的返回信息
        if actually_business_code == 0:

            # 解析返回信息或调用自定义函数

            # 精确返回的内容
            if res_accurate:
                pass
                # return deviceCode

            # 全部信息返回
            info_dict = dict()
            return info_dict if info_dict else JsonHelper.parseJson_by_objectpath(
                res_json, "$.response_data")

        # 异常业务状态码下(已知异常), 函数的返回信息
        elif actually_business_code in exception_list:

            if business_exception:
                raise DefinedBusinessException("接口已知业务异常:修改密码")

            return JsonHelper.parseJson_by_objectpath(res_json,
                                                      "$.response_data")

        # 异常业务状态码下(未知异常), 函数的返回信息
        else:
            raise UndefinedBusinessException("接口未知业务异常:修改密码")