ソースを参照

增加风险测评字段

kobe6258 6 ヶ月 前
コミット
31720d9f8f

+ 9 - 0
controllers/media/media_controller.go

@@ -148,7 +148,16 @@ func (m *MediaController) GetMedia(mediaType string, mediaId int) {
 			m.FailedResult("获取媒体详情失败", result)
 			return
 		}
+		detailType := m.Data["detailType"]
 		mediaDetail, err := media.GetMediaById(mediaType, mediaId)
+		switch detailType {
+		case "logout":
+			logger.Info("当前用户未登录,展示部分详情")
+			mediaDetail.Src = ""
+			mediaDetail.Login = false
+		case "login":
+			mediaDetail.Login = true
+		}
 		if err != nil {
 			m.FailedResult("获取媒体详情失败", result)
 			return

+ 15 - 1
controllers/report/report_controller.go

@@ -259,12 +259,26 @@ func (r *ReportController) Count() {
 func (r *ReportController) GetReport(reportId int) {
 	controllers.Wrap(&r.BaseController, func() (result *controllers.WrapData, err error) {
 		result = r.InitWrapData("获取研报详情失败")
-		reportDetail, err := report.GetReportById(reportId)
+		detailType := r.Data["detailType"]
+		var login bool
+		if detailType == "logout" {
+			logger.Info("当前用户未登录,展示部分详情")
+			login = false
+		}
+		if detailType == "login" {
+			login = true
+		}
+		reportDetail, err := report.GetReportById(reportId, login)
 		if err != nil {
 			r.FailedResult("获取研报详情失败", result)
 			err = exception.New(exception.GetReportFailed)
 			return
 		}
+		if detailType == "logout" {
+			logger.Info("当前用户未登录,展示部分详情")
+		}
+		if detailType == "login" {
+		}
 		r.SuccessResult("获取研报详情成功", reportDetail, result)
 		return
 	})

+ 1 - 0
domian/media/media_service.go

@@ -49,6 +49,7 @@ type MediaDTO struct {
 	PermissionIDs         string   `json:"permissionIds"`
 	PermissionNames       []string `json:"permissionNames,omitempty"`
 	Highlight             []string `json:"highlight,omitempty"`
+	Login                 bool     `json:"login"`
 }
 
 func SearchMediaList(mediaType string, key string, from int, size int, max int64) (reports []MediaDTO, err error) {

+ 1 - 0
domian/report/report_service.go

@@ -73,6 +73,7 @@ type ReportDTO struct {
 	PdfUrl           string          `json:"pdfUrl,omitempty"`
 	CoverSrc         int             `json:"coverSrc"`
 	CoverUrl         string          `json:"coverUrl"`
+	Login            bool            `json:"login"`
 }
 
 type Detail struct {

+ 32 - 0
middleware/auth_middleware.go

@@ -39,6 +39,10 @@ func rd() *cache.RedisCache {
 	return rdCache
 }
 
+var detailRoutes = []string{
+	"/media/media",
+	"/report/report",
+}
 var publicRoutes = []string{
 	"/auth/areaCodes",
 	"/auth/wxAppid",
@@ -123,6 +127,14 @@ func AuthMiddleware() web.FilterFunc {
 					return
 				}
 			}
+			//详情信息需要登录token才能看到全部
+			if detail(path) {
+				if info.TokenType != jwt.AccessToken || info.Mobile == "-" || info.Mobile == "" {
+					ctx.Input.SetData("detailType", "logout")
+				} else {
+					ctx.Input.SetData("detailType", "login")
+				}
+			}
 			//if userInfo.Mobile == "-" && path != baseUrl+"/auth/login" {
 			//	logger.Error("用户手机号为空:%v", err)
 			//	_ = ctx.JSONResp(illegalUser())
@@ -186,6 +198,26 @@ func allowed(path string) bool {
 	return false
 }
 
+func detail(path string) bool {
+	for _, p := range detailRoutes {
+		if stringUtils.IsBlank(p) {
+			continue
+		}
+		src := baseUrl + p
+		if strings.HasSuffix(p, "*") {
+			target := src[:len(src)-1]
+			if strings.HasPrefix(path, target) {
+				return true
+			}
+		} else {
+			if src == path {
+				return true
+			}
+		}
+	}
+	return false
+}
+
 func needCheckLoginStatus(path string) bool {
 	for _, p := range privateRoutes {
 		if stringUtils.IsBlank(p) {

+ 2 - 1
models/eta/eta_report.go

@@ -11,7 +11,7 @@ import (
 
 const (
 	colunms      = "id,author,abstract,title,publish_time,state,modify_time,"
-	detailColumn = "id,author,abstract,title,publish_time,content,collaborate_type,report_layout,video_url,video_name,video_play_seconds,head_resource_id,end_resource_id,has_chapter,need_splice,state,modify_time"
+	detailColumn = "id,author,abstract,title,publish_time,content,content_sub,collaborate_type,report_layout,video_url,video_name,video_play_seconds,head_resource_id,end_resource_id,has_chapter,need_splice,state,modify_time"
 	Published    = 2
 	Passed       = 6
 
@@ -46,6 +46,7 @@ type ETAReport struct {
 	Author           string    `gorm:"column:author;size:50;"`
 	PublishTime      time.Time `gorm:"column:publish_time"`
 	Content          string    `gorm:"column:content"`
+	ContentSub       string    `gorm:"column:content_sub"`
 	CollaborateType  int       `gorm:"column:collaborate_type"`
 	ReportLayout     int       `gorm:"column:report_layout"`
 	VideoUrl         string    `gorm:"column:video_url"`

+ 16 - 4
service/report/report_service.go

@@ -60,23 +60,29 @@ type RecordCount struct {
 	Additional string
 }
 
-func GetReportById(reportId int) (report reportService.ReportDTO, err error) {
+func GetReportById(reportId int, login bool) (report reportService.ReportDTO, err error) {
 	report, err = reportService.GetGetReportById(reportId)
 	if err != nil {
 		logger.Error("获取研报失败:%v", err)
 		err = exception.New(exception.GetReportFailed)
 		return
 	}
-	var detail interface{}
 	var pdfUrl string
 	switch report.Source {
 	case SourceETA:
+		var detail reportService.ETAReportDTO
 		detail, err = getETAReportDetail(&report)
 		if err != nil {
-			logger.Error("获取研报详情失败失败:%v")
+			logger.Error("获取研报详情失败失败:%v", err)
 			err = exception.New(exception.GetReportFailed)
 			return
 		}
+		if !login {
+			detail.Content = ""
+			report.Login = false
+		} else {
+			report.Login = true
+		}
 		var jsonStr []byte
 		jsonStr, err = json.Marshal(detail)
 		if err != nil {
@@ -92,7 +98,13 @@ func GetReportById(reportId int) (report reportService.ReportDTO, err error) {
 			err = exception.New(exception.GetReportFailed)
 			return
 		}
-		report.PdfUrl = pdfUrl
+		if !login {
+			report.PdfUrl = ""
+			report.Login = false
+		} else {
+			report.PdfUrl = pdfUrl
+			report.Login = true
+		}
 		return
 	default:
 		logger.Error("不支持的研报来演:%v")