|
@@ -3,10 +3,10 @@ package services
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "github.com/mozillazg/go-pinyin"
|
|
"hongze/hongze_data_crawler/models"
|
|
"hongze/hongze_data_crawler/models"
|
|
"hongze/hongze_data_crawler/utils"
|
|
"hongze/hongze_data_crawler/utils"
|
|
"rdluck_tools/http"
|
|
"rdluck_tools/http"
|
|
- "strconv"
|
|
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -43,14 +43,23 @@ type Message struct {
|
|
var indexCode string
|
|
var indexCode string
|
|
var indexCodeMap = make(map[string]string)
|
|
var indexCodeMap = make(map[string]string)
|
|
|
|
|
|
-func shIndexCodeGenerator(shortName, indexName,suffix string) string {
|
|
|
|
|
|
+func shIndexCodeGenerator(shortName, indexName, contractCode, suffix string) string {
|
|
if shortName == ""{
|
|
if shortName == ""{
|
|
indexCode = ""
|
|
indexCode = ""
|
|
return 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,_ := indexCodeMap[indexName]
|
|
indexCode,_ := indexCodeMap[indexName]
|
|
if indexCode == "" {
|
|
if indexCode == "" {
|
|
- indexCode = fmt.Sprintf("SH%s", strconv.FormatInt(time.Now().UnixNano(), 10)+suffix)
|
|
|
|
|
|
+ indexCode = strResult + contractCode + suffix
|
|
indexCodeMap[indexName] = indexCode
|
|
indexCodeMap[indexName] = indexCode
|
|
err := models.AddBaseFromTradeMapping(indexName, indexCode, "SH")
|
|
err := models.AddBaseFromTradeMapping(indexName, indexCode, "SH")
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -98,50 +107,49 @@ func SyncRankingFromShangHai() {
|
|
for _, v := range allIndex {
|
|
for _, v := range allIndex {
|
|
indexKey := v.DealName + v.BuyName + v.SoldName
|
|
indexKey := v.DealName + v.BuyName + v.SoldName
|
|
existIndexMap[indexKey] = v
|
|
existIndexMap[indexKey] = v
|
|
- indexCodeMap[v.DealName] = v.DealCode
|
|
|
|
- indexCodeMap[v.BuyName] = v.BuyCode
|
|
|
|
- indexCodeMap[v.SoldName] = v.SoldCode
|
|
|
|
}
|
|
}
|
|
var itemVerifyCode int
|
|
var itemVerifyCode int
|
|
//处理指标
|
|
//处理指标
|
|
for _, p := range position {
|
|
for _, p := range position {
|
|
if p.Rank > 0 && p.Rank <40 && p.ParticipantName1 != "" {
|
|
if p.Rank > 0 && p.Rank <40 && p.ParticipantName1 != "" {
|
|
- //成交量
|
|
|
|
- item.Rank = p.Rank
|
|
|
|
- item.DealShortName = p.ParticipantName1
|
|
|
|
- item.BuyShortName = p.ParticipantName2
|
|
|
|
- item.SoldShortName = p.ParticipantName3
|
|
|
|
- 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 = shIndexCodeGenerator(item.DealShortName, item.DealName, "deal")
|
|
|
|
- item.BuyCode = shIndexCodeGenerator(item.BuyShortName, item.BuyName, "buy")
|
|
|
|
- item.SoldCode = shIndexCodeGenerator(item.SoldShortName, item.SoldCode, "sold")
|
|
|
|
- item.DealValue = p.Deal
|
|
|
|
- item.DealChange = p.Change1
|
|
|
|
- item.BuyValue = p.BuyIn
|
|
|
|
- item.BuyChange = p.Change2
|
|
|
|
- item.SoldValue = p.SoldOut
|
|
|
|
- item.SoldChange = p.Change3
|
|
|
|
- item.ClassifyName = strings.Replace(p.ProductName, " ", "", -1)
|
|
|
|
- item.ClassifyType = strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
|
- item.Frequency = "日度"
|
|
|
|
- item.CreateTime = time.Now()
|
|
|
|
- item.ModifyTime = time.Now()
|
|
|
|
- item.DataTime = tradeDate
|
|
|
|
|
|
+ if strings.Replace(p.ProductName, " ", "", -1) != "20号胶"{
|
|
|
|
+ //成交量
|
|
|
|
+ item.Rank = p.Rank
|
|
|
|
+ item.DealShortName = p.ParticipantName1
|
|
|
|
+ item.BuyShortName = p.ParticipantName2
|
|
|
|
+ item.SoldShortName = p.ParticipantName3
|
|
|
|
+ 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 = shIndexCodeGenerator(item.DealShortName, item.DealName, p.ContractCode, "deal")
|
|
|
|
+ item.BuyCode = shIndexCodeGenerator(item.BuyShortName, item.BuyName, p.ContractCode, "buy")
|
|
|
|
+ item.SoldCode = shIndexCodeGenerator(item.SoldShortName, item.SoldName, p.ContractCode, "sold")
|
|
|
|
+ item.DealValue = p.Deal
|
|
|
|
+ item.DealChange = p.Change1
|
|
|
|
+ item.BuyValue = p.BuyIn
|
|
|
|
+ item.BuyChange = p.Change2
|
|
|
|
+ item.SoldValue = p.SoldOut
|
|
|
|
+ item.SoldChange = p.Change3
|
|
|
|
+ item.ClassifyName = strings.Replace(p.ProductName, " ", "", -1)
|
|
|
|
+ item.ClassifyType = strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
|
+ item.Frequency = "日度"
|
|
|
|
+ item.CreateTime = time.Now()
|
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
|
+ item.DataTime = tradeDate
|
|
|
|
|
|
- itemVerifyCode = item.BuyValue + item.DealValue + item.SoldValue
|
|
|
|
- if existIndex, ok := existIndexMap[item.DealName + item.BuyName + item.SoldName]; !ok {
|
|
|
|
- newID, err := models.AddBaseFromTradeShangHaiIndex(item)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("insert error:", err)
|
|
|
|
- }
|
|
|
|
- fmt.Println("insert new indexID:", newID)
|
|
|
|
- } else if existIndex != nil && itemVerifyCode != (existIndex.DealValue+existIndex.BuyValue+existIndex.SoldValue) {
|
|
|
|
- //更新
|
|
|
|
- err := models.ModifyBaseFromTradeShangHaiIndex(item.DealValue, item.BuyValue, item.SoldValue, existIndex.BaseFromTradeShangHaiIndexId)
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println("data update err:", err)
|
|
|
|
|
|
+ itemVerifyCode = item.BuyValue + item.DealValue + item.SoldValue
|
|
|
|
+ if existIndex, ok := existIndexMap[item.DealName + item.BuyName + item.SoldName]; !ok {
|
|
|
|
+ newID, err := models.AddBaseFromTradeShangHaiIndex(item)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("insert error:", err)
|
|
|
|
+ }
|
|
|
|
+ fmt.Println("insert new indexID:", newID)
|
|
|
|
+ } else if existIndex != nil && itemVerifyCode != (existIndex.DealValue+existIndex.BuyValue+existIndex.SoldValue) {
|
|
|
|
+ //更新
|
|
|
|
+ err := models.ModifyBaseFromTradeShangHaiIndex(item.DealValue, item.BuyValue, item.SoldValue, existIndex.BaseFromTradeShangHaiIndexId)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("data update err:", err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|