Browse Source

对多作者推送每个作者的消息

kobe6258 8 months ago
parent
commit
df3d9f048f
1 changed files with 29 additions and 24 deletions
  1. 29 24
      domian/report/report_service.go

+ 29 - 24
domian/report/report_service.go

@@ -458,30 +458,35 @@ func syncESAndSendMessage(reports []reportDao.Report) (err error) {
 			logger.Error("获取研报作者失败:%v", err)
 			continue
 		}
-		if len(userIds) > 0 {
-			usersStr := stringUtils.IntToStringSlice(userIds)
-			Meta := userService.MetaData{
-				AuthorName:    report.Author,
-				AuthorId:      author.Id,
-				SourceId:      report.ID,
-				PublishedTime: report.PublishedTime,
-			}
-			metaStr, _ := json.Marshal(Meta)
-			toStr := strings.Join(usersStr, ",")
-			UUID := uuid.New()
-			uuidStr := UUID.String()
-			metaContent := userService.MetaInfoDTO{
-				From:       "HT",
-				Uid:        "report:" + uuidStr,
-				Meta:       string(metaStr),
-				MetaType:   "USER_NOTICE",
-				SourceType: "REPORT",
-				To:         toStr,
-			}
-			err = userService.CreateMetaInfo(metaContent)
-			if err != nil {
-				logger.Error("创建Meta信息失败:%v", err)
-				return err
+		authors := strings.Split(report.Author, ",")
+		authors = stringUtils.RemoveEmptyStrings(authors)
+		if len(authors) > 0 && len(userIds) > 0 {
+			logger.Info("推送META信息,用户ID:%v", userIds)
+			for _, authorName := range authors {
+				usersStr := stringUtils.IntToStringSlice(userIds)
+				Meta := userService.MetaData{
+					AuthorName:    authorName,
+					AuthorId:      author.Id,
+					SourceId:      report.ID,
+					PublishedTime: report.PublishedTime,
+				}
+				metaStr, _ := json.Marshal(Meta)
+				toStr := strings.Join(usersStr, ",")
+				UUID := uuid.New()
+				uuidStr := UUID.String()
+				metaContent := userService.MetaInfoDTO{
+					From:       "HT",
+					Uid:        "report:" + uuidStr,
+					Meta:       string(metaStr),
+					MetaType:   "USER_NOTICE",
+					SourceType: "REPORT",
+					To:         toStr,
+				}
+				err = userService.CreateMetaInfo(metaContent)
+				if err != nil {
+					logger.Error("创建Meta信息失败:%v", err)
+					return err
+				}
 			}
 		}
 	}