import os import re entity_dir = r"d:/Projects/洛川康复中医院/imurs/src/main/java/com/imurs/entity" # Header print("| Table Name | Entity Class | Description |") print("| :--- | :--- | :--- |") files = sorted([f for f in os.listdir(entity_dir) if f.endswith(".java")]) for f in files: path = os.path.join(entity_dir, f) content = "" try: with open(path, 'r', encoding='utf-8') as file: content = file.read() except UnicodeDecodeError: try: with open(path, 'r', encoding='gbk') as file: content = file.read() except: pass if not content: continue # Extract Table Name table_match = re.search(r'@TableName\s*\(\s*(?:value\s*=\s*)?"([^"]+)"\s*\)', content) if not table_match: table_match = re.search(r"@TableName\s*\(\s*(?:value\s*=\s*)?'([^']+)'\s*\)", content) table_name = table_match.group(1) if table_match else "" # Extract Class Name class_match = re.search(r'public\s+class\s+(\w+)', content) class_name = class_match.group(1) if class_match else f.replace(".java", "") # Extract Description description = "" if class_match: start_index = class_match.start() # Search backwards from class definition preceding = content[:start_index] # Find all javadoc blocks # We want the one closest to the class def, but typically it is the last one in 'preceding' # unless there are other methods/fields above (unlikely for entity start) comments = list(re.finditer(r'/\*\*(.*?)\*/', preceding, re.DOTALL)) if comments: # Use the last one last_comment = comments[-1] raw_comment = last_comment.group(1) # Clean comment lines = raw_comment.split('\n') desc_lines = [] for line in lines: line = line.strip() # Remove comment markers * line = re.sub(r'^\*+', '', line).strip() if not line: continue if line.startswith("@"): continue desc_lines.append(line) description = " ".join(desc_lines) # Escape pipes description = description.replace("|", "\\|") if table_name: print(f"| `{table_name}` | `{class_name}` | {description} |")