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
+32 -1
View File
@@ -10,8 +10,11 @@ type PHISHealthRecord struct {
Birthday string
MobileNumber string
RegionCode string
RegionName string
ManaDoctorID string
ManaDoctorName string
ManaUnitID string
ManaUnitName string
NationCode string
EducationCode string
WorkCode string
@@ -51,8 +54,15 @@ type DictSnapshot struct {
Insurance Dict
}
type MasterDataLookup interface {
RegionCodeByName(name string) (string, bool)
DoctorIDByName(name string) (string, bool)
ManaUnitIDByName(name string) (string, bool)
}
type MapContext struct {
Dicts DictSnapshot
Dicts DictSnapshot
MasterData MasterDataLookup
}
func DefaultDictSnapshot() DictSnapshot {
@@ -72,6 +82,7 @@ func MapHealthRecord(src PHISHealthRecord, ctx MapContext) (MappedHealthRecord,
if ctx.Dicts.Sex.Name == "" {
ctx.Dicts = DefaultDictSnapshot()
}
resolveMasterData(&src, ctx.MasterData)
var errs []ValidationError
for _, field := range []struct {
name string
@@ -112,6 +123,26 @@ func MapHealthRecord(src PHISHealthRecord, ctx MapContext) (MappedHealthRecord,
return mapped, errs
}
func resolveMasterData(src *PHISHealthRecord, lookup MasterDataLookup) {
if lookup == nil {
return
}
if src.RegionCode == "" && src.RegionName != "" {
if code, ok := lookup.RegionCodeByName(src.RegionName); ok {
src.RegionCode = code
}
}
if src.ManaDoctorID == "" && src.ManaDoctorName != "" {
if code, ok := lookup.DoctorIDByName(src.ManaDoctorName); ok {
src.ManaDoctorID = code
}
}
if src.ManaUnitID == "" && src.ManaUnitName != "" {
if code, ok := lookup.ManaUnitIDByName(src.ManaUnitName); ok {
src.ManaUnitID = code
}
}
}
func mapCode(dict Dict, code string, errs *[]ValidationError) string {
if code == "" {
return ""