tag.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_web_mfyx/models"
  5. "hongze/hongze_web_mfyx/services"
  6. "hongze/hongze_web_mfyx/utils"
  7. )
  8. type TagController struct {
  9. BaseAuthController
  10. }
  11. type BaseTagController struct {
  12. BaseCommonController
  13. }
  14. // @Title 获取标签列表-自定义顺序
  15. // @Description 获取标签列表-自定义顺序接口
  16. // @Success 200 {object} cygx.ChartPermissionResp
  17. // @router /list/custom [get]
  18. func (this *TagController) TagCustomizeList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.User
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. var condition string
  32. var resp models.CygxTagListResp
  33. hasPermission, err := services.GetUserHasPermissionSimple(sysUser)
  34. if err != nil {
  35. br.Msg = "获取信息失败"
  36. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  37. return
  38. }
  39. if hasPermission > 1 {
  40. list := make([]*models.CygxTagList, 0)
  41. resp.List = list
  42. br.Ret = 200
  43. br.Success = true
  44. br.Msg = "获取成功"
  45. br.Data = resp
  46. return
  47. }
  48. list, err := models.GetCygxTagList(condition)
  49. if err != nil {
  50. br.Msg = "获取标签失败"
  51. br.ErrMsg = "获取标签信息失败,Err:" + err.Error()
  52. return
  53. }
  54. for _, v := range list {
  55. if v.ArticleTypes != "" {
  56. v.CheckList = append(v.CheckList, "A")
  57. }
  58. if v.ActivityTypes != "" {
  59. v.CheckList = append(v.CheckList, "B")
  60. }
  61. if v.Industries != "" {
  62. v.CheckList = append(v.CheckList, "C")
  63. }
  64. if v.SubjectNames != "" {
  65. v.CheckList = append(v.CheckList, "D")
  66. }
  67. //固定标签默认都属于,前端互斥使用
  68. if v.TagType > 0 {
  69. v.CheckList = []string{"A", "B", "C", "D"}
  70. }
  71. }
  72. //var condition string
  73. condition = ` AND permission_name IN ('医药','消费','科技','智造','策略') `
  74. listPermission, err := models.GetChartPermissionReportAll(condition)
  75. if err != nil {
  76. br.Msg = "获取信息失败"
  77. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  78. return
  79. }
  80. item := new(models.ChartPermissionResp)
  81. item.ChartPermissionId = utils.GU_SHOU_ID
  82. item.PermissionName = utils.GU_SHOU_NAME
  83. listPermission = append(listPermission, item)
  84. resp.List = list
  85. resp.ListPermission = listPermission
  86. br.Ret = 200
  87. br.Success = true
  88. br.Msg = "获取成功"
  89. br.Data = resp
  90. }
  91. // @Title 记录点击信息
  92. // @Description 记录点击信息
  93. // @Param request body cygx.CygxTagIdReq true "type json string"
  94. // @Success 200 Ret=200 发布成功
  95. // @router /add/history [post]
  96. func (this *TagController) History() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. user := this.User
  103. if user == nil {
  104. br.Msg = "请登录"
  105. br.ErrMsg = "请登录,用户信息为空"
  106. br.Ret = 408
  107. return
  108. }
  109. var req models.CygxTagIdReq
  110. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  111. if err != nil {
  112. br.Msg = "参数解析异常!"
  113. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  114. return
  115. }
  116. tagId := req.TagId
  117. if tagId == 0 {
  118. br.Msg = "参数错误"
  119. br.ErrMsg = "参数错误,id不可为空"
  120. return
  121. }
  122. go services.AddCygxTagHistory(user, tagId)
  123. br.Ret = 200
  124. br.Success = true
  125. br.Msg = "记录成功"
  126. }
  127. // @Title 首页标签列表
  128. // @Description 首页标签列表接口
  129. // @Success 200 {object} cygx.CygxTagListLabelResp
  130. // @router /list/label [get]
  131. func (this *BaseTagController) ListLabel() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. resp := new(models.CygxTagListLabelResp)
  138. key := "mfyx_tag_list"
  139. conf, e := models.GetConfigByCode(key)
  140. if e != nil {
  141. br.Msg = "获取失败"
  142. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  143. return
  144. }
  145. if conf.ConfigValue == "" {
  146. br.Msg = "获取失败"
  147. br.ErrMsg = "首页头部导航配置值有误"
  148. return
  149. }
  150. if e = json.Unmarshal([]byte(conf.ConfigValue), &resp); e != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  153. return
  154. }
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = resp
  159. }