check_controllers.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const fs = require('fs');
  2. const path = require('path');
  3. function walk(dir) {
  4. let r = [];
  5. if (!fs.existsSync(dir)) return r;
  6. fs.readdirSync(dir).forEach(f => {
  7. const p = path.join(dir, f);
  8. fs.statSync(p).isDirectory() ? r = r.concat(walk(p)) : r.push(p);
  9. });
  10. return r;
  11. }
  12. // Collect all controllers from fs-admin-saas and fs-company (fs-saas)
  13. const modules = [
  14. { name: 'fs-saasadmin (fs-admin-saas)', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-admin-saas/src/main/java/com/fs' },
  15. { name: 'fs-saas (fs-company)', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-company/src/main/java/com/fs' }
  16. ];
  17. const controllerMap = new Map(); // prefix -> [{module, class, profile, requestMapping}]
  18. modules.forEach(mod => {
  19. const controllerFiles = walk(mod.dir).filter(f => f.endsWith('.java') && f.toLowerCase().includes('controller'));
  20. controllerFiles.forEach(f => {
  21. let c = fs.readFileSync(f, 'utf8');
  22. // Find @RequestMapping/@GetMapping/@PostMapping etc at class level
  23. const classRequestMappingMatch = c.match(/@RequestMapping\s*\(\s*["']([^"']+)["']\s*\)/);
  24. const classPrefix = classRequestMappingMatch ? classRequestMappingMatch[1] : '';
  25. // Find @Profile annotation
  26. const profileMatch = c.match(/@Profile\s*\(\s*[{"]([^}"]+)[}"]\s*\)/);
  27. let profile = 'no-profile';
  28. if (profileMatch) {
  29. profile = profileMatch[1].replace(/"/g, '').trim();
  30. }
  31. // Find class name
  32. const classMatch = c.match(/public\s+class\s+(\w+)/);
  33. const className = classMatch ? classMatch[1] : path.basename(f, '.java');
  34. // Find method-level request mappings
  35. const methodMappings = [];
  36. const methodRe = /@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=|path\s*=)?\s*["']([^"']+)["']/g;
  37. let mm;
  38. while ((mm = methodRe.exec(c)) !== null) {
  39. methodMappings.push(mm[2]);
  40. }
  41. // Also check for @RequestMapping with multiple paths at method level
  42. const multiMethodRe = /@(GetMapping|PostMapping|PutMapping|DeleteMapping|RequestMapping)\s*\(\s*(?:value\s*=|path\s*=)?\s*\{([^}]+)\}/g;
  43. let mmm;
  44. while ((mmm = multiMethodRe.exec(c)) !== null) {
  45. const paths = mmm[2].match(/["']([^"']+)["']/g);
  46. if (paths) paths.forEach(p => {
  47. const clean = p.replace(/["']/g, '');
  48. methodMappings.push(clean);
  49. });
  50. }
  51. const fullPath = classPrefix;
  52. if (classPrefix) {
  53. if (!controllerMap.has(classPrefix)) controllerMap.set(classPrefix, []);
  54. controllerMap.get(classPrefix).push({
  55. module: mod.name,
  56. class: className,
  57. profile: profile,
  58. requestMapping: classPrefix,
  59. file: f,
  60. methodCount: methodMappings.length
  61. });
  62. }
  63. });
  64. });
  65. // Print all controller prefixes and their modules/profiles
  66. console.log('Controller prefixes and their modules/profiles:');
  67. const sorted = [...controllerMap.entries()].sort((a, b) => a[0].localeCompare(b[0]));
  68. sorted.forEach(([prefix, infos]) => {
  69. infos.forEach(info => {
  70. console.log(` ${prefix} -> ${info.module} | class=${info.class} | profile=${info.profile} | methods=${info.methodCount}`);
  71. });
  72. });