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) } } }