feat: date_start в name_hash — различаем периоды

This commit is contained in:
2026-06-28 10:04:49 +04:00
parent 19e602fd62
commit 2b971c3c90
+7 -3
View File
@@ -45,7 +45,7 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
if action == "ADD":
nr = op.get("new_row", {})
name = nr.get("name", "")
name_hash = _hash(name)
name_hash = _hash(name, nr.get("date_start"))
execute(
"""INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash,
new_values, comment, status, prompt_version, source_document_id, raw_llm_response)
@@ -116,9 +116,13 @@ def apply_ops(contract_id, supplement_id, document_id, ops, prompt_id, raw_llm_r
return {"added": added, "updated": updated, "deleted": deleted}
def _hash(name):
def _hash(name, date_start=None):
"""Нормализованный хеш услуги. Включает date_start чтобы различать периоды."""
import hashlib
return hashlib.sha256(name.strip().lower().encode()).hexdigest()[:16]
key = name.strip().lower()
if date_start:
key += "|" + str(date_start)
return hashlib.sha256(key.encode()).hexdigest()[:16]
def _upsert_spec_current(contract_id, name_hash, row):