feat: 飞牛NAS成本审核更新 - 新增SKU、更新价格表、清理归档及订单记录,同步auto-check改动

This commit is contained in:
12600k-rog-d4
2026-08-27 00:44:44 +08:00
parent bde60dbea0
commit a172a9bb5e
82 changed files with 1804 additions and 1180 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
@@ -51,16 +52,20 @@ type chartPayload struct {
// testCard 单个测试卡片数据
type testCard struct {
Name string `json:"name"`
Label string `json:"label"`
Status string `json:"status"`
Duration string `json:"duration"`
Score float64 `json:"score"`
ScoreUnit string `json:"score_unit"`
ScoreHint string `json:"score_hint"`
Metrics []kvPair `json:"metrics"`
Output string `json:"output"`
Chart *chartPayload `json:"chart,omitempty"`
Name string `json:"name"`
Label string `json:"label"`
Status string `json:"status"`
Duration string `json:"duration"`
Score float64 `json:"score"`
ScoreUnit string `json:"score_unit"`
ScoreHint string `json:"score_hint"`
Metrics []kvPair `json:"metrics"`
Benchmarks []BenchItem `json:"benchmarks,omitempty"` // 性能/温度基准评级
OverallLevel Level `json:"overall_level,omitempty"` // 综合评级(各项最差)
OverallText string `json:"overall_text,omitempty"`
OverallColor string `json:"overall_color,omitempty"`
Output string `json:"output"`
Chart *chartPayload `json:"chart,omitempty"`
}
// reportHTMLData 报告整体数据
@@ -76,7 +81,14 @@ type reportHTMLData struct {
}
// WriteReportHTML 生成综合 HTML 报告(跑分卡片 + 多曲线图),返回文件路径
// 默认文件名report-<ip>.html
func WriteReportHTML(ip string, report *Report, reportDir string) (string, error) {
filename := fmt.Sprintf("report-%s.html", SanitizeFilename(ip))
return WriteReportHTMLTo(ip, report, reportDir, filename)
}
// WriteReportHTMLTo 生成综合 HTML 报告到指定文件名,返回完整文件路径
func WriteReportHTMLTo(ip string, report *Report, reportDir, filename string) (string, error) {
data := buildReportData(ip, report)
dataJSON, err := json.Marshal(data)
if err != nil {
@@ -88,11 +100,11 @@ func WriteReportHTML(ip string, report *Report, reportDir string) (string, error
if err := os.MkdirAll(reportDir, 0755); err != nil {
return "", err
}
filename := fmt.Sprintf("%s/report-%s.html", reportDir, SanitizeFilename(ip))
if err := os.WriteFile(filename, []byte(html), 0644); err != nil {
path := filepath.Join(reportDir, filename)
if err := os.WriteFile(path, []byte(html), 0644); err != nil {
return "", err
}
return filename, nil
return path, nil
}
func buildReportData(ip string, report *Report) reportHTMLData {
@@ -105,13 +117,18 @@ func buildReportData(ip string, report *Report) reportHTMLData {
Summary: report.Summary(),
SysInfo: report.SysInfo,
}
// 硬件型号:从 sysInfo["cpu"] 读取,用于按硬件库匹配基准
cpuModel := ""
if report.SysInfo != nil {
cpuModel = report.SysInfo["cpu"]
}
for _, res := range report.Results {
data.Cards = append(data.Cards, buildCard(res))
data.Cards = append(data.Cards, buildCard(cpuModel, res))
}
return data
}
func buildCard(res Result) testCard {
func buildCard(cpuModel string, res Result) testCard {
card := testCard{
Name: string(res.Type),
Label: testLabel(res.Type),
@@ -128,6 +145,16 @@ func buildCard(res Result) testCard {
Value: fmt.Sprintf("%.1f%s", res.Metrics[name], MetricUnit(name)),
})
}
// 性能/温度基准评级(仅在有数据时填充;按硬件库匹配专属阈值)
if items := EvaluateResult(res, cpuModel); len(items) > 0 {
card.Benchmarks = items
if lvl := OverallLevel(items); lvl != "" {
d := LevelMeta(lvl)
card.OverallLevel = lvl
card.OverallText = d.Text
card.OverallColor = d.Color
}
}
if len(res.Samples) > 0 {
if payload, ok := buildChart(res); ok {
card.Chart = &payload