tag.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. )
  7. type TagController struct {
  8. BaseAuthController
  9. }
  10. // @Title 获取标签列表-自定义顺序
  11. // @Description 获取标签列表-自定义顺序接口
  12. // @Success 200 {object} cygx.ChartPermissionResp
  13. // @router /list/custom [get]
  14. func (this *TagController) TagCustomizeList() {
  15. br := new(models.BaseResponse).Init()
  16. defer func() {
  17. this.Data["json"] = br
  18. this.ServeJSON()
  19. }()
  20. sysUser := this.User
  21. if sysUser == nil {
  22. br.Msg = "请登录"
  23. br.ErrMsg = "请登录,SysUser Is Empty"
  24. br.Ret = 408
  25. return
  26. }
  27. var condition string
  28. var resp models.CygxTagListResp
  29. hasPermission, err := services.GetUserHasPermissionSimple(sysUser)
  30. if err != nil {
  31. br.Msg = "获取信息失败"
  32. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  33. return
  34. }
  35. if hasPermission > 1 {
  36. list := make([]*models.CygxTagList, 0)
  37. resp.List = list
  38. br.Ret = 200
  39. br.Success = true
  40. br.Msg = "获取成功"
  41. br.Data = resp
  42. return
  43. }
  44. list, err := models.GetCygxTagList(condition)
  45. if err != nil {
  46. br.Msg = "获取标签失败"
  47. br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
  48. return
  49. }
  50. resp.List = list
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. // @Title 记录点击信息
  57. // @Description 记录点击信息
  58. // @Param request body cygx.CygxTagIdReq true "type json string"
  59. // @Success 200 Ret=200 发布成功
  60. // @router /add/history [post]
  61. func (this *TagController) History() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. this.Data["json"] = br
  65. this.ServeJSON()
  66. }()
  67. user := this.User
  68. if user == nil {
  69. br.Msg = "请登录"
  70. br.ErrMsg = "请登录,用户信息为空"
  71. br.Ret = 408
  72. return
  73. }
  74. var req models.CygxTagIdReq
  75. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  76. if err != nil {
  77. br.Msg = "参数解析异常!"
  78. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  79. return
  80. }
  81. tagId := req.TagId
  82. if tagId == 0 {
  83. br.Msg = "参数错误"
  84. br.ErrMsg = "参数错误,id不可为空"
  85. return
  86. }
  87. go services.AddCygxTagHistory(user, tagId)
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "记录成功"
  91. }