controller.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package chat
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "bet24.com/log"
  6. coreClient "bet24.com/servers/coreservice/client"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // 获取机器人聊天列表
  10. func GetList(c *gin.Context) {
  11. var ret struct {
  12. RecordCount int
  13. List []robot_chat
  14. }
  15. resp := coreClient.GetRobotChatList()
  16. if resp.Data != "" {
  17. if err := json.Unmarshal([]byte(resp.Data), &ret.List); err != nil {
  18. log.Error("chat.GetList json unmarshal error %v", err)
  19. }
  20. }
  21. c.JSON(http.StatusOK, ret)
  22. return
  23. }
  24. // 获取机器人聊天信息
  25. func GetInfo(c *gin.Context) {
  26. var req robot_chat
  27. if err := c.ShouldBind(&req); err != nil {
  28. log.Debug("%s shouldBind err %v", "chat.GetInfo", err)
  29. return
  30. }
  31. var info robot_chat
  32. resp := coreClient.GetRobotChatInfo(req.UserId)
  33. if resp.Data != "" {
  34. if err := json.Unmarshal([]byte(resp.Data), &info); err != nil {
  35. log.Error("chat.GetInfo json unmarshal error %v", err)
  36. }
  37. }
  38. var ret struct {
  39. RecordCount int
  40. List []robot_chat
  41. }
  42. ret.List = append(ret.List, info)
  43. c.JSON(http.StatusOK, ret)
  44. return
  45. }
  46. // 添加机器人聊天信息
  47. func AddInfo(c *gin.Context) {
  48. var req robot_chat
  49. if err := c.ShouldBind(&req); err != nil {
  50. log.Debug("%s shouldBind err %v", "chat.AddInfo", err)
  51. return
  52. }
  53. info := coreClient.AddRobotChatInfo(req.UserId, req.Msg, req.Seconds, req.BeginTime, req.EndTime)
  54. c.JSON(http.StatusOK, info)
  55. return
  56. }
  57. // 修改机器人聊天信息
  58. func UpdateInfo(c *gin.Context) {
  59. var req robot_chat
  60. if err := c.ShouldBind(&req); err != nil {
  61. log.Debug("%s shouldBind err %v", "chat.UpdateInfo", err)
  62. return
  63. }
  64. info := coreClient.UpdateRobotChatInfo(req.UserId, req.Msg, req.Seconds, req.BeginTime, req.EndTime)
  65. c.JSON(http.StatusOK, info)
  66. return
  67. }
  68. // 删除机器人聊天信息
  69. func DelInfo(c *gin.Context) {
  70. var req robot_chat
  71. if err := c.ShouldBind(&req); err != nil {
  72. log.Debug("%s shouldBind err %v", "chat.DelInfo", err)
  73. return
  74. }
  75. info := coreClient.DelRobotChatInfo(req.UserId)
  76. c.JSON(http.StatusOK, info)
  77. return
  78. }