瀏覽代碼

weibo_link_auto_task

Xingyu Xian 2 天之前
父節點
當前提交
727fad19ac
共有 4 個文件被更改,包括 90 次插入11 次删除
  1. 2 2
      db/project_task.go
  2. 2 1
      db/project_task_link_statistic.go
  3. 60 0
      service/autoTask.go
  4. 26 8
      service/talent_platform_link_statistic.go

+ 2 - 2
db/project_task.go

@@ -1345,7 +1345,7 @@ func GetProjectTaskIdList(ctx context.Context, projectId string) ([]string, int6
 	// Get count first
 	var total int64
 	if err := db.Model(gorm_model.YoungeeTaskInfo{}).
-		Where("data_status = ? and project_id = ?", 5, projectId).
+		Where("link_status = ? and project_id = ?", 5, projectId).
 		Count(&total).
 		Error; err != nil {
 		logrus.WithContext(ctx).Errorf("[GetProjectTaskIdList] error counting task, err:%+v", err)
@@ -1356,7 +1356,7 @@ func GetProjectTaskIdList(ctx context.Context, projectId string) ([]string, int6
 	var taskIds []string
 	err := db.Debug().
 		Model(gorm_model.YoungeeTaskInfo{}).
-		Where("data_status = ? and project_id = ?", 5, projectId).
+		Where("link_status = ? and project_id = ?", 5, projectId).
 		Order("update_at desc").
 		Pluck("task_id", &taskIds).
 		Error

+ 2 - 1
db/project_task_link_statistic.go

@@ -22,8 +22,9 @@ func CreateProjectTaskLinkStatistic(ctx context.Context, stat *gorm_model.Projec
 	}
 
 	// 设置默认时间
-	if stat.CreateTime.IsZero() {
+	if stat.CreateTime == nil {
 		var currentTime time.Time
+		currentTime = time.Now()
 		stat.CreateTime = &currentTime
 	}
 

+ 60 - 0
service/autoTask.go

@@ -59,6 +59,11 @@ func AutoTask() error {
 		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
@@ -224,3 +229,58 @@ func UpdateLocalTaskRedBookLinkData() {
 		}
 	}
 }
+
+// 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
+						}
+					}
+				}
+			}
+		}
+	}
+}

+ 26 - 8
service/talent_platform_link_statistic.go

@@ -82,6 +82,7 @@ func parseWeiboStats(jsonData []byte) (likes, comments, reposts, reads string, e
 		nil
 }
 
+// GetRedBookLinkDetail 获取小红书链接数据详情
 func GetRedBookLinkDetail(ctx context.Context, shareText string) (int, int, int, int, error) {
 
 	url := "http://120.46.92.62:6888/api/xhs/note_detail"
@@ -150,19 +151,36 @@ func GetRedBookLinkDetail(ctx context.Context, shareText string) (int, int, int,
 	return like, comment, collect, share, nil
 }
 
+// GetWeiBoLinkDetail 获取微博链接数据详情
 func GetWeiBoLinkDetail(ctx context.Context, shareText string) (int, int, int, int, error) {
-	url := "http://api.moreapi.cn/api/weibo/post_detail"
+	url := "http://120.46.92.62:6888/api/weibo/post_detail"
 	method := "POST"
 
-	payload := strings.NewReader(`{
-    "id":"",
-    "share_text":"",
-    "proxy":""
-}`)
+	fmt.Println(shareText)
+
+	requestBody := struct {
+		Id        string `json:"id"`
+		ShareText string `json:"share_text"`
+		Proxy     string `json:"proxy"`
+	}{
+		Id:        "",
+		ShareText: shareText,
+		Proxy:     "",
+	}
+
+	jsonData, err := json.Marshal(requestBody)
+	if err != nil {
+		fmt.Println("JSON编码失败:", err)
+		return 0, 0, 0, 0, err
+	}
+
+	payload := strings.NewReader(string(jsonData))
 
 	client := &http.Client{}
 	req, err := http.NewRequest(method, url, payload)
 
+	fmt.Println(req)
+
 	if err != nil {
 		//fmt.Println(err)
 		return 0, 0, 0, 0, err
@@ -171,14 +189,14 @@ func GetWeiBoLinkDetail(ctx context.Context, shareText string) (int, int, int, i
 
 	res, err := client.Do(req)
 	if err != nil {
-		//fmt.Println(err)
+		fmt.Println(err)
 		return 0, 0, 0, 0, err
 	}
 	defer res.Body.Close()
 
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
-		//fmt.Println(err)
+		fmt.Println(err)
 		return 0, 0, 0, 0, err
 	}
 	// fmt.Println(string(body))