package service import ( "context" "fmt" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" "time" "youngee_b_api/app/service" "youngee_b_api/db" "youngee_b_api/model/gorm_model" ) func AutoTask() error { c := cron.New(cron.WithSeconds()) //spec := "0 */30 * * * ?" //cron表达式,每半小时执行一次 spec := "0 */2 * * * ?" //cron表达式,每1分钟一次 //spec := "*/10 * * * * ?" //cron表达式,每10秒一次 /* _, err1 := c.AddFunc(spec, AutoTaskUpdateStatus) if err1 != nil { log.Println("service [AutoTaskUpdateStatus] error:", err1) return err1 } _, err2 := c.AddFunc("@midnight", AutoTaskUpdateApplyTimes) if err2 != nil { log.Println("service [AutoTaskUpdateApplyTimes] error:", err2) return err2 } _, err3 := c.AddFunc(spec, AutoTaskCompleteSelection) if err3 != nil { log.Println("service [AutoTaskCompleteSecTask] error:", err2) return err3 } */ _, err4 := c.AddFunc(spec, GetAutoDraftDefaultTask) if err4 != nil { log.Println("service [GetAutoDraftDefaultTask] error:", err4) return err4 } _, err5 := c.AddFunc(spec, GetAutoLinkDefaultTask) if err5 != nil { log.Println("service [GetAutoLinkDefaultTask] error:", err5) return err5 } _, err6 := c.AddFunc(spec, GetAutoCaseCloseDefaultTask) if err6 != nil { log.Println("service [GetAutoCaseCloseDefaultTask] error:", err6) return err6 } _, err7 := c.AddFunc(spec, UpdateProjectTaskRedBookLinkData) if err7 != nil { log.Println("service [UpdateProjectTaskRedBookLinkData] error:", err7) return err7 } _, err8 := c.AddFunc(spec, UpdateLocalTaskRedBookLinkData) if err8 != nil { log.Println("service [UpdateLocalTaskRedBookLinkData] error:", err8) return err8 } _, err9 := c.AddFunc(spec, UpdateProjectTaskWeiBoLinkData) if err9 != nil { log.Println("service [UpdateProjectTaskWeiBoLinkData] error:", err9) return err9 } _, err10 := c.AddFunc(spec, UpdateLocalTaskWeiBoLinkData) if err10 != nil { log.Println("service [UpdateProjectTaskWeiBoLinkData] error:", err10) return err10 } _, err11 := c.AddFunc(spec, UpdateProjectTaskDouyinLinkData) if err11 != nil { log.Println("service [UpdateProjectTaskDouyinLinkData] error:", err11) return err11 } _, err12 := c.AddFunc(spec, UpdateLocalTaskDouyinLinkData) if err12 != nil { log.Println("service [UpdateLocalTaskDouyinLinkData] error:", err12) return err12 } _, err13 := c.AddFunc(spec, UpdateProjectTaskKuaishouLinkData) if err13 != nil { log.Println("service [UpdateProjectTaskKuaishouLinkData] error:", err13) return err13 } _, err14 := c.AddFunc(spec, UpdateLocalTaskKuaishouLinkData) if err14 != nil { log.Println("service [UpdateLocalTaskKuaishouLinkData] error:", err14) return err14 } _, err15 := c.AddFunc(spec, UpdateProjectTaskBilibiliLinkData) if err15 != nil { log.Println("service [UpdateProjectTaskBilibiliLinkData] error:", err15) return err15 } _, err16 := c.AddFunc(spec, UpdateLocalTaskBilibiliLinkData) if err16 != nil { log.Println("service [UpdateLocalTaskBilibiliLinkData] error:", err16) return err16 } fmt.Println(spec) c.Start() return nil } func AutoTaskUpdateStatus() { err := db.AutoUpdateStatus() log.Println("AutoTaskUpdateStatus is running ,Time :", time.Now()) if err != nil { log.Println("AutoTaskUpdateStatus error : ", err) } } func AutoTaskUpdateApplyTimes() { err := db.AutoUpdateApplyTimes() log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now()) if err != nil { log.Println("AutoUpdateApplyTimes error : ", err) } } func AutoTaskCompleteSelection() { err := db.AutoCompleteSelection() log.Println("AutoUpdateApplyTimes is running ,Time :", time.Now()) if err != nil { log.Println("AutoUpdateApplyTimes error : ", err) } } // GetAutoDraftDefaultTask 初稿超时违约 func GetAutoDraftDefaultTask() { err := db.GetAutoDraftDefaultTask() log.Println("GetAutoDraftDefaultInPicTask is running ,Time :", time.Now()) if err != nil { log.Println("GetAutoDraftDefaultInPicTask error : ", err) } } // GetAutoLinkDefaultTask 链接超时违约 func GetAutoLinkDefaultTask() { err := db.GetAutoLinkDefaultTask() log.Println("GetAutoLinkDefaultTask is running ,Time :", time.Now()) if err != nil { log.Println("GetAutoDraftDefaultInPicTask error : ", err) } } // GetAutoCaseCloseDefaultTask 数据超时违约 func GetAutoCaseCloseDefaultTask() { err := db.GetAutoCaseCloseDefaultTask() log.Println("GetAutoCaseCloseDefaultTask is running ,Time :", time.Now()) if err != nil { log.Println("GetAutoCaseCloseDefaultTask error : ", err) } } // UpdateProjectTaskRedBookLinkData 定时拉取小红书平台,种草子任务链接数据 func UpdateProjectTaskRedBookLinkData() { log.Println("UpdateProjectTaskRedBookLinkData is running ,Time :", time.Now()) // 1. 符合条件的project ctx := context.Background() projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 1) if projectIdListErr != nil { log.Println("GetProjectIdList error : ", projectIdListErr) return } // 2. 符合条件的task if projectIdList != nil && projectIdListTotal != 0 { for _, projectId := range projectIdList { taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := GetRedBookLinkDetail(ctx, linkInfo) if moreApiErr != nil { log.Println("GetRedBookLinkDetail error : ", moreApiErr) continue } createData := gorm_model.ProjectTaskLinkStatistic{ ProjectId: projectId, TaskId: taskId, PlatformId: 1, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateLocalTaskRedBookLinkData 定时拉取小红书平台,本地生活子任务链接数据 func UpdateLocalTaskRedBookLinkData() { log.Println("UpdateLocalTaskRedBookLinkData is running ,Time :", time.Now()) // 1. 符合条件的local ctx := context.Background() localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 1) if localIdListErr != nil { log.Println("GetLocalIdList error : ", localIdListErr) return } // 2. 符合条件的task if localIdList != nil && localIdListTotal != 0 { for _, localId := range localIdList { taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := GetRedBookLinkDetail(ctx, linkInfo) if moreApiErr != nil { log.Println("GetRedBookLinkDetail error : ", moreApiErr) continue } createData := gorm_model.LocalTaskLinkStatistic{ LocalId: localId, TaskId: taskId, PlatformId: 1, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateProjectTaskWeiBoLinkData 定时拉取微博平台,种草子任务链接数据 func UpdateProjectTaskWeiBoLinkData() { log.Println("UpdateProjectTaskWeiBoLinkData is running ,Time :", time.Now()) // 1. 符合条件的project ctx := context.Background() projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 3) if projectIdListErr != nil { log.Println("GetProjectIdList error : ", projectIdListErr) return } // 2. 符合条件的task if projectIdList != nil && projectIdListTotal != 0 { for _, projectId := range projectIdList { taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := GetWeiBoLinkDetail(ctx, linkInfo) if moreApiErr != nil { log.Println("GetWeiBoLinkDetail error : ", moreApiErr) continue } createData := gorm_model.ProjectTaskLinkStatistic{ ProjectId: projectId, TaskId: taskId, PlatformId: 3, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateLocalTaskWeiBoLinkData 定时拉取微博平台,本地生活子任务链接数据 func UpdateLocalTaskWeiBoLinkData() { log.Println("UpdateLocalTaskWeiBoLinkData is running ,Time :", time.Now()) // 1. 符合条件的local ctx := context.Background() localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 3) if localIdListErr != nil { log.Println("GetLocalIdList error : ", localIdListErr) return } // 2. 符合条件的task if localIdList != nil && localIdListTotal != 0 { for _, localId := range localIdList { taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId) if taskIdErr != nil { log.Println("UpdateLocalTaskWeiBoLinkData error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := GetWeiBoLinkDetail(ctx, linkInfo) if moreApiErr != nil { log.Println("GetWeiBoLinkDetail error : ", moreApiErr) continue } createData := gorm_model.LocalTaskLinkStatistic{ LocalId: localId, TaskId: taskId, PlatformId: 3, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateProjectTaskDouyinLinkData 定时拉取抖音平台,种草子任务链接数据 func UpdateProjectTaskDouyinLinkData() { log.Println("UpdateProjectTaskDouyinLinkData is running ,Time :", time.Now()) // 1. 符合条件的project ctx := context.Background() projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 2) if projectIdListErr != nil { log.Println("GetProjectIdList error : ", projectIdListErr) return } // 2. 符合条件的task if projectIdList != nil && projectIdListTotal != 0 { for _, projectId := range projectIdList { taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetDouyinStatistic(linkInfo) if moreApiErr != nil { log.Println("GetDouyinStatistic error : ", moreApiErr) continue } createData := gorm_model.ProjectTaskLinkStatistic{ ProjectId: projectId, TaskId: taskId, PlatformId: 2, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateLocalTaskDouyinLinkData 定时拉取抖音平台,本地生活子任务链接数据 func UpdateLocalTaskDouyinLinkData() { log.Println("UpdateLocalTaskDouyinLinkData is running ,Time :", time.Now()) // 1. 符合条件的local ctx := context.Background() localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 2) if localIdListErr != nil { log.Println("GetLocalIdList error : ", localIdListErr) return } // 2. 符合条件的task if localIdList != nil && localIdListTotal != 0 { for _, localId := range localIdList { taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId) if taskIdErr != nil { log.Println("GetLocalTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetDouyinStatistic(linkInfo) if moreApiErr != nil { log.Println("GetWeiBoLinkDetail error : ", moreApiErr) continue } createData := gorm_model.LocalTaskLinkStatistic{ LocalId: localId, TaskId: taskId, PlatformId: 2, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateLocalTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateProjectTaskKuaishouLinkData 定时拉取快手平台,种草子任务链接数据 func UpdateProjectTaskKuaishouLinkData() { log.Println("UpdateProjectTaskKuaishouLinkData is running ,Time :", time.Now()) // 1. 符合条件的project ctx := context.Background() projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 4) if projectIdListErr != nil { log.Println("GetProjectIdList error : ", projectIdListErr) return } // 2. 符合条件的task if projectIdList != nil && projectIdListTotal != 0 { for _, projectId := range projectIdList { taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetKuaishouStatistic(linkInfo) if moreApiErr != nil { log.Println("GetKuaishouStatistic error : ", moreApiErr) continue } createData := gorm_model.ProjectTaskLinkStatistic{ ProjectId: projectId, TaskId: taskId, PlatformId: 4, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateLocalTaskKuaishouLinkData 定时拉取快手平台,本地生活子任务链接数据 func UpdateLocalTaskKuaishouLinkData() { log.Println("UpdateLocalTaskKuaishouLinkData is running ,Time :", time.Now()) // 1. 符合条件的local ctx := context.Background() localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 4) if localIdListErr != nil { log.Println("GetLocalIdList error : ", localIdListErr) return } // 2. 符合条件的task if localIdList != nil && localIdListTotal != 0 { for _, localId := range localIdList { taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId) if taskIdErr != nil { log.Println("GetLocalTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetKuaishouStatistic(linkInfo) if moreApiErr != nil { log.Println("GetKuaishouStatistic error : ", moreApiErr) continue } createData := gorm_model.LocalTaskLinkStatistic{ LocalId: localId, TaskId: taskId, PlatformId: 4, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateLocalTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateProjectTaskBilibiliLinkData 定时拉取b站平台,种草子任务链接数据 func UpdateProjectTaskBilibiliLinkData() { log.Println("UpdateProjectTaskBilibiliLinkData is running ,Time :", time.Now()) // 1. 符合条件的project ctx := context.Background() projectIdList, projectIdListTotal, projectIdListErr := db.GetProjectIdList(ctx, 8, 5) if projectIdListErr != nil { log.Println("GetProjectIdList error : ", projectIdListErr) return } // 2. 符合条件的task if projectIdList != nil && projectIdListTotal != 0 { for _, projectId := range projectIdList { taskIdList, taskIdTotal, taskIdErr := db.GetProjectTaskIdList(ctx, projectId) if taskIdErr != nil { log.Println("GetProjectTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetBilibiliStatistic(linkInfo) if moreApiErr != nil { log.Println("GetBilibiliStatistic error : ", moreApiErr) continue } createData := gorm_model.ProjectTaskLinkStatistic{ ProjectId: projectId, TaskId: taskId, PlatformId: 5, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateProjectTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateProjectTaskLinkStatistic error : ", createErr) continue } } } } } } } // UpdateLocalTaskBilibiliLinkData 定时拉取b站平台,本地生活子任务链接数据 func UpdateLocalTaskBilibiliLinkData() { log.Println("UpdateLocalTaskBilibiliLinkData is running ,Time :", time.Now()) // 1. 符合条件的local ctx := context.Background() localIdList, localIdListTotal, localIdListErr := db.GetLocalIdList(ctx, 8, 5) if localIdListErr != nil { log.Println("GetLocalIdList error : ", localIdListErr) return } // 2. 符合条件的task if localIdList != nil && localIdListTotal != 0 { for _, localId := range localIdList { taskIdList, taskIdTotal, taskIdErr := db.GetLocalTaskIdList(ctx, localId) if taskIdErr != nil { log.Println("GetLocalTaskIdList error : ", taskIdErr) continue } if taskIdList != nil && taskIdTotal != 0 { for _, taskId := range taskIdList { linkInfo, linkErr := db.GetProjectTaskLinkInfo(ctx, taskId, 1) if linkErr != nil { log.Println("GetProjectTaskLinkInfo error : ", linkErr) continue } if linkInfo != "" { like, comment, collect, share, moreApiErr := service.MoreapiService{}.GetBilibiliStatistic(linkInfo) if moreApiErr != nil { log.Println("GetKuaishouStatistic error : ", moreApiErr) continue } createData := gorm_model.LocalTaskLinkStatistic{ LocalId: localId, TaskId: taskId, PlatformId: 5, VoteCount: like, CommitCount: comment, CollectionCount: collect, ViewCount: share, } createErr := db.CreateLocalTaskLinkStatistic(ctx, &createData) if createErr != nil { log.Println("CreateLocalTaskLinkStatistic error : ", createErr) continue } } } } } } }