""" cooperation经费来源显示问题调试脚本 问题:修复后出国记录的查看详情中的经费来源显示的还是cooperation 调试步骤: 1. 登录系统获取token 2. 获取出国记录列表,找到cooperation经费来源的记录 3. 查看记录详情,检查返回的数据结构 4. 分析budgetSource和budgetSourceText字段的值 5. 确定问题的具体原因 执行时间: 2025-01-07 22:50:00 """ import requests import json from typing import Dict, Any, Optional, List class CooperationBudgetSourceDebugger: def __init__(self): self.base_url = "http://localhost:8080" self.token = None self.headers = { 'Content-Type': 'application/json', 'clientid': 'e5cd7e4891bf95d1d19206ce24a7b32e', 'referer': 'http://localhost' } def login(self) -> bool: """登录获取token""" try: login_url = f"{self.base_url}/login" login_data = { "username": "admin", "password": "admin123", "code": "1234", "uuid": "test-uuid" } response = requests.post(login_url, json=login_data, headers=self.headers) if response.status_code == 200: result = response.json() if result.get('code') == 200: self.token = result['data']['access_token'] self.headers['Authorization'] = f'Bearer {self.token}' print("✅ 登录成功") return True else: print(f"❌ 登录失败: {result.get('msg', '未知错误')}") return False else: print(f"❌ 登录请求失败: HTTP {response.status_code}") return False except Exception as e: print(f"❌ 登录异常: {str(e)}") return False def get_record_list(self) -> Optional[List[Dict[str, Any]]]: """获取出国记录列表""" try: url = f"{self.base_url}/rs/overseas/record/list" params = { 'pageNum': 1, 'pageSize': 20 } response = requests.get(url, params=params, headers=self.headers) if response.status_code == 200: result = response.json() if result.get('code') == 200: records = result['data']['rows'] print(f"✅ 获取到 {len(records)} 条出国记录") return records else: print(f"❌ 获取记录列表失败: {result.get('msg')}") return None else: print(f"❌ 请求失败: HTTP {response.status_code}") return None except Exception as e: print(f"❌ 获取记录列表异常: {str(e)}") return None def get_record_detail(self, record_id: str) -> Optional[Dict[str, Any]]: """获取出国记录详情""" try: url = f"{self.base_url}/rs/overseas/record/{record_id}" response = requests.get(url, headers=self.headers) if response.status_code == 200: result = response.json() if result.get('code') == 200: record_detail = result['data'] print(f"✅ 获取到记录详情: {record_id}") return record_detail else: print(f"❌ 获取记录详情失败: {result.get('msg')}") return None else: print(f"❌ 请求失败: HTTP {response.status_code}") return None except Exception as e: print(f"❌ 获取记录详情异常: {str(e)}") return None def debug_cooperation_records(self): """调试cooperation经费来源记录""" print("🔍 开始调试cooperation经费来源显示问题...") # 获取记录列表 records = self.get_record_list() if not records: print("⚠️ 没有找到出国记录数据") return print("\n📋 分析记录列表中的经费来源:") cooperation_records = [] for i, record in enumerate(records): record_id = record.get('recordId') budget_source = record.get('budgetSource') budget_source_text = record.get('budgetSourceText') print(f" 记录 {i+1} (ID: {record_id}): budgetSource='{budget_source}', budgetSourceText='{budget_source_text}'") if budget_source == 'cooperation': cooperation_records.append({ 'record_id': record_id, 'budget_source': budget_source, 'budget_source_text': budget_source_text }) if not cooperation_records: print("\n⚠️ 列表中没有找到经费来源为cooperation的记录") # 检查是否有其他经费来源 all_sources = set(record.get('budgetSource') for record in records if record.get('budgetSource')) print(f" 当前存在的经费来源: {list(all_sources)}") return print(f"\n🎯 找到 {len(cooperation_records)} 条cooperation经费来源记录") # 详细分析每条cooperation记录 for coop_record in cooperation_records: record_id = coop_record['record_id'] print(f"\n📊 详细分析记录 ID: {record_id}") print(f" 列表中显示 - budgetSource: '{coop_record['budget_source']}'") print(f" 列表中显示 - budgetSourceText: '{coop_record['budget_source_text']}'") # 获取详情页面数据 record_detail = self.get_record_detail(str(record_id)) if record_detail: detail_budget_source = record_detail.get('budgetSource') detail_budget_source_text = record_detail.get('budgetSourceText') print(f" 详情页显示 - budgetSource: '{detail_budget_source}'") print(f" 详情页显示 - budgetSourceText: '{detail_budget_source_text}'") # 分析问题 print(f" 🔍 问题分析:") if detail_budget_source_text == 'cooperation': print(f" ❌ 问题确认: 详情页budgetSourceText显示为'{detail_budget_source_text}'") print(f" 🔧 应该显示: '合作单位'") # 检查可能的原因 if detail_budget_source == 'cooperation': print(f" 💡 分析: budgetSource值正确为'cooperation'") print(f" 💡 问题: getBudgetSourceText()方法可能未生效") else: print(f" 💡 问题: budgetSource值异常为'{detail_budget_source}'") elif detail_budget_source_text == '合作单位': print(f" ✅ 正常: 详情页budgetSourceText正确显示为'{detail_budget_source_text}'") else: print(f" ⚠️ 异常: 详情页budgetSourceText显示为'{detail_budget_source_text}'") # 显示完整的详情数据结构(用于调试) print(f" 📋 完整详情数据结构:") self.print_relevant_fields(record_detail) else: print(f" ❌ 无法获取记录详情") def print_relevant_fields(self, record: Dict[str, Any]): """打印相关字段用于调试""" relevant_fields = [ 'recordId', 'budgetSource', 'budgetSourceText', 'purpose', 'purposeText', 'completionStatus', 'completionStatusText' ] for field in relevant_fields: value = record.get(field) print(f" {field}: '{value}'") def test_backend_restart_needed(self): """检查是否需要重启后端服务""" print("\n🔄 检查后端服务状态:") print(" 💡 如果代码修改后问题仍然存在,可能需要:") print(" 1. 重启后端服务 (Spring Boot)") print(" 2. 清除应用缓存") print(" 3. 确认代码编译生效") try: # 简单的健康检查 health_url = f"{self.base_url}/actuator/health" response = requests.get(health_url, headers=self.headers, timeout=5) if response.status_code == 200: print(" ✅ 后端服务运行正常") else: print(" ⚠️ 后端服务状态异常") except: print(" ⚠️ 无法访问后端健康检查接口") def suggest_solutions(self): """建议解决方案""" print("\n💡 可能的解决方案:") print(" 1. 🔄 重启后端服务:") print(" cd backend && mvn spring-boot:run") print(" 2. 🔧 检查代码编译:") print(" 确认RsOverseasRecordVo.java的修改已编译生效") print(" 3. 🧹 清除缓存:") print(" 检查是否有Redis或其他缓存影响") print(" 4. 📊 检查数据库:") print(" 确认数据库中budgetSource字段的实际值") print(" 5. 🔍 调试模式:") print(" 在getBudgetSourceText()方法中添加日志输出") def run_debug(self): """运行完整调试流程""" print("🚀 开始cooperation经费来源显示问题调试") print("="*60) # 登录 if not self.login(): return # 调试cooperation记录 self.debug_cooperation_records() # 检查后端服务状态 self.test_backend_restart_needed() # 建议解决方案 self.suggest_solutions() print("="*60) print("🎯 调试完成") print("💡 请根据上述分析结果采取相应的解决措施") if __name__ == "__main__": debugger = CooperationBudgetSourceDebugger() debugger.run_debug()