| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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;
- }
- const modules = [
- { name: 'fs-saasadmin', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-admin-saas/src/main/java/com/fs' },
- { name: 'fs-saas', dir: 'D:/ylrz/ylrz_saas_his_scrm/fs-company/src/main/java/com/fs' }
- ];
- const controllerMap = new Map();
- 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');
-
- const classRequestMappingMatch = c.match(/@RequestMapping\s*\(\s*["']([^"']+)["']\s*\)/);
- const classPrefix = classRequestMappingMatch ? classRequestMappingMatch[1] : '';
-
- const profileMatch = c.match(/@Profile\s*\(\s*[{"]([^}"]+)[}"]\s*\)/);
- let profile = 'no-profile';
- if (profileMatch) {
- profile = profileMatch[1].replace(/"/g, '').trim();
- }
-
- const classMatch = c.match(/public\s+class\s+(\w+)/);
- const className = classMatch ? classMatch[1] : path.basename(f, '.java');
-
- if (classPrefix) {
- if (!controllerMap.has(classPrefix)) controllerMap.set(classPrefix, []);
- controllerMap.get(classPrefix).push({
- module: mod.name,
- class: className,
- profile: profile,
- requestMapping: classPrefix,
- file: f.replace('D:/ylrz/ylrz_saas_his_scrm/', '')
- });
- }
- });
- });
- // Write results to file
- let output = 'Controller prefixes and their modules/profiles:\n';
- const sorted = [...controllerMap.entries()].sort((a, b) => a[0].localeCompare(b[0]));
- sorted.forEach(([prefix, infos]) => {
- infos.forEach(info => {
- output += `${prefix} -> ${info.module} | class=${info.class} | profile=${info.profile} | file=${info.file}\n`;
- });
- });
- fs.writeFileSync('D:/ylrz/saasadminui/controller_analysis.txt', output, 'utf8');
- console.log('Written to controller_analysis.txt, total prefixes: ' + controllerMap.size);
|