config.go 3.3 KB

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