config.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. type BaseConfigController struct {
  12. BaseCommonController
  13. }
  14. // @Title 获取搜索推荐词
  15. // @Description 获取搜索推荐词
  16. // @Success 200 {object} models.ConfigResp
  17. // @router /detail [get]
  18. func (this *ConfigController) BrowseHistoryList() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. resp := new(models.ConfigResp)
  25. detail := new(models.CygxConfig)
  26. //configCode := "hot_search"
  27. //detail, err := models.GetConfigByCode(configCode)
  28. hotSearch, err := models.GetHotSearch()
  29. if err != nil {
  30. br.Msg = "获取数据失败"
  31. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  32. return
  33. }
  34. chartList, err := models.GetChartListConfig()
  35. if err != nil {
  36. br.Msg = "获取信息失败"
  37. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  38. return
  39. }
  40. for _, v := range chartList {
  41. item := new(models.KeyWord)
  42. item.KeyWord = v.Title
  43. resp.List = append(resp.List, item)
  44. }
  45. hotList, err := models.GetSearchKeyWordTop()
  46. if err != nil {
  47. br.Msg = "获取信息失败"
  48. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  49. return
  50. }
  51. for _, v := range hotList {
  52. item := new(models.KeyWord)
  53. item.KeyWord = v.KeyWord
  54. resp.ListHot = append(resp.ListHot, item)
  55. }
  56. detail.ConfigValue = hotSearch
  57. resp.Item = detail
  58. br.Msg = "获取成功!"
  59. br.Ret = 200
  60. br.Success = true
  61. br.Data = resp
  62. }
  63. // @Title 页面访问统计
  64. // @Description 上传页面访问统计
  65. // @Param request body models.CygxPageHistoryRecordRep true "type json string"
  66. // @Success Ret=200 新增成功
  67. // @router /pageHistory [post]
  68. func (this *ConfigController) PageHistory() {
  69. br := new(models.BaseResponse).Init()
  70. defer func() {
  71. this.Data["json"] = br
  72. this.ServeJSON()
  73. }()
  74. user := this.User
  75. if user == nil {
  76. br.Msg = "请登录"
  77. br.ErrMsg = "请登录,SysUser Is Empty"
  78. br.Ret = 408
  79. return
  80. }
  81. var req models.CygxPageHistoryRecordRep
  82. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  83. if err != nil {
  84. br.Msg = "参数解析异常!"
  85. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  86. return
  87. }
  88. pageType := req.PageType
  89. var havePageType bool
  90. PageType := []string{"Summary", "SummarySearch", "Report", "ReportSearch", "IndustryList", "Activit", "ActivitSearch", "ActivitParticulars", "ReportParticulars", "MySchedule", "LabelMore", "ArticleCopy"}
  91. for _, v := range PageType {
  92. if pageType == v {
  93. havePageType = true
  94. }
  95. }
  96. if !havePageType {
  97. br.Msg = "新增失败"
  98. br.ErrMsg = "PageType参数类型错误:" + pageType
  99. return
  100. }
  101. item := new(models.CygxPageHistoryRecord)
  102. item.UserId = user.UserId
  103. item.CreateTime = time.Now()
  104. item.Mobile = user.Mobile
  105. item.Email = user.Email
  106. item.CompanyId = user.CompanyId
  107. item.CompanyName = user.CompanyName
  108. item.DetailId = req.DetailId
  109. item.ChartPermissionId = req.ChartPermissionId
  110. item.IndustrialManagementId = req.IndustrialManagementId
  111. item.PageType = req.PageType
  112. _, err = models.AddCygxPageHistoryRecord(item)
  113. if err != nil {
  114. br.Msg = "新增访问记录失败"
  115. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  116. return
  117. }
  118. br.Ret = 200
  119. br.Success = true
  120. br.Msg = "新增成功"
  121. }
  122. // @Title 获取研选说明
  123. // @Description 获取研选说明接口
  124. // @Success 200 {object} models.ConfigResp
  125. // @router /descriptionOfResearch [get]
  126. func (this *ConfigController) DescriptionOfResearch() {
  127. br := new(models.BaseResponse).Init()
  128. defer func() {
  129. this.Data["json"] = br
  130. this.ServeJSON()
  131. }()
  132. configCode := "description_of_research"
  133. detail, err := models.GetConfigByCode(configCode)
  134. if err != nil {
  135. br.Msg = "获取数据失败"
  136. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  137. return
  138. }
  139. resp := new(models.ConfigResp)
  140. resp.Item = detail
  141. br.Msg = "获取成功!"
  142. br.Ret = 200
  143. br.Success = true
  144. br.Data = resp
  145. }
  146. // @Title 获取搜索推荐词(无需token)
  147. // @Description 获取搜索推荐词(无需token)
  148. // @Success 200 {object} models.ConfigResp
  149. // @router /detailPublic [get]
  150. func (this *BaseConfigController) HotDetail() {
  151. br := new(models.BaseResponse).Init()
  152. defer func() {
  153. this.Data["json"] = br
  154. this.ServeJSON()
  155. }()
  156. detail := new(models.CygxConfig)
  157. hotSearch, err := models.GetHotSearch()
  158. if err != nil {
  159. br.Msg = "获取数据失败"
  160. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  161. return
  162. }
  163. detail.ConfigValue = hotSearch
  164. resp := new(models.ConfigResp)
  165. resp.Item = detail
  166. br.Msg = "获取成功!"
  167. br.Ret = 200
  168. br.Success = true
  169. br.Data = resp
  170. }
  171. // @Title 用户搜索记录统计
  172. // @Description 用户搜索记录统计
  173. // @Param KeyWord query string false "搜索关键词"
  174. // @Success Ret=200 新增成功
  175. // @router /user/search/keyWordLog [post]
  176. func (this *ConfigController) KeyWordLog() {
  177. br := new(models.BaseResponse).Init()
  178. defer func() {
  179. this.Data["json"] = br
  180. this.ServeJSON()
  181. }()
  182. var req models.CygxSearchKeyWordLogRep
  183. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  184. if err != nil {
  185. br.Msg = "参数解析异常!"
  186. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  187. return
  188. }
  189. keyWord := req.KeyWord
  190. if keyWord == "" {
  191. br.Msg = "搜索内容不能为空"
  192. return
  193. }
  194. user := this.User
  195. if user == nil {
  196. br.Msg = "请登录"
  197. br.ErrMsg = "请登录,SysUser Is Empty"
  198. br.Ret = 408
  199. return
  200. }
  201. if keyWord != "" {
  202. go services.AddUserSearchLog(user, keyWord, 1)
  203. }
  204. br.Ret = 200
  205. br.Success = true
  206. br.Msg = "新增成功"
  207. }