12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package eta_trial
- import (
- "eta/eta_bridge/controller/resp"
- "eta/eta_bridge/global"
- "eta/eta_bridge/models/crm"
- etaTrialReq "eta/eta_bridge/models/request/eta_trial"
- "eta/eta_bridge/utils"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "sort"
- "strings"
- )
- // GetQuestionnaireList
- // @Description 获取问卷列表
- // @Success 200 {string} string "操作成功"
- // @Router /eta_trial/questionnaire/list [post]
- func (a *EtaTrialController) GetQuestionnaireList(c *gin.Context) {
- ob := new(crm.EtaTrialQuestionnaire)
- list, e := ob.List(``, make([]interface{}, 0))
- if e != nil {
- resp.FailData("获取失败", "获取问卷列表失败, Err: "+e.Error(), c)
- return
- }
- var result crm.EtaTrialQuestionnaireResp
- for _, v := range list {
- item := crm.EtaTrialQuestionnaireRespItem{
- QuestionnaireId: v.QuestionnaireId,
- Question: v.Question,
- Type: v.Type,
- Sort: v.Sort,
- Option: strings.Split(v.Options, "~#"),
- IsMust: v.IsMust,
- CreateTime: v.CreateTime.Format(utils.FormatDateTime),
- }
- result.List = append(result.List, item)
- }
- sort.Sort(result)
- resp.OkData("操作成功", result, c)
- }
- // QuestionnaireCommit
- // @Description 提交问卷
- // @Success 200 {string} string "操作成功"
- // @Router /eta_trial/questionnaire/commit [post]
- func (a *EtaTrialController) QuestionnaireCommit(c *gin.Context) {
- var req etaTrialReq.QuestionnaireCommitReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- if len(req.List) == 0 {
- return
- }
- ob := new(crm.EtaTrialQuestionnaireRecord)
- if e := ob.CreateMulti(req.List); e != nil {
- resp.FailData("操作失败", "新增试用客户问卷记录失败, Err:"+e.Error(), c)
- return
- }
- resp.OkData("操作成功", true, c)
- }
|