micro-bundle/internal/logic/questionnaire_survey.go
2026-03-11 16:54:41 +08:00

74 lines
2.4 KiB
Go

package logic
import (
"encoding/json"
"errors"
"micro-bundle/internal/dao"
"micro-bundle/internal/model"
"micro-bundle/pb/bundle"
"github.com/samber/lo"
)
func SendQuestionnaireSurvey(req *bundle.SendQuestionnaireSurveyRequest) (*bundle.SendQuestionnaireSurveyResponse, error) {
resp, err := dao.SendQuestionnaireSurvey(req)
if err != nil {
return nil, err
}
return resp, nil
}
func GetQuestionnaireSurveyInfo(req *bundle.GetQuestionnaireSurveyInfoRequest) (*bundle.GetQuestionnaireSurveyInfoResponse, error) {
resp := new(bundle.GetQuestionnaireSurveyInfoResponse)
data, err := dao.GetQuestionnaireSurveyInfo(req)
if err != nil {
return nil, errors.New("获取问卷信息失败")
}
bundleInfo := &bundle.SurveyBundleInfo{}
err = json.Unmarshal([]byte(data.BundleInfo), bundleInfo)
if err != nil {
return nil, errors.New("反序列化失败")
}
resp.UserName = data.UserName
resp.BundleInfo.BundleName = bundleInfo.BundleName
resp.BundleInfo.StartAt = bundleInfo.StartAt
resp.BundleInfo.ExpiredAt = bundleInfo.ExpiredAt
resp.BundleInfo.BundleAccountNumber = bundleInfo.BundleAccountNumber
resp.BundleInfo.BundleVideoNumber = bundleInfo.BundleVideoNumber
resp.BundleInfo.IncreaseVideoNumber = bundleInfo.IncreaseVideoNumber
resp.BundleInfo.BundleImageNumber = bundleInfo.BundleImageNumber
resp.BundleInfo.BundleDataNumber = bundleInfo.BundleDataNumber
resp.BundleInfo.BundleCompetitiveNumber = bundleInfo.BundleCompetitiveNumber
return resp, nil
}
func CreateQuestionnaireSurveyAnswer(req *bundle.CreateQuestionnaireSurveyAnswerRequest) (*bundle.CreateQuestionnaireSurveyAnswerResponse, error) {
resp := new(bundle.CreateQuestionnaireSurveyAnswerResponse)
err := dao.CreateQuestionnaireSurveyAnswer(req)
if err != nil {
return nil, err
}
return resp, nil
}
func GetQuestionnaireSurveyList(req *bundle.GetQuestionnaireSurveyListRequest) (resp *bundle.GetQuestionnaireSurveyListResponse, err error) {
resp = &bundle.GetQuestionnaireSurveyListResponse{}
data, total, err := dao.GetQuestionnaireSurveyList(req)
if err != nil {
return nil, err
}
resp.Total = int32(total)
resp.Page = req.Page
resp.Size = req.PageSize
resp.SurveyList = lo.Map(data, func(m *model.QuestionnaireSurvey, _ int) *bundle.SurveyListInfo {
return &bundle.SurveyListInfo{
UserName: m.UserName,
UserTel: m.UserTel,
SurveyTitle: m.SurveyTitle,
SurveyStatus: int32(m.SurveyStatus),
SurveyUrl: m.SurveyUrl,
}
})
return resp, nil
}