feat: 增加定时任务获取数据指标

This commit is contained in:
cjy 2025-12-17 19:31:49 +08:00
parent e424cef29f
commit 0c4d0f221b
6 changed files with 16043 additions and 0 deletions

13479
api/aryshare/ayrshare.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,900 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: pb/ayrshare.proto
package aryshare
import (
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
_ "google.golang.org/protobuf/types/descriptorpb"
_ "github.com/mwitkow/go-proto-validators"
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
func (this *UserTag) Validate() error {
return nil
}
func (this *InstagramOptions) Validate() error {
for _, item := range this.UserTags {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("UserTags", err)
}
}
}
return nil
}
func (this *TikTokOptions) Validate() error {
return nil
}
func (this *PostRequest) Validate() error {
if this.Post == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Post", fmt.Errorf(`post内容不能为空`))
}
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
if this.InstagramOptions != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.InstagramOptions); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("InstagramOptions", err)
}
}
if this.TikTokOptions != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.TikTokOptions); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("TikTokOptions", err)
}
}
return nil
}
func (this *PostId) Validate() error {
return nil
}
func (this *PostItem) Validate() error {
for _, item := range this.PostIds {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PostIds", err)
}
}
}
return nil
}
func (this *PostResponse) Validate() error {
for _, item := range this.Posts {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Posts", err)
}
}
}
for _, item := range this.PostIds {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PostIds", err)
}
}
}
return nil
}
func (this *GetPostRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`帖子ID不能为空`))
}
return nil
}
func (this *GetPostResponse) Validate() error {
for _, item := range this.PostIds {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PostIds", err)
}
}
}
return nil
}
func (this *GetUserRequest) Validate() error {
return nil
}
func (this *Timestamp) Validate() error {
return nil
}
func (this *TwitterUsage) Validate() error {
return nil
}
func (this *DisplayName) Validate() error {
if this.TwitterUsage != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.TwitterUsage); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("TwitterUsage", err)
}
}
return nil
}
func (this *GetUserResponse) Validate() error {
if this.Created != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Created); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Created", err)
}
}
for _, item := range this.DisplayNames {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("DisplayNames", err)
}
}
}
return nil
}
func (this *CreateProfileRequest) Validate() error {
if this.Title == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Title", fmt.Errorf(`title不能为空`))
}
return nil
}
func (this *CreateProfileResponse) Validate() error {
return nil
}
func (this *GetProfilesRequest) Validate() error {
return nil
}
func (this *ProfileItem) Validate() error {
if this.Created != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Created); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Created", err)
}
}
return nil
}
func (this *Pagination) Validate() error {
return nil
}
func (this *GetProfilesResponse) Validate() error {
for _, item := range this.Profiles {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Profiles", err)
}
}
}
if this.Pagination != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Pagination); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Pagination", err)
}
}
return nil
}
func (this *Email) Validate() error {
return nil
}
func (this *GenerateJWTRequest) Validate() error {
if this.ProfileKey == "" {
return github_com_mwitkow_go_proto_validators.FieldError("ProfileKey", fmt.Errorf(`profileKey不能为空`))
}
if this.Email != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Email); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Email", err)
}
}
return nil
}
func (this *GenerateJWTResponse) Validate() error {
return nil
}
func (this *HistoryPostId) Validate() error {
return nil
}
func (this *HistoryItem) Validate() error {
for _, item := range this.PostIds {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PostIds", err)
}
}
}
if this.ScheduleDate != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.ScheduleDate); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("ScheduleDate", err)
}
}
return nil
}
func (this *GetHistoryRequest) Validate() error {
return nil
}
func (this *GetHistoryResponse) Validate() error {
for _, item := range this.History {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("History", err)
}
}
}
return nil
}
func (this *GetHistoryByIdRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`帖子ID不能为空`))
}
return nil
}
func (this *GetHistoryByIdResponse) Validate() error {
for _, item := range this.PostIds {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PostIds", err)
}
}
}
if this.ScheduleDate != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.ScheduleDate); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("ScheduleDate", err)
}
}
return nil
}
func (this *PlatformPost) Validate() error {
return nil
}
func (this *GetHistoryByPlatformRequest) Validate() error {
if this.Platform == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platform", fmt.Errorf(`平台名称不能为空`))
}
return nil
}
func (this *GetHistoryByPlatformResponse) Validate() error {
for _, item := range this.Posts {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Posts", err)
}
}
}
return nil
}
func (this *SendMessageRequest) Validate() error {
if this.Platform == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platform", fmt.Errorf(`平台不能为空`))
}
if this.RecipientId == "" {
return github_com_mwitkow_go_proto_validators.FieldError("RecipientId", fmt.Errorf(`接收者ID不能为空`))
}
return nil
}
func (this *MessageItem) Validate() error {
return nil
}
func (this *SendMessageResponse) Validate() error {
for _, item := range this.Messages {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Messages", err)
}
}
}
return nil
}
func (this *GetMessagesRequest) Validate() error {
if this.Platform == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platform", fmt.Errorf(`平台不能为空`))
}
return nil
}
func (this *MessageAttachment) Validate() error {
return nil
}
func (this *MessageSenderDetails) Validate() error {
return nil
}
func (this *MessageRecipientDetails) Validate() error {
return nil
}
func (this *MessageReaction) Validate() error {
return nil
}
func (this *GetMessagesItem) Validate() error {
if this.SenderDetails != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.SenderDetails); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("SenderDetails", err)
}
}
if this.RecipientDetails != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.RecipientDetails); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("RecipientDetails", err)
}
}
for _, item := range this.Attachments {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Attachments", err)
}
}
}
for _, item := range this.Reactions {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Reactions", err)
}
}
}
return nil
}
func (this *ConversationParticipant) Validate() error {
return nil
}
func (this *ConversationDetail) Validate() error {
if this.Participant != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Participant); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Participant", err)
}
}
return nil
}
func (this *GetMessagesResponse) Validate() error {
for _, item := range this.Messages {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Messages", err)
}
}
}
for _, item := range this.ConversationsDetails {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("ConversationsDetails", err)
}
}
}
return nil
}
func (this *PostCommentRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`id不能为空`))
}
if this.Comment == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Comment", fmt.Errorf(`comment不能为空`))
}
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
return nil
}
func (this *InstagramCommentResponse) Validate() error {
return nil
}
func (this *TikTokCommentResponse) Validate() error {
return nil
}
func (this *BlueskyCommentResponse) Validate() error {
return nil
}
func (this *FacebookCommentResponse) Validate() error {
return nil
}
func (this *LinkedInCommentResponse) Validate() error {
return nil
}
func (this *TwitterCommentResponse) Validate() error {
return nil
}
func (this *YouTubeCommentResponse) Validate() error {
return nil
}
func (this *PlatformError) Validate() error {
return nil
}
func (this *PostCommentResponse) Validate() error {
if this.Instagram != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Instagram); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Instagram", err)
}
}
if this.Tiktok != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Tiktok); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Tiktok", err)
}
}
for _, item := range this.Errors {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Errors", err)
}
}
}
if this.Bluesky != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Bluesky); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Bluesky", err)
}
}
if this.Facebook != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Facebook); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Facebook", err)
}
}
if this.Linkedin != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Linkedin); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Linkedin", err)
}
}
if this.Twitter != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Twitter); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Twitter", err)
}
}
if this.Youtube != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Youtube); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Youtube", err)
}
}
return nil
}
func (this *GetCommentRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`id不能为空`))
}
return nil
}
func (this *InstagramUser) Validate() error {
return nil
}
func (this *InstagramUserInfo) Validate() error {
return nil
}
func (this *InstagramComment) Validate() error {
if this.From != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.From); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("From", err)
}
}
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
if this.User != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.User); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("User", err)
}
}
return nil
}
func (this *TikTokComment) Validate() error {
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
return nil
}
func (this *BlueskyComment) Validate() error {
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
return nil
}
func (this *FacebookUser) Validate() error {
return nil
}
func (this *FacebookParent) Validate() error {
if this.From != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.From); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("From", err)
}
}
return nil
}
func (this *FacebookComment) Validate() error {
if this.From != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.From); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("From", err)
}
}
if this.Parent != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Parent); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Parent", err)
}
}
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
return nil
}
func (this *LinkedInMedia) Validate() error {
return nil
}
func (this *LinkedInFrom) Validate() error {
return nil
}
func (this *LinkedInComment) Validate() error {
if this.From != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.From); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("From", err)
}
}
for _, item := range this.Media {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Media", err)
}
}
}
return nil
}
func (this *RedditUser) Validate() error {
return nil
}
func (this *RedditComment) Validate() error {
if this.From != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.From); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("From", err)
}
}
return nil
}
func (this *ThreadsComment) Validate() error {
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
return nil
}
func (this *TwitterPublicMetrics) Validate() error {
return nil
}
func (this *TwitterReferencedTweet) Validate() error {
return nil
}
func (this *TwitterReplyTo) Validate() error {
if this.PublicMetrics != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.PublicMetrics); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PublicMetrics", err)
}
}
return nil
}
func (this *TwitterComment) Validate() error {
if this.PublicMetrics != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.PublicMetrics); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("PublicMetrics", err)
}
}
for _, item := range this.ReferencedTweets {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("ReferencedTweets", err)
}
}
}
if this.ReplyTo != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.ReplyTo); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("ReplyTo", err)
}
}
return nil
}
func (this *YouTubeReply) Validate() error {
return nil
}
func (this *YouTubeComment) Validate() error {
for _, item := range this.Replies {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Replies", err)
}
}
}
return nil
}
func (this *GetCommentResponse) Validate() error {
for _, item := range this.Instagram {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Instagram", err)
}
}
}
for _, item := range this.Tiktok {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Tiktok", err)
}
}
}
for _, item := range this.Bluesky {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Bluesky", err)
}
}
}
for _, item := range this.Facebook {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Facebook", err)
}
}
}
for _, item := range this.Linkedin {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Linkedin", err)
}
}
}
for _, item := range this.Reddit {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Reddit", err)
}
}
}
for _, item := range this.Threads {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Threads", err)
}
}
}
for _, item := range this.Twitter {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Twitter", err)
}
}
}
for _, item := range this.Youtube {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Youtube", err)
}
}
}
return nil
}
func (this *DeleteCommentRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`id不能为空`))
}
return nil
}
func (this *InstagramDeleteResponse) Validate() error {
return nil
}
func (this *TikTokDeleteResponse) Validate() error {
return nil
}
func (this *DeleteCommentResponse) Validate() error {
return nil
}
func (this *ReplyCommentRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`id不能为空`))
}
if this.Comment == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Comment", fmt.Errorf(`comment不能为空`))
}
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
return nil
}
func (this *InstagramReplyResponse) Validate() error {
return nil
}
func (this *TikTokReplyResponse) Validate() error {
return nil
}
func (this *BlueskyReplyResponse) Validate() error {
return nil
}
func (this *FacebookReplyResponse) Validate() error {
return nil
}
func (this *LinkedInReplyResponse) Validate() error {
return nil
}
func (this *TwitterReplyResponse) Validate() error {
return nil
}
func (this *YouTubeReplyResponse) Validate() error {
return nil
}
func (this *ReplyCommentResponse) Validate() error {
if this.Instagram != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Instagram); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Instagram", err)
}
}
if this.Tiktok != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Tiktok); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Tiktok", err)
}
}
if this.Bluesky != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Bluesky); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Bluesky", err)
}
}
if this.Facebook != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Facebook); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Facebook", err)
}
}
if this.Linkedin != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Linkedin); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Linkedin", err)
}
}
if this.Twitter != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Twitter); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Twitter", err)
}
}
if this.Youtube != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Youtube); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Youtube", err)
}
}
return nil
}
func (this *GetPostAnalyticsRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`帖子ID不能为空`))
}
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
return nil
}
func (this *GetPostAnalyticsBySocialIDRequest) Validate() error {
if this.Id == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Id", fmt.Errorf(`Social Post ID不能为空`))
}
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
return nil
}
func (this *GetPostAnalyticsResponse) Validate() error {
return nil
}
func (this *GetSocialAnalyticsRequest) Validate() error {
if len(this.Platforms) < 1 {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
for _, item := range this.Platforms {
if item == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platforms", fmt.Errorf(`platforms平台列表不能为空`))
}
}
return nil
}
func (this *GetSocialAnalyticsResponse) Validate() error {
return nil
}
func (this *AutoHashtagsRequest) Validate() error {
if this.Post == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Post", fmt.Errorf(`post内容不能为空`))
}
return nil
}
func (this *AutoHashtagsResponse) Validate() error {
return nil
}
func (this *CheckBannedHashtagRequest) Validate() error {
if this.Hashtag == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Hashtag", fmt.Errorf(`hashtag不能为空`))
}
return nil
}
func (this *CheckBannedHashtagResponse) Validate() error {
return nil
}
func (this *HashtagRecommendation) Validate() error {
return nil
}
func (this *RecommendHashtagsRequest) Validate() error {
if this.Keyword == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Keyword", fmt.Errorf(`keyword不能为空`))
}
return nil
}
func (this *RecommendHashtagsResponse) Validate() error {
for _, item := range this.Recommendations {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Recommendations", err)
}
}
}
return nil
}
func (this *SearchHashtagsRequest) Validate() error {
if this.Keyword == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Keyword", fmt.Errorf(`keyword不能为空`))
}
return nil
}
func (this *SearchHashtagInfo) Validate() error {
return nil
}
func (this *SearchHashtagChild) Validate() error {
return nil
}
func (this *SearchHashtagChildren) Validate() error {
for _, item := range this.Data {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
}
}
}
return nil
}
func (this *SearchHashtagMedia) Validate() error {
if this.Children != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Children); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Children", err)
}
}
return nil
}
func (this *SearchHashtagsResponse) Validate() error {
if this.Hashtag != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Hashtag); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Hashtag", err)
}
}
for _, item := range this.SearchResults {
if item != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("SearchResults", err)
}
}
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,9 @@ func InitTasks() error {
err = cm.AddTask("artistAutoConfirmAnalysis", "0 */1 * * * *", ArtistAutoConfirmAnalysisTask) err = cm.AddTask("artistAutoConfirmAnalysis", "0 */1 * * * *", ArtistAutoConfirmAnalysisTask)
err = cm.AddTask("refreshWorkAnalysisApprovalStatus", "0 */1 * * * *", RefreshWorkAnalysisApprovalStatusTask) err = cm.AddTask("refreshWorkAnalysisApprovalStatus", "0 */1 * * * *", RefreshWorkAnalysisApprovalStatusTask)
// 每天 00:30 和 12:30 执行 Ayrshare 指标采集任务
err = cm.AddTask("ayrshareMetricsCollector", "30 0,12 * * *", AyrshareMetricsCollectorTask)
if err != nil { if err != nil {
log.Printf("添加测试任务失败: %v", err) log.Printf("添加测试任务失败: %v", err)
} }
@ -103,3 +106,8 @@ func ArtistAutoConfirmAnalysisTask() {
serverCast.ProcessAnalysisTask(context.Background(), analysisUuid) serverCast.ProcessAnalysisTask(context.Background(), analysisUuid)
} }
} }
// AyrshareMetricsCollectorTask Ayrshare 指标采集定时任务(每天 00:30 和 12:30 执行)
func AyrshareMetricsCollectorTask() {
serverCast.ExecuteAyrshareMetricsCollector()
}

View File

@ -10,6 +10,8 @@ import (
) )
func AnalysisRouter(r *gin.RouterGroup) { func AnalysisRouter(r *gin.RouterGroup) {
r.POST("analysis/trigger-ayrshare-metrics", serviceCast.TriggerAyrshareMetricsCollector)
analysis := r.Group("analysis") analysis := r.Group("analysis")
analysis.Use(middleware.CheckWebLogin(service.AccountProvider)) analysis.Use(middleware.CheckWebLogin(service.AccountProvider))
{ {
@ -29,6 +31,7 @@ func AnalysisRouter(r *gin.RouterGroup) {
analysis.POST("artist-metrics-single", serviceCast.ArtistMetricsDailyWindow) // 艺人指标日窗口 analysis.POST("artist-metrics-single", serviceCast.ArtistMetricsDailyWindow) // 艺人指标日窗口
analysis.POST("tobe-confirmed-list", serviceCast.TobeConfirmedList) // 待确认数据列表 analysis.POST("tobe-confirmed-list", serviceCast.TobeConfirmedList) // 待确认数据列表
analysis.POST("update-approval-id", serviceCast.UpdateWorkAnalysisApprovalID) // 更新作品分析审批ID analysis.POST("update-approval-id", serviceCast.UpdateWorkAnalysisApprovalID) // 更新作品分析审批ID
// analysis.POST("trigger-ayrshare-metrics", serviceCast.TriggerAyrshareMetricsCollector) // 手动触发 Ayrshare 指标采集任务
} }

View File

@ -2,8 +2,10 @@ package cast
import ( import (
"context" "context"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"fonchain-fiee/api/aryshare"
"fonchain-fiee/api/bundle" "fonchain-fiee/api/bundle"
"fonchain-fiee/api/cast" "fonchain-fiee/api/cast"
"fonchain-fiee/pkg/cache" "fonchain-fiee/pkg/cache"
@ -17,6 +19,7 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/common/constant"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -639,3 +642,545 @@ func autoConfirmAnalysis(ctx context.Context, analysisUuid string) (err error) {
} }
return return
} }
// TriggerAyrshareMetricsCollector 手动触发 Ayrshare 指标采集任务
func TriggerAyrshareMetricsCollector(ctx *gin.Context) {
// 在后台 goroutine 中执行任务,避免阻塞 HTTP 请求
go func() {
// 同时使用 zap 和 fmt.Printf 确保日志输出到终端
zap.L().Info("手动触发 Ayrshare 指标采集任务")
fmt.Printf("[%s] 手动触发 Ayrshare 指标采集任务\n", time.Now().Format("2006-01-02 15:04:05"))
executeAyrshareMetricsCollector()
}()
service.Success(ctx, map[string]string{
"message": "任务已触发,正在后台执行",
})
return
}
// ExecuteAyrshareMetricsCollector 提供给定时任务调用的 Ayrshare 指标采集入口
func ExecuteAyrshareMetricsCollector() {
executeAyrshareMetricsCollector()
}
// executeAyrshareMetricsCollector 执行 Ayrshare 指标采集任务
func executeAyrshareMetricsCollector() {
ctx := context.Background()
zap.L().Info("开始执行 Ayrshare 指标采集任务")
fmt.Printf("[%s] [INFO] 开始执行 Ayrshare 指标采集任务\n", time.Now().Format("2006-01-02 15:04:05"))
// 获取当前日期中国时区格式YYYYMMDD
loc, _ := time.LoadLocation("Asia/Shanghai")
now := time.Now().In(loc)
dateCN := now.Year()*10000 + int(now.Month())*100 + now.Day()
// 第一步获取所有状态为1的艺人AyrShare信息
mediaMetricsList, err := collectMediaMetricsForAyrshare(ctx, dateCN)
if err != nil {
zap.L().Error("采集账号指标失败", zap.Error(err))
fmt.Printf("[%s] [ERROR] 采集账号指标失败: %v\n", time.Now().Format("2006-01-02 15:04:05"), err)
return
}
// 批量插入账号指标
if len(mediaMetricsList) > 0 {
req := &cast.UpsertMediaMetricsDailyBatchReq{
Data: mediaMetricsList,
}
resp, err := service.CastProvider.UpsertMediaMetricsDailyBatch(ctx, req)
if err != nil {
zap.L().Error("批量插入账号指标失败", zap.Error(err))
fmt.Printf("[%s] [ERROR] 批量插入账号指标失败: %v\n", time.Now().Format("2006-01-02 15:04:05"), err)
} else if resp != nil && resp.Success {
zap.L().Info("批量插入账号指标成功", zap.Int("count", len(mediaMetricsList)))
fmt.Printf("[%s] [INFO] 批量插入账号指标成功,数量: %d\n", time.Now().Format("2006-01-02 15:04:05"), len(mediaMetricsList))
}
}
// 第二步:获取作品指标
workMetricsList, err := collectWorkMetricsForAyrshare(ctx, dateCN)
if err != nil {
zap.L().Error("采集作品指标失败", zap.Error(err))
fmt.Printf("[%s] [ERROR] 采集作品指标失败: %v\n", time.Now().Format("2006-01-02 15:04:05"), err)
return
}
// 批量插入作品指标
if len(workMetricsList) > 0 {
req := &cast.UpsertWorkMetricsDailyBatchReq{
Data: workMetricsList,
}
resp, err := service.CastProvider.UpsertWorkMetricsDailyBatch(ctx, req)
if err != nil {
zap.L().Error("批量插入作品指标失败", zap.Error(err))
fmt.Printf("[%s] [ERROR] 批量插入作品指标失败: %v\n", time.Now().Format("2006-01-02 15:04:05"), err)
} else if resp != nil && resp.Success {
zap.L().Info("批量插入作品指标成功", zap.Int("count", len(workMetricsList)))
fmt.Printf("[%s] [INFO] 批量插入作品指标成功,数量: %d\n", time.Now().Format("2006-01-02 15:04:05"), len(workMetricsList))
}
}
zap.L().Info("Ayrshare 指标采集任务执行完成")
fmt.Printf("[%s] [INFO] Ayrshare 指标采集任务执行完成\n", time.Now().Format("2006-01-02 15:04:05"))
}
// collectMediaMetricsForAyrshare 采集账号指标
func collectMediaMetricsForAyrshare(ctx context.Context, dateCN int) ([]*cast.MediaMetricsDailyItem, error) {
metricsList := make([]*cast.MediaMetricsDailyItem, 0)
page := int32(1)
pageSize := int32(500)
fmt.Printf("[%s] [INFO] 开始采集账号指标\n", time.Now().Format("2006-01-02 15:04:05"))
for {
// 获取状态为1的艺人AyrShare信息
req := &cast.GetArtistAyrShareInfoReq{
Status: 1, // 状态为1表示有效
Page: page,
PageSize: pageSize,
}
resp, err := service.CastProvider.GetArtistAyrShareInfo(ctx, req)
if err != nil {
zap.L().Error("获取艺人AyrShare信息失败", zap.Error(err), zap.Int32("page", page))
fmt.Printf("[%s] [ERROR] 获取艺人AyrShare信息失败页码: %d, 错误: %v\n", time.Now().Format("2006-01-02 15:04:05"), page, err)
return metricsList, err
}
if resp == nil || resp.Data == nil || len(resp.Data) == 0 {
break
}
fmt.Printf("[%s] [INFO] 获取到第 %d 页艺人信息,数量: %d\n", time.Now().Format("2006-01-02 15:04:05"), page, len(resp.Data))
// 对每个艺人调用 GetSocialAnalytics
for _, artistInfo := range resp.Data {
if artistInfo.ProfileKey == "" {
zap.L().Warn("艺人ProfileKey为空跳过", zap.String("artistUuid", artistInfo.ArtistUuid))
fmt.Printf("[%s] [WARN] 艺人ProfileKey为空跳过artistUuid: %s\n", time.Now().Format("2006-01-02 15:04:05"), artistInfo.ArtistUuid)
continue
}
// 调用 GetSocialAnalytics平台为 ["instagram", "tiktok"]
socialReq := &aryshare.GetSocialAnalyticsRequest{
Platforms: []string{"instagram", "tiktok"},
ProfileKey: artistInfo.ProfileKey,
}
socialResp, err := service.AyrshareProvider.GetSocialAnalytics(ctx, socialReq)
if err != nil {
zap.L().Warn("获取社交分析数据失败", zap.Error(err), zap.String("profileKey", artistInfo.ProfileKey))
fmt.Printf("[%s] [WARN] 获取社交分析数据失败profileKey: %s, 错误: %v\n", time.Now().Format("2006-01-02 15:04:05"), artistInfo.ProfileKey, err)
continue
}
fmt.Println("socialResp", socialResp)
// 解析 JSON 数据并构建指标
items := parseSocialAnalyticsToMediaMetricsForAyrshare(socialResp, artistInfo, dateCN)
metricsList = append(metricsList, items...)
// 避免请求过于频繁
time.Sleep(200 * time.Millisecond)
}
// 如果返回的数据少于 pageSize说明已经是最后一页
if len(resp.Data) < int(pageSize) {
break
}
page++
}
fmt.Printf("[%s] [INFO] 账号指标采集完成,共采集 %d 条\n", time.Now().Format("2006-01-02 15:04:05"), len(metricsList))
fmt.Println("metricsList", metricsList)
return metricsList, nil
}
// parseSocialAnalyticsToMediaMetricsForAyrshare 解析社交分析数据并转换为媒体指标
func parseSocialAnalyticsToMediaMetricsForAyrshare(socialResp *aryshare.GetSocialAnalyticsResponse, artistInfo *cast.ArtistAyrShareInfo, dateCN int) []*cast.MediaMetricsDailyItem {
items := make([]*cast.MediaMetricsDailyItem, 0)
// 解析 Instagram 数据
if socialResp.Instagram != "" {
// 调试:打印 Instagram JSON 字符串的前500字符
instaPreview := socialResp.Instagram
if len(instaPreview) > 500 {
instaPreview = instaPreview[:500] + "..."
}
fmt.Printf("[%s] [DEBUG] Instagram JSON 字符串预览: %s\n", time.Now().Format("2006-01-02 15:04:05"), instaPreview)
item := parsePlatformDataForAyrshare(socialResp.Instagram, "instagram", artistInfo, dateCN)
if item != nil {
items = append(items, item)
fmt.Printf("[%s] [INFO] 解析 Instagram 账号指标成功,艺人: %s\n", time.Now().Format("2006-01-02 15:04:05"), artistInfo.ArtistUuid)
}
}
// 解析 TikTok 数据
if socialResp.Tiktok != "" {
// 调试:打印 TikTok JSON 字符串的前500字符
tiktokPreview := socialResp.Tiktok
if len(tiktokPreview) > 500 {
tiktokPreview = tiktokPreview[:500] + "..."
}
fmt.Printf("[%s] [DEBUG] TikTok JSON 字符串预览: %s\n", time.Now().Format("2006-01-02 15:04:05"), tiktokPreview)
item := parsePlatformDataForAyrshare(socialResp.Tiktok, "tiktok", artistInfo, dateCN)
if item != nil {
items = append(items, item)
fmt.Printf("[%s] [INFO] 解析 TikTok 账号指标成功,艺人: %s\n", time.Now().Format("2006-01-02 15:04:05"), artistInfo.ArtistUuid)
}
}
fmt.Println("items", items)
fmt.Println("items length", len(items))
return items
}
// parsePlatformDataForAyrshare 解析平台数据JSON格式
func parsePlatformDataForAyrshare(jsonData, platform string, artistInfo *cast.ArtistAyrShareInfo, dateCN int) *cast.MediaMetricsDailyItem {
// 调试:打印原始 JSON 数据截取前500字符避免日志过长
jsonPreview := jsonData
fmt.Printf("parsePlatformDataForAyrshare 原始 JSON 数据: %s\n", jsonPreview)
var rootData map[string]interface{}
if err := json.Unmarshal([]byte(jsonData), &rootData); err != nil {
zap.L().Warn("解析平台数据失败", zap.Error(err), zap.String("platform", platform))
fmt.Printf("parsePlatformDataForAyrshare 解析平台数据失败,平台: %s, 错误: %v\n", platform, err)
return nil
}
// 调试:打印根数据的所有 key
rootKeys := make([]string, 0, len(rootData))
for k := range rootData {
rootKeys = append(rootKeys, k)
}
fmt.Printf("parsePlatformDataForAyrshare 根数据字段: %v\n", rootKeys)
// 根据平台映射平台ID1 TikTok, 3 Instagram
var platformID uint32
if platform == "tiktok" {
platformID = 1
} else if platform == "instagram" {
platformID = 3
} else {
return nil
}
// 从根数据中提取 analytics 对象,实际数据在 analytics 字段下
var analyticsData map[string]interface{}
if analyticsVal, ok := rootData["analytics"]; ok {
if analyticsMap, ok := analyticsVal.(map[string]interface{}); ok {
analyticsData = analyticsMap
} else {
fmt.Printf("parsePlatformDataForAyrshare analytics 字段类型不正确: %T\n", analyticsVal)
}
} else {
fmt.Printf("[%s] [WARN] %s 根数据中没有找到 analytics 字段\n", time.Now().Format("2006-01-02 15:04:05"), platform)
}
// 如果没有 analytics 字段,尝试直接从根数据提取(兼容旧格式)
if analyticsData == nil {
analyticsData = rootData
fmt.Printf("parsePlatformDataForAyrshare 使用根数据作为 analytics 数据\n")
}
// 调试:打印 analytics 数据的所有 key帮助诊断字段名
if len(analyticsData) > 0 {
keys := make([]string, 0, len(analyticsData))
for k := range analyticsData {
keys = append(keys, k)
}
fmt.Printf("parsePlatformDataForAyrshare analytics 数据字段: %v\n", keys)
} else {
fmt.Printf("parsePlatformDataForAyrshare analytics 数据为空\n")
}
// 提取指标数据(根据 Ayrshare API 的实际返回结构)
// Instagram 字段followersCount, likeCount, mediaCount, viewsCount, commentsCount
// TikTok 字段videoCountTotal, viewCountTotal, commentCountTotal, shareCountTotal
item := &cast.MediaMetricsDailyItem{
Uuid: uuid.NewString(),
ArtistUuid: artistInfo.ArtistUuid,
MediaAccUserID: "", // MediaAccUserID 需要通过其他接口获取,暂时留空
MediaName: "", // MediaName 需要通过其他接口获取,暂时留空
ArtistName: "", // ArtistName 需要通过其他接口获取,暂时留空
ArtistPhone: "", // ArtistPhone 需要通过其他接口获取,暂时留空
PlatformID: platformID,
Date: int32(dateCN),
// 粉丝数Instagram 使用 followsCountTikTok 可能没有直接对应字段
FansCount: extractInt64ForAyrshare(analyticsData, "followsCount", "followersCount", "followers", "followerCount", "fans", "fanCount"),
// 观看量Instagram 使用 viewsCountTikTok 使用 viewCountTotal
ViewsCount: extractInt64ForAyrshare(analyticsData, "viewCountTotal", "viewsCount", "views", "viewCount", "viewCountPeriod"),
// 点赞数Instagram 使用 likeCount
LikesCount: extractInt64ForAyrshare(analyticsData, "likeCount", "likes", "likesCount", "likeCountTotal"),
// 评论数Instagram 使用 commentsCountTikTok 使用 commentCountTotal
CommentsCount: extractInt64ForAyrshare(analyticsData, "commentCountTotal", "commentsCount", "comments", "commentCount", "commentCountPeriod"),
// 分享数Instagram 使用 reachCountTikTok 使用 shareCountTotal
SharesCount: extractInt64ForAyrshare(analyticsData, "shareCountTotal", "shares", "shareCount", "sharesCount", "shareCountPeriod"),
// 视频数Instagram 使用 mediaCountTikTok 使用 videoCountTotal
VideoCount: extractInt64ForAyrshare(analyticsData, "mediaCount", "videoCountTotal", "videos", "videoCount", "videosCount"),
// 图片/媒体数Instagram 可能没有直接对应字段,使用 posts 等
ImageCount: extractInt64ForAyrshare(analyticsData, "posts", "postCount", "postsCount", "images", "imageCount", "imagesCount"),
}
// 调试:打印提取到的指标值
fmt.Printf("parsePlatformDataForAyrshare 提取的指标 - 粉丝数: %d, 观看量: %d, 点赞数: %d, 评论数: %d, 分享数: %d, 视频数: %d, 图片数: %d\n",
item.FansCount, item.ViewsCount, item.LikesCount, item.CommentsCount, item.SharesCount, item.VideoCount, item.ImageCount)
return item
}
// extractInt64ForAyrshare 从 map 中提取 int64 值,尝试多个可能的 key
// getMapKeys 获取 map 的所有键,用于调试
func getMapKeys(m map[string]interface{}) []string {
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return keys
}
func extractInt64ForAyrshare(data map[string]interface{}, keys ...string) int64 {
for _, key := range keys {
if val, ok := data[key]; ok {
// 调试:打印找到的字段和值
fmt.Printf("extractInt64ForAyrshare 找到字段 %s, 值: %v, 类型: %T\n", key, val, val)
switch v := val.(type) {
case float64:
return int64(v)
case int64:
return v
case int:
return int64(v)
case int32:
return int64(v)
case string:
// 如果是字符串,尝试解析为数字
if key == "viewCountPeriod" || key == "commentCountPeriod" || key == "shareCountPeriod" {
// 这些字段是字符串,跳过
continue
}
// 尝试将字符串解析为数字
if num, err := strconv.ParseInt(v, 10, 64); err == nil {
return num
}
if num, err := strconv.ParseFloat(v, 64); err == nil {
return int64(num)
}
}
}
}
return 0
}
// collectWorkMetricsForAyrshare 采集作品指标
func collectWorkMetricsForAyrshare(ctx context.Context, dateCN int) ([]*cast.WorkMetricsDailyItem, error) {
metricsList := make([]*cast.WorkMetricsDailyItem, 0)
fmt.Printf("[%s] [INFO] 开始采集作品指标\n", time.Now().Format("2006-01-02 15:04:05"))
// 调用 ListWorkPlatformInfoPlatformIDs=[1,3], PublishMediaStatus=2, PageSize=99999999
req := &cast.ListWorkPlatformInfoReq{
PlatformIDs: []uint32{1, 3}, // 1 TikTok, 3 Instagram
PublishMediaStatus: 2, // 状态为2
Page: 1,
PageSize: 99999999,
}
resp, err := service.CastProvider.ListWorkPlatformInfo(ctx, req)
if err != nil {
return metricsList, err
}
fmt.Println("--------------------------------")
fmt.Println("66666666666666666666666666666")
fmt.Println("resp", resp)
fmt.Println("66666666666666666666666666666")
fmt.Println("--------------------------------")
if resp == nil || resp.Data == nil || len(resp.Data) == 0 {
zap.L().Info("没有作品平台信息")
return metricsList, nil
}
// 对每个作品调用 GetPostAnalytics
for _, platformInfo := range resp.Data {
if platformInfo.PublishMediaID == "" || platformInfo.WorkUuid == "" {
continue
}
// 只处理 TikTok(1) 和 Instagram(3) 平台
if platformInfo.PlatformID != 1 && platformInfo.PlatformID != 3 {
continue
}
// 通过 ArtistUuid 获取艺人的 AyrShare 信息,获取 profileKey
artistAyrShareReq := &cast.GetArtistAyrShareInfoReq{
ArtistUuid: platformInfo.ArtistUuid,
Status: 1, // 状态为1表示有效
Page: 1,
PageSize: 1,
}
artistAyrShareResp, err := service.CastProvider.GetArtistAyrShareInfo(ctx, artistAyrShareReq)
if err != nil || artistAyrShareResp == nil || len(artistAyrShareResp.Data) == 0 {
zap.L().Warn("获取艺人AyrShare信息失败", zap.Error(err), zap.String("artistUuid", platformInfo.ArtistUuid))
fmt.Printf("collectWorkMetricsForAyrshare 获取艺人AyrShare信息失败artistUuid: %s, 错误: %v\n", platformInfo.ArtistUuid, err)
continue
}
profileKey := artistAyrShareResp.Data[0].ProfileKey
if profileKey == "" {
zap.L().Warn("作品ProfileKey为空跳过", zap.String("workUuid", platformInfo.WorkUuid))
fmt.Printf("collectWorkMetricsForAyrshare 作品ProfileKey为空跳过workUuid: %s\n", platformInfo.WorkUuid)
continue
}
// 调用 GetPostAnalytics 接口
var postReq *aryshare.GetPostAnalyticsRequest
if platformInfo.PlatformID == 1 {
// TikTok 平台
postReq = &aryshare.GetPostAnalyticsRequest{
Id: platformInfo.PublishMediaID,
Platforms: []string{"tiktok"},
ProfileKey: profileKey,
}
} else if platformInfo.PlatformID == 3 {
// Instagram 平台
postReq = &aryshare.GetPostAnalyticsRequest{
Id: platformInfo.PublishMediaID,
Platforms: []string{"instagram"},
ProfileKey: profileKey,
}
}
postResp, err := service.AyrshareProvider.GetPostAnalytics(ctx, postReq)
fmt.Println("--------------------------------")
fmt.Println("postResp", postResp)
fmt.Println("--------------------------------")
if err != nil {
zap.L().Warn("获取作品分析数据失败", zap.Error(err), zap.String("publishMediaID", platformInfo.PublishMediaID))
fmt.Printf("collectWorkMetricsForAyrshare 获取作品分析数据失败publishMediaID: %s, 错误: %v\n", platformInfo.PublishMediaID, err)
continue
}
// 解析作品分析数据并构建指标
item := parsePostAnalyticsToWorkMetricsForAyrshare(postResp, platformInfo, dateCN)
if item != nil {
fmt.Println("--------------------------------")
fmt.Println("test")
fmt.Println("item", item)
fmt.Println("--------------------------------")
metricsList = append(metricsList, item)
fmt.Printf("collectWorkMetricsForAyrshare 解析作品指标成功workUuid: %s, platformID: %d\n", platformInfo.WorkUuid, platformInfo.PlatformID)
}
// 避免请求过于频繁
time.Sleep(200 * time.Millisecond)
}
fmt.Println("--------------------------------")
fmt.Println("metricsList", metricsList)
fmt.Println("--------------------------------")
fmt.Printf("collectWorkMetricsForAyrshare 作品指标采集完成,共采集 %d 条\n", len(metricsList))
return metricsList, nil
}
// parsePostAnalyticsToWorkMetricsForAyrshare 解析作品分析数据并转换为作品指标
func parsePostAnalyticsToWorkMetricsForAyrshare(postResp *aryshare.GetPostAnalyticsResponse, platformInfo *cast.WorkPlatformInfo, dateCN int) *cast.WorkMetricsDailyItem {
fmt.Println("--------------------------------")
fmt.Println("44444444444444444444444444444")
fmt.Println("platformInfo", platformInfo)
fmt.Println("44444444444444444444444444444")
fmt.Println("--------------------------------")
// 根据平台ID选择对应的 JSON 数据
var jsonData string
if platformInfo.PlatformID == 1 { // TikTok
jsonData = postResp.Tiktok
} else if platformInfo.PlatformID == 3 { // Instagram
jsonData = postResp.Instagram
} else {
return nil
}
if jsonData == "" {
return nil
}
// 解析 JSON 数据
var rootData map[string]interface{}
if err := json.Unmarshal([]byte(jsonData), &rootData); err != nil {
zap.L().Warn("解析作品分析数据失败", zap.Error(err))
fmt.Printf("parsePostAnalyticsToWorkMetricsForAyrshare 解析作品分析数据失败workUuid: %s, 错误: %v\n", platformInfo.WorkUuid, err)
return nil
}
// 调试:打印根数据的键
fmt.Printf("[DEBUG] 根数据包含的键: %v\n", getMapKeys(rootData))
// 从根数据中提取 analytics 对象,实际数据可能在 analytics 字段下
var analyticsData map[string]interface{}
if analyticsVal, ok := rootData["analytics"]; ok {
if analyticsMap, ok := analyticsVal.(map[string]interface{}); ok {
analyticsData = analyticsMap
fmt.Printf("analytics 字段提取数据,包含的键: %v\n", getMapKeys(analyticsData))
}
}
// 如果没有 analytics 字段,尝试直接从根数据提取(兼容旧格式)
if analyticsData == nil {
analyticsData = rootData
fmt.Printf("parsePostAnalyticsToWorkMetricsForAyrshare 使用根数据作为 analyticsData包含的键: %v\n", getMapKeys(analyticsData))
}
// 构建作品指标项,使用 ListWorkPlatformInfo 返回的字段信息
item := &cast.WorkMetricsDailyItem{
Uuid: uuid.NewString(),
WorkUuid: platformInfo.WorkUuid,
ArtistUuid: platformInfo.ArtistUuid,
MediaAccUserID: platformInfo.PlatformUserID, // 使用平台用户ID
MediaName: platformInfo.PlatformUserName, // 平台用户名
ArtistName: platformInfo.ArtistName, // 艺人名字
ArtistPhone: platformInfo.ArtistPhone, // 艺人手机号
PlatformID: platformInfo.PlatformID,
Date: int32(dateCN),
}
// 根据平台ID使用不同的字段提取逻辑
if platformInfo.PlatformID == 3 {
// Instagram 平台
// 访问量:使用 viewsCount
item.ViewsCount = extractInt64ForAyrshare(analyticsData, "viewsCount", "viewCount", "views")
// 点赞数:使用 likeCount
item.LikesCount = extractInt64ForAyrshare(analyticsData, "likeCount", "likes", "likesCount")
// 评论数Instagram 可能没有评论数字段,尝试多种可能
item.CommentsCount = extractInt64ForAyrshare(analyticsData, "commentsCount", "commentCount", "comments")
// 分享数:使用 sharesCount注意是复数形式
item.SharesCount = extractInt64ForAyrshare(analyticsData, "sharesCount", "shareCount", "shares")
// 打印解析结果
fmt.Printf("parsePostAnalyticsToWorkMetricsForAyrshare Instagram 作品指标解析完成 - workUuid: %s, 访问量: %d, 点赞数: %d, 评论数: %d, 分享数: %d\n",
platformInfo.WorkUuid,
item.ViewsCount, item.LikesCount, item.CommentsCount, item.SharesCount)
} else if platformInfo.PlatformID == 1 {
// TikTok 平台
// 访问量:使用 viewCountTotal
item.ViewsCount = extractInt64ForAyrshare(analyticsData, "viewCountTotal", "viewCount", "views", "videoViews")
// 点赞数:使用 likeCount
item.LikesCount = extractInt64ForAyrshare(analyticsData, "likeCount", "likes", "likesCount")
// 评论数:使用 commentCountTotal
item.CommentsCount = extractInt64ForAyrshare(analyticsData, "commentCountTotal", "commentCount", "comments", "commentsCount")
// 分享数:使用 shareCountTotal
item.SharesCount = extractInt64ForAyrshare(analyticsData, "shareCountTotal", "shareCount", "shares", "sharesCount")
// 打印解析结果
fmt.Printf("parsePostAnalyticsToWorkMetricsForAyrshare TikTok 作品指标解析完成 - workUuid: %s, 访问量: %d, 点赞数: %d, 评论数: %d, 分享数: %d\n",
platformInfo.WorkUuid,
item.ViewsCount, item.LikesCount, item.CommentsCount, item.SharesCount)
}
fmt.Println("--------------------------------")
fmt.Println("5555555555555555555555")
fmt.Println("item", item)
fmt.Println("5555555555555555555555")
fmt.Println("--------------------------------")
return item
}