|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_index_lib/models"
|
|
|
"fmt"
|
|
|
+ "github.com/mozillazg/go-pinyin"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -13,6 +14,8 @@ type ExchangeCrawler struct {
|
|
|
BaseAuthController
|
|
|
}
|
|
|
|
|
|
+var ineIndexCodeMap = make(map[string]string)
|
|
|
+
|
|
|
// @Title 刷新数据
|
|
|
// @Description 刷新数据接口
|
|
|
// @Param request body models.AddEdbClassifyReq true "type json string"
|
|
@@ -31,7 +34,13 @@ func (this *ExchangeCrawler) RefreshIne() {
|
|
|
br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ allCode, err := models.GetIndexCodeFromMapping("Ine")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("select Code err:", err)
|
|
|
+ }
|
|
|
+ for _, item := range allCode {
|
|
|
+ ineIndexCodeMap[item.IndexName] = item.IndexCode
|
|
|
+ }
|
|
|
message := req.Data
|
|
|
var position = message.OCursor
|
|
|
var tradeDate = message.ReportDate
|
|
@@ -59,9 +68,9 @@ func (this *ExchangeCrawler) RefreshIne() {
|
|
|
item.DealName = strings.Replace(fmt.Sprintf("%s", p.Participantabbr1+"_"+p.Instrumentid+"_成交量(手)"), " ", "", -1)
|
|
|
item.BuyName = strings.Replace(fmt.Sprintf("%s", p.Participantabbr2+"_"+p.Instrumentid+"_持买单量(手)"), " ", "", -1)
|
|
|
item.SoldName = strings.Replace(fmt.Sprintf("%s", p.Participantabbr3+"_"+p.Instrumentid+"_持卖单量(手)"), " ", "", -1)
|
|
|
- item.DealCode = models.IneIndexCodeGenerator(item.DealShortName, item.DealName, p.Instrumentid, "deal")
|
|
|
- item.BuyCode = models.IneIndexCodeGenerator(item.BuyShortName, item.BuyName, p.Instrumentid, "buy")
|
|
|
- item.SoldCode = models.IneIndexCodeGenerator(item.SoldShortName, item.SoldName, p.Instrumentid, "sold")
|
|
|
+ item.DealCode = IneIndexCodeGenerator(item.DealShortName, item.DealName, p.Instrumentid, "deal")
|
|
|
+ item.BuyCode = IneIndexCodeGenerator(item.BuyShortName, item.BuyName, p.Instrumentid, "buy")
|
|
|
+ item.SoldCode = IneIndexCodeGenerator(item.SoldShortName, item.SoldName, p.Instrumentid, "sold")
|
|
|
item.ClassifyName = strings.Replace(p.Productname, " ", "", -1)
|
|
|
item.ClassifyType = strings.Replace(p.Instrumentid, " ", "", -1)
|
|
|
item.Frequency = "日度"
|
|
@@ -111,9 +120,9 @@ func (this *ExchangeCrawler) RefreshIne() {
|
|
|
item.DealName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.Instrumentid+"_成交量(手)"), " ", "", -1)
|
|
|
item.BuyName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.Instrumentid+"_持买单量(手)"), " ", "", -1)
|
|
|
item.SoldName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.Instrumentid+"_持卖单量(手)"), " ", "", -1)
|
|
|
- item.DealCode = models.IneIndexCodeGenerator("top20", item.DealName, p.Instrumentid, "deal")
|
|
|
- item.BuyCode = models.IneIndexCodeGenerator("top20", item.BuyName, p.Instrumentid, "buy")
|
|
|
- item.SoldCode = models.IneIndexCodeGenerator("top20", item.SoldName, p.Instrumentid, "sold")
|
|
|
+ item.DealCode = IneIndexCodeGenerator("top20", item.DealName, p.Instrumentid, "deal")
|
|
|
+ item.BuyCode = IneIndexCodeGenerator("top20", item.BuyName, p.Instrumentid, "buy")
|
|
|
+ item.SoldCode = IneIndexCodeGenerator("top20", item.SoldName, p.Instrumentid, "sold")
|
|
|
item.ClassifyName = strings.Replace(p.Productname, " ", "", -1)
|
|
|
item.ClassifyType = strings.Replace(p.Instrumentid, " ", "", -1)
|
|
|
item.Frequency = "日度"
|
|
@@ -162,6 +171,8 @@ func (this *ExchangeCrawler) RefreshIne() {
|
|
|
br.Success = true
|
|
|
}
|
|
|
|
|
|
+var indexCodeMap = make(map[string]string)
|
|
|
+
|
|
|
// @Title 刷新数据
|
|
|
// @Description 刷新数据接口
|
|
|
// @Param request body models.AddEdbClassifyReq true "type json string"
|
|
@@ -180,6 +191,14 @@ func (this *ExchangeCrawler) RefreshSH() {
|
|
|
br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ allCode, err := models.GetIndexCodeFromMapping("SH")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("select Code err:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, item := range allCode {
|
|
|
+ indexCodeMap[item.IndexName] = item.IndexCode
|
|
|
+ }
|
|
|
|
|
|
message := req.Data
|
|
|
var position = message.Position
|
|
@@ -210,9 +229,9 @@ func (this *ExchangeCrawler) RefreshSH() {
|
|
|
item.DealName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName1+"_"+p.ContractCode+"_成交量(手)"), " ", "", -1)
|
|
|
item.BuyName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName2+"_"+p.ContractCode+"_持买单量(手)"), " ", "", -1)
|
|
|
item.SoldName = strings.Replace(fmt.Sprintf("%s", p.ParticipantName3+"_"+p.ContractCode+"_持卖单量(手)"), " ", "", -1)
|
|
|
- item.DealCode = models.ShIndexCodeGenerator(item.DealShortName, item.DealName, contractCode, "deal")
|
|
|
- item.BuyCode = models.ShIndexCodeGenerator(item.BuyShortName, item.BuyName, contractCode, "buy")
|
|
|
- item.SoldCode = models.ShIndexCodeGenerator(item.SoldShortName, item.SoldName, contractCode, "sold")
|
|
|
+ item.DealCode = ShIndexCodeGenerator(item.DealShortName, item.DealName, contractCode, "deal")
|
|
|
+ item.BuyCode = ShIndexCodeGenerator(item.BuyShortName, item.BuyName, contractCode, "buy")
|
|
|
+ item.SoldCode = ShIndexCodeGenerator(item.SoldShortName, item.SoldName, contractCode, "sold")
|
|
|
item.ClassifyName = strings.Replace(p.ProductName, " ", "", -1)
|
|
|
item.ClassifyType = strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
item.Frequency = "日度"
|
|
@@ -266,9 +285,9 @@ func (this *ExchangeCrawler) RefreshSH() {
|
|
|
item.DealName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.ContractCode+"_成交量(手)"), " ", "", -1)
|
|
|
item.BuyName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.ContractCode+"_持买单量(手)"), " ", "", -1)
|
|
|
item.SoldName = strings.Replace(fmt.Sprintf("%s", "top20_"+p.ContractCode+"_持卖单量(手)"), " ", "", -1)
|
|
|
- item.DealCode = models.ShIndexCodeGenerator("top20", item.DealName, contractCode, "deal")
|
|
|
- item.BuyCode = models.ShIndexCodeGenerator("top20", item.BuyName, contractCode, "buy")
|
|
|
- item.SoldCode = models.ShIndexCodeGenerator("top20", item.SoldName, contractCode, "sold")
|
|
|
+ item.DealCode = ShIndexCodeGenerator("top20", item.DealName, contractCode, "deal")
|
|
|
+ item.BuyCode = ShIndexCodeGenerator("top20", item.BuyName, contractCode, "buy")
|
|
|
+ item.SoldCode = ShIndexCodeGenerator("top20", item.SoldName, contractCode, "sold")
|
|
|
item.ClassifyName = strings.Replace(p.ProductName, " ", "", -1)
|
|
|
item.ClassifyType = strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
item.Frequency = "日度"
|
|
@@ -318,3 +337,59 @@ func (this *ExchangeCrawler) RefreshSH() {
|
|
|
br.Msg = "获取成功"
|
|
|
br.Success = true
|
|
|
}
|
|
|
+
|
|
|
+func ShIndexCodeGenerator(shortName, indexName, contractCode, suffix string) string {
|
|
|
+ if shortName == "" {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ strResult := ""
|
|
|
+ if shortName != "top20" {
|
|
|
+ //取公司全拼
|
|
|
+ a := pinyin.NewArgs()
|
|
|
+ rows := pinyin.LazyPinyin(shortName, a)
|
|
|
+ for i := 0; i < len(rows); i++ {
|
|
|
+ strResult += rows[i]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ strResult = "top20"
|
|
|
+ }
|
|
|
+ indexCode, _ := indexCodeMap[indexName]
|
|
|
+ if indexCode == "" {
|
|
|
+ indexCode = strResult + contractCode + suffix
|
|
|
+ indexCode = strings.Replace(indexCode, " ", "", -1)
|
|
|
+ indexCodeMap[indexName] = indexCode
|
|
|
+ err := models.AddBaseFromTradeMapping(indexName, indexCode, "SH")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add Code err:", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return strings.Replace(indexCode, " ", "", -1)
|
|
|
+}
|
|
|
+
|
|
|
+func IneIndexCodeGenerator(shortName, indexName, Instrumentid, suffix string) string {
|
|
|
+ if shortName == "" {
|
|
|
+ return ""
|
|
|
+ }
|
|
|
+ strResult := ""
|
|
|
+ if shortName != "top20" {
|
|
|
+ //取公司全拼
|
|
|
+ a := pinyin.NewArgs()
|
|
|
+ rows := pinyin.LazyPinyin(shortName, a)
|
|
|
+ for i := 0; i < len(rows); i++ {
|
|
|
+ strResult += rows[i]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ strResult = "top20"
|
|
|
+ }
|
|
|
+ ineIndexCode, _ := ineIndexCodeMap[indexName]
|
|
|
+ if ineIndexCode == "" {
|
|
|
+ ineIndexCode = strResult + Instrumentid + suffix
|
|
|
+ ineIndexCode = strings.Replace(ineIndexCode, " ", "", -1)
|
|
|
+ ineIndexCodeMap[indexName] = ineIndexCode
|
|
|
+ err := models.AddBaseFromTradeMapping(indexName, ineIndexCode, "INE")
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("add Code err:", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return strings.Replace(ineIndexCode, " ", "", -1)
|
|
|
+}
|