package controllers import ( "encoding/json" "hongze/hongze_cygx/models" "time" ) type ConfigController struct { BaseAuthController } type BaseConfigController struct { BaseCommonController } // @Title 获取搜索推荐词 // @Description 获取搜索推荐词 // @Success 200 {object} models.ConfigResp // @router /detail [get] func (this *ConfigController) BrowseHistoryList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() resp := new(models.ConfigResp) detail := new(models.CygxConfig) //configCode := "hot_search" //detail, err := models.GetConfigByCode(configCode) hotSearch, err := models.GetHotSearch() if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } chartList, err := models.GetChartListConfig() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取用户信息失败,Err:" + err.Error() return } for _, v := range chartList { item := new(models.KeyWord) item.KeyWord = v.Title resp.List = append(resp.List, item) } hotList, err := models.GetSearchKeyWordTop() if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取用户信息失败,Err:" + err.Error() return } for _, v := range hotList { item := new(models.KeyWord) item.KeyWord = v.KeyWord resp.ListHot = append(resp.ListHot, item) } detail.ConfigValue = hotSearch resp.Item = detail br.Msg = "获取成功!" br.Ret = 200 br.Success = true br.Data = resp } // @Title 页面访问统计 // @Description 上传页面访问统计 // @Param request body models.CygxPageHistoryRecordRep true "type json string" // @Success Ret=200 新增成功 // @router /pageHistory [post] func (this *ConfigController) PageHistory() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.CygxPageHistoryRecordRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } pageType := req.PageType var havePageType bool PageType := []string{"Summary", "SummarySearch", "Report", "ReportSearch", "IndustryList", "Activit", "ActivitSearch", "ActivitParticulars", "ReportParticulars", "MySchedule", "LabelMore", "ArticleCopy"} for _, v := range PageType { if pageType == v { havePageType = true } } if !havePageType { br.Msg = "新增失败" br.ErrMsg = "PageType参数类型错误:" + pageType return } item := new(models.CygxPageHistoryRecord) item.UserId = user.UserId item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.DetailId = req.DetailId item.ChartPermissionId = req.ChartPermissionId item.IndustrialManagementId = req.IndustrialManagementId item.PageType = req.PageType _, err = models.AddCygxPageHistoryRecord(item) if err != nil { br.Msg = "新增访问记录失败" br.ErrMsg = "新增访问记录失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "新增成功" } // @Title 获取研选说明 // @Description 获取研选说明接口 // @Success 200 {object} models.ConfigResp // @router /descriptionOfResearch [get] func (this *ConfigController) DescriptionOfResearch() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() configCode := "description_of_research" detail, err := models.GetConfigByCode(configCode) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ConfigResp) resp.Item = detail br.Msg = "获取成功!" br.Ret = 200 br.Success = true br.Data = resp } // @Title 获取搜索推荐词(无需token) // @Description 获取搜索推荐词(无需token) // @Success 200 {object} models.ConfigResp // @router /detailPublic [get] func (this *BaseConfigController) HotDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() detail := new(models.CygxConfig) hotSearch, err := models.GetHotSearch() if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } detail.ConfigValue = hotSearch resp := new(models.ConfigResp) resp.Item = detail br.Msg = "获取成功!" br.Ret = 200 br.Success = true br.Data = resp }