|
@@ -41,14 +41,16 @@ type message struct {
|
|
|
}
|
|
|
|
|
|
var ineIndexCode string
|
|
|
-var ineIndexCodeMap = make(map[string]struct{})
|
|
|
+var ineIndexCodeMap = make(map[string]string)
|
|
|
|
|
|
-func IneIndexCodeGenerator() string {
|
|
|
- for {
|
|
|
+func IneIndexCodeGenerator(indexName string) string {
|
|
|
+ ineIndexCode,_ := ineIndexCodeMap[indexName]
|
|
|
+ if ineIndexCode == "" {
|
|
|
ineIndexCode = fmt.Sprintf("INE%s", time.Now().Format(utils.FormatDateTimeUnSpace)+strconv.Itoa(utils.GetRandInt(1, 100)))
|
|
|
- if _, ok := ineIndexCodeMap[ineIndexCode]; !ok {
|
|
|
- ineIndexCodeMap[ineIndexCode] = struct{}{}
|
|
|
- break
|
|
|
+ ineIndexCodeMap[indexName] = ineIndexCode
|
|
|
+ err := models.AddBaseFromTradeMapping(indexName, ineIndexCode, "INE")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add Code err:", err)
|
|
|
}
|
|
|
}
|
|
|
return ineIndexCode
|
|
@@ -56,6 +58,13 @@ func IneIndexCodeGenerator() string {
|
|
|
|
|
|
// SyncRankingFromIne 上海能源交易中心持单排名
|
|
|
func SyncRankingFromIne() {
|
|
|
+ allCode, err := models.GetIndexCodeFromMapping("Ine")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("select Code err:", err)
|
|
|
+ }
|
|
|
+ for _, item := range allCode {
|
|
|
+ ineIndexCodeMap[item.IndexName] = item.IndexCode
|
|
|
+ }
|
|
|
//获取新的指标信息
|
|
|
for i := 180; i > 0; i-- {
|
|
|
var message Message
|
|
@@ -82,6 +91,9 @@ func SyncRankingFromIne() {
|
|
|
for _, v := range allIndex {
|
|
|
indexKey := v.DealName + v.BuyName + v.SoldName + tradeDate
|
|
|
existIndexMap[indexKey] = v
|
|
|
+ ineIndexCodeMap[v.BuyName] = v.BuyCode
|
|
|
+ ineIndexCodeMap[v.SoldName] = v.SoldCode
|
|
|
+ ineIndexCodeMap[v.DealName] = v.DealCode
|
|
|
}
|
|
|
var itemVerifyCode int
|
|
|
//处理指标
|
|
@@ -95,9 +107,9 @@ func SyncRankingFromIne() {
|
|
|
item.DealName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName1+"_成交量"+"_"+p.ProductName+"_"+p.ContractCode), " ", "", -1)
|
|
|
item.BuyName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName2+"_持买单量"+"_"+p.ProductName+"_"+p.ContractCode), " ", "", -1)
|
|
|
item.SoldName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName3+"_持卖单量"+"_"+p.ProductName+"_"+p.ContractCode), " ", "", -1)
|
|
|
- item.DealCode = IneIndexCodeGenerator()
|
|
|
- item.BuyCode = IneIndexCodeGenerator()
|
|
|
- item.SoldCode = IneIndexCodeGenerator()
|
|
|
+ item.DealCode = IneIndexCodeGenerator(item.DealName)
|
|
|
+ item.BuyCode = IneIndexCodeGenerator(item.BuyName)
|
|
|
+ item.SoldCode = IneIndexCodeGenerator(item.SoldName)
|
|
|
item.DealValue = p.Deal
|
|
|
item.DealChange = p.Change1
|
|
|
item.BuyValue = p.BuyIn
|