diff --git a/internal/dao/questionnaire_survey.go b/internal/dao/questionnaire_survey.go index 0aee32b..1e7a99b 100644 --- a/internal/dao/questionnaire_survey.go +++ b/internal/dao/questionnaire_survey.go @@ -2,6 +2,7 @@ package dao import ( "encoding/json" + "errors" "micro-bundle/internal/model" "micro-bundle/pb/bundle" "micro-bundle/pkg/app" @@ -9,6 +10,7 @@ import ( "time" "github.com/google/uuid" + "gorm.io/gorm" ) func SendQuestionnaireSurvey(req *bundle.SendQuestionnaireSurveyRequest) (resp *bundle.SendQuestionnaireSurveyResponse, err error) { @@ -36,6 +38,9 @@ func SendQuestionnaireSurvey(req *bundle.SendQuestionnaireSurveyRequest) (resp * Where("user_tel = ? and deleted_at is null", req.UserTel). First(&questionnaireInfo).Error if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + resp.Status = 0 + } return resp, err } if questionnaireInfo.UserId != 0 { @@ -102,6 +107,9 @@ func GetQuestionnaireSurveyInfo(req *bundle.GetQuestionnaireSurveyInfoRequest) ( Order("created_at desc"). First(&questionnaireInfo).Error if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errors.New("问卷信息不存在") + } return data, err } return data, nil