kobe6258 il y a 7 mois
Parent
commit
42cdeb7d24

+ 58 - 15
domian/report/report_service.go

@@ -2,14 +2,37 @@ package report
 
 import (
 	"encoding/json"
+<<<<<<< Updated upstream
 	"eta_mini_ht_api/common/component/es"
 	logger "eta_mini_ht_api/common/component/log"
 	"eta_mini_ht_api/common/utils/page"
+=======
+<<<<<<< Updated upstream
+	"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"
+	"eta/eta_mini_ht_api/models"
+	"eta/eta_mini_ht_api/models/eta"
+	etaDao "eta/eta_mini_ht_api/models/eta"
+	reportDao "eta/eta_mini_ht_api/models/report"
+=======
+	"eta_mini_ht_api/common/component/es"
+	logger "eta_mini_ht_api/common/component/log"
+	"eta_mini_ht_api/common/utils/page"
+	stringUtils "eta_mini_ht_api/common/utils/string"
+	userService "eta_mini_ht_api/domian/user"
+>>>>>>> Stashed changes
 	"eta_mini_ht_api/models"
 	"eta_mini_ht_api/models/eta"
 	etaDao "eta_mini_ht_api/models/eta"
 	reportDao "eta_mini_ht_api/models/report"
+<<<<<<< Updated upstream
+=======
+	"github.com/google/uuid"
+>>>>>>> Stashed changes
+>>>>>>> Stashed changes
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -257,25 +280,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_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 := user.GetInitMetaInfos()
+	for _, meta := range metas {
+		list = append(list, convertToUserDTO())
+	}
+}

+ 19 - 6
models/user/meta_info.go

@@ -1,6 +1,8 @@
 package user
 
 import (
+	"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,14 @@ 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
+}

+ 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{}
 	}

+ 25 - 2
task/message/notice_task.go

@@ -1,29 +1,46 @@
 package message
 
 import (
+<<<<<<< Updated upstream
 	logger "eta_mini_ht_api/common/component/log"
 	"eta_mini_ht_api/common/contants"
 	"eta_mini_ht_api/domian/financial_analyst"
 	"eta_mini_ht_api/models/eta"
 	"eta_mini_ht_api/task/base"
+=======
+<<<<<<< Updated upstream
+	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"
+>>>>>>> Stashed changes
 	"fmt"
 	"github.com/google/uuid"
+=======
+	logger "eta_mini_ht_api/common/component/log"
+	"eta_mini_ht_api/common/contants"
+	"eta_mini_ht_api/domian/financial_analyst"
+	userService "eta_mini_ht_api/domian/user"
+	"eta_mini_ht_api/models/eta"
+	"eta_mini_ht_api/task/base"
+>>>>>>> Stashed changes
 	"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 := userService.getInitMetaInfos()
 	//报告和媒体
 	var wg sync.WaitGroup
 	wg.Add(2)
+<<<<<<< Updated upstream
 	UUID := uuid.New()
 	uuidStr := UUID.String()
 	timeBefore := time.Now().Add(-duration)
@@ -39,7 +56,13 @@ func (au *AuthorTask) Execute(taskDetail *base.TaskDetail) error {
 		defer wg.Done()
 	}(uuidStr)
 	wg.Wait()
+<<<<<<< Updated upstream
 	
+=======
+
+=======
+>>>>>>> Stashed changes
+>>>>>>> Stashed changes
 	return nil
 }