| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import fs from "fs";
- import {
- registerImageBuffer,
- renderDocxReport,
- } from "../src/server/reportService/docxReportBuilder.js";
- import {
- buildFarmCategoryBarOption,
- buildFarmLevelPieOption,
- buildTurbineTrendChartOptions,
- } from "../src/server/reportService/healthChartBuilder.js";
- import { renderEchartsOption } from "../src/server/reportService/echartsRenderer.js";
- import {
- initChartService,
- shutdownChartService,
- } from "../src/server/utils/chartService/index.js";
- await initChartService();
- const map = {};
- registerImageBuffer(
- map,
- "health_fig1",
- await renderEchartsOption(
- buildFarmLevelPieOption({
- overallScore: 80,
- excellentCount: 2,
- goodCount: 1,
- fairCount: 1,
- poorCount: 0,
- }),
- { width: 760, height: 420 },
- ),
- );
- registerImageBuffer(
- map,
- "health_fig2",
- await renderEchartsOption(
- buildFarmCategoryBarOption({
- overallScore: 80,
- systemScore: 75,
- componentScore: 70,
- structureScore: 72,
- }),
- { width: 760, height: 360 },
- ),
- );
- const trendPoints = [
- {
- birthday: "2026-08-01",
- overallScore: 80,
- rotorScore: 70,
- towerScore: 75,
- yawSystemScore: 72,
- pitchSystemScore: 71,
- hydraulicSystemScore: 70,
- controlSystemScore: 69,
- generatorScore: 68,
- gearboxScore: 67,
- mainShaftScore: 66,
- converterScore: 65,
- },
- {
- birthday: "2026-08-02",
- overallScore: 82,
- rotorScore: 71,
- towerScore: 75,
- yawSystemScore: 73,
- pitchSystemScore: 72,
- hydraulicSystemScore: 71,
- controlSystemScore: 70,
- generatorScore: 69,
- gearboxScore: 68,
- mainShaftScore: 67,
- converterScore: 66,
- },
- ];
- const trendCharts = buildTurbineTrendChartOptions(trendPoints, trendPoints[1]);
- const renderedCharts = [];
- for (const chart of trendCharts) {
- const imageKey = `health_trend_WT01_${chart.key}`;
- registerImageBuffer(
- map,
- imageKey,
- await renderEchartsOption(chart.option, {
- width: 760,
- height: chart.key === "overall" ? 260 : 300,
- }),
- );
- renderedCharts.push({
- chart_title: chart.title,
- trend_image: imageKey,
- });
- }
- const out = await renderDocxReport({
- templateName: "health-report-template.docx",
- skipPatch: false,
- imageBufferMap: map,
- renderData: {
- 风场名称: "测试风场",
- farm_name: "测试风场",
- field_id: "F1",
- create_time: "2026-08-13",
- source_datetime: "2026-08-12",
- turbine_count: "1",
- valid_turbine_count: "1",
- turbine_types: "TEST",
- overall_score: "80",
- system_score: "75",
- component_score: "70",
- "structure_score/未评估": "72",
- excellent_count: "2",
- good_count: "1",
- fair_count: "1",
- poor_count: "0",
- overall_level_text: "良",
- main_level: "良",
- level_distribution_text: "优2台",
- overall_summary_text: "测试",
- focus_engine_list: "WT01",
- chart_fig1: "health_fig1",
- chart_fig2: "health_fig2",
- turbine_trends: [
- { engine_title: "WT01 风机健康趋势图", charts: renderedCharts },
- ],
- },
- });
- fs.writeFileSync("templates/_smoke_health_report.docx", out);
- console.log("smoke ok, size=", out.length);
- await shutdownChartService();
- process.exit(0);
|