瀏覽代碼

no message

xingzai 3 年之前
父節點
當前提交
c123c74de8
共有 1 個文件被更改,包括 67 次插入30 次删除
  1. 67 30
      services/commodity_trade_dalian.go

+ 67 - 30
services/commodity_trade_dalian.go

@@ -68,8 +68,8 @@ func SyncRankingFromDalianSearch(dayNum int) (err error) {
 	for _, v := range list {
 		listDataMap[v.DealShortName+v.ClassifyType+v.DataTime] = v.BaseFromTradeDalianIndexId
 	}
-	n := utils.GetRandInt(10, 120)
-	time.Sleep(time.Duration(n) * time.Second)
+	//n := utils.GetRandInt(10, 120)
+	//time.Sleep(time.Duration(n) * time.Second)
 
 	var ContractId string
 	var CarietyCode string
@@ -251,11 +251,13 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 	var rank, shortName, dealValue, dealChange, buyName, buyValue, buyChange, soldName, soldValue, soldChange string
 	table.Find("tr").Each(func(i int, tr *goquery.Selection) {
 		tds := tr.Find("td")
-		//fmt.Println(tds.Length(), "长度:", i)
-		if tds.Length() == 0 || tds.Length() == 7 || i == 23 {
-			tdText := tds.Text()
-			utils.FileLog.Info(tdText)
-		} else {
+		fmt.Println(tds.Length(), "长度:", i)
+		if tds.Length() == 0 || tds.Length() == 7 {
+			if i == 23 {
+				tdText := tds.Text()
+				utils.FileLog.Info(tdText)
+			}
+		} else if i == 23 {
 			item := new(models.BaseFromTradeDalianIndex)
 			tds.Each(func(tk int, td *goquery.Selection) {
 				tdText := td.Text()
@@ -294,29 +296,16 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 			item.Rank = rank
 			item.DealShortName = shortName
 			item.DealName = shortName + "_" + contractId + "_成交量"
-			if val, ok := listIndexCodeMap[item.DealName]; ok {
-				item.DealCode = val
-			} else {
-				item.DealCode = GetIndexCodeGeneratorPinYing(shortName, item.DealName, contractId, "deal", "DL")
-			}
+
 			item.DealValue = dealValue
 			item.BuyShortName = buyName
 			item.DealChange = dealChange
 			item.BuyName = buyName + "_" + contractId + "_持买单量"
-			if val, ok := listIndexCodeMap[item.BuyName]; ok {
-				item.BuyCode = val
-			} else {
-				item.BuyCode = GetIndexCodeGeneratorPinYing(buyName, item.BuyName, contractId, "buy", "DL")
-			}
+
 			item.BuyValue = buyValue
 			item.BuyChange = buyChange
 			item.SoldShortName = soldName
 			item.SoldName = soldName + "_" + contractId + "_持卖单量"
-			if val, ok := listIndexCodeMap[item.SoldName]; ok {
-				item.SoldCode = val
-			} else {
-				item.SoldCode = GetIndexCodeGeneratorPinYing(soldName, item.SoldName, contractId, "sold", "DL")
-			}
 			item.SoldValue = soldValue
 			item.SoldChange = soldChange
 			item.Frequency = "日度"
@@ -325,6 +314,48 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 			item.CreateTime = time.Now().Format(utils.FormatDateTime)
 			item.ModifyTime = time.Now().Format(utils.FormatDateTime)
 			item.DataTime = dateTime.Format(utils.FormatDate)
+			//处理指标Id
+			if i != 23 {
+				if val, ok := listIndexCodeMap[item.DealName]; ok {
+					item.DealCode = val
+				} else {
+					item.DealCode = GetIndexCodeGeneratorPinYing(shortName, item.DealName, contractId, "deal", "DL")
+				}
+				if val, ok := listIndexCodeMap[item.BuyName]; ok {
+					item.BuyCode = val
+				} else {
+					item.BuyCode = GetIndexCodeGeneratorPinYing(buyName, item.BuyName, contractId, "buy", "DL")
+				}
+				if val, ok := listIndexCodeMap[item.SoldName]; ok {
+					item.SoldCode = val
+				} else {
+					item.SoldCode = GetIndexCodeGeneratorPinYing(soldName, item.SoldName, contractId, "sold", "DL")
+				}
+			}
+
+			if i == 23 {
+				item.Rank = "999"
+				item.DealName = "top20_" + contractId + "_成交量(手)"
+				if val, ok := listIndexCodeMap[item.DealName]; ok {
+					item.DealCode = val
+				} else {
+					item.DealCode = GetIndexCodeGeneratorPinYing("top20", item.DealName, contractId, "deal", "DL")
+				}
+				item.BuyName = "top20_" + contractId + "_持买单量(手)"
+				if val, ok := listIndexCodeMap[item.BuyName]; ok {
+					item.BuyCode = val
+				} else {
+					item.BuyCode = GetIndexCodeGeneratorPinYing("top20", item.BuyName, contractId, "buy", "DL")
+				}
+				item.SoldName = "top20_" + contractId + "_持卖单量(手)"
+
+				if val, ok := listIndexCodeMap[item.SoldName]; ok {
+					item.SoldCode = val
+				} else {
+					item.SoldCode = GetIndexCodeGeneratorPinYing("top20", item.SoldName, contractId, "sold", "DL")
+				}
+			}
+			fmt.Println(item)
 			if val, ok := listDataMap[item.DealShortName+item.ClassifyType+item.DataTime]; !ok {
 				addSql += models.GetAddSql(item)
 				isAdd = true
@@ -337,6 +368,7 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 					}
 				}
 			}
+
 		}
 	})
 	addSql = strings.TrimRight(addSql, ",")
@@ -363,16 +395,21 @@ func GetIndexCodeGeneratorPinYing(shortName, indexName, contractCode, suffix, ex
 		indexCode = ""
 		return indexCode
 	}
-	//取公司前两个字的全拼
-	a := pinyin.NewArgs()
-	rows := pinyin.Pinyin(shortName, a)
-	strResult := ""
-	for i := 0; i < len(rows[:2]); i++ {
-		if len(rows[i]) != 0 {
-			strResult += rows[i][0]
+	if shortName == "top20" {
+		indexCode = "top20" + contractCode + suffix
+	} else {
+		//取公司前四个字的全拼
+		a := pinyin.NewArgs()
+		rows := pinyin.Pinyin(shortName, a)
+		strResult := ""
+		for i := 0; i < len(rows[:4]); i++ {
+			if len(rows[i]) != 0 {
+				strResult += rows[i][0]
+			}
 		}
+		indexCode = strResult + contractCode + suffix
 	}
-	indexCode = strResult + contractCode + suffix
+
 	err := models.AddBaseFromTradeMapping(indexName, indexCode, exchange)
 	if err != nil {
 		fmt.Println("add Code err:", err)