You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"healthapi/internal/model"
|
|
"healthapi/internal/svc"
|
|
"healthapi/internal/types"
|
|
"healthapi/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetSurveyStatusLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewGetSurveyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSurveyStatusLogic {
|
|
return &GetSurveyStatusLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetSurveyStatusLogic) GetSurveyStatus() (resp *types.SurveyStatusResp, err error) {
|
|
userID, err := GetUserIDFromCtx(l.ctx)
|
|
if err != nil {
|
|
return nil, errorx.ErrUnauthorized
|
|
}
|
|
|
|
resp = &types.SurveyStatusResp{}
|
|
|
|
// 检查基础信息
|
|
var profile model.HealthProfile
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&profile).Error; err == nil {
|
|
resp.BasicInfo = true
|
|
resp.MedicalHistory = true
|
|
resp.FamilyHistory = true
|
|
resp.Allergy = true
|
|
}
|
|
|
|
// 检查生活习惯
|
|
var lifestyle model.LifestyleInfo
|
|
if err := l.svcCtx.DB.Where("user_id = ?", userID).First(&lifestyle).Error; err == nil {
|
|
resp.Lifestyle = true
|
|
}
|
|
|
|
// 检查是否全部完成
|
|
resp.Completed = resp.BasicInfo && resp.Lifestyle
|
|
|
|
return resp, nil
|
|
}
|
|
|