package logic import ( "context" "healthapi/internal/model" "healthapi/internal/svc" "healthapi/internal/types" "healthapi/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type SubmitMedicalHistoryLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewSubmitMedicalHistoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubmitMedicalHistoryLogic { return &SubmitMedicalHistoryLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *SubmitMedicalHistoryLogic) SubmitMedicalHistory(req *types.SubmitMedicalHistoryReq) (resp *types.CommonResp, err error) { userID, err := GetUserIDFromCtx(l.ctx) if err != nil { return nil, errorx.ErrUnauthorized } var profile model.HealthProfile if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&profile).Error; err != nil { return nil, errorx.NewCodeError(errorx.CodeBadRequest, "请先填写基础信息") } history := model.MedicalHistory{ HealthProfileID: profile.ID, DiseaseName: req.DiseaseName, DiseaseType: req.DiseaseType, DiagnosedDate: req.DiagnosedDate, Status: req.Status, Notes: req.Notes, } if err := l.svcCtx.DB.Create(&history).Error; err != nil { return nil, errorx.ErrServerError } return &types.CommonResp{Code: 0, Message: "提交成功"}, nil }