瀏覽代碼

indexCode生成逻辑优化

ziwen 3 年之前
父節點
當前提交
ccea24fc05
共有 2 個文件被更改,包括 7 次插入7 次删除
  1. 5 5
      services/commodity_trade_ine.go
  2. 2 2
      services/task.go

+ 5 - 5
services/commodity_trade_ine.go

@@ -43,10 +43,10 @@ type message struct {
 var ineIndexCode string
 var ineIndexCodeMap = make(map[string]string)
 
-func IneIndexCodeGenerator(indexName string) string {
+func IneIndexCodeGenerator(indexName,suffix  string) string {
 	ineIndexCode,_ := ineIndexCodeMap[indexName]
 	if ineIndexCode == "" {
-		ineIndexCode = fmt.Sprintf("INE%s", time.Now().Format(utils.FormatDateTimeUnSpace)+strconv.Itoa(utils.GetRandInt(1, 100)))
+		ineIndexCode = fmt.Sprintf("INE%s", time.Now().Format(utils.FormatDateTimeUnSpace)+strconv.Itoa(utils.GetRandInt(1, 100))+suffix)
 		ineIndexCodeMap[indexName] = ineIndexCode
 		err := models.AddBaseFromTradeMapping(indexName, ineIndexCode, "INE")
 		if err != nil {
@@ -107,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.DealName)
-				item.BuyCode = IneIndexCodeGenerator(item.BuyName)
-				item.SoldCode = IneIndexCodeGenerator(item.SoldName)
+				item.DealCode = IneIndexCodeGenerator(item.DealName, "deal")
+				item.BuyCode = IneIndexCodeGenerator(item.BuyName, "buy")
+				item.SoldCode = IneIndexCodeGenerator(item.SoldName, "sold")
 				item.DealValue = p.Deal
 				item.DealChange = p.Change1
 				item.BuyValue = p.BuyIn

+ 2 - 2
services/task.go

@@ -7,10 +7,10 @@ import (
 func Task() {
 	fmt.Println("start crawler")
 	//同步郑州商品交易所排名
-	SyncRankingFromZhengzhou()
+	//SyncRankingFromZhengzhou()
 
 	//SyncRankingFromShangHai()
-	//SyncRankingFromIne()
+	SyncRankingFromIne()
 	//SyncRankingFromCffex()
 
 	//SyncRankingFromDalian2()