check_controllers2.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const modules = [
  13. { name: 'fs-saasadmin', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-admin-saas/src/main/java/com/fs' },
  14. { name: 'fs-saas', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-company/src/main/java/com/fs' }
  15. ];
  16. const controllerMap = new Map();
  17. modules.forEach(mod => {
  18. const controllerFiles = walk(mod.dir).filter(f => f.endsWith('.java') && f.toLowerCase().includes('controller'));
  19. controllerFiles.forEach(f => {
  20. let c = fs.readFileSync(f, 'utf8');
  21. const classRequestMappingMatch = c.match(/@RequestMapping\s*\(\s*["']([^"']+)["']\s*\)/);
  22. const classPrefix = classRequestMappingMatch ? classRequestMappingMatch[1] : '';
  23. const profileMatch = c.match(/@Profile\s*\(\s*[{"]([^}"]+)[}"]\s*\)/);
  24. let profile = 'no-profile';
  25. if (profileMatch) {
  26. profile = profileMatch[1].replace(/"/g, '').trim();
  27. }
  28. const classMatch = c.match(/public\s+class\s+(\w+)/);
  29. const className = classMatch ? classMatch[1] : path.basename(f, '.java');
  30. if (classPrefix) {
  31. if (!controllerMap.has(classPrefix)) controllerMap.set(classPrefix, []);
  32. controllerMap.get(classPrefix).push({
  33. module: mod.name,
  34. class: className,
  35. profile: profile,
  36. requestMapping: classPrefix,
  37. file: f.replace('D:/ylrz/ylrz_saas_his_scrm/', '')
  38. });
  39. }
  40. });
  41. });
  42. // Write results to file
  43. let output = 'Controller prefixes and their modules/profiles:\n';
  44. const sorted = [...controllerMap.entries()].sort((a, b) => a[0].localeCompare(b[0]));
  45. sorted.forEach(([prefix, infos]) => {
  46. infos.forEach(info => {
  47. output += `${prefix} -> ${info.module} | class=${info.class} | profile=${info.profile} | file=${info.file}\n`;
  48. });
  49. });
  50. fs.writeFileSync('D:/ylrz/saasadminui/controller_analysis.txt', output, 'utf8');
  51. console.log('Written to controller_analysis.txt, total prefixes: ' + controllerMap.size);