tag.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. )
  8. type TagController struct {
  9. BaseAuthController
  10. }
  11. // @Title 获取标签列表-自定义顺序
  12. // @Description 获取标签列表-自定义顺序接口
  13. // @Success 200 {object} cygx.ChartPermissionResp
  14. // @router /list/custom [get]
  15. func (this *TagController) TagCustomizeList() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. this.Data["json"] = br
  19. this.ServeJSON()
  20. }()
  21. sysUser := this.User
  22. if sysUser == nil {
  23. br.Msg = "请登录"
  24. br.ErrMsg = "请登录,SysUser Is Empty"
  25. br.Ret = 408
  26. return
  27. }
  28. var condition string
  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. br.Ret = 200
  38. br.Success = true
  39. br.Msg = "获取成功"
  40. br.Data = list
  41. return
  42. }
  43. list, err := models.GetCygxTagList(condition)
  44. for _, v := range list {
  45. if v.ArticleTypes != "" {
  46. v.CheckList = append(v.CheckList, "A")
  47. }
  48. if v.ActivityTypes != "" {
  49. v.CheckList = append(v.CheckList, "B")
  50. }
  51. if v.Industries != "" {
  52. v.CheckList = append(v.CheckList, "C")
  53. }
  54. if v.SubjectNames != "" {
  55. v.CheckList = append(v.CheckList, "D")
  56. }
  57. //固定标签默认都属于,前端互斥使用
  58. if v.TagType > 0 {
  59. v.CheckList = []string{"A", "B", "C", "D"}
  60. }
  61. }
  62. if err != nil {
  63. br.Msg = "获取标签失败"
  64. br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
  65. return
  66. }
  67. //var condition string
  68. condition = ` AND permission_name IN ('医药','消费','科技','智造','策略') `
  69. listPermission, err := models.GetChartPermissionReportAll(condition)
  70. if err != nil {
  71. br.Msg = "获取信息失败"
  72. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  73. return
  74. }
  75. item := new(models.ChartPermission)
  76. item.ChartPermissionId = utils.GU_SHOU_ID
  77. item.PermissionName = utils.GU_SHOU_NAME
  78. listPermission = append(listPermission, item)
  79. resp := new(models.CygxTagListResp)
  80. resp.List = list
  81. resp.ListPermission = listPermission
  82. br.Ret = 200
  83. br.Success = true
  84. br.Msg = "获取成功"
  85. br.Data = resp
  86. }
  87. // @Title 记录点击信息
  88. // @Description 记录点击信息
  89. // @Param request body cygx.CygxTagIdReq true "type json string"
  90. // @Success 200 Ret=200 发布成功
  91. // @router /add/history [post]
  92. func (this *TagController) History() {
  93. br := new(models.BaseResponse).Init()
  94. defer func() {
  95. this.Data["json"] = br
  96. this.ServeJSON()
  97. }()
  98. user := this.User
  99. if user == nil {
  100. br.Msg = "请登录"
  101. br.ErrMsg = "请登录,用户信息为空"
  102. br.Ret = 408
  103. return
  104. }
  105. var req models.CygxTagIdReq
  106. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  107. if err != nil {
  108. br.Msg = "参数解析异常!"
  109. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  110. return
  111. }
  112. tagId := req.TagId
  113. if tagId == 0 {
  114. br.Msg = "参数错误"
  115. br.ErrMsg = "参数错误,id不可为空"
  116. return
  117. }
  118. go services.AddCygxTagHistory(user, tagId)
  119. br.Ret = 200
  120. br.Success = true
  121. br.Msg = "记录成功"
  122. }