Пример #1
0
def energy_electricity():
    logger.info('/energy_electricity')
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        # 参数校验
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            logger.debug(data)
            if 'uid' in data.keys() and 'check_id' in data.keys():
                # 检查uid
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        # 获取数据
        if user is not None:
            # 查询物联网接口数据
            # logger.debug(post_json(0, 'success', check_info.get_env_outdoor()))
            # 替换unity_id为物联网id
            data[
                'check_id'], check_name = check_info_wlw.get_wlw_id_by_unity_id(
                    data.get('check_id'))
            return check_info_wlw.get_info_wlw(
                config.URL_WLW + '/energy_electricity', json.dumps(data))

            # 查询虚拟数据
            # return post_json(0, 'success', check_info.get_energy_electricity(data.get('check_id')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
Пример #2
0
def env_outdoor_history():
    logger.info('/env_outdoor_history')
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        # 参数校验
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            logger.debug(data)
            if 'uid' in data.keys() and 'data_type' in data.keys(
            ) and data.get('data_type') in ("year", "month", "day"):
                # 检查uid
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        # 获取数据
        if user is not None:
            # 查询物联网接口数据
            # logger.debug(post_json(0, 'success', check_info.get_env_outdoor()))
            return check_info_wlw.get_info_wlw(
                config.URL_WLW + '/env_outdoor_history', request.get_data())

            # 查询虚拟数据
            # return post_json(0, 'success', check_info.env_outdoor_history(data.get('data_type')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
Пример #3
0
def monitor_check_ea():
    logger.info('/monitor_check_ea')
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        # 参数校验
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            logger.debug(data)
            if 'uid' in data.keys() and 'check_id' in data.keys():
                # 检查uid
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        # 获取数据
        if user is not None:
            # 查询虚拟数据,以便获得设备信息、图片等
            result_dict = check_info.get_device_ea_data(data.get('check_id'))
            # 替换check_id 和 前端显示名称
            data[
                'check_id'], check_name = check_info_wlw.get_wlw_id_by_unity_id(
                    data.get('check_id'))
            # 使用替换后的check_id查询物联网接口数据,以便获得设备状态
            result_json_wlw = check_info_wlw.get_info_wlw(
                config.URL_WLW + '/monitor_check_ea_wlw', json.dumps(data))

            try:
                # 替换位置名称
                result_dict['device_name'] = check_name
                # 物联网数据转为字典
                result_dict_wlw = json.loads(result_json_wlw)

                # 物联网状态替换虚拟数据状态
                result_dict['device_status'] = result_dict_wlw['data'][
                    'device_status']

            except Exception as e:
                logger.error('load json to dict error, {}'.format(repr(e)))

            return post_json(0, 'success', result_dict)

            # 查询虚拟数据
            # return post_json(0, 'success', check_info.get_device_ea_data(data.get('check_id')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
Пример #4
0
def env_indoor():
    logger.info('/env_indoor')
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        # 参数校验
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            logger.debug(data)
            if 'uid' in data.keys() and 'position_id' in data.keys():
                # 检查uid
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        # 获取数据
        if user is not None:
            # 查询物联网接口数据
            # logger.debug(post_json(0, 'success', check_info.get_env_outdoor()))
            # 替换unity_id为物联网id
            data[
                'position_id'], position_name = check_info_wlw.get_wlw_id_by_unity_id(
                    data.get('position_id'))
            result_json = check_info_wlw.get_info_wlw(
                config.URL_WLW + '/env_indoor', json.dumps(data))
            try:
                # 替换位置名称
                result_dict = json.loads(result_json)
                result_dict['data']['position_name'] = position_name

                # 替换voc读数 数字转中文
                result_dict['data']['voc'] = config.VOC_LEVEL[
                    result_dict['data']['voc']]

                result_json = json.dumps(result_dict)

            except Exception as e:
                logger.error('load json to dict error', repr(e))

            return result_json

            # 查询虚拟数据
            # return post_json(0, 'success', check_info.get_env_indoor(data.get('position_id')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')