Beispiel #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')
Beispiel #2
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')
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 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')
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')
Beispiel #6
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')
Beispiel #7
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')
Beispiel #8
0
def doc_chapter():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'docid' in data.keys():
                if UserDal.check_uid(data) is not None:
                    result = doc_dal.DocDal().doc_chapter(data)
                    if result is not None:
                        doc_dict = result[0]
                        doc_chapter_list = result[1]
                        data = dict(
                            docid=doc_dict['docid'],
                            docname=doc_dict['docname'],
                            doctype=doc_dict['doctype'],
                            chapters=doc_chapter_list,
                        )
                        return post_json('success', data=data)
                    else:
                        return post_json('success', '提取目录出错')
                else:
                    return post_json('error', '用户校验出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #9
0
def doc_create():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if g.string == 'token认证失败':
            return post_json('error', g.string)
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            uid = jwt_utils.get_uid_token(request)[0]
            data.update({'uid': uid})
            if 'docname' in data.keys() and 'doctype' in data.keys():
                new_doc = doc_dal.DocDal().insert_doc_and_get_doc(data)
                if new_doc is not None:
                    # doc_id = new_doc['doc_id']
                    # return post_json('success', data=dict(docid=doc_id))
                    doc_dal.DocDal().copy_file(new_doc['doc_type'],
                                               new_doc['doc_id'])
                    return post_json('success', '新建文档成功')
                else:
                    return post_json('error', '新建文档出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #10
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')
Beispiel #11
0
def doc_keywords():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'doctype' in data.keys():
                keywords = doc_dal.DocDal().get_doc_keywords(data)
                return post_json('success', data=keywords)
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #12
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')
Beispiel #13
0
def 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())
            if 'uname' in data.keys() and 'passwd' in data.keys():
                user = user_dal.UserDal().login_auth(data)
            else:
                return '输入参数不完整或者不正确'
        else:
            return '输入参数不完整或者不正确'
        if user is not None:
            return post_json(0, 'success', user.to_dict())
        else:
            return post_json(data='用户名或密码错误')
    else:
        return render_template('404.html')
Beispiel #14
0
def doc_save():
    if is_json(request.get_data()):
        data = json.loads(request.get_data())
        # with open("1.txt", "a") as code:
        #     code.write(request.path+"\n"+request.url+"\n"+request.get_data()+"\n")
        if 'status' in data.keys() and 'url' in data.keys(
        ) and 'key' in data.keys():
            if data['status'] == 2:
                doc_path = doc_dal.DocDal().get_doc_path_by_key(data['key'])
                url = data['url']
                doc_dal.DocDal().save_file(url, doc_path, data['key'])
                return post_json('success', '保存成功')
            else:
                return "{\"error\":0}"
        else:
            return "{\"error\":0}"
    else:
        return "{\"error\":0}"
Beispiel #15
0
def get_doc_by_id():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'doc_id' in data.keys():
                doc_dict = doc_dal.DocDal.get_doc_by_id(data)
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
        if doc_dict is not None:
            return post_json('success', data=doc_dict)
        else:
            return post_json('error', '获取文档出错')
    else:
        return render_template('404.html')
Beispiel #16
0
def doc_create():
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys():
                if UserDal.check_uid(data) is not None:
                    doc_typeinfo = doc_dal.DocDal().get_doc_typeinfo()
                else:
                    return "用户校验出错"
            else:
                return '输入参数不完整或者不正确'
        else:
            return '输入参数不完整或者不正确'
        return post_json(0, 'success', dict(doctypeinfo=doc_typeinfo))
    else:
        return render_template('404.html')
Beispiel #17
0
def logout():
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'uname' in data.keys():
                success = True
            else:
                return '输入参数不完整或者不正确'
        else:
            return '输入参数不完整或者不正确'
        data = json.loads(request.get_data())
        if success:
            return post_json(0, 'success', data='用户登出成功')
        else:
            return post_json(data='用户登出失败')
    else:
        return render_template('404.html')
Beispiel #18
0
def register_name_check():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uname' in data.keys():
                success = user_dal.UserDal().register_name_check(data)
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')

        if success:
            return post_json('success', '注册用户名不存在,可以注册')
        else:
            return post_json('error', '注册用户名已经存在,换一个用户名试试')
    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')
Beispiel #20
0
def register():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uname' in data.keys() and 'passwd' in data.keys() and 'nickname' in data.keys() \
                    and 'mail' in data.keys():
                success = user_dal.UserDal().register(data)
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
        if success:
            return post_json('success', '注册成功')
        else:
            return post_json('error', '注册失败')
    else:
        return render_template('404.html')
Beispiel #21
0
def security_bim():
    logger.info('/security_bim')
    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 'security_time' in data.keys() and 'device_id' in data.keys():
                # 存入数据库
                check_security.save_security_msg(data)
                return post_json(0, 'success')
            else:
                return post_json(data='输入参数不完整或者不正确')
        else:
            return post_json(data='json校验失败')
    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')
Beispiel #23
0
def doc_delete():
    if request.method == 'GET':
        return '<h1>请使用post方法</h1>'
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'docid' in data.keys():
                if UserDal.check_uid(data) is not None:
                    rowcount = doc_dal.DocDal().delete_doc(data)
                else:
                    return "用户校验出错"
            else:
                return '输入参数不完整或者不正确'
        else:
            return '输入参数不完整或者不正确'
        if rowcount > 0:
            return post_json(0, 'success', data='删除文档成功')
        else:
            return post_json(data='删除文档出错')
    else:
        return render_template('404.html')
Beispiel #24
0
def doc_check_t():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'docid' in data.keys() and 'cpcode' in data.keys() \
                    and 'tmcode' in data.keys() and 'tminputcode' in data.keys():
                if UserDal.check_uid(data) is not None:
                    tcontentlist = doc_dal.DocDal().doc_check_t(data)
                    if doc_check_t is not None:
                        return post_json('success', data=tcontentlist)
                    else:
                        return post_json('error', '模板查询出错')
                else:
                    return post_json('error', '用户校验出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #25
0
def doc_save_temp():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'docid' in data.keys() and 'cpcode' in data.keys() \
                    and 'cpcontent' in data.keys():
                if UserDal.check_uid(data) is not None:
                    doc_save_return = doc_dal.DocDal().doc_save_temp(data)
                    if doc_save_return is not None:
                        return post_json('success', '暂存数据成功')
                    else:
                        return post_json('error', '数据暂存出错')
                else:
                    return post_json('error', '用户校验出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #26
0
def doc_download():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uid' in data.keys() and 'docid' in data.keys():
                if UserDal.check_uid(data) is None:
                    return post_json('error', '用户校验出错')
                if doc_dal.DocDal.get_doc_by_id(data) is None:
                    return post_json('error', '该文档不存在或已删除')
                doc_url = doc_dal.DocDal().get_doc_url(data, request)
                if doc_url is not None:
                    return post_json('success', data=doc_url)
                else:
                    return post_json('error', '文档下载出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #27
0
def doc_delete():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        if g.string == 'token认证失败':
            return post_json('error', g.string)
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            uid = jwt_utils.get_uid_token(request)[0]
            data.update({'uid': uid})
            if 'docid' in data.keys():
                rowcount = doc_dal.DocDal().delete_doc(data)
                if rowcount > 0:
                    return post_json('success', '删除文档成功')
                else:
                    return post_json('success', '删除文档出错')
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
    else:
        return render_template('404.html')
Beispiel #28
0
def login():
    if request.method == 'GET':
        return post_json('error', '请使用post方法')
    elif request.method == 'POST':
        login_time = int(time.time())
        if is_json(request.get_data()):
            data = json.loads(request.get_data())
            if 'uname' in data.keys() and 'passwd' in data.keys():
                user = user_dal.UserDal().login_auth(data, login_time)
            else:
                return post_json('error', '输入参数不完整或者不正确')
        else:
            return post_json('error', '输入参数不完整或者不正确')
        if user is not None:
            token = jwt_utils.encode_auth_token(user.uid, login_time)
            session.pop(user.uid, None)
            session[user.uid] = token
            return post_json('success', data=token.decode())
        else:
            return post_json('error', '用户名或密码错误')
    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 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_dict = user.to_dict()
            return_dict['ulevel'] = user.get_ulevel()
            return post_json(0, 'success', return_dict)
            # return post_json(0, 'success', user.get_id())
        else:
            return post_json(data='用户名或密码错误')
    else:
        return render_template('404.html')