calendar_researcher_question.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "hongze/hz_crm_api/models"
  5. "hongze/hz_crm_api/models/roadshow"
  6. "hongze/hz_crm_api/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // @Title 路演客户问答保存接口
  11. // @Description 路演客户问答保存接口
  12. // @Param request body roadshow.RoadShowQuestionSaveReq true "type json string"
  13. // @Success Ret=200 保存成功
  14. // @router /question/save [post]
  15. func (this *CalendarController) QuestionAdd() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.SysUser
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. deleteCache := true
  29. cacheKey := "CACHE_RS_ACTIVITY_QUESTION_SAVE_" + strconv.Itoa(sysUser.AdminId)
  30. defer func() {
  31. if deleteCache {
  32. utils.Rc.Delete(cacheKey)
  33. }
  34. }()
  35. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  36. deleteCache = false
  37. br.Msg = "系统处理中,请稍后重试!"
  38. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  39. return
  40. }
  41. var req roadshow.RoadShowQuestionSaveReq
  42. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  43. if err != nil {
  44. br.Msg = "参数解析异常!"
  45. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  46. return
  47. }
  48. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  49. br.Msg = "参数错误!"
  50. return
  51. }
  52. calendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  53. if err != nil {
  54. br.Msg = "获取路演记录失败!"
  55. br.ErrMsg = "获取路演记录失败,Err:" + err.Error()
  56. return
  57. }
  58. if calendarResearcherItem.QuestionStatus == 1 {
  59. br.Msg = "问答已填写,不可重复提交!"
  60. return
  61. }
  62. err = roadshow.RoadShowQuestionSave(&req)
  63. if err != nil {
  64. br.Msg = "保存失败!"
  65. br.ErrMsg = "保存失败,Err:" + err.Error()
  66. return
  67. }
  68. br.Ret = 200
  69. br.Success = true
  70. br.Msg = "保存成功"
  71. br.IsAddLog = true
  72. }
  73. // ResearcherList
  74. // @Title 获取路演客户问答信息接口
  75. // @Description 获取路演客户问答信息接口
  76. // @Param RsCalendarResearcherId query int true "路演研究员记录ID"
  77. // @Success 200 {object} roadshow.ResearcherGroup
  78. // @router /question/list [get]
  79. func (this *CalendarController) QuestionList() {
  80. br := new(models.BaseResponse).Init()
  81. defer func() {
  82. this.Data["json"] = br
  83. this.ServeJSON()
  84. }()
  85. rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
  86. if rsCalendarResearcherId <= 0 {
  87. br.Msg = "参数错误!"
  88. return
  89. }
  90. list, err := roadshow.GetRoadShowQuestionList(rsCalendarResearcherId)
  91. if err != nil && err.Error() != utils.ErrNoRow() {
  92. br.Msg = "获取失败!"
  93. br.ErrMsg = "获取失败,Err:" + err.Error()
  94. return
  95. }
  96. br.Ret = 200
  97. br.Success = true
  98. br.Msg = "获取成功"
  99. br.Data = list
  100. }