Ver Fonte

fix:修复研报添加版头,然后在版图素材库中删掉该版头,提示操作失败,并清空了研报内容

Roc há 2 meses atrás
pai
commit
2bfc458058
2 ficheiros alterados com 24 adições e 15 exclusões
  1. 12 7
      controllers/report_share.go
  2. 12 8
      controllers/smart_report.go

+ 12 - 7
controllers/report_share.go

@@ -3,6 +3,7 @@ package controllers
 import (
 	"encoding/json"
 	"eta/eta_report/models"
+	"eta/eta_report/utils"
 	"fmt"
 	"html"
 	"strings"
@@ -46,24 +47,28 @@ func (this *ReportShareController) Detail() {
 
 	if report.HeadResourceId > 0 {
 		headResource, err := models.GetResourceItemById(report.HeadResourceId)
-		if err != nil {
+		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "操作失败"
 			br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
 			return
 		}
-		report.HeadImg = headResource.ImgUrl
-		report.HeadStyle = headResource.Style
+		if headResource != nil && headResource.ResourceId > 0 {
+			report.HeadImg = headResource.ImgUrl
+			report.HeadStyle = headResource.Style
+		}
 	}
 
 	if report.EndResourceId > 0 {
 		endResource, err := models.GetResourceItemById(report.EndResourceId)
-		if err != nil {
+		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "操作失败"
-			br.ErrMsg = "获取资源库版失败, Err: " + err.Error()
+			br.ErrMsg = "获取资源库版失败, Err: " + err.Error()
 			return
 		}
-		report.EndImg = endResource.ImgUrl
-		report.EndStyle = endResource.Style
+		if endResource != nil && endResource.ResourceId > 0 {
+			report.EndImg = endResource.ImgUrl
+			report.EndStyle = endResource.Style
+		}
 	}
 
 	resp := new(models.ReportShareDetailResp)

+ 12 - 8
controllers/smart_report.go

@@ -53,24 +53,28 @@ func (this *SmartReportController) Detail() {
 	resp.Report = models.FormatSmartReport2Item(item)
 	if resp.Report.HeadResourceId > 0 {
 		headResource, err := models.GetResourceItemById(resp.Report.HeadResourceId)
-		if err != nil {
+		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "操作失败"
-			br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
+			br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
 			return
 		}
-		resp.Report.HeadImg = headResource.ImgUrl
-		resp.Report.HeadStyle = headResource.Style
+		if headResource != nil && headResource.ResourceId > 0 {
+			resp.Report.HeadImg = headResource.ImgUrl
+			resp.Report.HeadStyle = headResource.Style
+		}
 	}
 
 	if resp.Report.EndResourceId > 0 {
 		endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
-		if err != nil {
+		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "操作失败"
-			br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
+			br.ErrMsg = "获取资源库版尾失败, Err: " + err.Error()
 			return
 		}
-		resp.Report.EndImg = endResource.ImgUrl
-		resp.Report.EndStyle = endResource.Style
+		if endResource != nil && endResource.ResourceId > 0 {
+			resp.Report.EndImg = endResource.ImgUrl
+			resp.Report.EndStyle = endResource.Style
+		}
 	}
 	// 免责声明
 	conf, e := models.GetBusinessConf()