config.go 4.0 KB

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