feat: 大屏新增虚拟工位滚动栏与多订单轮播,附件表增加删除原因及彻底清除留痕字段

This commit is contained in:
SunYF
2026-10-29 18:16:53 +08:00
parent 4d3c4e2c3a
commit 11dbdaae75
75 changed files with 6801 additions and 965 deletions
+163 -40
View File
@@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"sort"
"strings"
"sync"
"time"
@@ -40,16 +41,22 @@ import (
type ItemDef struct {
Key string `json:"key"`
Name string `json:"name"`
Desc string `json:"desc"` // 业务说明(index.html 与前端展示用)
Kind string `json:"kind"` // log | attachment
}
// MESItems MES 端可选数据项(event_log/plc_send_log/workpiece_lifecycle_log/alert/attachment)。
var MESItems = []ItemDef{
{Key: "event_log", Name: "操作日志", Kind: "log"},
{Key: "plc_send_log", Name: "PLC下发日志", Kind: "log"},
{Key: "workpiece_lifecycle_log", Name: "工件生命周期日志", Kind: "log"},
{Key: "alert", Name: "预警消息", Kind: "log"},
{Key: "attachment", Name: "业务附件", Kind: "attachment"},
{Key: "event_log", Name: "操作日志", Kind: "log",
Desc: "系统操作日志:记录用户登录及工单/设备/参数等操作流水,用于安全审计与责任追溯。"},
{Key: "plc_send_log", Name: "PLC下发日志", Kind: "log",
Desc: "PLC 下发指令流水:记录系统向 PLC/设备下发的每条指令与执行结果,用于设备动作追溯。"},
{Key: "workpiece_lifecycle_log", Name: "工件生命周期日志", Kind: "log",
Desc: "工件生命周期日志:记录工件从上线到下线在各工位的流转事件,用于生产过程追溯。"},
{Key: "alert", Name: "预警消息", Kind: "log",
Desc: "预警消息:设备与生产过程产生的异常、预警记录,用于问题回溯分析。"},
{Key: "attachment", Name: "业务附件", Kind: "attachment",
Desc: "业务附件:工单/检验等上传的图片与文档,按原始相对路径存放在包内 attachments/ 目录。"},
}
// BackupRequest 备份请求。
@@ -62,11 +69,17 @@ type BackupRequest struct {
}
// CleanupRequest 清理请求。
// Mode: ""=整窗清理(须完整备份覆盖);"covered"=仅清理已覆盖段(未备份段保留)。
// Force=true 时无视覆盖直接整窗清理,须填写 AckName/AckPhone 留痕(警示用)。
type CleanupRequest struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Items []string `json:"items"`
Operator string `json:"operator"`
Mode string `json:"mode"`
Force bool `json:"force"`
AckName string `json:"ackName"`
AckPhone string `json:"ackPhone"`
}
// ItemResult 单项导出结果。
@@ -99,10 +112,23 @@ type MissingSeg struct {
End int64 `json:"end"`
}
// CoverageResult 覆盖校验结果。
// CoverageRecord 覆盖该时间窗的备份记录(供前端覆盖地图展示)。
type CoverageRecord struct {
ID int `json:"id"`
ExecutedAt int64 `json:"executedAt"`
RangeStart int64 `json:"rangeStart"`
RangeEnd int64 `json:"rangeEnd"`
BackupPath string `json:"backupPath"`
Operator string `json:"operator"`
TotalSize int64 `json:"totalSize"`
}
// CoverageResult 覆盖校验结果(Covered=已覆盖段,Missing=缺失段,Records=覆盖本窗的备份记录)。
type CoverageResult struct {
OK bool `json:"ok"`
Missing []MissingSeg `json:"missing"`
OK bool `json:"ok"`
Covered []MissingSeg `json:"covered"`
Missing []MissingSeg `json:"missing"`
Records []CoverageRecord `json:"records"`
}
// Progress 任务进度。
@@ -243,6 +269,8 @@ func (s *Service) runBackup(jobID string, req BackupRequest) {
"rangeStartText": tStart.Format("2006-01-02 15:04:05"),
"rangeEndText": tEnd.Format("2006-01-02 15:04:05"),
"operator": req.Operator,
"targetPath": req.TargetPath,
"zipPath": zipPath,
"items": results,
"totalSize": total,
"checksum": "",
@@ -256,8 +284,8 @@ func (s *Service) runBackup(jobID string, req BackupRequest) {
return
}
// index.html(清单 + 校验,不内嵌预览)
indexHTML := buildIndexHTML("MES 备份清单", manifest, "")
// index.html(清单 + 目录/使用/恢复说明,不内嵌预览)
indexHTML := buildIndexHTML("MES 数据备份清单", manifest, "", MESItems)
if err := zw.WriteFile("index.html", []byte(indexHTML)); err != nil {
_ = zw.Close()
_ = f.Close()
@@ -321,6 +349,7 @@ func (s *Service) exportLog(ctx context.Context, zw *zipWriter, h io.Writer, key
}
func (s *Service) exportAttachment(ctx context.Context, zw *zipWriter, h io.Writer, tStart, tEnd time.Time) (ItemResult, error) {
// 全量快照:不过滤删除状态(含已删除附件),元数据标注删除信息,确保彻底清除后仍可从备份包找回
rows, err := s.client.Attachment.Query().
Where(attachment.CreatedAtGTE(tStart), attachment.CreatedAtLTE(tEnd)).All(ctx)
if err != nil {
@@ -338,7 +367,7 @@ func (s *Service) exportAttachment(ctx context.Context, zw *zipWriter, h io.Writ
// 文件不存在(可能已挪走):仅记录元数据
meta = append(meta, map[string]any{
"id": r.ID, "fileName": r.FileName, "filePath": r.FilePath,
"fileSize": r.FileSize, "missing": true,
"fileSize": r.FileSize, "missing": true, "deleted": r.Deleted,
})
continue
}
@@ -355,7 +384,7 @@ func (s *Service) exportAttachment(ctx context.Context, zw *zipWriter, h io.Writ
ir.Bytes += n
meta = append(meta, map[string]any{
"id": r.ID, "fileName": r.FileName, "filePath": r.FilePath,
"fileSize": r.FileSize, "bytes": n,
"fileSize": r.FileSize, "bytes": n, "deleted": r.Deleted,
})
}
mb, _ := json.MarshalIndent(meta, "", " ")
@@ -504,6 +533,9 @@ func (s *Service) StartCleanup(req CleanupRequest) (string, error) {
if len(req.Items) == 0 {
return "", fmt.Errorf("请至少选择一个数据项")
}
if req.Force && req.Mode == "covered" {
return "", fmt.Errorf("参数冲突:强制清理与仅清理已覆盖段不可同时选择")
}
jobID := newJobID()
s.mu.Lock()
s.jobs[jobID] = &Progress{JobID: jobID, Phase: "cleanup", Stage: "checking", Percent: 0}
@@ -513,17 +545,28 @@ func (s *Service) StartCleanup(req CleanupRequest) (string, error) {
}
// CheckCoverage 校验备份覆盖(供前端预检)。
// 返回:Covered=已覆盖段(可用于「仅清理已覆盖部分」),Missing=缺失段,
// Records=与本时间窗相交的 success 备份记录(供覆盖地图展示)。
func (s *Service) CheckCoverage(start, end int64) (CoverageResult, error) {
recs, err := s.client.BackupRecord.Query().Where(backuprecord.StatusEQ("success")).All(context.Background())
if err != nil {
return CoverageResult{}, err
}
ivs := make([][2]int64, 0, len(recs))
outRecs := make([]CoverageRecord, 0, len(recs))
for _, r := range recs {
if r.RangeEnd < start || r.RangeStart > end {
continue
}
ivs = append(ivs, [2]int64{r.RangeStart, r.RangeEnd})
outRecs = append(outRecs, CoverageRecord{
ID: r.ID, ExecutedAt: r.ExecutedAt, RangeStart: r.RangeStart, RangeEnd: r.RangeEnd,
BackupPath: r.BackupPath, Operator: r.Operator, TotalSize: r.TotalSize,
})
}
missing := complement(ivs, start, end)
return CoverageResult{OK: len(missing) == 0, Missing: missing}, nil
sort.Slice(outRecs, func(i, j int) bool { return outRecs[i].RangeStart < outRecs[j].RangeStart })
covered, missing := coverageSegments(ivs, start, end)
return CoverageResult{OK: len(missing) == 0, Covered: covered, Missing: missing, Records: outRecs}, nil
}
func (s *Service) runCleanup(jobID string, req CleanupRequest) {
@@ -542,30 +585,96 @@ func (s *Service) runCleanup(jobID string, req CleanupRequest) {
s.failCleanup(jobID, req, fmt.Errorf("覆盖校验失败:%w", err))
return
}
if !cov.OK {
s.failCleanup(jobID, req, fmt.Errorf("该时间窗未被完整备份,禁止清理。缺失时间段:%s",
var deleted, skipped []ItemResult
forced := false
if cov.OK {
// 整窗均已被备份覆盖:直接清理
tStart, tEnd := time.Unix(req.Start, 0), time.Unix(req.End, 0)
if deleted, skipped, err = s.cleanWindow(ctx, tStart, tEnd, req.Items, setStage); err != nil {
s.failCleanup(jobID, req, err)
return
}
} else if req.Mode == "covered" {
// 部分清理:逐段清理已覆盖部分,未备份段保留
if len(cov.Covered) == 0 {
s.failCleanup(jobID, req, fmt.Errorf("该时间窗内没有任何已被备份的数据段,无法清理。缺失时间段:%s", formatMissing(cov.Missing)))
return
}
for i, seg := range cov.Covered {
setStage("cleaning", i*90/len(cov.Covered),
fmt.Sprintf("清理已覆盖段 %s ~ %s …", time.Unix(seg.Start, 0).Format("2006-01-02"), time.Unix(seg.End, 0).Format("2006-01-02")))
tStart, tEnd := time.Unix(seg.Start, 0), time.Unix(seg.End, 0)
var d, sk []ItemResult
if d, sk, err = s.cleanWindow(ctx, tStart, tEnd, req.Items, setStage); err != nil {
s.failCleanup(jobID, req, err)
return
}
deleted = append(deleted, d...)
skipped = append(skipped, sk...)
}
} else if req.Force {
// 强制清理:未完整备份仍坚持整窗清理,须实名留痕
if err = validateAck(req); err != nil {
s.failCleanup(jobID, req, err)
return
}
forced = true
tStart, tEnd := time.Unix(req.Start, 0), time.Unix(req.End, 0)
if deleted, skipped, err = s.cleanWindow(ctx, tStart, tEnd, req.Items, setStage); err != nil {
s.failCleanup(jobID, req, err)
return
}
} else {
s.failCleanup(jobID, req, fmt.Errorf(
"该时间窗未被完整备份,禁止清理。缺失时间段:%s。可选:① 先补齐缺失段备份;② 仅清理已覆盖部分(未备份段保留);③ 强制清理(需实名确认,风险自担)。",
formatMissing(cov.Missing)))
return
}
tStart := time.Unix(req.Start, 0)
tEnd := time.Unix(req.End, 0)
deleted := make([]ItemResult, 0, len(req.Items))
skipped := make([]ItemResult, 0, len(req.Items))
// 2) 清理记录 + event_log
status := "cleanup"
evKind, detail := "backup.cleanup", fmt.Sprintf("按时间窗清理(%s ~ %s):%s",
time.Unix(req.Start, 0).Format("2006-01-02"), time.Unix(req.End, 0).Format("2006-01-02"),
summaryDeleted(deleted, skipped))
if forced {
status = "cleanup_forced"
evKind = "backup.cleanup.forced"
detail = fmt.Sprintf("强制清理(该时间窗未被完整备份,缺失:%s;操作确认人:%s,手机号:%s):%s",
formatMissing(cov.Missing), req.AckName, req.AckPhone, summaryDeleted(deleted, skipped))
} else if !cov.OK { // covered 模式
detail += fmt.Sprintf("(仅清理已覆盖部分,未备份段已保留:%s)", formatMissing(cov.Missing))
}
s.writeCleanupRecord(req, status, deleted, skipped)
s.ev.Write(ctx, evKind, "", req.Operator, "backup", "", detail, nil)
setStage("done", 100, "清理完成")
s.mu.Lock()
if j, ok := s.jobs[jobID]; ok {
j.Done = true
j.Result = CleanupResult{RangeStart: req.Start, RangeEnd: req.End, Deleted: deleted, Skipped: skipped}
}
s.mu.Unlock()
}
// cleanWindow 清理单个时间窗内的指定数据项(物理删除)。
func (s *Service) cleanWindow(ctx context.Context, tStart, tEnd time.Time, keys []string, setStage func(string, int, string)) ([]ItemResult, []ItemResult, error) {
deleted := make([]ItemResult, 0, len(keys))
skipped := make([]ItemResult, 0, len(keys))
itemNames := make(map[string]string, len(MESItems))
for _, it := range MESItems {
itemNames[it.Key] = it.Name
}
// 2) 逐表清理
for i, key := range req.Items {
setStage("cleaning", int(float64(i)/float64(len(req.Items))*90), "清理 "+itemName(itemNames, key)+" …")
for i, key := range keys {
pct := 0
if len(keys) > 0 {
pct = i * 90 / len(keys)
}
setStage("cleaning", pct, "清理 "+itemName(itemNames, key)+" …")
if key == "attachment" {
d, sk, e := s.cleanupAttachment(ctx, tStart, tEnd)
if e != nil {
s.failCleanup(jobID, req, fmt.Errorf("清理附件失败:%w", e))
return
return nil, nil, fmt.Errorf("清理附件失败:%w", e)
}
d.Key, d.Name = key, itemName(itemNames, key)
sk.Key, sk.Name = key, itemName(itemNames, key)
@@ -576,26 +685,40 @@ func (s *Service) runCleanup(jobID string, req CleanupRequest) {
} else {
n, e := s.cleanupLog(ctx, key, tStart, tEnd)
if e != nil {
s.failCleanup(jobID, req, fmt.Errorf("清理 %s 失败:%w", itemName(itemNames, key), e))
return
return nil, nil, fmt.Errorf("清理 %s 失败:%w", itemName(itemNames, key), e)
}
deleted = append(deleted, ItemResult{Key: key, Name: itemName(itemNames, key), Rows: n, Bytes: 0})
}
}
return deleted, skipped, nil
}
// 3) 清理动作本身写一条 event_log
s.ev.Write(ctx, "backup.cleanup", "", req.Operator, "backup", "",
fmt.Sprintf("按时间窗清理(%s ~ %s):%s",
time.Unix(req.Start, 0).Format("2006-01-02"), time.Unix(req.End, 0).Format("2006-01-02"),
summaryDeleted(deleted, skipped)), nil)
setStage("done", 100, "清理完成")
s.mu.Lock()
if j, ok := s.jobs[jobID]; ok {
j.Done = true
j.Result = CleanupResult{RangeStart: req.Start, RangeEnd: req.End, Deleted: deleted, Skipped: skipped}
// writeCleanupRecord 清理成功后写一条 backup_record(status=cleanup / cleanup_forced),
// 备份记录与清理记录统一在「备份/清理历史」中展示;覆盖校验仅认 success,不受影响。
func (s *Service) writeCleanupRecord(req CleanupRequest, status string, deleted, skipped []ItemResult) {
items := make([]ItemResult, 0, len(deleted)+len(skipped))
items = append(items, deleted...)
items = append(items, skipped...)
itemsJSON, _ := json.Marshal(items)
var total int64
for _, d := range deleted {
total += d.Bytes
}
s.mu.Unlock()
c := s.client.BackupRecord.Create().
SetExecutedAt(time.Now().Unix()).
SetRangeStart(req.Start).
SetRangeEnd(req.End).
SetBackupPath("").
SetTotalSize(total).
SetItemsJSON(string(itemsJSON)).
SetStatus(status).
SetOperator(req.Operator).
SetChecksum("").
SetScope("mes")
if status == "cleanup_forced" {
c = c.SetAckName(strings.TrimSpace(req.AckName)).SetAckPhone(strings.TrimSpace(req.AckPhone))
}
_, _ = c.Save(context.Background())
}
func (s *Service) cleanupLog(ctx context.Context, key string, tStart, tEnd time.Time) (int64, error) {
+3
View File
@@ -117,6 +117,8 @@ type RecordItem struct {
Scope string `json:"scope"`
ItemsJSON string `json:"itemsJson"`
Checksum string `json:"checksum"`
AckName string `json:"ackName"`
AckPhone string `json:"ackPhone"`
}
// RecordsResult 历史列表(分页)。
@@ -172,6 +174,7 @@ func (s *Service) ListRecords(page, size int, status, scope string) (RecordsResu
ID: r.ID, ExecutedAt: r.ExecutedAt, RangeStart: r.RangeStart, RangeEnd: r.RangeEnd,
BackupPath: r.BackupPath, TotalSize: r.TotalSize, Status: r.Status,
Operator: r.Operator, Scope: r.Scope, ItemsJSON: r.ItemsJSON, Checksum: r.Checksum,
AckName: r.AckName, AckPhone: r.AckPhone,
})
}
return RecordsResult{Total: total, List: list, Page: page, Size: size}, nil
+148 -14
View File
@@ -4,7 +4,9 @@ import (
"crypto/rand"
"fmt"
"io"
"path/filepath"
"reflect"
"regexp"
"strings"
"time"
)
@@ -89,6 +91,50 @@ func formatMissing(segs []MissingSeg) string {
return strings.Join(parts, ";")
}
// coverageSegments 基于已排序备份区间计算 [start,end] 内的已覆盖段与缺失段(均为闭区间,秒)。
// covered=窗口 ∩ 备份区间并集(合并相邻/重叠段);missing=窗口内未被任何备份覆盖的段。
func coverageSegments(intervals [][2]int64, start, end int64) (covered, missing []MissingSeg) {
if start > end {
return nil, nil
}
ivs := make([][2]int64, 0, len(intervals))
for _, iv := range intervals {
if iv[0] <= iv[1] && iv[1] >= start && iv[0] <= end {
ivs = append(ivs, [2]int64{maxInt64(iv[0], start), minInt64(iv[1], end)})
}
}
sortIntervals(ivs)
// 合并重叠/相邻段 → covered
merged := make([][2]int64, 0, len(ivs))
for _, iv := range ivs {
if n := len(merged); n > 0 && iv[0] <= merged[n-1][1]+1 {
if iv[1] > merged[n-1][1] {
merged[n-1][1] = iv[1]
}
continue
}
merged = append(merged, iv)
}
covered = make([]MissingSeg, 0, len(merged))
for _, iv := range merged {
covered = append(covered, MissingSeg{Start: iv[0], End: iv[1]})
}
return covered, complement(intervals, start, end)
}
// validateAck 强制清理实名留痕校验。
var phoneRe = regexp.MustCompile(`^1\d{10}$`)
func validateAck(req CleanupRequest) error {
if strings.TrimSpace(req.AckName) == "" {
return fmt.Errorf("强制清理须填写确认人姓名(警示留痕)")
}
if !phoneRe.MatchString(strings.TrimSpace(req.AckPhone)) {
return fmt.Errorf("强制清理须填写有效的 11 位手机号(警示留痕)")
}
return nil
}
func summaryDeleted(deleted, skipped []ItemResult) string {
var b strings.Builder
for _, d := range deleted {
@@ -103,29 +149,117 @@ func summaryDeleted(deleted, skipped []ItemResult) string {
return strings.TrimRight(b.String(), ";")
}
// buildIndexHTML 生成备份清单页(仅清单 + 校验,不内嵌预览)。
func buildIndexHTML(title string, manifest map[string]any, checksum string) string {
// htmlEscape 最小 HTML 转义(路径/操作人可能含特殊字符)。
func htmlEscape(s string) string {
return strings.NewReplacer("&", "&amp;", "<", "&lt;", ">", "&gt;", `"`, "&#34;").Replace(s)
}
// buildIndexHTML 生成备份包内 index.html:清单 + 包内目录说明 + 打开/校验/恢复指引。
// 双击即可离线查看;不内嵌数据预览(数据在包内 data.jsonl 与 attachments/ 中)。
func buildIndexHTML(title string, manifest map[string]any, checksum string, defs []ItemDef) string {
items, _ := manifest["items"].([]ItemResult)
zipPath, _ := manifest["zipPath"].(string)
if zipPath == "" {
zipPath, _ = manifest["targetPath"].(string)
}
zipName := "备份包"
if zipPath != "" {
zipName = filepath.Base(zipPath)
}
descByName := make(map[string]string, len(defs))
for _, d := range defs {
descByName[d.Name] = d.Desc
}
// 数据项明细行
var rows strings.Builder
for _, it := range items {
fmt.Fprintf(&rows, "<tr><td>%s</td><td>%d</td><td>%s</td></tr>\n", it.Name, it.Rows, humanBytes(it.Bytes))
desc := descByName[it.Name]
loc := htmlEscape(it.Key) + "/data.jsonl"
if it.Key == "attachments" || it.Key == "attachment" {
loc = "attachments/(附件原文件,含已删除)+ attachment/data.jsonl(元数据,含删除状态标注)"
}
fmt.Fprintf(&rows, "<tr><td>%s</td><td class=\"desc\">%s</td><td><code>%s</code></td><td>%d</td><td>%s</td></tr>\n",
htmlEscape(it.Name), htmlEscape(desc), loc, it.Rows, humanBytes(it.Bytes))
}
if checksum == "" {
if c, ok := manifest["checksum"].(string); ok {
checksum = c
// 包内目录树
var tree strings.Builder
fmt.Fprintf(&tree, "%s\n├─ index.html ← 本文件(清单 / 使用说明 / 恢复指引)\n├─ manifest.json ← 机器可读元数据(记事本可直接查看)\n", zipName)
for _, it := range items {
if it.Key == "attachments" || it.Key == "attachment" {
fmt.Fprintf(&tree, "├─ attachments/ ← 附件原文件(按备份时的原始相对路径存放)\n└─ attachment/\n └─ data.jsonl ← 附件元数据索引(每行一条 JSON)\n")
} else {
fmt.Fprintf(&tree, "├─ %s/\n └─ data.jsonl ← %s(每行一条 JSON,可用记事本/VS Code 打开)\n", it.Key, htmlEscape(it.Name))
}
}
treeStr := htmlEscape(tree.String())
cs := checksum
if cs == "" {
cs = "(见 backup_record.checksum)"
if c, ok := manifest["checksum"].(string); ok {
cs = c
}
}
csHTML := "<p class=\"meta\">校验和(sha256):包内为流式写入无法回填,请以系统内「数据归档 → 备份/清理历史 → 详情」中的校验和为准。</p>"
if cs != "" {
csHTML = "<p class=\"meta\">校验和(sha256):<code>" + cs + "</code></p>"
}
verifyCmd := ""
if zipPath != "" {
verifyCmd = "<p class=\"meta\">本地核对完整 zip 文件:在命令行执行 <code>certutil -hashfile \"" + htmlEscape(zipPath) + "\" SHA256</code>,与历史详情中的校验和比对。</p>"
}
return fmt.Sprintf(`<!doctype html><html lang="zh"><head><meta charset="utf-8">
<title>%s</title><style>body{font-family:-apple-system,Segoe UI,Roboto,sans-serif;margin:32px;color:#222}
h2{margin-bottom:8px}h3{margin-top:24px}table{border-collapse:collapse;margin-top:8px}td,th{border:1px solid #ddd;padding:6px 12px;text-align:left}
.meta{color:#666;font-size:13px}</style></head><body>
<title>%s</title><style>
body{font-family:-apple-system,"Segoe UI",Roboto,"Microsoft YaHei",sans-serif;margin:32px auto;max-width:900px;color:#222;line-height:1.7}
h2{margin-bottom:4px}h3{margin-top:28px;border-bottom:1px solid #eee;padding-bottom:6px}
table{border-collapse:collapse;margin-top:8px;width:100%%}td,th{border:1px solid #ddd;padding:6px 10px;text-align:left;vertical-align:top}
th{background:#f7f8fa}td.desc{color:#555;font-size:13px}
.meta{color:#666;font-size:13px}code{background:#f4f4f5;padding:1px 5px;border-radius:3px;font-size:13px;word-break:break-all}
pre{background:#f7f8fa;border:1px solid #e5e7eb;border-radius:6px;padding:12px 16px;font-size:13px;overflow:auto;line-height:1.6}
.box{border:1px solid #f0d896;background:#fdf6e3;border-radius:6px;padding:10px 14px;font-size:13px}
ol li,ul li{margin-bottom:6px}
</style></head><body>
<h2>%s</h2>
<p class="meta">范围:%s ~ %s | 操作人:%s | 校验和(sha256):%s</p>
<h3>数据项</h3><table><tr><th>数据项</th><th>行数</th><th>字节</th></tr>%s</table>
<p class="meta">本文件仅作清单与校验用途,不内嵌任何数据预览。完整数据见包内各 data.jsonl 与 attachments/ 目录。</p>
</body></html>`, title, title, manifest["rangeStartText"], manifest["rangeEndText"], manifest["operator"], cs, rows.String())
<p class="meta">
备份时间窗:<b>%s ~ %s</b>(含起止日)| 生成时间:%s | 操作人:%s<br>
归档位置:<code>%s</code><br>
数据项:共 %d 项 | 明细大小合计:%s(zip 实际大小以文件属性为准,压缩后略小)
</p>
%s
%s
<h3>一、包内目录结构</h3>
<pre>%s</pre>
<h3>二、数据项明细</h3>
<table><tr><th>数据项</th><th>业务说明</th><th>包内位置</th><th>行数 / 文件数</th><th>大小</th></tr>%s</table>
<h3>三、如何打开与查看</h3>
<ol>
<li><b>本文件</b>:双击即可离线查看,无需联网、无需安装任何软件。</li>
<li><b>日志类数据(data.jsonl)</b>:每行一条 JSON 记录。用记事本 / Notepad++ / VS Code 直接打开查看;如需用 Excel 分析,请在 Excel 中「数据 → 获取数据 → 自文件 → 从 JSON」导入(切勿直接双击用 Excel 打开,避免长数字精度丢失)。</li>
<li><b>附件(attachments/ 目录)</b>:按备份时的原始相对路径存放原文件,可直接双击打开(图片、PDF、Office 文档等)。附件的清单(编号、原文件名、路径、大小、删除状态)见 <code>attachment/data.jsonl</code>——时间窗内已删除的附件同样包含在包内(元数据 deleted 标注),本机彻底清除后可凭包内拷贝找回(介质可读性由保管人自行核对)。</li>
<li><b>manifest.json</b>:机器可读元数据(时间窗、数据项、大小、生成时间、操作人),可供脚本化核对或二次导入使用。</li>
</ol>
<h3>四、恢复与保管说明</h3>
<div class="box">
<b>本包为离线冷备份,删除系统数据前请务必确认:</b>
<ul style="margin:6px 0">
<li>备份盘(U 盘 / 移动硬盘)已妥善保管,建议<b>双份异地保存</b>,并标注备份日期与时间窗;</li>
<li>本系统当前版本未提供自动恢复功能,如需将数据导回系统,请联系系统管理员按 manifest.json 逐项人工导入;</li>
<li>校验和与该次备份的详细信息(操作人、数据项、大小)可在系统「数据归档 → 备份/清理历史」中按时间窗查到。</li>
</ul>
</div>
<p class="meta" style="margin-top:20px">本文件由系统在备份时自动生成,仅作清单、说明与校验用途,不含任何业务数据内容。</p>
</body></html>`,
title, title,
manifest["rangeStartText"], manifest["rangeEndText"], manifest["generatedAt"], manifest["operator"],
htmlEscape(zipPath), len(items), humanBytes(sumItemBytes(items)),
csHTML, verifyCmd, treeStr, rows.String())
}
func sumItemBytes(items []ItemResult) int64 {
var n int64
for _, it := range items {
n += it.Bytes
}
return n
}