import pandas as pd from db import MysqlSession from db.mysql import ZxPhrec def check_unclarity(): file_path = r'D:\Echo\Downloads\unclare.xlsx' # 将 your_file.xlsx 替换为你的文件路径 df = pd.read_excel(file_path) # 循环读取 pk_phrec 列 output_file_path = 'check_unclarity_result.txt' with open(output_file_path, 'w') as f: for pk_phrec in df['pk_phrec']: session = MysqlSession() phrec = session.query(ZxPhrec.pk_phrec, ZxPhrec.cfjaddress2, ZxPhrec.unsharp_flag).filter( ZxPhrec.pk_phrec == pk_phrec ).one_or_none() session.close() if phrec and phrec.unsharp_flag == 0: f.write(f"{phrec.pk_phrec} {phrec.cfjaddress2}\n") def check_clarity(): file_path = r'D:\Echo\Downloads\unclare.xlsx' df = pd.read_excel(file_path) session = MysqlSession() phrecs = (session.query(ZxPhrec.pk_phrec, ZxPhrec.cfjaddress2, ZxPhrec.unsharp_flag) .filter(ZxPhrec.pk_phrec >= 30810206) .filter(ZxPhrec.pk_phrec <= 31782247) .filter(ZxPhrec.unsharp_flag == 1) .all()) session.close() output_file_path = 'check_clarity_result.txt' with open(output_file_path, 'w') as f: for phrec in phrecs: if phrec.pk_phrec not in df['pk_phrec'].to_list(): f.write(f"{phrec.pk_phrec} {phrec.cfjaddress2}\n") if __name__ == '__main__': check_clarity()