tag.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/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. hasPermission, err := services.GetUserHasPermissionSimple(sysUser)
  29. if err != nil {
  30. br.Msg = "获取信息失败"
  31. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  32. return
  33. }
  34. if hasPermission > 1 {
  35. list := make([]*models.CygxTagList, 0)
  36. br.Ret = 200
  37. br.Success = true
  38. br.Msg = "获取成功"
  39. br.Data = list
  40. return
  41. }
  42. list, err := models.GetCygxTagList(condition)
  43. for _, v := range list {
  44. if v.ArticleTypes != "" {
  45. v.Atag = true
  46. }
  47. if v.ActivityTypes != "" {
  48. v.Btag = true
  49. }
  50. if v.Industries != "" {
  51. v.Ctag = true
  52. }
  53. if v.SubjectNames != "" {
  54. v.Dtag = true
  55. }
  56. }
  57. if err != nil {
  58. br.Msg = "获取标签失败"
  59. br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
  60. return
  61. }
  62. br.Ret = 200
  63. br.Success = true
  64. br.Msg = "获取成功"
  65. br.Data = list
  66. }
  67. // @Title 记录点击信息
  68. // @Description 记录点击信息
  69. // @Param request body cygx.CygxTagIdReq true "type json string"
  70. // @Success 200 Ret=200 发布成功
  71. // @router /add/history [post]
  72. func (this *TagController) History() {
  73. br := new(models.BaseResponse).Init()
  74. defer func() {
  75. this.Data["json"] = br
  76. this.ServeJSON()
  77. }()
  78. user := this.User
  79. if user == nil {
  80. br.Msg = "请登录"
  81. br.ErrMsg = "请登录,用户信息为空"
  82. br.Ret = 408
  83. return
  84. }
  85. var req models.CygxTagIdReq
  86. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  87. if err != nil {
  88. br.Msg = "参数解析异常!"
  89. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  90. return
  91. }
  92. tagId := req.TagId
  93. if tagId == 0 {
  94. br.Msg = "参数错误"
  95. br.ErrMsg = "参数错误,id不可为空"
  96. return
  97. }
  98. go services.AddCygxTagHistory(user, tagId)
  99. br.Ret = 200
  100. br.Success = true
  101. br.Msg = "记录成功"
  102. }