Ver Fonte

过滤下架产品

kobe6258 há 4 meses atrás
pai
commit
4bedfaf98b
2 ficheiros alterados com 69 adições e 5 exclusões
  1. 1 1
      models/config/permission.go
  2. 68 4
      service/report/report_service.go

+ 1 - 1
models/config/permission.go

@@ -93,7 +93,7 @@ func GetSecondPermissionsByClassifyID(classifyId int) (permissionList []Permissi
 	//sql := "select chart_permission_id, permission_name from chart_permission WHERE chart_permission_id in( select DISTINCT cpskwp.chart_permission_id from chart_permission_search_key_word_mapping cpskwp  where cpskwp.classify_id=? order by cpskwp.chart_permission_id)"
 	//err = doSql(sql, &chartPermissionList, classifyID)
 	db := models.Main()
-	err = db.Model(&Permission{}).Select("permission_id, name").Where("permission_id in ( select DISTINCT pcm.permission_id from permission_classify_mapping pcm  where pcm.classify_id=? order by pcm.permission_id)", classifyId).Find(&permissionList).Error
+	err = db.Model(&Permission{}).Select("permission_id, name,risk_level").Where("permission_id in ( select DISTINCT pcm.permission_id from permission_classify_mapping pcm  where pcm.classify_id=? order by pcm.permission_id)", classifyId).Find(&permissionList).Error
 	return
 }
 

+ 68 - 4
service/report/report_service.go

@@ -1,6 +1,7 @@
 package report
 
 import (
+	"encoding/json"
 	"errors"
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/exception"
@@ -154,17 +155,28 @@ func GetReportById(reportId int, login bool, userId int) (report *reportService.
 	var reportInfo reportService.ReportDTO
 	reportInfo, err = reportService.GetReportById(reportId)
 	if err != nil {
-		logger.Error("获取研报失败:%v", err)
+		logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
 		err = exception.NewWithException(exception.GetReportFailed, err.Error())
 		return
 	}
 	mappingRiskLevel, userRiskStatus, err := user.CheckUserRiskMatchStatus(userId)
 	if err != nil {
-		logger.Error("获取研报失败:%v", err)
+		logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
 		err = exception.NewWithException(exception.GetReportFailed, err.Error())
 		return
 	}
-	return DealReportInfo(&reportInfo, login, userId, mappingRiskLevel, userRiskStatus)
+	report, err = DealReportInfo(&reportInfo, login, userId, mappingRiskLevel, userRiskStatus)
+	if err != nil {
+		logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
+		err = exception.NewWithException(exception.GetReportFailed, err.Error())
+		return
+	}
+	err = getReportContent(report, login)
+	if err != nil {
+		logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
+		err = exception.NewWithException(exception.GetReportFailed, err.Error())
+	}
+	return
 }
 
 func GetTotalPageCountByPermissionIds(permissionIds []int, isLogin bool, userId int) (total int64, latestId int64, ids map[string][]int, disCardIds []int, mappingRiskLevel, userRiskStatus string) {
@@ -222,7 +234,59 @@ func dealReportInfo(list []reportService.ReportDTO, isLogin bool, userId int, ma
 	resultList = list
 	return
 }
+func getETAReportDetail(report *reportService.ReportDTO) (etaReport reportService.ETAReportDTO, err error) {
+	return reportService.GetETAReport(report.OrgId)
+}
 
+func getHTReportDetail(report *reportService.ReportDTO) (url string, err error) {
+	return reportService.GetHtReport(report.OrgId)
+}
+func getReportContent(report *reportService.ReportDTO, login bool) (err error) {
+	var pdfUrl string
+	switch report.Source {
+	case SourceETA:
+		var detail reportService.ETAReportDTO
+		detail, err = getETAReportDetail(report)
+		if err != nil {
+			logger.Error("获取研报详情失败失败:%v", err)
+			return
+		}
+		if !login {
+			detail.Content = ""
+		} else {
+			if report.RiskLevelStatus != RiskLevelMatch {
+				detail.Content = ""
+			}
+		}
+		var jsonStr []byte
+		jsonStr, err = json.Marshal(detail)
+		if err != nil {
+			logger.Error("生成研报详情失败:%v", err)
+			return
+		}
+		report.Detail = jsonStr
+		return
+	case SourceHT:
+		pdfUrl, err = getHTReportDetail(report)
+		if err != nil {
+			logger.Error("获取研报详情失败失败:%v")
+			err = exception.New(exception.GetReportFailed)
+			return
+		}
+		if !login {
+			report.PdfUrl = ""
+		} else {
+			if report.RiskLevelStatus == RiskLevelMatch {
+				report.PdfUrl = pdfUrl
+			}
+		}
+		return
+	default:
+		logger.Error("不支持的研报来演:%v")
+		err = exception.New(exception.GetReportFailed)
+		return
+	}
+}
 func DealReportInfo(report *reportService.ReportDTO, isLogin bool, userId int, mappingRiskLevel, userRiskStatus string) (resultReport *reportService.ReportDTO, err error) {
 	report.Login = isLogin
 	report.Permissions, report.PermissionNames = GetReportPermissionNames(report.OrgId, report.Source)
@@ -339,8 +403,8 @@ func DealReportInfo(report *reportService.ReportDTO, isLogin bool, userId int, m
 			}
 		}
 	}
-
 	resultReport = report
+
 	return
 }