config.go 3.2 KB

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