config.go 5.7 KB

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