kobe6258 7 달 전
부모
커밋
ef0c70034f
5개의 변경된 파일101개의 추가작업 그리고 58개의 파일을 삭제
  1. 40 15
      domian/report/report_service.go
  2. 34 1
      domian/user/meta_info.go
  3. 24 6
      models/user/meta_info.go
  4. 1 1
      models/user/user_analyst_follow_list.go
  5. 2 35
      task/message/notice_task.go

+ 40 - 15
domian/report/report_service.go

@@ -2,6 +2,9 @@ package report
 
 import (
 	"encoding/json"
+	stringUtils "eta/eta_mini_ht_api/common/utils/string"
+	userService "eta/eta_mini_ht_api/domian/user"
+
 	"eta/eta_mini_ht_api/common/component/es"
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/utils/page"
@@ -9,7 +12,9 @@ import (
 	"eta/eta_mini_ht_api/models/eta"
 	etaDao "eta/eta_mini_ht_api/models/eta"
 	reportDao "eta/eta_mini_ht_api/models/report"
+	"github.com/google/uuid"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -257,25 +262,45 @@ func SyncETAReportList(list []eta.ETAReport) (err error) {
 		return
 	}
 	//生产meta信息
-	//for _, report := range reports {
-	//userIds := userService.GetPostUser(report.Author, report.PublishedTime)
-	//usersStr := stringUtils.IntToStringSlice(userIds)
-	//Meta :=
-	//toStr := strings.Join(usersStr, ",")
-	////user.SyncMeta(etaReportList[i])
-	//userService.MetaInfoDTO{
-	//	From:       "ETA",
-	//	Meta:       string(list),
-	//	MetaType:   "USER_NOTICE",
-	//	SourceType: "REPORT",
-	//	To:         toStr,
-	//	Uid:        userIds[0],
-	//}
-	//}
+	logger.Info("生成推送META信息")
+	for _, report := range reports {
+		userIds := userService.GetPostUser(report.Author, report.PublishedTime)
+		if len(userIds) > 0 {
+			usersStr := stringUtils.IntToStringSlice(userIds)
+			Meta := reportMeta{
+				AuthorName:    report.Author,
+				PublishedTime: report.PublishedTime,
+				ReportId:      report.ID,
+				Title:         report.Title,
+			}
+			metaStr, _ := json.Marshal(Meta)
+			toStr := strings.Join(usersStr, ",")
+			UUID := uuid.New()
+			uuidStr := UUID.String()
+			metaContent := userService.MetaInfoDTO{
+				From:       "ETA",
+				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
+			}
+		}
+
+	}
 	return
 }
 
 type reportMeta struct {
+	ReportId      int    `json:"reportId"`
+	AuthorName    string `json:"authorName"`
+	Title         string `json:"title"`
+	PublishedTime string `json:"publishedTime"`
 }
 
 func GetListOrderByConditionWeekly(week bool, column string, limit int, order models.Order) (dtoList []ReportDTO, err error) {

+ 34 - 1
domian/user/meta_info.go

@@ -1,10 +1,43 @@
 package user
 
+import "eta/eta_mini_ht_api/models/user"
+
 type MetaInfoDTO struct {
-	Uid        int
+	Uid        string
 	Meta       string
 	From       string
 	To         string
 	SourceType string
 	MetaType   string
 }
+
+func CreateMetaInfo(dto MetaInfoDTO) (err error) {
+	return user.CreateMetaInfo(convertToMetaInfo(dto))
+}
+func convertToMetaInfo(dto MetaInfoDTO) user.MetaInfo {
+	return user.MetaInfo{
+		Uid:        dto.Uid,
+		Meta:       dto.Meta,
+		From:       dto.From,
+		To:         dto.To,
+		SourceType: user.SourceType(dto.SourceType),
+		MetaType:   user.MetaType(dto.MetaType),
+	}
+}
+func convertToMetaDTO(dto user.MetaInfo) MetaInfoDTO {
+	return MetaInfoDTO{
+		Uid:        dto.Uid,
+		Meta:       dto.Meta,
+		From:       dto.From,
+		To:         dto.To,
+		SourceType: string(dto.SourceType),
+		MetaType:   string(dto.MetaType),
+	}
+}
+
+func GetInitMetaInfos() (list []MetaInfoDTO) {
+	metas := userDao.GetInitMetaInfos()
+	for _, meta := range metas {
+		list = append(list, convertToUserDTO())
+	}
+}

+ 24 - 6
models/user/meta_info.go

@@ -1,6 +1,8 @@
 package user
 
 import (
+	"eta/eta_mini_ht_api/models"
+	"gorm.io/gorm"
 	"time"
 )
 
@@ -9,11 +11,11 @@ type SourceType string
 type MetaType string
 
 const (
-	UserNoticeType  MetaType = "USER_NOTICE"
-	InitMetaType    MetaType = "INIT"
-	PendingMetaType MetaType = "PENDING"
-	FinishMetaType  MetaType = "FINISH"
-	FailedMetaType  MetaType = "FAILED"
+	UserNoticeType    MetaType   = "USER_NOTICE"
+	InitStatusType    StatusType = "INIT"
+	PendingStatusType StatusType = "PENDING"
+	FinishStatusType  StatusType = "FINISH"
+	FailedStatusType  StatusType = "FAILED"
 
 	ReportSourceType SourceType = "REPORT"
 	VideoSourceType  SourceType = "VIDEO"
@@ -23,7 +25,7 @@ const (
 // MetaInfo 表示 meta_infos 表的模型
 type MetaInfo struct {
 	Id          int        `gorm:"primaryKey;autoIncrement;column:id"`
-	Uid         int        `gorm:"column:uid"`
+	Uid         string     `gorm:"column:uid"`
 	Meta        string     `gorm:"column:meta"`
 	From        string     `gorm:"column:from"`
 	To          string     `gorm:"column:to"`
@@ -33,3 +35,19 @@ type MetaInfo struct {
 	CreatedTime time.Time
 	UpdatedTime time.Time
 }
+
+func (mt *MetaInfo) BeforeCreate(_ *gorm.DB) (err error) {
+	mt.CreatedTime = time.Now()
+	mt.Status = InitStatusType
+	return nil
+}
+
+func CreateMetaInfo(metaInfo MetaInfo) (err error) {
+	db := models.Main()
+	return db.Create(&metaInfo).Error
+}
+
+func GetInitMetaInfos() (list []MetaInfo) {
+	db := models.Main()
+	err := db.Where("status = ?", InitStatusType).Order("id asc").Limit(100).Find(&list).Error
+}

+ 1 - 1
models/user/user_analyst_follow_list.go

@@ -30,7 +30,7 @@ type UserAnalystFollowList struct {
 
 func GetPostUser(authorName string, PublishTime string) (ids []int) {
 	db := models.Main()
-	err := db.Select("user_id").Where("financial_analyst_name = ? and followed = ? and financial_analyst_name=? and followed_time <=?", authorName, Following, PublishTime).Order("followed_time desc").Find(&ids).Error
+	err := db.Model(&UserAnalystFollowList{}).Select("user_id").Where("financial_analyst_name = ? and followed = ? and followed_time <=?", authorName, Following, PublishTime).Order("followed_time desc").Find(&ids).Error
 	if err != nil {
 		return []int{}
 	}

+ 2 - 35
task/message/notice_task.go

@@ -3,58 +3,25 @@ package message
 import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/contants"
-	"eta/eta_mini_ht_api/domian/financial_analyst"
-	"eta/eta_mini_ht_api/models/eta"
 	"eta/eta_mini_ht_api/task/base"
-	"fmt"
-	"github.com/google/uuid"
-	"sync"
-	"time"
 )
 
 var (
 	taskName base.TaskType = "NoticeTask"
 	cron                   = "0/5 * * * * *"
-	duration               = 5 * time.Second
 )
 
 // Execute Task ETA取研报的数据
 func (au *AuthorTask) Execute(taskDetail *base.TaskDetail) error {
 	logger.Info(contants.TaskFormat, "监听更新通知开始")
+	//metaInfoList := userServcie.getInitMetaInfos()
 	//报告和媒体
-	var wg sync.WaitGroup
-	wg.Add(2)
-	UUID := uuid.New()
-	uuidStr := UUID.String()
-	timeBefore := time.Now().Add(-duration)
-	fmt.Printf("监听更新通知开始:%v", timeBefore)
-	//监听报告
-	go func(uuid string) {
-		defer wg.Done()
-		//list := reportService.GetNewReportByPublishTime(timeBefore)
-		//	users := userService.GetNoticeUsersByReports(list)
-	}(uuidStr)
-	//监听媒体
-	go func(uuid string) {
-		defer wg.Done()
-	}(uuidStr)
-	wg.Wait()
-
 	return nil
 }
 
 type AuthorTask struct {
 }
 
-func convert(author eta.ReportAuthor) financial_analyst.FinancialAnalystDTO {
-	return financial_analyst.FinancialAnalystDTO{
-		Deleted: author.IsDelete,
-		ETAId:   author.Id,
-		Name:    author.ReportAuthor,
-		Status:  author.Enable,
-	}
-}
 func init() {
-	authorTask := base.NewTask(taskName, cron, new(AuthorTask), base.PROD)
-	base.RegisterTask(&authorTask)
+
 }