From 036a73a0429630b187cf823f851e212936b1a280 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 11 Jan 2024 16:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=9C=9C=E6=BA=90=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/task/init.go | 1 + app/task/md/cron_key.go | 1 + .../svc_data_collect_cron_miyuan_real_news.go | 57 ++++++++++++++++++- ...ask_data_collect_cron_miyuan_real_news1.go | 21 +++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 app/task/task_data_collect_cron_miyuan_real_news1.go diff --git a/app/task/init.go b/app/task/init.go index 072f36d..ff7bdb3 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -88,6 +88,7 @@ func initTasks() { jobs[taskMd.DataCollectCronHaodankuRealNews10] = taskDataCollectCronHaodankuRealNews10 // jobs[taskMd.DataCollectCronMiyuanRealNews] = taskDataCollectCronMiyuanRealNews // + jobs[taskMd.DataCollectCronMiyuanRealNews1] = taskDataCollectCronMiyuanRealNews1 // jobs[taskMd.DataCollectCronMiyuanRealNews10] = taskDataCollectCronMiyuanRealNews10 // } diff --git a/app/task/md/cron_key.go b/app/task/md/cron_key.go index 8c010f7..1c88dae 100644 --- a/app/task/md/cron_key.go +++ b/app/task/md/cron_key.go @@ -5,5 +5,6 @@ const ( DataCollectCronHaodankuRealNews10 = "data_collect_cron_haodanku_real_news10" DataCollectCronMiyuanRealNews = "data_collect_cron_miyuan_real_news" + DataCollectCronMiyuanRealNews1 = "data_collect_cron_miyuan_real_news1" DataCollectCronMiyuanRealNews10 = "data_collect_cron_miyuan_real_news10" ) diff --git a/app/task/svc/svc_data_collect_cron_miyuan_real_news.go b/app/task/svc/svc_data_collect_cron_miyuan_real_news.go index d60ca1a..b40cd33 100644 --- a/app/task/svc/svc_data_collect_cron_miyuan_real_news.go +++ b/app/task/svc/svc_data_collect_cron_miyuan_real_news.go @@ -15,7 +15,62 @@ import ( func DataCollectCronMiyuanRealNews(types int) { key := md.ZhiosRealNewsData //es.CreateIndexIfNotExists(key, md.ZhiosRealNewsDataField) - ids := []string{"MC", "TM", "JD", "PDD", "CD", "ZD", "MS", "QYH", "TM", "BJ", "HJ"} + ids := []string{"CD", "MS", "TM", "JD", "PDD"} + //ids = []string{"CD"} + num := 10 + if types == 0 { + ids = []string{""} + num = 3 + } + size := 10 + now := time.Now() + fmt.Println("============", time.Since(now)) + for _, v := range ids { + for i := 1; i <= num; i++ { + time.Sleep(time.Microsecond * 10) // 等待10毫秒 + newsData, err := gzmiyuan.GetGzmiRealData(utils.IntToStr(size), utils.IntToStr(i), v) + utils.FilePutContents("my", utils.SerializeStr(newsData)) + if err != nil { + utils.FilePutContents("my", err.Error()) + } + if newsData == nil || err != nil { + continue + } + platformMap := map[string]string{"TM": "10010", "BJ": "10009", "HJ": "10008", "MC": "10001", "TB": "10003", "JD": "10004", "PDD": "10005", "CD": "10006", "ZD": "10002", "MS": "10007", "QYH": "10000"} + for _, item := range newsData { + var tmp = md2.RealNewsData{ + Id: item.Id, + CateId: utils.SerializeStr([]string{platformMap[item.OpenType]}), + Images: utils.SerializeStr(strings.Split(item.XianbaoImageUrl, ",")), + Platform: "my", + StartTime: utils.TimeStdParseUnix(item.CreateTime), + OldContent: item.XianbaoContent, + } + tmp.Key = php2go.Md5("hdk_real_news_my_" + utils.IntToStr(item.Id)) + var uniqueId = tmp.Key + doc, _ := es.FirstDoc(key, uniqueId) + if doc == nil { + goodsList := ToContent(item.XianbaoContent) + + tmp.Content = utils.SerializeStr(goodsList) + fmt.Println(tmp) + createDocRet, err := es.CreateDoc(key, uniqueId, tmp) + if err != nil { + return + } + fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet) + } + + } + } + + } + fmt.Println("==========================end", time.Since(now)) +} +func DataCollectCronMiyuanRealNews1(types int) { + key := md.ZhiosRealNewsData + //es.CreateIndexIfNotExists(key, md.ZhiosRealNewsDataField) + ids := []string{"ZD", "MC", "QYH", "TM", "BJ", "HJ"} //ids = []string{"CD"} num := 10 if types == 0 { diff --git a/app/task/task_data_collect_cron_miyuan_real_news1.go b/app/task/task_data_collect_cron_miyuan_real_news1.go new file mode 100644 index 0000000..166c9ff --- /dev/null +++ b/app/task/task_data_collect_cron_miyuan_real_news1.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskDataCollectCronMiyuanRealNews1() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.DataCollectCronMiyuanRealNews1(1) + <-ch +}