Ejemplo n.º 1
0
def create_ext_table_info():
    data = request.json
    data["sync_column"] = ",".join(data["sync_column"])
    data["order_column"] = ",".join(data["order_column"])

    service.create_ext_table_info(data)
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 2
0
def get_ext_table_infos():
    total, ext_table_infos = service.get_ext_table_infos(request.args)
    return jsonify_with_data(APIError.OK,
                             data={
                                 "total": total,
                                 "items": ext_table_infos
                             })
Ejemplo n.º 3
0
def create_ext_datasource_con():
    data = request.json
    try:
        service.create_ext_datasource_con(data)
    except ExtDatasourceConExists as e:
        return jsonify_with_error(APIError.CONFLICT, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 4
0
def login():
    data = request.json
    try:
        token = service.login(data["username"], data["password"])
        return jsonify_with_data(APIError.OK, data={"token": token})
    except LoginFailed as e:
        return jsonify_with_error(APIError.UNAUTHORIZED)
Ejemplo n.º 5
0
def get_ext_datasource_con():
    try:
        ext_datasource_con = service.get_ext_datasource_con(
            request.args["source_id"])
    except ExtDatasourceConNotExist as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    return jsonify_with_data(APIError.OK, data=ext_datasource_con)
Ejemplo n.º 6
0
def copy_ext_table_info():
    data = request.json
    try:
        service.copy_ext_table_info(data)
    except (ExtDatasourceNotExist, ErpNotMatch, TableNotExist) as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 7
0
def create_sql():
    data = request.json
    sql = data.get('sql')
    source_id = data.get('source_id')
    if not all([source_id, sql]):
        return jsonify_with_error(APIError.VALIDATE_ERROR, '参数不全')

    data_source = ext_check_table.get_datasource_by_source_id(
        source_id.upper())
    if data_source is None:
        return jsonify_with_error(APIError.NOTFOUND,
                                  "source_id 有误, 请检查source_id是否正确")
    db_name = data_source.get('db_name')
    database = db_name.get('database')
    if not all([db_name, database]):
        return jsonify_with_error(APIError.BAD_REQUEST, "数据库信息不全,请检查")

    data_source['database'] = database
    error = ext_check_table.connect_test(**data_source)
    if error:
        return jsonify_with_error(APIError.BAD_REQUEST, "对方数据库连接失败!")

    result = ext_check_table.execute_sql(sql)
    if result == "error":
        return jsonify_with_error(APIError.VALIDATE_ERROR, 'sql错误!')
    for i in result:
        table_head = [k for k in i.keys()]
        return jsonify_with_data(APIError.OK,
                                 data={
                                     'table_head': table_head,
                                     'result': result
                                 })
Ejemplo n.º 8
0
def batch_modify_ext_table_info():
    data = request.json
    total, success = service.batch_ext_table_info(data)
    if total != success:
        message = "total:%s, success:%s" % (total, success)
        return jsonify_with_error(APIError.PARTIALLY_SUCCESS, message)
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 9
0
def get_ext_clean_info_target_tables(source_id):
    """
    获取某个source_id下所有生效的的目标表的表名称
    :param source_id:
    :return:
    """
    data = services.get_ext_clean_info_template_target_tables(source_id)
    return jsonify_with_data(APIError.OK, data={"tables": data})
Ejemplo n.º 10
0
def get_ext_clean_info_target_table(source_id):
    """
    获得还未添加的目标表,用于新增单个目标表的下拉选项
    :param source_id:
    :return:
    """
    tables = services.get_ext_clean_info_target_table(source_id)
    return jsonify_with_data(APIError.OK, data={"tables": tables})
Ejemplo n.º 11
0
def modify_ext_datasource_con(id):
    data = request.json
    try:
        service.modify_ext_datasource_con(id, data)
    except ExtDatasourceConNotExist as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    except ExtDatasourceConExists as e:
        return jsonify_with_error(APIError.CONFLICT, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 12
0
def get_ext_check(source_id, target_table):
    date = request.args.get("date")
    if date is None:
        date = arrow.now().shift(days=-1).format('YYYY-MM-DD')

    source_id = source_id.upper()
    target_table = target_table.lower()

    # 查看本地数据库是否有数
    my_data = ExtCheckNum.query.filter_by(source_id=source_id,
                                          date=date,
                                          target_table=target_table).first()
    if my_data and my_data.num > 500:
        return jsonify_with_data(APIError.OK, data={'num': my_data.num})

    if (source_id in ['59YYYYYYYYYYYYY', '70YYYYYYYYYYYYY', '73YYYYYYYYYYYYY'
                      ]) and target_table == 'goodsflow':
        num = ext_check_table.ext_serial(source_id, date)
        ext_check_table.create_check_num(source_id, target_table, num, date)
        return jsonify_with_data(APIError.OK, data={'num': num})

    # 测试数据库是否能够正常连接,无法连接就返回错误信息
    data_source = ext_check_table.get_datasource_by_source_id(source_id)
    if data_source is None:
        return jsonify_with_error(APIError.NOTFOUND,
                                  "source_id 有误, 请检查source_id是否正确")
    db_name = data_source.get('db_name')
    database = db_name.get('database')
    if not all([db_name, database]):
        return jsonify_with_error(APIError.BAD_REQUEST, "数据库信息不全,请检查")

    data_source['database'] = database

    error = ext_check_table.connect_test(**data_source)
    if error:
        return jsonify_with_error(APIError.BAD_REQUEST, "对方数据库连接失败!")
    num = ext_check_table.get_target_num(source_id, target_table, date)
    if not num:
        return jsonify_with_error(APIError.NOTFOUND, "sql not found")

    num = list(num[0].values())[0]
    ext_check_table.create_check_num(source_id, target_table, num, date)

    return jsonify_with_data(APIError.OK, data={'num': num})
Ejemplo n.º 13
0
def ext_save_sql():
    data = request.json
    sql = data.get('sql')
    target_table = data.get('target_table')
    source_id = data.get('source_id')
    if not all([sql, source_id]):
        return jsonify_with_error(APIError.VALIDATE_ERROR, '参数有误')

    ext_check_table.create_test_query(source_id, sql, target_table)
    return jsonify_with_data(APIError.OK,
                             data={'result': '{}保存成功'.format(source_id)})
Ejemplo n.º 14
0
def get_ext_clean_info_table(source_id):
    """
    获取该source_id对应下的配置为抓取的表,用于选择原始表的下拉选项
    :param source_id:
    :return:
    """
    try:
        tables = services.get_ext_clean_info_table(source_id)
    except ExtTableInfoNotFound as e:
        return jsonify_with_error(APIError.BAD_REQUEST, str(e))
    return jsonify_with_data(APIError.OK, data={"tables": tables})
Ejemplo n.º 15
0
def modify_ext_table_info(id):
    data = request.json
    if data.get("sync_column") is not None:
        data["sync_column"] = ",".join(data["sync_column"])
    if data.get("order_column") is not None:
        data["order_column"] = ",".join(data["order_column"])
    try:
        service.modify_ext_table_info(id, data)
    except ExtTableInfoNotExist as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 16
0
def copy_ext_clean_info():
    """
    将某个source_id的所有目标表配置copy复制到另一个source_id所有目标表,用于同个erp类型
    :return:
    """
    data = request.get_json()
    try:
        services.copy_ext_clean_info(data)
    except (ExtDatasourceNotExist, TableNotExist) as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 17
0
def delete_ext_clean_info(id):
    """
    逻辑删除单个目标表, 该目标表原先的配置不清除
    :param id:
    :return:
    """
    try:
        services.delete_ext_clean_info(id)
    except ExtCleanInfoNotFound as e:
        return jsonify_with_error(APIError.BAD_REQUEST, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 18
0
def create_ext_clean_info():
    """
    新建单个目标表
    :return:
    """
    data = request.get_json()
    try:
        services.create_ext_clean_info(data)
    except ExtDatasourceNotExist as e:
        return jsonify_with_error(APIError.BAD_REQUEST, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 19
0
def get_ext_clean_info_target():
    """
    获取source_id下的某个目标表的信息
    :return:
    """
    source_id = request.args.get("source_id")
    target = request.args.get("target")
    try:
        data = services.get_ext_clean_info_target(source_id, target)
    except (ExtCleanInfoParameterError, ExtCleanInfoNotFound) as e:
        return jsonify_with_error(APIError.VALIDATE_ERROR, str(e))
    return jsonify_with_data(APIError.OK, data={"target": data})
Ejemplo n.º 20
0
def copy_ext_clean_info_table():
    """
    将某个source_id的单个目标表配置copy复制到另一个source_id单个目标表,用于同个erp类型
    :return:
    """
    data = request.get_json()
    try:
        services.copy_ext_clean_info_table(data)
    except (ExtDatasourceNotExist, TableNotExist,
            ExtCleanInfoParameterError) as e:
        return jsonify_with_error(APIError.VALIDATE_ERROR, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 21
0
def modifly_ext_clean_info(id):
    """
    修改单个目标表
    :param id:
    :return:
    """
    data = request.get_json()
    try:
        services.modifly_ext_clean_info(id, data)
    except (ExtCleanInfoNotFound, ExtCleanInfoTableNotFound,
            ExtCleanInfoColumnNotFound) as e:
        return jsonify_with_error(APIError.BAD_REQUEST, str(e))
    return jsonify_with_data(APIError.OK, data={})
Ejemplo n.º 22
0
def get_ext_clean_infos():
    """
    获得source_id下所有的配置的目标表
    :return:
    """
    source_id = request.args.get("source_id")
    page = int(request.args.get("page", 1))
    per_page = int(request.args.get("per_page", PER_PAGE))
    try:
        total, items = services.get_ext_clean_infos(source_id, page, per_page)
    except (ExtCleanInfoParameterError, ExtDatasourceNotExist) as e:
        return jsonify_with_error(APIError.BAD_REQUEST, str(e))
    return jsonify_with_data(APIError.OK,
                             data={
                                 "total": total,
                                 "items": items
                             })
Ejemplo n.º 23
0
def get_ext_table_info(id):
    try:
        ext_table_info = service.get_ext_table_info(id)
    except ExtTableInfoNotExist as e:
        return jsonify_with_error(APIError.NOTFOUND, str(e))
    return jsonify_with_data(APIError.OK, data=ext_table_info)