From 0f93039dc3da1d2e206a68f509afbe819e195849 Mon Sep 17 00:00:00 2001 From: dark Date: Mon, 2 Feb 2026 13:18:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E4=BF=AE=E5=A4=8D=E5=81=A5?= =?UTF-8?q?=E5=BA=B7=E6=A8=A1=E5=9E=8B=20ID=20=E5=AD=97=E6=AE=B5=20JSON=20?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 显式定义 ID 字段并添加 json:"id" 标签 - 解决 GORM 嵌入 Model 导致 ID 序列化为大写问题 - 修复前端删除病史记录时 ID 为 undefined 的问题 Co-authored-by: Cursor --- server/internal/model/health.go | 51 +++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/server/internal/model/health.go b/server/internal/model/health.go index ff0c1fc..4eadc7b 100644 --- a/server/internal/model/health.go +++ b/server/internal/model/health.go @@ -1,35 +1,48 @@ package model -import "gorm.io/gorm" +import ( + "time" + + "gorm.io/gorm" +) // MedicalHistory 既往病史 type MedicalHistory struct { - gorm.Model - HealthProfileID uint `gorm:"index" json:"health_profile_id"` - DiseaseName string `gorm:"size:100" json:"disease_name"` - DiseaseType string `gorm:"size:50" json:"disease_type"` // chronic, surgery, other - DiagnosedDate string `gorm:"size:20" json:"diagnosed_date"` - Status string `gorm:"size:20" json:"status"` // cured, treating, controlled - Notes string `gorm:"type:text" json:"notes"` + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` + HealthProfileID uint `gorm:"index" json:"health_profile_id"` + DiseaseName string `gorm:"size:100" json:"disease_name"` + DiseaseType string `gorm:"size:50" json:"disease_type"` // chronic, surgery, other + DiagnosedDate string `gorm:"size:20" json:"diagnosed_date"` + Status string `gorm:"size:20" json:"status"` // cured, treating, controlled + Notes string `gorm:"type:text" json:"notes"` } // FamilyHistory 家族病史 type FamilyHistory struct { - gorm.Model - HealthProfileID uint `gorm:"index" json:"health_profile_id"` - Relation string `gorm:"size:20" json:"relation"` // father, mother, grandparent - DiseaseName string `gorm:"size:100" json:"disease_name"` - Notes string `gorm:"type:text" json:"notes"` + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` + HealthProfileID uint `gorm:"index" json:"health_profile_id"` + Relation string `gorm:"size:20" json:"relation"` // father, mother, grandparent + DiseaseName string `gorm:"size:100" json:"disease_name"` + Notes string `gorm:"type:text" json:"notes"` } // AllergyRecord 过敏记录 type AllergyRecord struct { - gorm.Model - HealthProfileID uint `gorm:"index" json:"health_profile_id"` - AllergyType string `gorm:"size:20" json:"allergy_type"` // drug, food, other - Allergen string `gorm:"size:100" json:"allergen"` - Severity string `gorm:"size:20" json:"severity"` // mild, moderate, severe - ReactionDesc string `gorm:"type:text" json:"reaction_desc"` + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` + HealthProfileID uint `gorm:"index" json:"health_profile_id"` + AllergyType string `gorm:"size:20" json:"allergy_type"` // drug, food, other + Allergen string `gorm:"size:100" json:"allergen"` + Severity string `gorm:"size:20" json:"severity"` // mild, moderate, severe + ReactionDesc string `gorm:"type:text" json:"reaction_desc"` } // TableName 指定表名