config.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "time"
  6. )
  7. type ConfigController struct {
  8. BaseAuthController
  9. }
  10. type BaseConfigController struct {
  11. BaseCommonController
  12. }
  13. // @Title 获取搜索推荐词
  14. // @Description 获取搜索推荐词
  15. // @Success 200 {object} models.ConfigResp
  16. // @router /detail [get]
  17. func (this *ConfigController) BrowseHistoryList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. resp := new(models.ConfigResp)
  24. detail := new(models.CygxConfig)
  25. //configCode := "hot_search"
  26. //detail, err := models.GetConfigByCode(configCode)
  27. hotSearch, err := models.GetHotSearch()
  28. if err != nil {
  29. br.Msg = "获取数据失败"
  30. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  31. return
  32. }
  33. chartList, err := models.GetChartListConfig()
  34. if err != nil {
  35. br.Msg = "获取信息失败"
  36. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  37. return
  38. }
  39. for _, v := range chartList {
  40. item := new(models.KeyWord)
  41. item.KeyWord = v.Title
  42. resp.List = append(resp.List, item)
  43. }
  44. detail.ConfigValue = hotSearch
  45. resp.Item = detail
  46. br.Msg = "获取成功!"
  47. br.Ret = 200
  48. br.Success = true
  49. br.Data = resp
  50. }
  51. // @Title 页面访问统计
  52. // @Description 上传页面访问统计
  53. // @Param request body models.CygxPageHistoryRecordRep true "type json string"
  54. // @Success Ret=200 新增成功
  55. // @router /pageHistory [post]
  56. func (this *ConfigController) PageHistory() {
  57. br := new(models.BaseResponse).Init()
  58. defer func() {
  59. this.Data["json"] = br
  60. this.ServeJSON()
  61. }()
  62. user := this.User
  63. if user == nil {
  64. br.Msg = "请登录"
  65. br.ErrMsg = "请登录,SysUser Is Empty"
  66. br.Ret = 408
  67. return
  68. }
  69. var req models.CygxPageHistoryRecordRep
  70. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  71. if err != nil {
  72. br.Msg = "参数解析异常!"
  73. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  74. return
  75. }
  76. pageType := req.PageType
  77. var havePageType bool
  78. PageType := []string{"Summary", "SummarySearch", "Report", "ReportSearch", "IndustryList", "Activit", "ActivitSearch", "ActivitParticulars", "ReportParticulars", "MySchedule", "LabelMore", "ArticleCopy"}
  79. for _, v := range PageType {
  80. if pageType == v {
  81. havePageType = true
  82. }
  83. }
  84. if !havePageType {
  85. br.Msg = "新增失败"
  86. br.ErrMsg = "PageType参数类型错误:" + pageType
  87. return
  88. }
  89. item := new(models.CygxPageHistoryRecord)
  90. item.UserId = user.UserId
  91. item.CreateTime = time.Now()
  92. item.Mobile = user.Mobile
  93. item.Email = user.Email
  94. item.CompanyId = user.CompanyId
  95. item.CompanyName = user.CompanyName
  96. item.DetailId = req.DetailId
  97. item.ChartPermissionId = req.ChartPermissionId
  98. item.IndustrialManagementId = req.IndustrialManagementId
  99. item.PageType = req.PageType
  100. _, err = models.AddCygxPageHistoryRecord(item)
  101. if err != nil {
  102. br.Msg = "新增访问记录失败"
  103. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  104. return
  105. }
  106. br.Ret = 200
  107. br.Success = true
  108. br.Msg = "新增成功"
  109. }
  110. // @Title 获取研选说明
  111. // @Description 获取研选说明接口
  112. // @Success 200 {object} models.ConfigResp
  113. // @router /descriptionOfResearch [get]
  114. func (this *ConfigController) DescriptionOfResearch() {
  115. br := new(models.BaseResponse).Init()
  116. defer func() {
  117. this.Data["json"] = br
  118. this.ServeJSON()
  119. }()
  120. configCode := "description_of_research"
  121. detail, err := models.GetConfigByCode(configCode)
  122. if err != nil {
  123. br.Msg = "获取数据失败"
  124. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  125. return
  126. }
  127. resp := new(models.ConfigResp)
  128. resp.Item = detail
  129. br.Msg = "获取成功!"
  130. br.Ret = 200
  131. br.Success = true
  132. br.Data = resp
  133. }
  134. // @Title 获取搜索推荐词(无需token)
  135. // @Description 获取搜索推荐词(无需token)
  136. // @Success 200 {object} models.ConfigResp
  137. // @router /detailPublic [get]
  138. func (this *BaseConfigController) HotDetail() {
  139. br := new(models.BaseResponse).Init()
  140. defer func() {
  141. this.Data["json"] = br
  142. this.ServeJSON()
  143. }()
  144. detail := new(models.CygxConfig)
  145. hotSearch, err := models.GetHotSearch()
  146. if err != nil {
  147. br.Msg = "获取数据失败"
  148. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  149. return
  150. }
  151. detail.ConfigValue = hotSearch
  152. resp := new(models.ConfigResp)
  153. resp.Item = detail
  154. br.Msg = "获取成功!"
  155. br.Ret = 200
  156. br.Success = true
  157. br.Data = resp
  158. }