|
@@ -0,0 +1,88 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_task/models/data_manage"
|
|
|
+ "eta/eta_task/utils"
|
|
|
+ "fmt"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func SyncFromGuangzhouClassify() (err error) {
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["Source"] = utils.DATA_SOURCE_GFEX
|
|
|
+ method := `classify/list`
|
|
|
+ result, err := HttpPost("SyncFromGuangzhouClassify", method, data)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("SyncFromGuangzhouClassify HttpPost Err:", err.Error())
|
|
|
+ }
|
|
|
+ utils.FileLog.Info(result)
|
|
|
+ fmt.Println("SyncFromGuangzhouClassify result:", result)
|
|
|
+
|
|
|
+ respObj := new(data_manage.GuangzhouClassifyResp)
|
|
|
+ err = json.Unmarshal([]byte(result), &respObj)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ allClassify, err := data_manage.GetBaseFromTradeGuangzhouClassifyAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ existIndexMap := make(map[int]*data_manage.BaseFromTradeGuangzhouClassify)
|
|
|
+ for _, v := range allClassify {
|
|
|
+ existIndexMap[v.BaseFromTradeGuangzhouClassifyId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, item := range respObj.Data {
|
|
|
+ if _, ok := existIndexMap[item.BaseFromTradeGuangzhouClassifyId]; !ok {
|
|
|
+ newID, err := data_manage.AddBaseFromTradeGuangzhouClassify(item)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("AddBaseFromTradeGuangzhouClassify error:", err)
|
|
|
+ }
|
|
|
+ fmt.Println("AddBaseFromTradeGuangzhouClassify new indexID:", newID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func SyncFromGuangzhouIndex() (err error) {
|
|
|
+ method := `index/list`
|
|
|
+ data := make(map[string]interface{})
|
|
|
+ data["Source"] = utils.DATA_SOURCE_GFEX
|
|
|
+ result, err := HttpPost("SyncFromGuangzhou", method, data)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("SyncFromGuangzhou HttpPost Err:", err.Error())
|
|
|
+ }
|
|
|
+ utils.FileLog.Info(result)
|
|
|
+ fmt.Println("SyncFromGuangzhou result:", result)
|
|
|
+
|
|
|
+ respObj := new(data_manage.GuangzhouIndexResp)
|
|
|
+ err = json.Unmarshal([]byte(result), &respObj)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ allIndex, err := data_manage.GetBaseFromTradeGuangzhouIndexAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ existIndexMap := make(map[int]*data_manage.BaseFromTradeGuangzhouIndex)
|
|
|
+ for _, v := range allIndex {
|
|
|
+ existIndexMap[v.BaseFromTradeGuangzhouIndexId] = v
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, item := range respObj.Data {
|
|
|
+ if _, ok := existIndexMap[item.BaseFromTradeGuangzhouIndexId]; !ok {
|
|
|
+ newID, err := data_manage.AddBaseFromTradeGuangzhouIndex(item)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("insert error:", err)
|
|
|
+ }
|
|
|
+ fmt.Println("insert new indexID:", newID)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|