package services import ( "encoding/json" "eta/eta_task/models/data_manage" "eta/eta_task/utils" "fmt" "time" ) // SyncEiaSteoIndex EIA STEO报告 指标 func SyncEiaSteoIndex() (err error) { var startDate string maxDate, err := data_manage.GetBaseFromEiaSteoIndexMaxDate() if err != nil || maxDate.IsZero() { startDate = time.Now().AddDate(0, 0, -1).Format(utils.FormatDate) + " 00:00:00" } else { startDate = maxDate.AddDate(0, 0, 1).Format(utils.FormatDate) + " 00:00:00" } method := `index/list` data := make(map[string]interface{}) data["Source"] = utils.DATA_SOURCE_EIA_STEO data["StartDate"] = startDate //data["EndDate"] = endDate result, err := HttpPost("SyncEiaSteoIndex", method, data) utils.FileLog.Info(result) fmt.Println(result) respObj := new(data_manage.EiaSteoIndexResp) err = json.Unmarshal([]byte(result), &respObj) if err != nil { fmt.Println("json.Unmarshal err:" + err.Error()) return err } //获取所有指标信息 某一天的 /*allIndex, err := data_manage.GetBaseFromEiaSteoIndexAll(startDate) if err != nil { fmt.Println("get GetBaseFromEiaSteoIndexAll err:" + err.Error()) return } existIndexMap := make(map[string]*data_manage.BaseFromEiaSteoIndex) for _, v := range allIndex { existIndexMap[v.IndexCode] = v }*/ for _, zv := range respObj.Data { //if _, ok := existIndexMap[zv.IndexCode]; !ok { newID, err := data_manage.InsertOrUpdateBaseFromEiaSteoIndex(zv) if err != nil { fmt.Println("InsertOrUpdateBaseFromEiaSteoIndex error:", err) } fmt.Println("InsertOrUpdateBaseFromEiaSteoIndex new indexID:", newID) //} } return err } // SyncEiaSteoIndexData EIA STEO报告 指标 func SyncEiaSteoIndexData() (err error) { startDate := time.Now().Format(utils.FormatDate) + " 00:00:00" method := `index/data/list` //获取所有指标信息 某一天的 allIndex, err := data_manage.GetBaseFromEiaSteoIndexAll(startDate) if err != nil { fmt.Println("get GetBaseFromEiaSteoIndexAll err:" + err.Error()) return } for _, zv := range allIndex { data := make(map[string]interface{}) data["Source"] = utils.DATA_SOURCE_EIA_STEO data["StartDate"] = startDate data["IndexCode"] = zv.IndexCode var result string result, err = HttpPost("SyncEiaSteoIndexData", method, data) utils.FileLog.Info(result) fmt.Println(result) respObj := new(data_manage.EiaSteoIndexDataResp) err = json.Unmarshal([]byte(result), &respObj) if err != nil { fmt.Println("json.Unmarshal err:" + err.Error()) return err } existDataMap := make(map[int]*data_manage.BaseFromEiaSteoData) allData, err1 := data_manage.GetBaseFromEiaSteoIndexDataAll(startDate) if err1 != nil { fmt.Println("get GetBaseFromEiaSteoIndexDataAll err:" + err1.Error()) return } for _, dv := range allData { existDataMap[dv.BaseFromEiaSteoDataId] = dv } for _, dv := range respObj.Data { if _, ok := existDataMap[dv.BaseFromEiaSteoDataId]; !ok { newID, err := data_manage.AddBaseFromEiaSteoData(dv) if err != nil { fmt.Println("insert error:", err) } fmt.Println("insert new indexID:", newID) } } } return err }