125 lines
4.0 KiB
Go
125 lines
4.0 KiB
Go
package bundle
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fonchain-fiee/api/bundle"
|
|
"fonchain-fiee/pkg/service"
|
|
"fonchain-fiee/pkg/service/bundle/model"
|
|
"fonchain-fiee/pkg/service/upload"
|
|
"fonchain-fiee/pkg/utils"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func IsSendSurvey(c *gin.Context) {
|
|
var req bundle.SendQuestionnaireSurveyRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
res, err := service.BundleProvider.SendQuestionnaireSurvey(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func QuestionnaireSurveyList(c *gin.Context) {
|
|
var req bundle.GetQuestionnaireSurveyListRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
res, err := service.BundleProvider.GetQuestionnaireSurveyList(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func QuestionnaireSurveyBundleInfo(c *gin.Context) {
|
|
var req bundle.GetQuestionnaireSurveyInfoRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
res, err := service.BundleProvider.GetQuestionnaireSurveyInfo(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
service.Success(c, res)
|
|
}
|
|
|
|
func QuestionnaireSurveyCreate(c *gin.Context) {
|
|
var req bundle.CreateQuestionnaireSurveyAnswerRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
address, err := utils.ReverseGeo(req.Longitude, req.Latitude, "ZhCN")
|
|
if err != nil {
|
|
service.Error(c, errors.New("获取地址失败"))
|
|
return
|
|
}
|
|
surveyInfo, err := service.BundleProvider.GetQuestionnaireSurveyInfo(c, &bundle.GetQuestionnaireSurveyInfoRequest{UserTel: req.UserTel})
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
templateDir := "./data/满意度调成报告模板.pdf"
|
|
outputPath := "/data/" + "questionnaire_" + uuid.NewString() + ".pdf"
|
|
err = utils.QuestionnaireSurveyPDF(templateDir, outputPath, &model.QuestionnairePDFData{
|
|
//CustomerNum: surveyInfo.BundleInfo.,
|
|
CustomerName: surveyInfo.UserName,
|
|
BundleName: surveyInfo.BundleInfo.BundleName,
|
|
BundleStartDate: surveyInfo.BundleInfo.StartAt,
|
|
BundleEndDate: surveyInfo.BundleInfo.ExpiredAt,
|
|
VideoNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.BundleVideoNumber), 10),
|
|
AccountNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.BundleAccountNumber), 10),
|
|
ImagesNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.BundleImageNumber), 10),
|
|
DataAnalysisNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.BundleDataNumber), 10),
|
|
CompetitiveNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.BundleCompetitiveNumber), 10),
|
|
ValueAddVideoNum: strconv.FormatInt(int64(surveyInfo.BundleInfo.IncreaseVideoNumber), 10),
|
|
Score1: int(req.SurveyAnswer.BundleAccountScore),
|
|
Score2: int(req.SurveyAnswer.BundleAccountScore),
|
|
Score3: int(req.SurveyAnswer.BundleImageScore),
|
|
Score4: int(req.SurveyAnswer.BundleDataScore),
|
|
Score5: int(req.SurveyAnswer.IncreaseVideoScore),
|
|
Score6: int(req.SurveyAnswer.ServiceResponseSpeed),
|
|
Score7: int(req.SurveyAnswer.ServiceStaffProfessionalism),
|
|
Opinion1: req.SurveyFeedback.MeritsReview,
|
|
Opinion2: req.SurveyFeedback.SuggestionsorImprovements,
|
|
Opinion3: req.SurveyFeedback.AdditionalComments,
|
|
Submitter: surveyInfo.UserName,
|
|
SubmissionDate: time.Now().Format(time.DateOnly),
|
|
Address: address,
|
|
})
|
|
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
outputUrl, ossErr := upload.PutBos(outputPath, upload.PdfType, true)
|
|
|
|
if ossErr != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
//service.Success(c, outputUrl)
|
|
//return
|
|
req.SurveyUrl = outputUrl
|
|
res, err := service.BundleProvider.CreateQuestionnaireSurveyAnswer(context.Background(), &req)
|
|
if err != nil {
|
|
service.Error(c, err)
|
|
return
|
|
}
|
|
service.Success(c, res)
|
|
}
|