feat(agent): 立账凭证检核
(cherry picked from commit f9e2fb5efc1ec7bf4f6e52e08dd3591b4e77edd9)
This commit is contained in:
1 parent
9bcbf9d211
commit
f615e56bb9
70 files changed
+4968
-108
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
backend/app/services/voucher_check/fingerprint.py
|
||||
|
||||
用途:根据共享盘目录直接子文件的元数据生成稳定 SHA-256 指纹。
|
||||
依赖:标准库 hashlib / json。
|
||||
逻辑:share_scanner 枚举文件后调用;runner 用指纹判断齐全票是否可跳过。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from typing import Iterable, Sequence
|
||||
|
||||
|
||||
def build_material_fingerprint(
|
||||
entries: Sequence[tuple[str, int, int]] | Iterable[tuple[str, int, int]],
|
||||
) -> str:
|
||||
"""
|
||||
对直接子文件元数据生成 SHA-256。
|
||||
核心逻辑:按文件名排序后序列化为 UTF-8 JSON,再哈希;不读取文件内容。
|
||||
|
||||
Args:
|
||||
entries: (filename, size, mtime_ns) 列表。
|
||||
|
||||
Returns:
|
||||
64 位十六进制 SHA-256;无文件时对空数组哈希。
|
||||
"""
|
||||
normalized = sorted(
|
||||
[(str(name), int(size), int(mtime_ns)) for name, size, mtime_ns in entries],
|
||||
key=lambda item: item[0],
|
||||
)
|
||||
payload = json.dumps(normalized, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
|
||||
return hashlib.sha256(payload).hexdigest()
|
||||
Reference in new issue
Block a user