示例#1
0
def fire_equipment():
    logger.info('/fire_equipment')
    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:
            return post_json(
                0, 'success',
                check_info.get_fire_equipment_data(data.get('check_id')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
示例#2
0
def security_msg_update():
    logger.info('/security_msg_update')
    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 'security_id' in data.keys(
            ) and 'security_update_code' in data.keys():
                # 检测规定参数是否存在
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
            # 获取数据
        if user is not None:
            success_label = check_security.update_security_msg(data)
            if success_label:
                return post_json(0, 'success')
            else:
                return post_json(data='update failed')
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
示例#3
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')
示例#4
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')
def env_indoor_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 'position_id' 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:
            return post_json(
                0, 'success',
                check_info.env_indoor_history(data.get('position_id'),
                                              data.get('data_type')))
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
def control_check_wlw():
    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 'device_type' 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:
            # return post_json(0, 'success', return_data)
            return post_json(
                0, 'success',
                check_info.get_control_check_wlw_data(data.get('device_type')))

        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
def config_property_update():
    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:
            flag = check_info.update_property_data(data)
            if flag == 1:
                return post_json(0, 'success')
            else:
                return post_json(1, 'fail', '更新失败')
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
示例#8
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')
示例#9
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')
def area_overview():
    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():
                user = user_dal.UserDal().check_uid(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        if user is not None:
            return post_json(0, 'success', check_info.get_area_overview())
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
示例#11
0
def login():
    logger.info('/login')
    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 'uname' in data.keys() and 'password' in data.keys():
                user = user_dal.UserDal().login_auth(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
        if user is not None:
            return post_json(0, 'success', user.to_dict())
        else:
            return post_json(data='用户名或密码错误')
    else:
        return render_template('404.html')
def register_name_check():
    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 'uname' in data.keys():
                success = user_dal.UserDal().register_name_check(data)
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')

        if success:
            return post_json(0, 'success', data='注册用户名不存在,可以注册')
        else:
            return post_json(data='注册用户名已经存在,换一个用户名试试')
    else:
        return render_template('404.html')
def data_download():
    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:
            return post_json(0, 'success', {"data_url": "data.xls"})
        else:
            return post_json(data='uid校验失败')
    else:
        return render_template('404.html')
def register():
    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 'uname' in data.keys() and 'password' in data.keys() and 'nickname' in data.keys() \
                    and 'apply_code' in data.keys():
                if data.get('apply_code') == config.APPLY_CODE:
                    success = user_dal.UserDal().register(data)
                else:
                    return post_json(2, 'success', data='邀请码不正确')
            else:
                return post_json(1, 'failed', data='输入参数不完整或者不正确')
        else:
            return post_json(1, 'failed', data='输入参数不完整或者不正确')
        if success:
            return post_json(0, 'success', data='注册成功')
        else:
            return post_json(data='注册失败')
    else:
        return render_template('404.html')