From 8a0d71a34ebfad6c6b76667770fa31c75b44d980 Mon Sep 17 00:00:00 2001 From: eson Date: Tue, 7 Jul 2020 12:04:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=B8=AA=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform_openrec.go | 29 ++++++++++++++++++++++++----- sql/intimate_source.sql | 2 ++ store.go | 2 +- store_test.go | 10 ++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 store_test.go diff --git a/platform_openrec.go b/platform_openrec.go index a4b95c0..dc2d780 100644 --- a/platform_openrec.go +++ b/platform_openrec.go @@ -7,6 +7,7 @@ import ( "github.com/474420502/hunter" ) +var targetTypeRanking = "openrec_ranking" var openrecRanking *OpenrecRanking // storeOpenrec 源存储实例, 为存储源数据的实现. 表格具体参考sql/intimate_source.sql @@ -30,24 +31,36 @@ func init() { } /* - CREATE TABLE `platform_openrec` ( +CREATE TABLE `platform_openrec` ( `url` text NOT NULL, `target_type` varchar(64) NOT NULL, `source` longtext DEFAULT NULL, `ext` json DEFAULT NULL, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `operator` tinyint NOT NULL, + KEY `operator_idx` (`operator`), KEY `update_time_idx` (`update_time`), KEY `target_type_idx` (`target_type`) ); */ -// PlatformOpenrec 存储源结构 type PlatformOpenrec struct { Url string // TargetType string // Source sql.NullString // Ext interface{} // UpdateTime time.Time // + Operator int32 // +} + +// GetOperator Get return Operator int32 +func (po *PlatformOpenrec) GetOperator() int32 { + return po.Operator +} + +// SetOperator Set Operator int32 +func (po *PlatformOpenrec) SetOperator(Operator int32) { + po.Operator = Operator } // GetUpdateTime Get return UpdateTime time.Time @@ -60,12 +73,12 @@ func (po *PlatformOpenrec) SetUpdateTime(UpdateTime time.Time) { po.UpdateTime = UpdateTime } -// GetExt Get return Ext map[string]interface +// GetExt Get return Ext interface{} func (po *PlatformOpenrec) GetExt() interface{} { return po.Ext } -// SetExt Set Ext map[string]interface +// SetExt Set Ext interface{} func (po *PlatformOpenrec) SetExt(Ext interface{}) { po.Ext = Ext } @@ -111,5 +124,11 @@ func (or *OpenrecRanking) Execute(cxt *hunter.TaskContext) { if err != nil { panic(err) } - cxt.SetShare("test", string(resp.Content())) + + data := &PlatformOpenrec{} + content := resp.Content() + data.SetSource(sql.NullString{String: string(content), Valid: len(content) > 0}) + data.SetUrl(cxt.Workflow().GetRawURL()) + data.SetTargetType(targetTypeRanking) + storeOpenrec.Save(data) } diff --git a/sql/intimate_source.sql b/sql/intimate_source.sql index f9e3aaf..de03a13 100644 --- a/sql/intimate_source.sql +++ b/sql/intimate_source.sql @@ -7,6 +7,8 @@ CREATE TABLE IF NOT EXISTS `platform_openrec` ( `source` longtext DEFAULT NULL, `ext` json DEFAULT NULL, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `operator` int DEFAULT 0, + KEY `operator_idx` (`operator`), KEY `update_time_idx` (`update_time`), KEY `target_type_idx` (`target_type`) ); \ No newline at end of file diff --git a/store.go b/store.go index 47f8f2a..ef9d1b8 100644 --- a/store.go +++ b/store.go @@ -35,6 +35,6 @@ func NewStore() *Store { func (store *Store) Save(isource ISource) { _, err := store.db.Exec("insert into `platform_openrec`(url, target_type, source, ext) values(?,?,?,?)", isource.GetUrl(), isource.GetTargetType(), isource.GetSource(), isource.GetExt()) if err != nil { - log.Println(err) + log.Fatalln(err) } } diff --git a/store_test.go b/store_test.go new file mode 100644 index 0000000..ef09f41 --- /dev/null +++ b/store_test.go @@ -0,0 +1,10 @@ +package main + +import ( + "testing" +) + +func TestStoreInsert(t *testing.T) { + // ht := hunter.NewHunter(openrecRanking) + // ht.Execute() +}