smoke-health-report.mjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import fs from "fs";
  2. import {
  3. registerImageBuffer,
  4. renderDocxReport,
  5. } from "../src/server/reportService/docxReportBuilder.js";
  6. import {
  7. buildFarmCategoryBarOption,
  8. buildFarmLevelPieOption,
  9. buildTurbineTrendChartOptions,
  10. } from "../src/server/reportService/healthChartBuilder.js";
  11. import { renderEchartsOption } from "../src/server/reportService/echartsRenderer.js";
  12. import {
  13. initChartService,
  14. shutdownChartService,
  15. } from "../src/server/utils/chartService/index.js";
  16. await initChartService();
  17. const map = {};
  18. registerImageBuffer(
  19. map,
  20. "health_fig1",
  21. await renderEchartsOption(
  22. buildFarmLevelPieOption({
  23. overallScore: 80,
  24. excellentCount: 2,
  25. goodCount: 1,
  26. fairCount: 1,
  27. poorCount: 0,
  28. }),
  29. { width: 760, height: 420 },
  30. ),
  31. );
  32. registerImageBuffer(
  33. map,
  34. "health_fig2",
  35. await renderEchartsOption(
  36. buildFarmCategoryBarOption({
  37. overallScore: 80,
  38. systemScore: 75,
  39. componentScore: 70,
  40. structureScore: 72,
  41. }),
  42. { width: 760, height: 360 },
  43. ),
  44. );
  45. const trendPoints = [
  46. {
  47. birthday: "2026-08-01",
  48. overallScore: 80,
  49. rotorScore: 70,
  50. towerScore: 75,
  51. yawSystemScore: 72,
  52. pitchSystemScore: 71,
  53. hydraulicSystemScore: 70,
  54. controlSystemScore: 69,
  55. generatorScore: 68,
  56. gearboxScore: 67,
  57. mainShaftScore: 66,
  58. converterScore: 65,
  59. },
  60. {
  61. birthday: "2026-08-02",
  62. overallScore: 82,
  63. rotorScore: 71,
  64. towerScore: 75,
  65. yawSystemScore: 73,
  66. pitchSystemScore: 72,
  67. hydraulicSystemScore: 71,
  68. controlSystemScore: 70,
  69. generatorScore: 69,
  70. gearboxScore: 68,
  71. mainShaftScore: 67,
  72. converterScore: 66,
  73. },
  74. ];
  75. const trendCharts = buildTurbineTrendChartOptions(trendPoints, trendPoints[1]);
  76. const renderedCharts = [];
  77. for (const chart of trendCharts) {
  78. const imageKey = `health_trend_WT01_${chart.key}`;
  79. registerImageBuffer(
  80. map,
  81. imageKey,
  82. await renderEchartsOption(chart.option, {
  83. width: 760,
  84. height: chart.key === "overall" ? 260 : 300,
  85. }),
  86. );
  87. renderedCharts.push({
  88. chart_title: chart.title,
  89. trend_image: imageKey,
  90. });
  91. }
  92. const out = await renderDocxReport({
  93. templateName: "health-report-template.docx",
  94. skipPatch: false,
  95. imageBufferMap: map,
  96. renderData: {
  97. 风场名称: "测试风场",
  98. farm_name: "测试风场",
  99. field_id: "F1",
  100. create_time: "2026-08-13",
  101. source_datetime: "2026-08-12",
  102. turbine_count: "1",
  103. valid_turbine_count: "1",
  104. turbine_types: "TEST",
  105. overall_score: "80",
  106. system_score: "75",
  107. component_score: "70",
  108. "structure_score/未评估": "72",
  109. excellent_count: "2",
  110. good_count: "1",
  111. fair_count: "1",
  112. poor_count: "0",
  113. overall_level_text: "良",
  114. main_level: "良",
  115. level_distribution_text: "优2台",
  116. overall_summary_text: "测试",
  117. focus_engine_list: "WT01",
  118. chart_fig1: "health_fig1",
  119. chart_fig2: "health_fig2",
  120. turbine_trends: [
  121. { engine_title: "WT01 风机健康趋势图", charts: renderedCharts },
  122. ],
  123. },
  124. });
  125. fs.writeFileSync("templates/_smoke_health_report.docx", out);
  126. console.log("smoke ok, size=", out.length);
  127. await shutdownChartService();
  128. process.exit(0);