|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
|
|
+ "github.com/robfig/cron/v3"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap"
|
|
@@ -22,22 +23,26 @@ var (
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
go updateMethod()
|
|
go updateMethod()
|
|
- go dealBidding()
|
|
|
|
- //go dealProject()
|
|
|
|
- //local, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
- //c := cron.New(cron.WithLocation(local), cron.WithSeconds())
|
|
|
|
- //eid, err := c.AddFunc(GF.Cron.Spec, test)
|
|
|
|
- //if err != nil {
|
|
|
|
- // log.Info("main", zap.Any("AddFunc err", err))
|
|
|
|
- //}
|
|
|
|
- //log.Info("main", zap.Any("eid", eid))
|
|
|
|
- //
|
|
|
|
- //c.Start()
|
|
|
|
- //defer c.Stop()
|
|
|
|
|
|
+
|
|
|
|
+ local, _ := time.LoadLocation("Asia/Shanghai")
|
|
|
|
+ c := cron.New(cron.WithLocation(local), cron.WithSeconds())
|
|
|
|
+ eid, err := c.AddFunc(GF.Cron.Spec, dealData)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Info("main", zap.Any("AddFunc err", err))
|
|
|
|
+ }
|
|
|
|
+ log.Info("main", zap.Any("eid", eid))
|
|
|
|
+
|
|
|
|
+ c.Start()
|
|
|
|
+ defer c.Stop()
|
|
//
|
|
//
|
|
select {}
|
|
select {}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func dealData() {
|
|
|
|
+ go dealBidding()
|
|
|
|
+ go dealProject()
|
|
|
|
+}
|
|
|
|
+
|
|
//dealBidding 处理标讯数据
|
|
//dealBidding 处理标讯数据
|
|
func dealBidding() {
|
|
func dealBidding() {
|
|
sess := MgoB.GetMgoConn()
|
|
sess := MgoB.GetMgoConn()
|
|
@@ -46,6 +51,7 @@ func dealBidding() {
|
|
var q interface{}
|
|
var q interface{}
|
|
var startTime = GF.Cron.Start
|
|
var startTime = GF.Cron.Start
|
|
|
|
|
|
|
|
+ now := time.Now()
|
|
ctx, _ := context.WithTimeout(context.Background(), 99999*time.Hour)
|
|
ctx, _ := context.WithTimeout(context.Background(), 99999*time.Hour)
|
|
coll := sess.M.C.Database(GF.MongoB.DB).Collection(GF.MongoB.Coll)
|
|
coll := sess.M.C.Database(GF.MongoB.DB).Collection(GF.MongoB.Coll)
|
|
find := options.Find().SetBatchSize(1000).SetSort(bson.D{bson.E{"comeintime", 1}}).SetProjection(bson.M{"comeintime": 1, "toptype": 1, "subtype": 1, "buyerclass": 1, "title": 1, "detail": 1, "package": 1, "funds": 1})
|
|
find := options.Find().SetBatchSize(1000).SetSort(bson.D{bson.E{"comeintime", 1}}).SetProjection(bson.M{"comeintime": 1, "toptype": 1, "subtype": 1, "buyerclass": 1, "title": 1, "detail": 1, "package": 1, "funds": 1})
|
|
@@ -56,12 +62,19 @@ func dealBidding() {
|
|
"$lte": GF.Cron.End,
|
|
"$lte": GF.Cron.End,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ } else if startTime != 0 {
|
|
q = map[string]interface{}{
|
|
q = map[string]interface{}{
|
|
"comeintime": map[string]interface{}{
|
|
"comeintime": map[string]interface{}{
|
|
"$gt": startTime,
|
|
"$gt": startTime,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
+ } else if startTime == 0 && GF.Cron.End == 0 {
|
|
|
|
+ //默认 取大于 昨天的数据
|
|
|
|
+ q = map[string]interface{}{
|
|
|
|
+ "comeintime": map[string]interface{}{
|
|
|
|
+ "$gt": time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location()).Unix(),
|
|
|
|
+ },
|
|
|
|
+ }
|
|
}
|
|
}
|
|
cur, err := coll.Find(ctx, q, find)
|
|
cur, err := coll.Find(ctx, q, find)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -134,15 +147,26 @@ func dealProject() {
|
|
now := time.Now()
|
|
now := time.Now()
|
|
|
|
|
|
var q interface{}
|
|
var q interface{}
|
|
- //targetTime := time.Date(now.Year(), now.Month(), now.Day()+GF.Cron.Start, 04, 20, 0, 0, now.Location())
|
|
|
|
- targetTime := time.Date(now.Year(), now.Month(), now.Day()+GF.Cron.Start, 0, 0, 0, 0, now.Location())
|
|
|
|
- todayTime := time.Date(now.Year(), now.Month(), now.Day()+GF.Cron.End, 0, 0, 0, 0, now.Location())
|
|
|
|
|
|
+ var startTime = GF.Cron.Start
|
|
|
|
|
|
- if GF.Cron.Start != 0 {
|
|
|
|
|
|
+ if startTime != 0 && GF.Cron.End != 0 {
|
|
|
|
+ q = map[string]interface{}{
|
|
|
|
+ "pici": map[string]interface{}{
|
|
|
|
+ "$gt": GF.Cron.Start,
|
|
|
|
+ "$lte": GF.Cron.End,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ } else if startTime != 0 {
|
|
|
|
+ q = map[string]interface{}{
|
|
|
|
+ "pici": map[string]interface{}{
|
|
|
|
+ "$gt": startTime,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ } else if startTime == 0 && GF.Cron.End == 0 {
|
|
|
|
+ //默认 取大于 昨天的数据
|
|
q = map[string]interface{}{
|
|
q = map[string]interface{}{
|
|
"pici": map[string]interface{}{
|
|
"pici": map[string]interface{}{
|
|
- "$gt": targetTime.Unix(),
|
|
|
|
- "$lte": todayTime.Unix(),
|
|
|
|
|
|
+ "$gt": time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, now.Location()).Unix(),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|