From 28319bf02af66c784910530de49cd68958e3e071 Mon Sep 17 00:00:00 2001 From: eson Date: Mon, 7 Sep 2020 18:52:59 +0800 Subject: [PATCH] TODO --- extractor_field.go | 24 +++++++++---------- store.go | 2 +- .../twitcasting_task1/twitcasting.go | 10 ++++---- utils.go | 6 +++++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/extractor_field.go b/extractor_field.go index 91a6f4a..d4266da 100644 --- a/extractor_field.go +++ b/extractor_field.go @@ -40,23 +40,23 @@ func (sl *StreamerList) Set(field string, value interface{}) { type Streamer struct { Uid int64 `field:"uid" uid:"auto"` // Platform Platform `field:"platform"` // - UserId string // + UserId *string `field:"user_id"` // - UserName sql.NullString // - LiveUrl sql.NullString // - Channel sql.NullString // - Tags interface{} - Ext interface{} // + UserName *sql.NullString `field:"user_name"` // + LiveUrl *sql.NullString `field:"live_url"` // + Channel *sql.NullString `field:"channel"` // + Tags interface{} `field:"tags"` + Ext interface{} `field:"ext"` // IsUpdateStreamer bool // 更新上面的内容 IsUpdateUrl bool - UpdateInterval int32 - UpdateUrl interface{} - LatestLogUid int64 - UpdateTime sql.NullTime // + UpdateInterval int32 `field:"update_interval"` + UpdateUrl interface{} `field:"update_url"` + LatestLogUid int64 `field:"latest_log_uid"` + UpdateTime *sql.NullTime `field:"update_time"` // - ErrorMsg sql.NullString - Operator int32 + ErrorMsg *sql.NullString `field:"error_msg"` + Operator int32 `field:"operator"` LastOperator int32 } diff --git a/store.go b/store.go index 673bb81..a3179dd 100644 --- a/store.go +++ b/store.go @@ -379,7 +379,7 @@ func (store *StoreExtractor) InsertStreamer(streamer *Streamer) (isExists bool) } }() - streamer.UpdateTime = sql.NullTime{Time: time.Now().Add(-time.Hour * 100000), Valid: true} + streamer.UpdateTime = &sql.NullTime{Time: time.Now().Add(-time.Hour * 100000), Valid: true} _, err = tx.Exec("INSERT IGNORE INTO "+StreamerTable+"(platform, user_id, user_name, live_url, update_url, tags, update_time) VALUES(?,?,?,?,?,?,?);", streamer.Platform, streamer.UserId, diff --git a/tasks/twitcasting/twitcasting_task1/twitcasting.go b/tasks/twitcasting/twitcasting_task1/twitcasting.go index e8a133a..dbd5bdf 100644 --- a/tasks/twitcasting/twitcasting_task1/twitcasting.go +++ b/tasks/twitcasting/twitcasting_task1/twitcasting.go @@ -122,17 +122,17 @@ func Execute() { // log.Println(sp) streamer := &intimate.Streamer{} streamer.Platform = intimate.Ptwitcasting - streamer.LiveUrl = sql.NullString{String: sp.LiveUrl, Valid: true} + streamer.LiveUrl = &sql.NullString{String: sp.LiveUrl, Valid: true} if btags, err := json.Marshal(sp.Tag); err != nil { log.Println(err) } else { streamer.Tags = btags } streamer.UpdateInterval = 120 - streamer.UpdateTime = sql.NullTime{Time: time.Now(), Valid: true} - streamer.UserName = sql.NullString{String: sp.UserName, Valid: true} - streamer.UserId = sp.UserId - streamer.Operator = 33 + streamer.UpdateTime = intimate.GetUpdateTimeNow() + streamer.UserName = &sql.NullString{String: sp.UserName, Valid: true} + streamer.UserId = &sp.UserId + streamer.Operator = 0 // estore.InsertStreamer(streamer) intimate.TStreamer.Insert(streamer) } diff --git a/utils.go b/utils.go index fda2b83..6bf7713 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,7 @@ package intimate import ( + "database/sql" "fmt" "log" "os" @@ -28,6 +29,11 @@ func init() { } +// GetUpdateTimeNow 获取马上更新时间. 与第一次连用 +func GetUpdateTimeNow() *sql.NullTime { + return &sql.NullTime{Time: time.Now().Add(-time.Hour * 100000), Valid: true} +} + // ParseNumber 去逗号解析数字 func ParseNumber(num string) (int64, error) { num = strings.Trim(num, " ")