fix-entity-fields.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. """
  3. 批量修复XgStudentInfo实体类中的字段映射
  4. 将不存在的字段标记为 exist = false
  5. """
  6. import re
  7. import os
  8. # 需要标记为不存在的字段
  9. NON_EXISTENT_FIELDS = [
  10. 'name_english', 'former_name', 'name_pinyin', 'marital_status', 'religion',
  11. 'photo_url', 'photo_path', 'enrollment_year', 'school_system', 'education_level',
  12. 'training_type', 'admission_category', 'source_region', 'middle_school',
  13. 'major_code', 'major_name', 'class_code', 'grade', 'college_code',
  14. 'counselor_id', 'counselor_name', 'class_teacher_id', 'class_teacher_name',
  15. 'current_address', 'postal_code', 'household_register_type', 'hukou_location',
  16. 'info_status', 'data_source', 'last_batch_id', 'last_audit_time',
  17. 'is_complete', 'completion_rate', 'ext_field1', 'ext_field2', 'ext_field3',
  18. 'ext_field4', 'ext_field5'
  19. ]
  20. def fix_entity_file():
  21. file_path = '../ruoyi-modules/ruoyi-xg-xx/src/main/java/org/dromara/xg/domain/XgStudentInfo.java'
  22. if not os.path.exists(file_path):
  23. print(f"文件不存在: {file_path}")
  24. return
  25. with open(file_path, 'r', encoding='utf-8') as f:
  26. content = f.read()
  27. # 修复每个字段
  28. for field in NON_EXISTENT_FIELDS:
  29. # 查找 @TableField("field_name") 并替换为 @TableField(value = "field_name", exist = false)
  30. pattern = f'@TableField\\("{field}"\\)'
  31. replacement = f'@TableField(value = "{field}", exist = false)'
  32. content = re.sub(pattern, replacement, content)
  33. # 保存修改后的文件
  34. with open(file_path, 'w', encoding='utf-8') as f:
  35. f.write(content)
  36. print("实体类字段映射修复完成")
  37. if __name__ == '__main__':
  38. fix_entity_file()