فهرست منبع

大连指标拼音拼接

xingzai 3 سال پیش
والد
کامیت
12efdfd543
1فایلهای تغییر یافته به همراه32 افزوده شده و 9 حذف شده
  1. 32 9
      services/commodity_trade_dalian.go

+ 32 - 9
services/commodity_trade_dalian.go

@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"fmt"
 	"github.com/PuerkitoBio/goquery"
+	"github.com/mozillazg/go-pinyin"
 	"hongze/hongze_data_crawler/models"
 	"hongze/hongze_data_crawler/utils"
 	"io/ioutil"
@@ -28,7 +29,7 @@ type SearchContractId struct {
 
 //同步 N天 之内的数据
 func SyncRankingFromDalianDo() {
-	for i := 200; i >= 0; i-- {
+	for i := 182; i >= 0; i-- {
 		SyncRankingFromDalianSearch(i)
 	}
 }
@@ -67,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
@@ -292,29 +293,29 @@ func DoHtml(body, name, contractId string, dateTime time.Time, listDataMap map[s
 			})
 			item.Rank = rank
 			item.DealShortName = shortName
-			item.DealName = shortName + "_成交量_" + contractId
+			item.DealName = shortName + "_" + contractId + "_成交量"
 			if val, ok := listIndexCodeMap[item.DealName]; ok {
 				item.DealCode = val
 			} else {
-				item.DealCode = DlIndexCodeGenerator(item.DealName, "deal")
+				item.DealCode = GetIndexCodeGeneratorPinYing(shortName, item.DealName, contractId, "deal", "DL")
 			}
 			item.DealValue = dealValue
 			item.BuyShortName = buyName
 			item.DealChange = dealChange
-			item.BuyName = buyName + "_持买单量_" + contractId
+			item.BuyName = buyName + "_" + contractId + "_持买单量"
 			if val, ok := listIndexCodeMap[item.BuyName]; ok {
 				item.BuyCode = val
 			} else {
-				item.BuyCode = DlIndexCodeGenerator(item.BuyName, "buy")
+				item.BuyCode = GetIndexCodeGeneratorPinYing(buyName, item.BuyName, contractId, "buy", "DL")
 			}
 			item.BuyValue = buyValue
 			item.BuyChange = buyChange
 			item.SoldShortName = soldName
-			item.SoldName = soldName + "_持卖单量_" + contractId
+			item.SoldName = soldName + "_" + contractId + "_持卖单量"
 			if val, ok := listIndexCodeMap[item.SoldName]; ok {
 				item.SoldCode = val
 			} else {
-				item.SoldCode = DlIndexCodeGenerator(item.SoldName, "sold")
+				item.SoldCode = GetIndexCodeGeneratorPinYing(soldName, item.SoldName, contractId, "sold", "DL")
 			}
 			item.SoldValue = soldValue
 			item.SoldChange = soldChange
@@ -357,6 +358,28 @@ func DlIndexCodeGenerator(indexName, suffix string) (ineIndexCode string) {
 	return ineIndexCode
 }
 
+func GetIndexCodeGeneratorPinYing(shortName, indexName, contractCode, suffix, exchange string) string {
+	if shortName == "" {
+		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]
+		}
+	}
+	indexCode = strResult + contractCode + suffix
+	err := models.AddBaseFromTradeMapping(indexName, indexCode, exchange)
+	if err != nil {
+		fmt.Println("add Code err:", err)
+	}
+	return indexCode
+}
+
 //大连交易所持单排名
 func GetDalianHtmlBody(dayNum int, contractId, carietyCode, varietyName string) (body string, err error) {
 	defer func() {