def read_raw_table_dict(module_info): table_dict = {} target_engine = base_tools.create_engine_from_module_info(module_info) #读表名,表信息 print('reading user_tables') attrs = Attributes.oracle_user_tables_attrs attrs_sql = base_tools.assemble_attrs(attrs, ',') sql = 'select ' + attrs_sql + ' from user_tables' ret = base_tools.execute_sql(target_engine, sql) for item in ret: table_dict[item[0]] = base_tools.convert_tuple_dict( item, attrs, range(1, 2)) table_dict[item[0]]['cols'] = [] print(("%d tables are red" % (len(ret), ))) print('reading user_tab_column') #读列名,列信息 attrs = Attributes.oracle_user_tab_column_attrs attrs_sql = base_tools.assemble_attrs(attrs, ',') sql = 'select ' + attrs_sql + ' from user_tab_columns' ret = base_tools.execute_sql(target_engine, sql) for item in ret: col_dict = base_tools.convert_tuple_dict(item, attrs, range(1, len(attrs))) table_dict[item[0]]['cols'].append(col_dict) table_dict[item[0]]['num_cols'] = len(table_dict[item[0]]['cols']) print(("%d columns are red" % (len(ret), ))) return table_dict
def report(): try: ret = {} module_name, result_time, result_name = base_tools.parse_request_json( request, "module_name", "result_time", "result_name") # data = request.json # module_name = data['module_name'] # result_time = data['result_time'] # result_name = data['result_name'] attrs = Attributes.result_store_attrs['integrity'] sql_attrs = base_tools.assemble_attrs(attrs, ',') if result_time == "": time_clause = "1" ov_clause = "table_name = \'over_view\'" else: time_clause = "result_time = \'%s\'" % (result_time, ) ov_clause = "table_name != \'over_view\'" module_clause = "module_name = \'%s\'" % (module_name, ) sql = 'select %s from integrity_result_store where %s and %s and %s' % ( sql_attrs, time_clause, ov_clause, module_clause) ret = base_tools.execute_sql(global_vars.write_engine, sql) result_list = [] for r in ret: result_list.append(base_tools.convert_tuple_dict(r, attrs)) return jsonify({'status': 1, 'result_list': result_list}) except Exception as e: return jsonify({'status': 0, 'Err_info': e.args[0]})
def integrity_detail_table(): try: module_name, table_name = base_tools.parse_request_json( request, "module_name", "table_name") result_name = Macro.ASSESS_INTEGRITY #获取数据表名 result_table_name = global_vars.result_store_table_name[result_name] # 组装sql中属性分句 attrs = Attributes.result_store_attrs[result_name] sql_attrs = base_tools.assemble_attrs(attrs, ',') #表名clause table_name_clause = 'table_name = \'%s\'' % (table_name, ) # 模块名从句,是否汇总从句 module_clause = "module_name = \'%s\'" % (module_name, ) # 组装sql,并执行 sql = 'select %s from %s where %s and %s order by result_time DESC' % ( sql_attrs, result_table_name, module_clause, table_name_clause) ret = base_tools.execute_sql(global_vars.write_engine, sql) #组装结果 result_list = [] for r in ret: result_list.append(base_tools.convert_tuple_dict(r, attrs)) return jsonify({'status': 1, 'result_list': result_list}) except Exception as e: return jsonify({ 'status': 0, 'func': 'detail_table', 'Err_info': e.args[0] })
def integrity_overview(): try: module_name, result_time = base_tools.parse_request_json( request, "module_name", "result_time") #result_time should be any of {recent, history, date time} result_name = Macro.ASSESS_INTEGRITY #组装sql中属性分句 attrs = Attributes.integrity_result_store_attrs sql_attrs = base_tools.assemble_attrs(attrs, ',') #获取数据表名 result_table_name = global_vars.result_store_table_name[result_name] #组装时间条件从句,如果没有指定具体时间,则全部获取 if result_time != 'recent' and result_time != 'history': #既不是recent也不是history,那就是具体时间 time_clause = "result_time = \'%s\'" % (result_time, ) else: time_clause = "1" #模块名从句,是否汇总从句 module_clause = "module_name = \'%s\'" % (module_name, ) #组装ov_clause ov_clause = "table_name = \'%s\'" % ('over_view', ) #组装sql,并执行 sql = 'select %s from %s where %s and %s and %s order by result_time DESC' % ( sql_attrs, result_table_name, time_clause, ov_clause, module_clause) print("report_overview:", sql) ret = base_tools.execute_sql(global_vars.write_engine, sql) #获取结果,如果result_time不是history,则只获取第一条,如为history,则全部获取 result_list = [] for r in ret: result_list.append(base_tools.convert_tuple_dict(r, attrs)) if result_time != 'history': break return jsonify({'status': 1, 'result_list': result_list}) except Exception as e: return jsonify({ 'status': 0, 'func': 'report_overview', 'Err_info': e.args[0] })