|
@@ -0,0 +1,232 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "hongze/hongze_cygx/models"
|
|
|
+ "hongze/hongze_cygx/services"
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// 报告
|
|
|
+type ReportSelectionController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 获取报告精选详情
|
|
|
+// @Description 获取报告精选详情接口
|
|
|
+// @Param ArticleId query int true "报告ID"
|
|
|
+// @Param IsBestNew query bool false "是否获取最新的一篇报告"
|
|
|
+// @Success 200 {object} models.ReportSelectionLetailResp
|
|
|
+// @router /detail [get]
|
|
|
+func (this *ReportSelectionController) Detail() {
|
|
|
+ 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
|
|
|
+ articleId, _ := this.GetInt("ArticleId")
|
|
|
+ isBestNew, _ := this.GetBool("IsBestNew")
|
|
|
+ if isBestNew {
|
|
|
+ tbdb := "cygx_report_selection"
|
|
|
+ condition := ` AND publish_status = 1 `
|
|
|
+ var pars []interface{}
|
|
|
+ list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range list {
|
|
|
+ articleId = v.ArticleId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if articleId < 1 {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp := new(models.ReportSelectionLetailResp)
|
|
|
+ //判断用户权限
|
|
|
+ hasPermission, err := services.GetUserhasPermission(user)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
|
|
|
+ }
|
|
|
+ detail, err := models.GetCygxReportSelectionInfoById(articleId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //未设置全部可见的只能给弘则内部查看
|
|
|
+ if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
|
|
|
+ resp.IsShow = true
|
|
|
+ }
|
|
|
+ fmt.Println(resp.IsShow)
|
|
|
+ resp.HasPermission = hasPermission
|
|
|
+ if hasPermission != 1 || !resp.IsShow {
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if detail.ReportLink != "" {
|
|
|
+ articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
|
|
|
+ detail.CeLueArticleId = articleIdLink
|
|
|
+ }
|
|
|
+ detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
|
|
|
+ existMap := make(map[int]int)
|
|
|
+ var items []*models.ReportSelectionChartPermission
|
|
|
+ var itemsSubject []*models.ReportSelectionChartLogPermission
|
|
|
+ listLog, err := models.GetReportSelectionlogListAll(articleId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
|
|
|
+ //获取行业核心逻辑汇总
|
|
|
+ listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ mapChartLog := make(map[string]string)
|
|
|
+ for _, v := range listChartLog {
|
|
|
+ mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
|
|
|
+ }
|
|
|
+ for _, v := range listLog {
|
|
|
+ item := new(models.ReportSelectionChartPermission)
|
|
|
+ itemSubject := new(models.ReportSelectionChartLogPermission)
|
|
|
+ itemSubject.PermissionName = v.PermissionName
|
|
|
+ if existMap[v.ChartPermissionId] == 0 {
|
|
|
+ //item.PermissionName = v.PermissionName + "领域深度报告和调研"
|
|
|
+ item.PermissionName = v.PermissionName
|
|
|
+ item.IcoLink = v.IcoLink
|
|
|
+ listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for k2, v2 := range listSonLog {
|
|
|
+ if v2.IndustrialManagementId != "" {
|
|
|
+ listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ listSonLog[k2].List = listIndustrial
|
|
|
+ if v2.Label != "" {
|
|
|
+ v2.CompanyLabel = strings.Split(v2.Label, "{|}")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
|
|
|
+ }
|
|
|
+ item.BodyChartSummary = mapChartLog[v.PermissionName]
|
|
|
+ item.List = listSonLog
|
|
|
+ items = append(items, item)
|
|
|
+ itemsSubject = append(itemsSubject, itemSubject)
|
|
|
+ //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
|
|
|
+ }
|
|
|
+ existMap[v.ChartPermissionId] = v.ChartPermissionId
|
|
|
+ }
|
|
|
+
|
|
|
+ historyRecord := new(models.CygxReportHistoryRecord)
|
|
|
+ historyRecord.UserId = uid
|
|
|
+ historyRecord.ArticleId = articleId
|
|
|
+ historyRecord.CreateTime = time.Now()
|
|
|
+ historyRecord.Mobile = user.Mobile
|
|
|
+ historyRecord.Email = user.Email
|
|
|
+ historyRecord.CompanyId = user.CompanyId
|
|
|
+ historyRecord.CompanyName = user.CompanyName
|
|
|
+ historyRecord.ReportType = "bgjx"
|
|
|
+ sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取信息失败"
|
|
|
+ br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ historyRecord.RealName = user.RealName
|
|
|
+ if sellerItem != nil {
|
|
|
+ historyRecord.SellerName = sellerItem.RealName
|
|
|
+ }
|
|
|
+
|
|
|
+ go models.AddCygxReportHistoryRecord(historyRecord)
|
|
|
+ resp.List = items
|
|
|
+ resp.ListPermissionSubject = itemsSubject
|
|
|
+ resp.Detail = detail
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 标的点击记录
|
|
|
+// @Description 标的点击记录接口
|
|
|
+// @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
|
|
|
+// @router /click/history [post]
|
|
|
+func (this *ReportSelectionController) ClickHistory() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ var req models.AddCygxReportSelectionSubjectHistoryReq
|
|
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.ArticleId <= 0 {
|
|
|
+ br.Msg = "文章不存在"
|
|
|
+ br.ErrMsg = "文章不存在,文章ID错误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if req.IndustrialSubjectId <= 0 {
|
|
|
+ br.Msg = "标的ID不存在"
|
|
|
+ br.ErrMsg = "标的ID不存在,标的ID错误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item := models.CygxReportSelectionSubjectHistory{
|
|
|
+ UserId: user.UserId,
|
|
|
+ ArticleId: req.ArticleId,
|
|
|
+ CreateTime: time.Now(),
|
|
|
+ ModifyTime: time.Now(),
|
|
|
+ Mobile: user.Mobile,
|
|
|
+ Email: user.Email,
|
|
|
+ CompanyId: user.CompanyId,
|
|
|
+ CompanyName: user.CompanyName,
|
|
|
+ IndustrialSubjectId: req.IndustrialSubjectId,
|
|
|
+ }
|
|
|
+ err = models.AddCygxReportSelectionSubjectHistory(&item)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "记录失败"
|
|
|
+ br.ErrMsg = "记录失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "记录成功"
|
|
|
+}
|