123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- package services
- import (
- "encoding/json"
- "eta/eta_crawler/models"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- "strconv"
- "time"
- )
- type EicListing struct {
- Name string `json:"name"`
- ShortName string `json:"short_name"`
- Type string `json:"type"`
- Eic string `json:"eic"`
- Country string `json:"country"`
- Url string `json:"url"`
- Facilities []Facilities `json:"facilities"`
- }
- type Facilities struct {
- Name string `json:"name"`
- Type string `json:"type"`
- Eic string `json:"eic"`
- Country string `json:"country"`
- Company string `json:"company"`
- Url string `json:"url"`
- }
- type Storage struct {
- Status string `json:"status"`
- GasDayStartedOn string `json:"gasDayStartedOn"`
- GasInStorage string `json:"gasInStorage"`
- Full string `json:"full"`
- Trend string `json:"trend"`
- Injection string `json:"injection"`
- Withdrawal string `json:"withdrawal"`
- WorkingGasVolume string `json:"workingGasVolume"`
- InjectionCapacity string `json:"injectionCapacity"`
- WithdrawalCapacity string `json:"withdrawalCapacity"`
- Info string `json:"info"`
- }
- var eicIndexCodeMap = make(map[string]string)
- func SyncStorageFromEic() {
- allCode, err := models.GetIndexCodeFromMapping("Eic")
- if err != nil {
- fmt.Println("select Code err:", err)
- }
- for _, item := range allCode {
- eicIndexCodeMap[item.IndexName] = item.IndexCode
- }
- baseUrl := "https://agsi.gie.eu/api/eic-listing/SSO/view"
- body, err := http.Get(baseUrl)
- if err != nil {
- fmt.Println("GetData Err:" + err.Error())
- return
- }
- var eicListing []EicListing
- err = json.Unmarshal(body, &eicListing)
- for _, sso := range eicListing {
- var codeMapList []*models.BaseFromTradeMapping
- existIndexMap := make(map[string]*models.BaseFromTradeEicIndex)
- //获取所有指标信息
- allIndex, err := models.GetSSOFromEicIndexAll(sso.Name)
- if err != nil {
- fmt.Println("select err:", err)
- }
- for _, v := range allIndex {
- existIndexMap[v.GasDayStartedOn+v.Name] = v
- }
- ssoUrl := sso.Url
- ssoBody, err := http.Get(ssoUrl)
- fmt.Println("ssoUrl:", ssoUrl)
- if err != nil {
- fmt.Println("GetData Err:" + err.Error())
- continue
- }
- var ssoStorages []Storage
- err = json.Unmarshal(ssoBody, &ssoStorages)
- //SSO item
- var ssoItems []*models.BaseFromTradeEicIndex
- for _, storageItem := range ssoStorages {
- gasInStorage, _ := strconv.ParseFloat(storageItem.GasInStorage, 64)
- full, _ := strconv.ParseFloat(storageItem.Full, 64)
- trend, _ := strconv.ParseFloat(storageItem.Trend, 64)
- injection, _ := strconv.ParseFloat(storageItem.Injection, 64)
- withdrawal, _ := strconv.ParseFloat(storageItem.Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(storageItem.WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(storageItem.InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(storageItem.WithdrawalCapacity, 64)
- ssoItem := models.BaseFromTradeEicIndex{
- BaseFromEicIndexId: 0,
- Country: sso.Country,
- Type: sso.Type,
- EicCode: sso.Country + sso.Eic,
- ShortName: sso.ShortName,
- Name: sso.Name,
- Status: storageItem.Status,
- GasDayStartedOn: storageItem.GasDayStartedOn,
- GasInStorage: gasInStorage,
- GasInStorageCode: sso.Country + sso.Eic + "GS",
- Full: full,
- FullCode: sso.Country + sso.Eic + "F",
- Trend: trend,
- TrendCode: sso.Country + sso.Eic + "T",
- Injection: injection,
- InjectionCode: sso.Country + sso.Eic + "In",
- Withdrawal: withdrawal,
- WithdrawalCode: sso.Country + sso.Eic + "Out",
- WorkingGasVolume: workingGasVolume,
- WorkingGasVolumeCode: sso.Country + sso.Eic + "WGV",
- InjectionCapacity: injectionCapacity,
- InjectionCapacityCode: sso.Country + sso.Eic + "IC",
- WithdrawalCapacity: withdrawalCapacity,
- WithdrawalCapacityCode: sso.Country + sso.Eic + "WC",
- Info: storageItem.Info,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- itemVerifyCode := ssoItem.GasInStorage + ssoItem.Full + ssoItem.Trend + ssoItem.Injection + ssoItem.Withdrawal
- if existIndex, ok := existIndexMap[ssoItem.GasDayStartedOn+ssoItem.Name]; !ok {
- ssoItems = append(ssoItems, &ssoItem)
- existIndexMap[ssoItem.GasDayStartedOn+ssoItem.Name] = &ssoItem
- } else if existIndex != nil && itemVerifyCode != (existIndex.GasInStorage+existIndex.Full+existIndex.Trend+existIndex.Injection+existIndex.Withdrawal) {
- //更新
- err := models.ModifyBaseFromEicIndex(ssoItem.GasInStorage, ssoItem.Full, ssoItem.Trend, ssoItem.Injection, ssoItem.Withdrawal, existIndex.BaseFromEicIndexId)
- if err != nil {
- fmt.Println("data update err:", err)
- }
- }
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name,
- IndexCode: sso.Country + sso.Eic,
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name] = sso.Country + sso.Eic
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"GS"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "GS",
- IndexCode: sso.Country + sso.Eic + "GS",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"GS"] = sso.Country + sso.Eic + "GS"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"F"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "F",
- IndexCode: sso.Country + sso.Eic + "F",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"F"] = sso.Country + sso.Eic + "F"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"T"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "T",
- IndexCode: sso.Country + sso.Eic + "T",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"T"] = sso.Country + sso.Eic + "T"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"In"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "In",
- IndexCode: sso.Country + sso.Eic + "In",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"In"] = sso.Country + sso.Eic + "In"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"Out"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "Out",
- IndexCode: sso.Country + sso.Eic + "Out",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"Out"] = sso.Country + sso.Eic + "Out"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"WGV"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "WGV",
- IndexCode: sso.Country + sso.Eic + "WGV",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"WGV"] = sso.Country + sso.Eic + "WGV"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"IC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "IC",
- IndexCode: sso.Country + sso.Eic + "IC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"IC"] = sso.Country + sso.Eic + "IC"
- }
- if _, ok := eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"WC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: sso.Country + "_" + sso.Name + "_" + "WC",
- IndexCode: sso.Country + sso.Eic + "WC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[sso.Country+"_"+sso.Name+"_"+"WC"] = sso.Country + sso.Eic + "WC"
- }
- if len(ssoItems) != 0 {
- successNums, err := models.AddEicDataMulti(ssoItems)
- fmt.Println("SSO successNums:", successNums)
- if err != nil {
- fmt.Println("AddSSODataMulti err:", err)
- }
- }
- facilities := sso.Facilities
- var facItems []*models.BaseFromTradeEicIndex
- for _, facility := range facilities {
- //获取所有指标信息
- allFacIndex, err := models.GetFacFromEicIndexAll(facility.Name)
- if err != nil {
- fmt.Println("select err:", err)
- }
- existFacIndexMap := make(map[string]*models.BaseFromTradeEicIndex)
- for _, v := range allFacIndex {
- existFacIndexMap[v.Name+v.GasDayStartedOn] = v
- }
- facUrl := facility.Url
- facBody, err := http.Get(ssoUrl)
- fmt.Println("facUrl:", facUrl)
- if err != nil {
- fmt.Println("GetData Err:" + err.Error())
- continue
- }
- var facStorages []Storage
- err = json.Unmarshal(facBody, &facStorages)
- for _, storageItem := range facStorages {
- gasInStorage, _ := strconv.ParseFloat(storageItem.GasInStorage, 64)
- full, _ := strconv.ParseFloat(storageItem.Full, 64)
- trend, _ := strconv.ParseFloat(storageItem.Trend, 64)
- injection, _ := strconv.ParseFloat(storageItem.Injection, 64)
- withdrawal, _ := strconv.ParseFloat(storageItem.Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(storageItem.WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(storageItem.InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(storageItem.WithdrawalCapacity, 64)
- facItem := models.BaseFromTradeEicIndex{
- BaseFromEicIndexId: 0,
- Country: facility.Country,
- Type: facility.Type,
- EicCode: facility.Country + facility.Eic,
- ShortName: sso.ShortName,
- Name: facility.Name,
- Status: storageItem.Status,
- GasDayStartedOn: storageItem.GasDayStartedOn,
- GasInStorage: gasInStorage,
- GasInStorageCode: facility.Country + facility.Eic + "GS",
- Full: full,
- FullCode: facility.Country + facility.Eic + "F",
- Trend: trend,
- TrendCode: facility.Country + facility.Eic + "T",
- Injection: injection,
- InjectionCode: facility.Country + facility.Eic + "In",
- Withdrawal: withdrawal,
- WithdrawalCode: facility.Country + facility.Eic + "Out",
- WorkingGasVolume: workingGasVolume,
- WorkingGasVolumeCode: facility.Country + facility.Eic + "WGV",
- InjectionCapacity: injectionCapacity,
- InjectionCapacityCode: facility.Country + facility.Eic + "IC",
- WithdrawalCapacity: withdrawalCapacity,
- WithdrawalCapacityCode: facility.Country + facility.Eic + "WC",
- Info: storageItem.Info,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- itemVerifyCode := facItem.GasInStorage + facItem.Full + facItem.Trend + facItem.Injection + facItem.Withdrawal
- if existIndex, ok := existFacIndexMap[facItem.Name+facItem.GasDayStartedOn]; !ok {
- facItems = append(facItems, &facItem)
- existFacIndexMap[facItem.Name+facItem.GasDayStartedOn] = &facItem
- } else if existIndex != nil && itemVerifyCode != (existIndex.GasInStorage+existIndex.Full+existIndex.Trend+existIndex.Injection+existIndex.Withdrawal) {
- //更新
- err := models.ModifyBaseFromEicIndex(facItem.GasInStorage, facItem.Full, facItem.Trend, facItem.Injection, facItem.Withdrawal, existIndex.BaseFromEicIndexId)
- if err != nil {
- fmt.Println("data update err:", err)
- }
- }
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name,
- IndexCode: facility.Country + facility.Eic,
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name] = facility.Country + facility.Eic
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"GS"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "GS",
- IndexCode: facility.Country + facility.Eic + "GS",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"GS"] = facility.Country + facility.Eic + "GS"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"F"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "F",
- IndexCode: facility.Country + facility.Eic + "F",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"F"] = facility.Country + facility.Eic + "F"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"T"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "T",
- IndexCode: facility.Country + facility.Eic + "T",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"T"] = facility.Country + facility.Eic + "T"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"In"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "In",
- IndexCode: facility.Country + facility.Eic + "In",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"In"] = facility.Country + facility.Eic + "In"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"Out"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "Out",
- IndexCode: facility.Country + facility.Eic + "Out",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"Out"] = facility.Country + facility.Eic + "Out"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"WGV"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "WGV",
- IndexCode: facility.Country + facility.Eic + "WGV",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"WGV"] = facility.Country + facility.Eic + "WGV"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"IC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "IC",
- IndexCode: facility.Country + facility.Eic + "IC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"IC"] = facility.Country + facility.Eic + "IC"
- }
- if _, ok := eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"WC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: facility.Country + "_" + facility.Name + "_" + "WC",
- IndexCode: facility.Country + facility.Eic + "WC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[facility.Country+"_"+facility.Name+"_"+"WC"] = facility.Country + facility.Eic + "WC"
- }
- }
- if len(facItems) != 0 {
- successNums, err := models.AddEicDataMulti(facItems)
- fmt.Println("fac successNums:", successNums)
- if err != nil {
- fmt.Println("AddFacDataMulti err:", err)
- }
- }
- if len(codeMapList) != 0 {
- successNums, err := models.AddEicCodeMulti(codeMapList)
- fmt.Println("codeMapping successNums:", successNums)
- if err != nil {
- fmt.Println("AddEicCodeMulti err:", err)
- }
- }
- }
- //国家级,洲际级统计
- var codeMapList []*models.BaseFromTradeMapping
- Countries := []string{"eu", "AT", "BE", "BG", "HR", "CZ",
- "DK", "FR", "DE", "HU", "IE", "IT", "LV", "NL", "PL",
- "PT", "RO", "SK", "ES", "SE", "GB", "ne", "RS", "UA"}
- for _, country := range Countries {
- var countryItems []*models.BaseFromTradeEicIndex
- //获取所有指标信息
- allFacIndex, err := models.GetCountryFromEicIndexAll(country)
- if err != nil {
- fmt.Println("select err:", err)
- }
- existFacIndexMap := make(map[string]*models.BaseFromTradeEicIndex)
- for _, v := range allFacIndex {
- existFacIndexMap[v.Name+v.GasDayStartedOn] = v
- }
- countryUrl := fmt.Sprintf("https://agsi.gie.eu/api/data/%s", country)
- fmt.Println("countryUrl:", countryUrl)
- body, err := http.Get(countryUrl)
- if err != nil {
- fmt.Println("GetData Err:" + err.Error())
- continue
- }
- var countryStorages []Storage
- err = json.Unmarshal(body, &countryStorages)
- for _, countryStorage := range countryStorages {
- gasInStorage, _ := strconv.ParseFloat(countryStorage.GasInStorage, 64)
- full, _ := strconv.ParseFloat(countryStorage.Full, 64)
- trend, _ := strconv.ParseFloat(countryStorage.Trend, 64)
- injection, _ := strconv.ParseFloat(countryStorage.Injection, 64)
- withdrawal, _ := strconv.ParseFloat(countryStorage.Withdrawal, 64)
- workingGasVolume, _ := strconv.ParseFloat(countryStorage.WorkingGasVolume, 64)
- injectionCapacity, _ := strconv.ParseFloat(countryStorage.InjectionCapacity, 64)
- withdrawalCapacity, _ := strconv.ParseFloat(countryStorage.WithdrawalCapacity, 64)
- countryItem := models.BaseFromTradeEicIndex{
- BaseFromEicIndexId: 0,
- Country: country,
- Type: "country",
- EicCode: country,
- ShortName: country,
- Name: country,
- Status: countryStorage.Status,
- GasDayStartedOn: countryStorage.GasDayStartedOn,
- GasInStorage: gasInStorage,
- GasInStorageCode: country + "GS",
- Full: full,
- FullCode: country + "F",
- Trend: trend,
- TrendCode: country + "T",
- Injection: injection,
- InjectionCode: country + "In",
- Withdrawal: withdrawal,
- WithdrawalCode: country + "Out",
- WorkingGasVolume: workingGasVolume,
- WorkingGasVolumeCode: country + "WGV",
- InjectionCapacity: injectionCapacity,
- InjectionCapacityCode: country + "IC",
- WithdrawalCapacity: withdrawalCapacity,
- WithdrawalCapacityCode: country + "WC",
- Info: countryStorage.Info,
- CreateTime: time.Now(),
- ModifyTime: time.Now(),
- }
- if country == "eu" || country == "ne" {
- countryItem.Type = "continent"
- }
- itemVerifyCode := countryItem.GasInStorage + countryItem.Full + countryItem.Trend + countryItem.Injection + countryItem.Withdrawal
- if existIndex, ok := existFacIndexMap[countryItem.Name+countryItem.GasDayStartedOn]; !ok {
- countryItems = append(countryItems, &countryItem)
- existFacIndexMap[countryItem.Name+countryItem.GasDayStartedOn] = &countryItem
- } else if existIndex != nil && itemVerifyCode != (existIndex.GasInStorage+existIndex.Full+existIndex.Trend+existIndex.Injection+existIndex.Withdrawal) {
- //更新
- err := models.ModifyBaseFromEicIndex(countryItem.GasInStorage, countryItem.Full, countryItem.Trend, countryItem.Injection, countryItem.Withdrawal, existIndex.BaseFromEicIndexId)
- if err != nil {
- fmt.Println("data update err:", err)
- }
- }
- }
- if len(countryItems) != 0 {
- successNums, err := models.AddEicDataMulti(countryItems)
- fmt.Println("Country successNums:", successNums)
- if err != nil {
- fmt.Println("AddCountryDataMulti err:", err)
- }
- }
- if _, ok := eicIndexCodeMap[country]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country,
- IndexCode: country,
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country] = country
- }
- if _, ok := eicIndexCodeMap[country+"_"+"GS"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "GS",
- IndexCode: country + "GS",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"GS"] = country + "GS"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"F"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "F",
- IndexCode: country + "F",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"F"] = country + "F"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"T"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "T",
- IndexCode: country + "T",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"T"] = country + "T"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"In"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "In",
- IndexCode: country + "In",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"In"] = country + "In"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"Out"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "Out",
- IndexCode: country + "Out",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"Out"] = country + "Out"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"WGV"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "WGV",
- IndexCode: country + "WGV",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"WGV"] = country + "WGV"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"IC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "IC",
- IndexCode: country + "IC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"IC"] = country + "IC"
- }
- if _, ok := eicIndexCodeMap[country+"_"+"WC"]; !ok {
- codeMappingItem := models.BaseFromTradeMapping{
- BaseFromTradeMappingId: 0,
- IndexName: country + "_" + "WC",
- IndexCode: country + "WC",
- Exchange: "EIC",
- }
- codeMapList = append(codeMapList, &codeMappingItem)
- eicIndexCodeMap[country+"_"+"WC"] = country + "WC"
- }
- }
- if len(codeMapList) != 0 {
- successNums, err := models.AddEicCodeMulti(codeMapList)
- fmt.Println("codeMapping successNums:", successNums)
- if err != nil {
- fmt.Println("AddEicCodeMulti err:", err)
- }
- }
- }
|