package controllers import ( "encoding/json" "hongze/hongze_api/cache" "hongze/hongze_api/models" "hongze/hongze_api/services" "hongze/hongze_api/utils" "html" "strconv" "time" ) //报告 type ReportController struct { BaseAuthController } //报告 type ReportCommonController struct { BaseCommonController } // @Title 日评详情 // @Description 日评详情接口 // @Param ReportId query int true "报告id" // @Success 200 {object} models.ReportDetailResp // @router /detail [get] func (this *ReportController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var status int var msg string reportId, err := this.GetInt("ReportId") if err != nil { br.Msg = "参数获取失败" br.ErrMsg = "参数获取失败,Err:" + err.Error() return } if reportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,报告id小于等于0" return } report, err := models.GetReportById(reportId) if err != nil { br.Msg = "该报告已删除" br.ErrMsg = "获取报告详情失败,Err:" + err.Error() return } if report == nil { status = 1 msg = "报告不存在" } report.ContentSub = html.UnescapeString(report.ContentSub) report.Content = html.UnescapeString(report.Content) productId := 1 maxPermissionCount := 0 maxPermissionCount, err = models.GetDefaultChartPermissionCountByCache(productId) if err != nil { br.Msg = "获取报告详情失败" br.ErrMsg = "获取产品默认最大权限数量失败,Err:" + err.Error() return } utils.FileLog.Info("report.detail %d,%d", user.CompanyId, productId) status, checkInfo, company, msg, brMsg, brErrMsg := services.CheckUserReportPermission(user, productId, report, maxPermissionCount) if brMsg != "" { br.Msg = brMsg br.ErrMsg = brErrMsg return } /*company, err := models.GetCompanyProductById(user.CompanyId, productId) if err != nil { if err.Error() != utils.ErrNoRow() { br.Msg = "获取报告详情失败" br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error() return } else { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" } } if company == nil { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" } else { if company.Status == utils.COMPANY_STATUS_LOSE || company.Status == utils.COMPANY_STATUS_FREEZE { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" } } if productId == 1 { reportType := "rddp" reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id if err != nil { if err.Error() != utils.ErrNoRow() { br.Msg = "获取报告详情失败" br.ErrMsg = "获取客户信息失败,Err:" + err.Error() return } else { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" } } if len(reportPermissionList) == 0 { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" } permissionMap := make(map[int]int) for _, v := range reportPermissionList { if _, ok := permissionMap[v.ReportChapterTypeId]; !ok { permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId } } if _, ok := permissionMap[reportId]; !ok { tips := "" status = 2 classifyNameSecond := report.ClassifyNameSecond if strings.Contains(classifyNameSecond, "宏观商品复盘") || strings.Contains(classifyNameSecond, "股债日评") || strings.Contains(classifyNameSecond, "每日经济数据备忘录") { tips = "宏观" } else if strings.Contains(classifyNameSecond, "知白守黑日评") || strings.Contains(classifyNameSecond, "动力煤数据点评") { tips = "黑色" } else if strings.Contains(classifyNameSecond, "化里化外日评") || strings.Contains(classifyNameSecond, "EIA原油库存点评") || strings.Contains(classifyNameSecond, "苯乙烯数据点评") || strings.Contains(classifyNameSecond, "聚酯数据点评") { tips = "化工" } else if strings.Contains(classifyNameSecond, "有声有色日度闲篇") { tips = "有色" } msg = "您还未开通" + tips + "权限,如有需要请联系对口销售" } }*/ if report.ClassifyNameFirst == "权益研报" { if report.ClassifyNameSecond == "近期路演精华" { report.TitleType = "路演精华" } else { report.TitleType = "权益" } } else { report.TitleType = "FICC" } //判断大小权限 /*{ if status == 2 { if company != nil { permissionCount, err := models.GetCompanyProductPermissionCount(company.CompanyId, productId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取权限信息失败,Err:" + err.Error() return } if permissionCount >= maxPermissionCount { status = 0 msg = "" } } } } //如果客户产品被禁用了,只有在试用状态下,才不允许查看报告,那么没有权限 if company != nil && company.IsSuspend > 0 && company.Status == "试用" { status = 2 msg = "您还未开通权限,如有需要请联系对口销售" }*/ if status == 2 { report.Content = report.ContentSub report.VideoUrl = "" report.VideoSize = "" report.VideoPlaySeconds = "" report.VideoName = "" } resp := new(models.ReportDetailResp) resp.Status = status resp.Msg = msg resp.Report = report //新增阅读记录 if status == 0 { record := new(models.ReportViewRecord) record.UserId = user.UserId record.ReportId = reportId record.Mobile = user.Mobile record.Email = user.Email record.RealName = user.RealName record.CompanyName = company.CompanyName record.CreateTime = time.Now() err = models.AddReportViewRecord(record) if err != nil { go utils.SendEmail(utils.APPNAME+"失败提醒", "新增报告阅读记录失败:Err:"+err.Error(), utils.EmailSendToUsers) } // 添加阅读日志的数据加入到redis go cache.PushViewRecordNewRedisData(record, user.CompanyId) //修改联系人最后一次阅读报告时间 go models.SetWxUserReportLastViewTime(user.UserId) } reportType := 0 if report.ClassifyNameFirst == "权益研报" { reportType = 1 } else { reportType = 2 } recommendList, err := models.GetRecommendList(reportId, reportType) if err != nil { br.Msg = "获取报告详情失败" br.ErrMsg = "获取报告推荐列表信息失败,Err:" + err.Error() return } recommendListLen := len(recommendList) for i := 0; i < recommendListLen; i++ { item := recommendList[i] recommendList[i].Content = html.UnescapeString(item.Content) recommendList[i].ContentSub = html.UnescapeString(item.ContentSub) count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond) if err != nil { br.Msg = "获取报告详情失败" br.ErrMsg = "判断报告权限信息失败,Err:" + err.Error() return } if count > 0 { recommendList[i].HasPermission = 1 } if item.ClassifyNameFirst == "权益研报" { if recommendList[i].ClassifyNameSecond == "近期路演精华" { recommendList[i].TitleType = "路演精华" } else { recommendList[i].TitleType = "权益" } } else { recommendList[i].TitleType = "FICC" } } resp.RecommendList = recommendList item, err := models.GetClassifyDetailById(report.ClassifyIdSecond) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取详情专栏失败,Err:" + err.Error() return } //新增访问日志 { record := new(models.UserAccessRecord) record.Uid = user.UserId record.Token = this.Token record.CreateTime = time.Now() record.Remark = strconv.Itoa(status) record.ReportId = reportId go models.AddUserAccessRecord(record) } resp.Classify = item resp.PermissionCheckInfo = checkInfo br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 日评列表 // @Description 日评列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param ClassifyId query int true "分类id" // @Success 200 {object} models.ReportListResp // @router /list [get] func (this *ReportController) ListReport() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") classifyId, _ := this.GetInt("ClassifyId") if classifyId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,分类id小于等于0" return } var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = utils.StartIndex(currentIndex, pageSize) total, err := models.GetReportListCount(classifyId) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } list, err := models.GetReportList(classifyId, startSize, pageSize) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() return } var hasPermission bool userPermission, err := services.CheckUserPermission(this.User.UserId) if err != nil { br.Msg = "绑定失败" br.ErrMsg = "绑定失败,判断权限失败:" + err.Error() return } if userPermission == 0 { hasPermission = true } reportType := "rddp" reportPermissionList, err := models.GetReportVarietyListByUserIdExt(user.UserId, reportType) //获取客户拥有权限的报告id if err != nil { if err.Error() != utils.ErrNoRow() { br.Msg = "获取报告详情失败" br.ErrMsg = "获取客户信息失败,Err:" + err.Error() return } else { hasPermission = false } } if len(reportPermissionList) == 0 { hasPermission = false } permissionMap := make(map[int]int) for _, v := range reportPermissionList { if _, ok := permissionMap[v.ReportChapterTypeId]; !ok { permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId } } listLen := len(list) for i := 0; i < listLen; i++ { item := list[i] count, err := models.GetReportPermission(user.UserId, item.ClassifyNameSecond) if err != nil { br.Msg = "获取失败" br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error() return } if count > 0 { list[i].HasPermission = 1 } if item.ClassifyNameFirst == "权益研报" { if list[i].ClassifyNameSecond == "近期路演精华" { list[i].TitleType = "路演精华" } else { list[i].TitleType = "权益" } } else { list[i].TitleType = "FICC" } if _, ok := permissionMap[item.Id]; !ok { list[i].VideoUrl = "" list[i].VideoName = "" list[i].VideoName = "" list[i].VideoPlaySeconds = "" } if hasPermission == false { list[i].VideoUrl = "" list[i].VideoName = "" list[i].VideoName = "" list[i].VideoPlaySeconds = "" } } page := models.GetPaging(currentIndex, pageSize, total) resp := new(models.ReportListResp) resp.Paging = page resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 新增报告浏览记录 // @Description 新增报告浏览记录接口 // @Param request body models.ReportRecordReq true "type json string" // @Success 200 新增成功 // @router /addUpdateLabel [post] func (this *ReportController) AddUpdateLabelReport() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.ReportRecordReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ReportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,报告id小于等于0" return } record := new(models.ReportViewLog) record.UserId = user.UserId record.ReportId = req.ReportId record.CreateTime = time.Now() err = models.AddReportViewLog(record) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "新增成功" } // @Title 新增报告浏览记录 // @Description 新增报告浏览记录接口 // @Param request body models.ReportRecordReq true "type json string" // @Success 200 新增成功 // @router /addViewRecord [post] func (this *ReportController) AddViewRecordReport() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.ReportRecordReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ReportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,报告id小于等于0" return } //查询企业信息 company, err := models.GetCompanyInfoById(user.CompanyId) if err != nil { if err.Error() != utils.ErrNoRow() { br.Msg = "获取用户管理企业信息失败" br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error() return } else { br.Msg = "获取用户管理企业信息失败" br.ErrMsg = "您还未开通权限,如有需要请联系对口销售" return } } record := new(models.ReportViewRecord) record.UserId = user.UserId record.ReportId = req.ReportId record.Mobile = user.Mobile record.Email = user.Email record.RealName = user.RealName record.CompanyName = company.CompanyName record.CreateTime = time.Now() err = models.AddReportViewRecord(record) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } // 添加阅读日志的数据加入到redis go cache.PushViewRecordNewRedisData(record, user.CompanyId) //修改联系人最后一次阅读报告时间 go models.SetWxUserReportLastViewTime(user.UserId) br.Ret = 200 br.Success = true br.Msg = "新增成功" } // @Title 新增音频阅读记录 // @Description 新增音频阅读记录接口 // @Param request body models.ReportRecordReq true "type json string" // @Success 200 新增成功 // @router /addAudioRecord [post] func (this *ReportController) AddAudioRecord() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.ReportRecordReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.ReportId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误,报告id小于等于0" return } record := new(models.ReportAudioRecord) record.UserId = user.UserId record.ReportId = req.ReportId record.CreateTime = time.Now() err = models.AddReportAudioRecord(record) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "新增成功" } //func init() { // fmt.Println("start") // content:=`<p><strong><u>需要开始观察和警惕全球库存周期回摆对资产价格的压力</u></strong></p><p>从经济惊喜指数上看,8月以来欧美和新兴市场的走势出现了显著的背离,美国和欧洲的经济惊喜指数都在8月见顶,9月开始回落,而新兴市场的经济惊喜指数却在一路上行。新兴市场的走强不是中国带动的,因为中国的经济惊喜指数从8月开始就基本保持稳定。新兴市场的强势更多是由于自身的原因。</p><p><iframe src="https://vmp.hzinsights.com/element/750/citibank_economic_surprise_index/%7C%7C%7C%7C%7C/" width="100%" height="350" border="none" style="border-width:0px; min-height:350px;"></iframe></p><p>新兴市场经济强势的根本原因是什么?是因为疫情之后自身的经济比欧美恢复得更好么?显然不是。我们以巴西为例,看巴西的制造业PMI,已经到达突破历史的“逆天水平”。</p><p><iframe src="https://vmp.hzinsights.com/element/762/brazil_pmi_stock_market/%7C%7C%7C%7C%7C/" width="100%" height="350" border="none" style="border-width:0px; min-height:350px;"></iframe></p>` // newContent:=html.UnescapeString(content) // utils.FileLog.Info("%s",newContent) // fmt.Println("end") //} // @Title 获取报告作者详情 // @Description 获取报告作者详情 // @Param ReportAuthor query string true "作者名称" // @Success 200 {object} models.ReportDetailResp // @router /author/detail [get] func (this *ReportController) AuthorDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } reportAuthor := this.GetString("ReportAuthor") if reportAuthor == "" { br.Msg = "参数错误" br.ErrMsg = "作者名称不能为空" return } author, err := models.GetReportAuthor(reportAuthor) if err != nil { br.Msg = "获取作者详情失败" br.ErrMsg = "获取作者详情失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = author }