const fs = require('fs'); const path = require('path'); function walk(dir) { let r = []; if (!fs.existsSync(dir)) return r; fs.readdirSync(dir).forEach(f => { const p = path.join(dir, f); fs.statSync(p).isDirectory() ? r = r.concat(walk(p)) : r.push(p); }); return r; } // Collect all controllers from fs-admin-saas and fs-company (fs-saas) const modules = [ { name: 'fs-saasadmin (fs-admin-saas)', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-admin-saas/src/main/java/com/fs' }, { name: 'fs-saas (fs-company)', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-company/src/main/java/com/fs' } ]; const controllerMap = new Map(); // prefix -> [{module, class, profile, requestMapping}] modules.forEach(mod => { const controllerFiles = walk(mod.dir).filter(f => f.endsWith('.java') && f.toLowerCase().includes('controller')); controllerFiles.forEach(f => { let c = fs.readFileSync(f, 'utf8'); // Find @RequestMapping/@GetMapping/@PostMapping etc at class level const classRequestMappingMatch = c.match(/@RequestMapping\s*\(\s*["']([^"']+)["']\s*\)/); const classPrefix = classRequestMappingMatch ? classRequestMappingMatch[1] : ''; // Find @Profile annotation const profileMatch = c.match(/@Profile\s*\(\s*[{"]([^}"]+)[}"]\s*\)/); let profile = 'no-profile'; if (profileMatch) { profile = profileMatch[1].replace(/"/g, '').trim(); } // Find class name const classMatch = c.match(/public\s+class\s+(\w+)/); const className = classMatch ? classMatch[1] : path.basename(f, '.java'); // Find method-level request mappings const methodMappings = []; const methodRe = /@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=|path\s*=)?\s*["']([^"']+)["']/g; let mm; while ((mm = methodRe.exec(c)) !== null) { methodMappings.push(mm[2]); } // Also check for @RequestMapping with multiple paths at method level const multiMethodRe = /@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=|path\s*=)?\s*\{([^}]+)\}/g; let mmm; while ((mmm = multiMethodRe.exec(c)) !== null) { const paths = mmm[2].match(/["']([^"']+)["']/g); if (paths) paths.forEach(p => { const clean = p.replace(/["']/g, ''); methodMappings.push(clean); }); } const fullPath = classPrefix; if (classPrefix) { if (!controllerMap.has(classPrefix)) controllerMap.set(classPrefix, []); controllerMap.get(classPrefix).push({ module: mod.name, class: className, profile: profile, requestMapping: classPrefix, file: f, methodCount: methodMappings.length }); } }); }); // Print all controller prefixes and their modules/profiles console.log('Controller prefixes and their modules/profiles:'); const sorted = [...controllerMap.entries()].sort((a, b) => a[0].localeCompare(b[0])); sorted.forEach(([prefix, infos]) => { infos.forEach(info => { console.log(` ${prefix} -> ${info.module} | class=${info.class} | profile=${info.profile} | methods=${info.methodCount}`); }); });