Esempio n. 1
0
def file_md5_upload(file):
    """
    文件md5上传
    :param file:
    :return:
    """
    print(file)
    if file.md5_id == '5d8d2a735876b2132fc4618dbf367c4c':
        return render_info(MyResponse('查询成功'), status=500)
    if file.md5_id == '47a7af5260e7d8d50c9b66374a63264e':
        return render_info(MyResponse('查询失败', '22'))
    return render_info(MyResponse('查询成功'))
Esempio n. 2
0
def img_files_flow_page(page, img_detail):
    """
    图片文件流加载
    :param page:
    :param img_detail:
    :return:
    """
    page, pagination = img_detail.dao_find_page(page)

    flow_img_details = []
    for img_detail in pagination.items:
        url = url_for('file.file_download',
                      id=img_detail.file_id,
                      md5_id=img_detail.file_md5)
        if not img_detail.is_handle:
            alt = '待处理'
        elif is_not_empty(img_detail.img_type):
            alt = img_detail.img_type.type_explain
        else:
            alt = img_detail.err_msg
        flow_info = FlowInfo(url, url, alt, img_detail.file_id)
        flow_img_details.append(flow_info)

    flow_img_details_dict, errors = FlowInfoSchema().dump(flow_img_details,
                                                          many=True)
    Assert.is_true(is_empty(errors), errors)

    page_dict, page_errors = PageSchema().dump(page)
    Assert.is_true(is_empty(page_errors), page_errors)
    page_dict['data'] = flow_img_details_dict

    return render_info(page_dict)
Esempio n. 3
0
def add_dict(sys_dict):
    """
    字典添加
    :param SysDict sys_dict:
    :return:
    """
    sys_dict.dao_add()
    return render_info(MyResponse(msg='添加成功!'))
Esempio n. 4
0
def add_lexer_ne(audio_lexer_ne):
    """
    新增词性分析
    :param AudioLexerModel audio_lexer_ne:
    :return:
    """
    audio_lexer_ne.dao_create()
    return render_info(MyResponse(msg='添加成功'))
Esempio n. 5
0
def menu_manage():
    """
    菜单管理页面
    :return:
    """
    menus = Menu().dao_get_all(is_dump=True)
    return render_info(MyResponse(msg='查询成功!', menus=menus),
                       template='sys/menu/menu_manage.html')
Esempio n. 6
0
def add_img_type(img_type):
    """
    添加图片类型
    :param ImgTypeModel img_type:
    :return:
    """
    img_type.dao_add()
    return render_info(MyResponse('添加成功'))
Esempio n. 7
0
def img_data_page(page, img_data):
    """
    图像流水分页查询
    :param page:
    :param img_data:
    :return:
    """
    page, _ = img_data.dao_find_page(page)
    return render_info(page)
Esempio n. 8
0
def login_validate(user):
    """
    登录验证
    :param user:
    :return:
    """
    if current_user.is_authenticated:
        return render_info(MyResponse(msg='登录成功'))

    real_user = User().dao_get_by_login_name(user.login_name)  # type: User
    Assert.is_true(is_not_empty(real_user),
                   assert_code=codes.login_fail,
                   assert_msg='账号未注册')
    if real_user.validate_password(user.password):
        # 密码验证成功
        login_user(real_user, False)
        return render_info(MyResponse(msg='登录成功'))
    return render_info(MyResponse(code=codes.login_fail, msg='用户名或密码不正确'))
Esempio n. 9
0
def dict_page(page, sys_dict):
    """
    字典分页查询
    :param page:
    :param SysDict sys_dict:
    :return:
    """
    page, _ = sys_dict.dao_find_page(page)
    return render_info(page)
Esempio n. 10
0
def max_sort(menu, id):
    """
    根据 id 查询子菜单最大最大排序值
    :param menu:
    :param id:
    :return:
    """
    sort = Menu().dao_get_max_sort_by_id(menu.id)
    return render_info(MyResponse(msg='查询成功!', sort=sort))
Esempio n. 11
0
def get_menus(menu, id):
    """
    根据父级菜单ID查询子级菜单
    :param menu:
    :param id:
    :return:
    """
    menus = user_util.get_menus_by_user(menu.id, is_dump=True)
    return render_info(MyResponse(msg='查询成功', menus=menus))
Esempio n. 12
0
def del_menu(menu):
    """
    删除系统菜单
    :param menu:
    :return:
    """
    menu = Menu().dao_get(menu.id)
    if is_not_empty(menu):
        menu.dao_delete()
    return render_info(MyResponse(msg='删除成功'))
Esempio n. 13
0
def add_menu(menu):
    """
    添加系统菜单
    :param menu:
    :return:
    """
    parent_menu = Menu().dao_get(menu.parent_id)
    Assert.is_true(is_not_empty(parent_menu),
                   '无效的父级菜单ID:{0}'.format(menu.parent_id))
    menu.dao_add()
    return render_info(MyResponse(msg='添加成功'))
Esempio n. 14
0
 def handle_unknown_error(e):
     """
     未知的异常
     :param e:
     :return:
     """
     try:
         return render_info(info=MyResponse.init_error(e), template='errors/500.html')
     finally:
         # 记录日志
         current_app.logger.exception(e)
Esempio n. 15
0
def put_menu(menu):
    """
    更新系统菜单
    :param menu:
    :return:
    """
    to_do_menu = Menu().dao_get(menu.id)
    Assert.is_true(is_not_empty(to_do_menu), '无效的菜单ID:{0}'.format(menu.id))
    parent_menu = Menu().dao_get(menu.parent_id)
    Assert.is_true(is_not_empty(parent_menu),
                   '无效的父级菜单ID:{0}'.format(menu.parent_id))

    to_do_menu.dao_put(menu)
    return render_info(MyResponse(msg='更新成功'))
Esempio n. 16
0
 def handle_validation_error(e):
     """
     422 参数校验错误
     :param e:
     :return:
     """
     return render_info(
         info=MyResponse(
             code=codes.unprocessable,
             msg=e.exc.messages if e.exc else repr(e)
         ),
         template='errors/422.html',
         status=codes.unprocessable
     )
Esempio n. 17
0
def get_img_data(img_data, id):
    """
    图片流水查询
    :param img_data:
    :param id:
    :return:
    """
    # 查询图片流水
    img_data = ImgDataModel().dao_get(img_data.id)  # type: ImgDataModel
    Assert.is_true(is_not_empty(img_data), '查无此数据', codes.no_data)
    img_data_dict, errors = ImgDataSchema(
        only=ImgDataSchema().dump_only_get()).dump(img_data)
    Assert.is_true(is_empty(errors), errors)
    return render_info(MyResponse(msg='查询成功', imgData=img_data_dict))
Esempio n. 18
0
 def page_not_found(e):
     """
     404
     :param e:
     :return:
     """
     return render_info(
         info=MyResponse(
             code=codes.not_found,
             msg='资源不存在'
         ),
         template='errors/404.html',
         status=codes.not_found
     )
Esempio n. 19
0
 def bad_request(e):
     """
     400
     :param e:
     :return:
     """
     return render_info(
         info=MyResponse(
             code=codes.bad,
             msg='无效的请求'
         ),
         template='errors/400.html',
         status=codes.bad
     )
Esempio n. 20
0
 def not_allowed(e):
     """
     405
     :param e:
     :return:
     """
     return render_info(
         info=MyResponse(
             code=codes.not_allowed,
             msg='无效的请求头或方法'
         ),
         template='errors/405.html',
         status=codes.not_allowed
     )
Esempio n. 21
0
 def handle_csrf_error(e):
     """
     CSRF验证失败
     :param e:
     :return:
     """
     return render_info(
         info=MyResponse(
             code=codes.bad,
             msg=e.description if e.description else repr(e)
         ),
         template='errors/400.html',
         status=codes.bad
     )
Esempio n. 22
0
def get_img(img_data, id):
    """
    根据 ID 流水号查询图片流水(附带路径)
    :param img_data:
    :param id:
    :return:
    """
    # 查询图片流水
    img_data = ImgDataModel.query.get(img_data.id)  # type: ImgDataModel
    Assert.is_true(is_not_empty(img_data), '查无此数据', codes.no_data)
    img_data_dict, errors = ImgDataSchema().dump(img_data)
    Assert.is_true(is_empty(errors), errors)

    # 过滤图片明细字典字段
    ImgDataSchema().filter_img_details(img_data_dict.get('imgDetails', []),
                                       ['fileData'])
    return render_info(MyResponse(msg='查询成功', imgData=img_data_dict))
Esempio n. 23
0
def ocr(ocrFile):
    """
    机动车销售发票 OCR识别
    :return:
    """
    app_sys = get_app_sys(ocrFile.app_sys_code)
    Assert.is_true(is_not_empty(app_sys),
                   '无效的应用系统:{0}'.format(ocrFile.app_sys_code),
                   codes.unprocessable)
    # 通过外键添加
    ocrFile.app_sys_id = app_sys.id

    file_model = FileModel()
    file_model.dao_create()

    # 资料写入磁盘
    file_path = encodes.base64_to_file(ocrFile.file_data.file_base64,
                                       current_app.config.get('OCR_FILE_DIR'),
                                       file_model.id,
                                       ocrFile.file_data.file_format)

    # OCR识别
    token = SysData().dao_get_key(system.SysKey.HUAWEI_CLOUD_TOKEN.value).value
    mvsi_result = OCR(token=token)\
        .mvsi(image_bs64=img.ImgUtil.img_compress(path=file_path, threshold=5))
    Assert.is_true(
        is_empty(mvsi_result.error_code),
        'OCR FAILED: 【{0}】【{1}】'.format(mvsi_result.error_code,
                                        mvsi_result.error_msg))
    mvsi_result_json, errors = MvsiResultSchema(
        only=MvsiResultSchema().only_success()).dump(mvsi_result)
    Assert.is_true(is_empty(errors), errors)

    # 信息入库
    mvsi = Mvsi(**mvsi_result_json)
    mvsi.dao_add(ocrFile, file_model, file_path)

    # json 序列化
    mvsi_json, errors = MvsiSchema().dump(mvsi)
    Assert.is_true(is_empty(errors), errors)
    return render_info(MyResponse('OCR SUCCESS', results=mvsi_json))
Esempio n. 24
0
def add_img(img_data):
    """
    图片文件入库
    :param ImgDataModel img_data:
    :return:
    """
    img_data.dao_create()
    app_sys = get_app_sys(img_data.app_sys_code)
    Assert.is_true(is_not_empty(app_sys),
                   '无效的应用系统:{0}'.format(img_data.app_sys_code),
                   codes.unprocessable)

    # 通过外键添加
    img_data.app_sys_id = app_sys.id

    # 创建资料目录
    loan_dir = FileUtil.path_join(current_app.config.get('DATA_DIR'),
                                  img_data.id)

    # 信息入库
    handle_info = img_data.dao_add_info(loan_dir)
    return render_info(MyResponse(msg='接收资料成功', handle_info=handle_info))
Esempio n. 25
0
def patch_img_detail_type(img_detail):
    """
    更新图片明细类型
    :param ImgDetailModel img_detail:
    :return:
    """
    img_type = ImgTypeModel().dao_get_by_code(img_detail.img_type_code)
    Assert.is_true(is_not_empty(img_type),
                   '无效的图片类型:{0}'.format(img_detail.img_type_code),
                   codes.unprocessable)

    img_detail_id = img_detail.id
    # 接口提交的更新者
    update_by = img_detail.update_by
    img_detail = ImgDetailModel().dao_get(
        img_detail_id)  # type: ImgDetailModel
    Assert.is_true(is_not_empty(img_detail),
                   '无查无此数据:{0}'.format(img_detail_id), codes.no_data)

    img_detail.update_by = update_by
    img_detail.dao_update_type(img_type.id)
    return render_info(MyResponse('更新成功'))
Esempio n. 26
0
def img_source_files_flow_page(img_data, id):
    """
    源文件流加载
    :param img_data:
    :param id:
    :return:
    """
    source_files = img_data.dao_get_source_files(img_data.id)
    Assert.is_true(is_not_empty(source_files), '查无此数据', codes.no_data)

    file_datas = []
    for source_file in source_files:
        url = url_for('file.file_download',
                      id=source_file.id,
                      md5_id=source_file.md5_id)
        if source_file.file_format.upper() == FileFormat.PDF.value:
            url = url + '/' + source_file.id
        flow_info = FlowInfo(url, url, source_file.file_name, source_file.id,
                             source_file.file_format)
        file_datas.append(flow_info)

    file_datas_dict, errors = FlowInfoSchema().dump(file_datas, many=True)
    Assert.is_true(is_empty(errors), errors)
    return render_info(MyResponse('查询成功', data=file_datas_dict))
Esempio n. 27
0
 def build_info(info):
     write_info(render_info(info))
     return render_info(info)
Esempio n. 28
0
def login():
    if current_user.is_authenticated:
        # 用户已登录认证
        return redirect(location=url_for(endpoint='sys.index'))
    return render_info(MyResponse(msg='账号未登录!', code=codes.not_logged_in),
                       template='sys/login.html')
Esempio n. 29
0
def push_info():
    print(json.dumps(request.json, indent=4, ensure_ascii=False))
    return render_info(MyResponse('OK'))