package controllers import ( "encoding/json" "fmt" "hongze/hongze_cygx/models" "strings" "time" ) //报告 type ReportController struct { BaseAuthController } type ReportCommonController struct { BaseCommonController } // @Title 行业报告分类列表接口 // @Description 获取行业报告分类列表接口 // @Param ChartPermissionId query int true "分类ID" // @Success 200 {object} models.IndustrialManagementList // @router /home/tradeList [get] func (this *ReportController) TradeList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() ChartPermissionId, _ := this.GetInt("ChartPermissionId") if ChartPermissionId < 1 { br.Msg = "请输入分类ID" return } list, err := models.GetTradeAll(ChartPermissionId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } resp := new(models.TradeReportMappingResp) resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 产业报告分类列表接口 // @Description 获取产业报告分类列表接口 // @Param ChartPermissionId query int true "分类ID" // @Param OrderColumn query int true "排序字段 ,NewTime最近更新 ,Recommend弘则推荐" // @Success 200 {object} models.IndustrialManagementList // @router /home/industryList [get] func (this *ReportController) IndustryList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() ChartPermissionId, _ := this.GetInt("ChartPermissionId") if ChartPermissionId < 1 { br.Msg = "请输入分类ID" return } list, err := models.GetIndustrialManagementAll(ChartPermissionId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } for k, v := range list { var analystStr string analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } list[k].AnalystList = analystList industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } list[k].IndustrialSubjectList = industrialSubjectList if len(analystList) > 0 { for _, v2 := range analystList { analystStr += v2.AnalystName + "/" } analystStr = strings.TrimRight(analystStr, "/") } list[k].Analyst = analystStr } resp := new(models.IndustrialManagementList) resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 置顶/取消置顶 // @Description 置顶 // @Param request body models.CygxIndustryTopRep true "type json string" // @Success 200 // @router /top [post] func (this *ReportController) ArticleCollect() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } uid := user.UserId var req models.CygxIndustryTopRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } industrialManagementId := req.IndustrialManagementId fmt.Println(industrialManagementId) countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } if countIndustrial == 0 { br.Msg = "产业不存在!" br.ErrMsg = "产业不存在" return } count, err := models.GetCygxIndustryTop(uid, industrialManagementId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleCollectResp) if count <= 0 { item := new(models.CygxIndustryTop) item.IndustrialManagementId = req.IndustrialManagementId item.UserId = uid item.CreateTime = time.Now() _, err = models.AddCygxIndustryTop(item) if err != nil { br.Msg = "置顶失败" br.ErrMsg = "置顶失败,Err:" + err.Error() return } br.Msg = "置顶成功" resp.Status = 1 } else { err = models.RemoveCygxIndustryTop(uid, industrialManagementId) if err != nil { br.Msg = "取消置顶失败" br.ErrMsg = "取消置顶失败,Err:" + err.Error() return } br.Msg = "已取消置顶" resp.Status = 2 } br.Ret = 200 br.Success = true br.Data = resp }