Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 9x 4x 4x 2x 2x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 1x 1x 5x 3x 3x 1x 1x 3x 4x 4x 4x 3x 4x 1x 1x 2x 1x 2x 1x 1x 1x | /**
* 构建器模式(Builder Pattern)
*
* 链式 API 构建结构化分析报告
*/
class ReportBuilder {
constructor() {
this.report = {
title: '',
metadata: {},
sections: []
};
}
setTitle(title) {
this.report.title = title;
return this;
}
setMetadata(metadata) {
this.report.metadata = {
...this.report.metadata,
...metadata
};
return this;
}
addSection(section) {
this.report.sections.push(section);
return this;
}
addExecutiveSummary(summary) {
this.report.sections.unshift({
type: 'executive_summary',
title: '执行摘要',
content: summary
});
return this;
}
addProblemSection(problem, category) {
this.report.sections.push({
type: 'problem',
title: '问题分析',
content: { problem, category }
});
return this;
}
addAssumptionsSection(assumptions) {
this.report.sections.push({
type: 'assumptions',
title: '假设识别与质疑',
content: assumptions
});
return this;
}
addWhyChainSection(whyChain) {
this.report.sections.push({
type: 'why_chain',
title: '5Why 分解链',
content: whyChain
});
return this;
}
addTruthsSection(truths, criteria) {
this.report.sections.push({
type: 'fundamental_truths',
title: '基本真理',
content: { truths, criteria }
});
return this;
}
addSolutionsSection(solutions) {
this.report.sections.push({
type: 'solutions',
title: '重构方案',
content: solutions
});
return this;
}
addComparisonSection(comparison) {
this.report.sections.push({
type: 'comparison',
title: '与传统方案对比',
content: comparison
});
return this;
}
build() {
return this.report;
}
/**
* 构建 Markdown 格式报告
* @returns {string}
*/
toMarkdown() {
let md = `# ${this.report.title}\n\n`;
// 元数据
if (Object.keys(this.report.metadata).length > 0) {
md += `**分析时间**: ${new Date().toISOString()}\n`;
md += `**分析类型**: ${this.report.metadata.category || '通用'}\n\n`;
}
// 各章节
for (const section of this.report.sections) {
md += `## ${section.title}\n\n`;
md += this._sectionToMarkdown(section);
md += '\n---\n\n';
}
return md;
}
_sectionToMarkdown(section) {
switch (section.type) {
case 'executive_summary':
return section.content;
case 'problem':
return `**问题**: ${section.content.problem}\n\n**分类**: ${section.content.category}`;
case 'assumptions':
return section.content.map((item, i) =>
`**假设${i+1}**: ${item.assumption}\n\n**质疑**: ${item.challenge}\n`
).join('\n');
case 'why_chain':
return section.content.map(item =>
`**Q${item.level}**: ${item.question}\n\n**A**: ${item.answer || '待填充'}\n`
).join('\n');
case 'fundamental_truths':
let truthMd = '**验证标准**:\n';
section.content.criteria.forEach((c, i) => truthMd += `${i+1}. ${c}\n`);
truthMd += '\n**基本真理**:\n';
section.content.truths.forEach((t, i) => truthMd += `${i+1}. ${t}\n`);
return truthMd;
case 'solutions':
return section.content.map(sol =>
`### ${sol.name}\n\n${sol.description}\n\n**优势**: ${sol.pros.join('、')}\n\n**劣势**: ${sol.cons.join('、')}\n`
).join('\n');
case 'comparison':
return `**对比维度**: ${section.content.dimensions.join('、')}`;
default:
return JSON.stringify(section.content, null, 2);
}
}
}
module.exports = { ReportBuilder };
|