Browse Source

Merge branch 'hotfix/oss_0211' into debug

hsun 1 month ago
parent
commit
2e04ca68bd

+ 24 - 3
controllers/report_open.go

@@ -400,7 +400,7 @@ func (this *ReportOpenController) ReportApprove() {
 			if req.ApproveType == 1 {
 				// 审批通过,将PPT或研报加入报告库中
 				go func() {
-					msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.DetailPdfUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now())
+					msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.DetailPdfUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now(), "")
 					if err != nil {
 						utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceAdd-报告知识资源库添加失败,reportId:%d,msg:%s,err: %v", v.Id, msg, err))
 						return
@@ -519,7 +519,7 @@ func (this *ReportOpenController) ReportApprove() {
 			if req.ApproveType == 1 {
 				// 审批通过,将PPT或研报加入报告库中
 				go func() {
-					msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.PptxUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now())
+					msg, err := knowledge.ReportKnowledgeResourceAdd(v.Title, []string{v.PptxUrl}, v.AdminId, v.AdminRealName, "市场研究报告/内部报告/日常报告", "市场信息研究所", time.Now(), "")
 					if err != nil {
 						utils.FileLog.Error(fmt.Sprintf("ReportKnowledgeResourceAdd-PPT知识资源报告库添加失败,pptId:%d,msg:%s,err: %v", v.PptId, msg, err))
 						return
@@ -821,6 +821,27 @@ func (this *ReportOpenController) ReportKnowledgeUpload() {
 		br.Msg = "发布时间格式不正确"
 		return
 	}
+	fmt.Printf("ReportKnowledgeUpload EmailUid: %s\n", req.EmailUid)
+
+	// 校验邮件UID是否已存在,若已存在那么不再重复上传和生成
+	if req.EmailUid != "" {
+		resourceOb := new(models.KnowledgeResource)
+		var cond string
+		var pars []interface{}
+		cond += ` AND email_uid = ?`
+		pars = append(pars, req.EmailUid)
+		count, e := resourceOb.GetCountByCondition(cond, pars)
+		if e != nil {
+			return
+		}
+		if count > 0 {
+			br.Ret = 200
+			br.Msg = "邮件资源已上传,忽略"
+			br.Success = true
+			return
+		}
+	}
+
 	fileUrls, msg, err := knowledge.UploadFormFile(this.Ctx.Request.MultipartForm.File)
 	if err != nil {
 		if msg == "" {
@@ -830,7 +851,7 @@ func (this *ReportOpenController) ReportKnowledgeUpload() {
 		br.ErrMsg = fmt.Sprintf("上传失败, %v", err)
 		return
 	}
-	msg, err = knowledge.ReportKnowledgeResourceAdd(req.Title, fileUrls, 0, "", req.ClassifyPath, req.Source, pushTime)
+	msg, err = knowledge.ReportKnowledgeResourceAdd(req.Title, fileUrls, 0, "", req.ClassifyPath, req.Source, pushTime, req.EmailUid)
 	if err != nil {
 		if msg == "" {
 			msg = "保存失败"

+ 8 - 0
models/knowledge_resource.go

@@ -3,6 +3,7 @@ package models
 import (
 	"eta_gn/eta_report/global"
 	"eta_gn/eta_report/utils"
+	"fmt"
 	"time"
 )
 
@@ -72,6 +73,7 @@ type KnowledgeResource struct {
 	OutId               int        `gorm:"column:out_id" description:"外部系统ID"`
 	IsDelete            int        `gorm:"column:is_delete;default:0;NOT NULL"`
 	OutSource           int        `gorm:"column:out_source" description:"外部来源:0:内部 1:智力共享 2:数据节点"`
+	EmailUid            string     `gorm:"column:email_uid" description:"邮件的UID"`
 }
 
 func (k KnowledgeResource) TableName() string {
@@ -159,3 +161,9 @@ func (k *KnowledgeClassify) GetChildClassifyIdByNamePath(resourceType int, class
 	err = global.DEFAULT_DmSQL.Raw(sql, classifyNameSecond, classifyNameThird, classifyNameFirst, resourceType).Scan(&id).Error
 	return
 }
+
+func (k *KnowledgeResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, k.TableName(), condition)
+	err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
+	return
+}

+ 1 - 0
models/report_open.go

@@ -58,4 +58,5 @@ type ReportKnowledgeUploadRep struct {
 	Source       string `form:"source" description:"文件来源"`
 	ClassifyPath string `form:"classify_path" description:"文件分类路径"`
 	PushTime     string `form:"push_time" description:"上传时间"`
+	EmailUid     string `form:"email_uid" description:"邮件在邮箱中的唯一ID"`
 }

+ 4 - 2
services/aws_s3.go

@@ -66,8 +66,10 @@ func (m *S3Oss) UploadFile(fileName, localFile, savePath string) (resourceUrl st
 
 	// 默认使用后端这个, 这里有两个配置的原因是
 	// 前端上传跨域问题可能会使用反向代理来解决, 这样的话同一个endpoint就会导致一端正常另一端不正常
-	endpoint := utils.S3Endpoint
-
+	endpoint := utils.S3BackEndpoint
+	if endpoint == "" {
+		endpoint = utils.S3Endpoint
+	}
 	accessKey := utils.S3AccessKeyId
 	secretKey := utils.S3AccessKeySecret
 	region := utils.S3Region

+ 2 - 1
services/knowledge/knowledge_resource.go

@@ -15,7 +15,7 @@ import (
 	"time"
 )
 
-func ReportKnowledgeResourceAdd(title string, fileUrl []string, adminId int, adminRealName, classifyPath, sourceFrom string, pushTime time.Time) (msg string, err error) {
+func ReportKnowledgeResourceAdd(title string, fileUrl []string, adminId int, adminRealName, classifyPath, sourceFrom string, pushTime time.Time, emailUid string) (msg string, err error) {
 	classifyObj := new(models.KnowledgeClassify)
 	var childClassifyId int
 	if classifyPath != "" {
@@ -62,6 +62,7 @@ func ReportKnowledgeResourceAdd(title string, fileUrl []string, adminId int, adm
 	obj.AdminRealName = adminRealName
 	obj.SourceFrom = sourceFrom
 	obj.StartTime = &pushTime
+	obj.EmailUid = emailUid
 	// 此处传入的url会在入库时存入knowledge_resource_file表中
 	if len(fileUrl) != 0 {
 		obj.IsFile = 1

+ 7 - 4
services/minio.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"errors"
 	"eta_gn/eta_report/utils"
+	"fmt"
 	"github.com/minio/minio-go/v7"
 	"github.com/minio/minio-go/v7/pkg/credentials"
 	"log"
@@ -70,7 +71,11 @@ func (m *MinioOss) UploadFile(fileName, filePath, savePath string) (string, erro
 	}
 
 	ctx := context.Background()
+	// 此处兼容一下前后端endpoint不一致的情况, 前端用minio_endpoint后端用minio_back_endpoint, minio_back_endpoint为空则都取前者
 	endpoint := utils.MinIoEndpoint
+	if utils.MinIoBackEndpoint != "" {
+		endpoint = utils.MinIoBackEndpoint
+	}
 	accessKeyID := utils.MinIoAccessKeyId
 	secretAccessKey := utils.MinIoAccessKeySecret
 	useSSL := false
@@ -87,10 +92,8 @@ func (m *MinioOss) UploadFile(fileName, filePath, savePath string) (string, erro
 	}
 	bucketName := utils.MinIoBucketname
 	exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
-	if errBucketExists == nil && exists {
-		log.Printf("We already own %s\n", bucketName)
-	} else {
-		log.Fatalln(err)
+	if errBucketExists != nil || !exists {
+		err = fmt.Errorf("BucketExists: %v; err: %v", exists, errBucketExists)
 		return "2", err
 	}
 

+ 4 - 0
utils/config.go

@@ -80,6 +80,7 @@ var (
 var (
 	MinIoBucketname       string
 	MinIoEndpoint         string
+	MinIoBackEndpoint     string
 	MinIoImghost          string
 	MinIoUploadDir        string
 	MinIoUpload_Audio_Dir string
@@ -93,6 +94,7 @@ var (
 // S3配置
 var (
 	S3Endpoint        string
+	S3BackEndpoint    string
 	S3BucketName      string
 	S3UploadDir       string
 	S3AccessKeyId     string
@@ -235,6 +237,7 @@ func init() {
 	// MinIo相关
 	{
 		MinIoEndpoint = config["minio_endpoint"]
+		MinIoBackEndpoint = config["minio_back_endpoint"]
 		MinIoBucketname = config["minio_bucket_name"]
 		MinIoImghost = config["minio_img_host"]
 		MinIoUploadDir = config["minio_upload_dir"]
@@ -249,6 +252,7 @@ func init() {
 	// S3-OSS相关
 	{
 		S3Endpoint = config["s3_endpoint"]
+		S3BackEndpoint = config["s3_back_endpoint"]
 		S3BucketName = config["s3_bucket_name"]
 		S3Host = config["s3_host"]
 		S3AccessKeyId = config["s3_access_key_id"]