config.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. hotList, err := models.GetSearchKeyWordTop()
  45. if err != nil {
  46. br.Msg = "获取信息失败"
  47. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  48. return
  49. }
  50. for _, v := range hotList {
  51. item := new(models.KeyWord)
  52. item.KeyWord = v.KeyWord
  53. resp.ListHot = append(resp.ListHot, item)
  54. }
  55. detail.ConfigValue = hotSearch
  56. resp.Item = detail
  57. br.Msg = "获取成功!"
  58. br.Ret = 200
  59. br.Success = true
  60. br.Data = resp
  61. }
  62. // @Title 页面访问统计
  63. // @Description 上传页面访问统计
  64. // @Param request body models.CygxPageHistoryRecordRep true "type json string"
  65. // @Success Ret=200 新增成功
  66. // @router /pageHistory [post]
  67. func (this *ConfigController) PageHistory() {
  68. br := new(models.BaseResponse).Init()
  69. defer func() {
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. user := this.User
  74. if user == nil {
  75. br.Msg = "请登录"
  76. br.ErrMsg = "请登录,SysUser Is Empty"
  77. br.Ret = 408
  78. return
  79. }
  80. var req models.CygxPageHistoryRecordRep
  81. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  82. if err != nil {
  83. br.Msg = "参数解析异常!"
  84. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  85. return
  86. }
  87. pageType := req.PageType
  88. var havePageType bool
  89. PageType := []string{"Summary", "SummarySearch", "Report", "ReportSearch", "IndustryList", "Activit", "ActivitSearch", "ActivitParticulars", "ReportParticulars", "MySchedule", "LabelMore", "ArticleCopy"}
  90. for _, v := range PageType {
  91. if pageType == v {
  92. havePageType = true
  93. }
  94. }
  95. if !havePageType {
  96. br.Msg = "新增失败"
  97. br.ErrMsg = "PageType参数类型错误:" + pageType
  98. return
  99. }
  100. item := new(models.CygxPageHistoryRecord)
  101. item.UserId = user.UserId
  102. item.CreateTime = time.Now()
  103. item.Mobile = user.Mobile
  104. item.Email = user.Email
  105. item.CompanyId = user.CompanyId
  106. item.CompanyName = user.CompanyName
  107. item.DetailId = req.DetailId
  108. item.ChartPermissionId = req.ChartPermissionId
  109. item.IndustrialManagementId = req.IndustrialManagementId
  110. item.PageType = req.PageType
  111. _, err = models.AddCygxPageHistoryRecord(item)
  112. if err != nil {
  113. br.Msg = "新增访问记录失败"
  114. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  115. return
  116. }
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "新增成功"
  120. }
  121. // @Title 获取研选说明
  122. // @Description 获取研选说明接口
  123. // @Success 200 {object} models.ConfigResp
  124. // @router /descriptionOfResearch [get]
  125. func (this *ConfigController) DescriptionOfResearch() {
  126. br := new(models.BaseResponse).Init()
  127. defer func() {
  128. this.Data["json"] = br
  129. this.ServeJSON()
  130. }()
  131. configCode := "description_of_research"
  132. detail, err := models.GetConfigByCode(configCode)
  133. if err != nil {
  134. br.Msg = "获取数据失败"
  135. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  136. return
  137. }
  138. resp := new(models.ConfigResp)
  139. resp.Item = detail
  140. br.Msg = "获取成功!"
  141. br.Ret = 200
  142. br.Success = true
  143. br.Data = resp
  144. }
  145. // @Title 获取搜索推荐词(无需token)
  146. // @Description 获取搜索推荐词(无需token)
  147. // @Success 200 {object} models.ConfigResp
  148. // @router /detailPublic [get]
  149. func (this *BaseConfigController) HotDetail() {
  150. br := new(models.BaseResponse).Init()
  151. defer func() {
  152. this.Data["json"] = br
  153. this.ServeJSON()
  154. }()
  155. detail := new(models.CygxConfig)
  156. hotSearch, err := models.GetHotSearch()
  157. if err != nil {
  158. br.Msg = "获取数据失败"
  159. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  160. return
  161. }
  162. detail.ConfigValue = hotSearch
  163. resp := new(models.ConfigResp)
  164. resp.Item = detail
  165. br.Msg = "获取成功!"
  166. br.Ret = 200
  167. br.Success = true
  168. br.Data = resp
  169. }