123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- package service
- import (
- "context"
- "fmt"
- "github.com/robfig/cron/v3"
- log "github.com/sirupsen/logrus"
- "time"
- "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
- }
- 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
- }
- }
- }
- }
- }
- }
- }
|