""" 检查模板的所有关联关系(包括未启用的) """ import pymysql import os from dotenv import load_dotenv load_dotenv() DB_CONFIG = { 'host': os.getenv('DB_HOST', '152.136.177.240'), 'port': int(os.getenv('DB_PORT', 5012)), 'user': os.getenv('DB_USER', 'finyx'), 'password': os.getenv('DB_PASSWORD', '6QsGK6MpePZDE57Z'), 'database': os.getenv('DB_NAME', 'finyx'), 'charset': 'utf8mb4' } TENANT_ID = 615873064429507639 TEMPLATE_ID = 1765432134276990 # 1.请示报告卡(初核谈话) def check_all_relations(): """检查模板的所有关联关系""" conn = pymysql.connect(**DB_CONFIG) cursor = conn.cursor(pymysql.cursors.DictCursor) try: print(f"检查模板 ID: {TEMPLATE_ID}") print("=" * 80) # 查询模板信息 cursor.execute(""" SELECT id, name, state FROM f_polic_file_config WHERE tenant_id = %s AND id = %s """, (TENANT_ID, TEMPLATE_ID)) template = cursor.fetchone() if template: print(f"模板名称: {template['name']}") print(f"模板状态: {template['state']}") else: print("模板不存在") return # 查询所有关联关系(包括 state=0 的) cursor.execute(""" SELECT fff.file_id, fff.filed_id, fff.state as relation_state, f.name as field_name, f.field_type, f.state as field_state FROM f_polic_file_field fff INNER JOIN f_polic_field f ON fff.filed_id = f.id AND fff.tenant_id = f.tenant_id WHERE fff.tenant_id = %s AND fff.file_id = %s ORDER BY f.field_type, f.name """, (TENANT_ID, TEMPLATE_ID)) all_relations = cursor.fetchall() print(f"\n所有关联关系数: {len(all_relations)}") # 按状态分组 enabled_relations = [r for r in all_relations if r['relation_state'] == 1 or (isinstance(r['relation_state'], bytes) and r['relation_state'] == b'\x01')] disabled_relations = [r for r in all_relations if r not in enabled_relations] print(f"启用的关联关系: {len(enabled_relations)}") print(f"未启用的关联关系: {len(disabled_relations)}") # 按字段类型分组 input_fields = [r for r in enabled_relations if r['field_type'] == 1] output_fields = [r for r in enabled_relations if r['field_type'] == 2] print(f"\n启用的输入字段关联: {len(input_fields)}") for r in input_fields: state_str = str(r['relation_state']) if not isinstance(r['relation_state'], bytes) else 'bytes' print(f" - {r['field_name']} (ID: {r['filed_id']}, relation_state: {state_str}, field_state: {r['field_state']})") print(f"\n启用的输出字段关联: {len(output_fields)}") for r in output_fields[:10]: state_str = str(r['relation_state']) if not isinstance(r['relation_state'], bytes) else 'bytes' print(f" - {r['field_name']} (ID: {r['filed_id']}, relation_state: {state_str}, field_state: {r['field_state']})") if len(output_fields) > 10: print(f" ... 还有 {len(output_fields) - 10} 个输出字段") # 检查未启用的关联关系 if disabled_relations: print(f"\n未启用的关联关系: {len(disabled_relations)}") disabled_input = [r for r in disabled_relations if r['field_type'] == 1] disabled_output = [r for r in disabled_relations if r['field_type'] == 2] print(f" 输入字段: {len(disabled_input)}, 输出字段: {len(disabled_output)}") finally: cursor.close() conn.close() if __name__ == '__main__': check_all_relations()