feat(cache): 建立字典缓存快照(T-103)

This commit is contained in:
ila
2026-07-07 21:16:52 +08:00
parent 74748c084b
commit 12346c9923
10 changed files with 295 additions and 15 deletions
+33
View File
@@ -68,6 +68,26 @@ func TestMapHealthRecordUsesInjectedDictSnapshot(t *testing.T) {
}
}
func TestMapHealthRecordUsesMasterDataLookupWhenCodesMissing(t *testing.T) {
src := validPHISHealthRecord()
src.RegionCode = ""
src.ManaDoctorID = ""
src.ManaUnitID = ""
src.RegionName = "测试网格"
src.ManaDoctorName = "测试医生"
src.ManaUnitName = "测试机构"
got, errs := MapHealthRecord(src, MapContext{
Dicts: DefaultDictSnapshot(),
MasterData: fakeMasterDataLookup{},
})
if len(errs) != 0 {
t.Fatalf("errors = %#v", errs)
}
if got.RegionCode != "441625000000" || got.ManaDoctorID != "doc-001" || got.ManaUnitID != "123456789" {
t.Fatalf("master data not resolved: %#v", got)
}
}
func TestGenerateCheckIDIsDeterministicAndVersionSensitive(t *testing.T) {
first := GenerateCheckID("PHIS", "JKDA", "record-001", "20260707010101")
second := GenerateCheckID("PHIS", "JKDA", "record-001", "20260707010101")
@@ -83,6 +103,19 @@ func TestGenerateCheckIDIsDeterministicAndVersionSensitive(t *testing.T) {
}
}
type fakeMasterDataLookup struct{}
func (fakeMasterDataLookup) RegionCodeByName(name string) (string, bool) {
return map[string]string{"测试网格": "441625000000"}[name], name == "测试网格"
}
func (fakeMasterDataLookup) DoctorIDByName(name string) (string, bool) {
return map[string]string{"测试医生": "doc-001"}[name], name == "测试医生"
}
func (fakeMasterDataLookup) ManaUnitIDByName(name string) (string, bool) {
return map[string]string{"测试机构": "123456789"}[name], name == "测试机构"
}
func validPHISHealthRecord() PHISHealthRecord {
return PHISHealthRecord{
SourceSystem: "PHIS",