kobe6258 6 дней назад
Родитель
Сommit
9b60fed095

+ 2 - 0
common/exception/exc_enums.go

@@ -113,6 +113,7 @@ const (
 	GetReportSearchRangeFailed
 	SearchKeyEmptyError
 	ReportRiskLevelUnSet
+	ReportDeleted
 )
 
 const (
@@ -253,6 +254,7 @@ var ErrorMap = map[int]string{
 	QueryReportPageFailed:        "分页查询报告列表失败",
 	SearchReportPageFailed:       "分页搜索报告列表失败",
 	GetReportFailed:              "获取研报详情失败",
+	ReportDeleted:                "研报已删除",
 	GetReportSearchRangeFailed:   "设置报告搜索范围失败",
 	SearchKeyEmptyError:          "搜索关键字不能为空",
 	ReportRiskLevelUnSet:         "报告未设置风险等级",

+ 6 - 1
controllers/report/report_controller.go

@@ -400,7 +400,12 @@ func (r *ReportController) GetReport(reportId int, productId int) {
 		wg.Wait()
 		reportDetail, err := report.GetReportById(reportId, isLogin(detailType), userInfo.Id)
 		if err != nil {
-			r.FailedResult("获取研报详情失败", result)
+			if exception.Equals(exception.ReportDeleted, err.Error()) {
+				r.FailedResult("报告已被删除,请返回重试", result)
+				err = exception.New(exception.ReportDeleted)
+				return
+			}
+			r.FailedResult("报告状态异常,请返回重试", result)
 			err = exception.New(exception.GetReportFailed)
 			return
 		}

+ 1 - 0
domian/report/eta_report_service.go

@@ -78,6 +78,7 @@ func GetETAReport(id int) (detail ETAReportDTO, err error) {
 	report, err := eta.GetETAReportById(id)
 	if err != nil {
 		logger.Error("获取ETA研报信息失败:%v", err)
+		return
 	}
 	var wg sync.WaitGroup
 	detail = convertToETAReportDTO(report)

+ 12 - 4
domian/report/report_service.go

@@ -626,7 +626,7 @@ func syncESAndSendMessage(reports []reportDao.Report) (err error) {
 			if !success {
 				logger.Error("更新es失败,reportId::%d,err:%v", report.ID, err)
 			}
-			if report.Status == reportDao.StatusUnPublish {
+			if report.Status == reportDao.StatusUnPublish || report.Status == reportDao.StatusDeleted {
 				//隐藏热度搜索
 				err = userDao.HiddenFlows(report.ID, message.ReportSourceType)
 				if err != nil {
@@ -665,8 +665,9 @@ func syncESAndSendMessage(reports []reportDao.Report) (err error) {
 	//生产meta信息
 	logger.Info("生成推送META信息")
 	for _, report := range reports {
-		if report.Status == reportDao.StatusUnPublish {
-			logger.Info("报告取消发布,不需要生成推送消息")
+		if report.Status == reportDao.StatusUnPublish || report.Status == reportDao.StatusDeleted {
+			logger.Info("报告取消发布或删除" +
+				",不需要生成推送消息")
 			continue
 		}
 		var From string
@@ -792,7 +793,10 @@ func InitHTReportList(list []ht.HTReport) (noRecord bool, err error) {
 }
 
 func htStatus(status int, isDelete int) reportDao.ReportStatus {
-	if isDelete == 1 || status != ht.Publish {
+	if isDelete == 1 {
+		return reportDao.StatusDeleted
+	}
+	if status != ht.Publish {
 		return reportDao.StatusUnPublish
 	}
 	return reportDao.StatusPublish
@@ -1176,3 +1180,7 @@ func GetReportListById(reportIds []int) (reportList []ReportDTO, err error) {
 	}
 	return
 }
+
+func DeleteReport(reportId int) (err error) {
+	return reportDao.DeleteReport(reportId)
+}

+ 15 - 1
models/eta/eta_report.go

@@ -1,10 +1,12 @@
 package eta
 
 import (
+	"errors"
 	"eta/eta_mini_ht_api/common/component/cache"
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/utils/redis"
 	"eta/eta_mini_ht_api/models"
+	"gorm.io/gorm"
 	"strings"
 	"time"
 )
@@ -99,8 +101,20 @@ func GetUpdateETAReports() (filterList []ETAReport, err error) {
 }
 
 func GetETAReportById(id int) (report ETAReport, err error) {
-	err = models.ETA().Table("report").Select(detailColumn).Where("id = ?", id).Where("state =? or state=?", Published, Passed).First(&report).Error
+	//err = models.ETA().Table("report").Select(detailColumn).Where("id = ?", id).Where("state =? or state=?", Published, Passed).First(&report).Error
+	//
+	err = models.ETA().Table("report").Select(detailColumn).Where("id = ?", id).First(&report).Error
 	if err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			logger.Error("查询eta报告失败,报告已删除,报告ID:%d", id)
+		} else {
+			logger.Error("查询eta报告失败:%v", err)
+		}
+		return
+	}
+	if report.State != Published && report.State != Passed {
+		logger.Error("eta报告未发布,ID:%d", id)
+		err = errors.New("eta报告未发布")
 		return
 	}
 	return

+ 9 - 4
models/report/report.go

@@ -24,10 +24,10 @@ const (
 	SourceHT        ReportSource = "HT"
 	StatusPublish                = "PUBLISH"
 	StatusUnPublish ReportStatus = "UNPUBLISH"
-
-	MaxBatchNum   = 1000
-	CommonColumns = "id,org_id,author,abstract,title,source,cover_src,published_time,status,plate_name,classify_id"
-	taskColumns   = "id,author,published_time,status,plate_name"
+	StatusDeleted   ReportStatus = "DELETED"
+	MaxBatchNum                  = 1000
+	CommonColumns                = "id,org_id,author,abstract,title,source,cover_src,published_time,status,plate_name,classify_id"
+	taskColumns                  = "id,author,published_time,status,plate_name"
 )
 
 type Report struct {
@@ -447,3 +447,8 @@ func GetReportListById(ids []int) (reports []Report, err error) {
 		Where("id in ?", ids).Find(&reports).Error
 	return
 }
+
+func DeleteReport(id int) error {
+	db := models.Main()
+	return db.Model(&Report{}).Where("id=?", id).Update("status", StatusDeleted).Error
+}

+ 10 - 0
service/report/report_service.go

@@ -174,6 +174,16 @@ func GetReportById(reportId int, login bool, userId int) (report *reportService.
 	err = getReportContent(report, login)
 	if err != nil {
 		logger.Error("获取研报失败:%v,研报ID:%d", err, report.ReportID)
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			//逻辑删除系统研报
+			deleteErr := reportService.DeleteReport(report.ReportID)
+			if deleteErr != nil {
+				logger.Error("报告删除失败:%v", deleteErr)
+			}
+			logger.Error("ETA报告删除")
+			err = exception.NewWithException(exception.ReportDeleted, err.Error())
+			return
+		}
 		err = exception.NewWithException(exception.GetReportFailed, err.Error())
 	}
 	return