Debug
This commit is contained in:
parent
2b24a5e25c
commit
11b73e179d
1 changed files with 12 additions and 38 deletions
|
|
@ -16,15 +16,15 @@ def is_ignored(name: str) -> bool:
|
|||
# Garante que a comparação é feita em caixa alta para robustez
|
||||
return FILTER_SUBSTRING in str(name).upper()
|
||||
|
||||
# --- FUNÇÃO HELPER PARA REMOÇÃO DE SOURCE_CODE (CORRIGIDA PARA CASE-INSENSITIVE) ---
|
||||
# --- FUNÇÃO HELPER PARA REMOÇÃO DE SOURCE_CODE ---
|
||||
|
||||
def _remove_source_code(item: Dict) -> Dict:
|
||||
"""
|
||||
Remove o campo 'SOURCE_CODE' ou 'source_code' de um item de dicionário.
|
||||
(Case-insensitive para chaves comuns de código-fonte).
|
||||
"""
|
||||
item_copy = item.copy()
|
||||
|
||||
# Verifica as chaves comuns
|
||||
if 'SOURCE_CODE' in item_copy:
|
||||
del item_copy['SOURCE_CODE']
|
||||
|
||||
|
|
@ -38,7 +38,6 @@ def _remove_source_code(item: Dict) -> Dict:
|
|||
def compare_fields(standard_fields: List[Dict], client_fields: List[Dict], table_name: str) -> List[Dict]:
|
||||
"""
|
||||
Compara os campos de uma tabela entre as estruturas padrão e cliente.
|
||||
(Mantida sem alteração, pois 'SOURCE_CODE' não é campo de tabela).
|
||||
"""
|
||||
discrepancies = []
|
||||
|
||||
|
|
@ -82,7 +81,7 @@ def compare_fields(standard_fields: List[Dict], client_fields: List[Dict], table
|
|||
return discrepancies
|
||||
|
||||
|
||||
# --- FUNÇÃO PRINCIPAL DE COMPARAÇÃO DE ESTRUTURAS (ADICIONANDO ELEMENTOS ENCONTRADOS) ---
|
||||
# --- FUNÇÃO PRINCIPAL DE COMPARAÇÃO DE ESTRUTURAS ---
|
||||
|
||||
def compare_structures(standard_structure: Dict[str, Any], client_structure: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
|
|
@ -98,9 +97,8 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
"tabelas_padrao": [],
|
||||
"tabelas_cliente": [],
|
||||
"outros_elementos": []
|
||||
},
|
||||
# NOVO CAMPO: Retorna os elementos que foram comparados e são idênticos/existentes
|
||||
"elementos_encontrados_e_comparados": {}
|
||||
}
|
||||
# Removido "elementos_encontrados_e_comparados" para simplificar o retorno da auditoria
|
||||
}
|
||||
|
||||
if not standard_structure or not client_structure:
|
||||
|
|
@ -137,7 +135,6 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
|
||||
client_tables_map = {}
|
||||
malformed_tables_data = []
|
||||
tables_found_and_compared = [] # Lista temporária para tabelas encontradas
|
||||
|
||||
for t in client_structure.get('tables', []):
|
||||
table_name = t.get('TABLE_NAME')
|
||||
|
|
@ -149,16 +146,9 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
})
|
||||
elif table_name:
|
||||
client_tables_map[table_name] = t
|
||||
if table_name in standard_tables_map:
|
||||
# Adiciona a tabela do padrão na lista de encontradas (sem SOURCE_CODE)
|
||||
tables_found_and_compared.append(_remove_source_code(standard_tables_map[table_name]))
|
||||
else:
|
||||
malformed_tables_data.append(t)
|
||||
|
||||
if tables_found_and_compared:
|
||||
# Armazena as tabelas encontradas
|
||||
audit_log["elementos_encontrados_e_comparados"]["tabelas"] = tables_found_and_compared
|
||||
|
||||
if malformed_tables_data:
|
||||
audit_log["discrepancias_encontradas"] = True
|
||||
audit_log["detalhes"]["estrutura_malformada_cliente"] = {
|
||||
|
|
@ -192,8 +182,8 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
|
||||
for element_key in elements_to_check:
|
||||
standard_elements = standard_structure.get(element_key, [])
|
||||
client_elements = client_structure.get(element_key, [])
|
||||
|
||||
# Filtra elementos ignorados no Padrão
|
||||
standard_elements_filtered = []
|
||||
for item in standard_elements:
|
||||
identifier = get_element_identifier(item)
|
||||
|
|
@ -207,7 +197,9 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
else:
|
||||
standard_elements_filtered.append(item)
|
||||
|
||||
# Filtra elementos ignorados no Cliente
|
||||
client_elements_filtered = []
|
||||
client_elements = client_structure.get(element_key, [])
|
||||
for item in client_elements:
|
||||
identifier = get_element_identifier(item)
|
||||
if is_ignored(identifier):
|
||||
|
|
@ -220,18 +212,8 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
else:
|
||||
client_elements_filtered.append(item)
|
||||
|
||||
# Mapeamento para buscar o original em caso de match
|
||||
# Usamos o dump do elemento limpo (sem source code) como chave
|
||||
standard_map_normalized = {}
|
||||
standard_elements_normalized = []
|
||||
|
||||
for item in standard_elements_filtered:
|
||||
normalized_item = _remove_source_code(item)
|
||||
standard_elements_normalized.append(normalized_item)
|
||||
# Mapeia o item normalizado para o item original (ainda sem source code, para evitar duplicação)
|
||||
standard_map_normalized[json.dumps(normalized_item, sort_keys=True)] = normalized_item
|
||||
|
||||
|
||||
# Criação de Sets a partir dos elementos normalizados (sem SOURCE_CODE) para comparação
|
||||
standard_elements_normalized = [_remove_source_code(item) for item in standard_elements_filtered]
|
||||
client_elements_normalized = [_remove_source_code(item) for item in client_elements_filtered]
|
||||
|
||||
try:
|
||||
|
|
@ -243,15 +225,7 @@ def compare_structures(standard_structure: Dict[str, Any], client_structure: Dic
|
|||
continue
|
||||
|
||||
missing_elements = standard_set - client_set
|
||||
found_elements = standard_set & client_set # Interseção dos sets
|
||||
|
||||
# 3. Adiciona os elementos encontrados à nova chave
|
||||
if found_elements:
|
||||
audit_log["elementos_encontrados_e_comparados"][element_key] = [
|
||||
standard_map_normalized[found_str] for found_str in found_elements
|
||||
]
|
||||
|
||||
# 4. Adiciona os elementos faltantes
|
||||
if missing_elements:
|
||||
audit_log["discrepancias_encontradas"] = True
|
||||
|
||||
|
|
@ -334,10 +308,10 @@ class ShowDatabaseService:
|
|||
"db_accessible": database_data.get("db_accessible", {}),
|
||||
"last_modified": database_data.get("last_modified", {}),
|
||||
|
||||
# --- CAMPOS DE DEBUG (FILTRADOS) ---
|
||||
# --- CAMPOS DE DEBUG (PARA VERIFICAÇÃO VISUAL) ---
|
||||
"estrutura_cliente_debug": debug_cliente,
|
||||
"estrutura_padrao_debug": debug_padrao,
|
||||
# ------------------------------------
|
||||
# ----------------------------------------------------
|
||||
|
||||
"auditoria_do_banco": auditoria_do_banco
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue