|
@@ -4,9 +4,9 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
|
- "github.com/rdlucklib/rdluck_tools/http"
|
|
|
"hongze/hongze_data_crawler/models"
|
|
|
"hongze/hongze_data_crawler/utils"
|
|
|
+ "github.com/rdlucklib/rdluck_tools/http"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -45,25 +45,21 @@ var indexCodeMap = make(map[string]string)
|
|
|
|
|
|
func shIndexCodeGenerator(shortName, indexName, contractCode, suffix string) string {
|
|
|
if shortName == "" {
|
|
|
- return ""
|
|
|
+ indexCode = ""
|
|
|
+ return indexCode
|
|
|
}
|
|
|
+ //取公司前两个字的全拼
|
|
|
+ a := pinyin.NewArgs()
|
|
|
+ rows := pinyin.Pinyin(shortName, a)
|
|
|
strResult := ""
|
|
|
- if shortName != "top20" {
|
|
|
- //取公司前两个字的全拼
|
|
|
- a := pinyin.NewArgs()
|
|
|
- rows := pinyin.Pinyin(shortName, a)
|
|
|
- for i := 0; i < len(rows[:2]); i++ {
|
|
|
- if len(rows[i]) != 0 {
|
|
|
- strResult += rows[i][0]
|
|
|
- }
|
|
|
+ for i := 0; i < len(rows[:2]); i++ {
|
|
|
+ if len(rows[i]) != 0 {
|
|
|
+ strResult += rows[i][0]
|
|
|
}
|
|
|
- } 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 {
|
|
@@ -77,7 +73,7 @@ func shIndexCodeGenerator(shortName, indexName, contractCode, suffix string) str
|
|
|
func SyncRankingFromShangHai() {
|
|
|
n := utils.GetRandInt(10, 120)
|
|
|
time.Sleep(time.Duration(n) * time.Second)
|
|
|
- allCode, err := models.GetIndexCodeFromMapping("SH")
|
|
|
+ allCode, err := models.GetIndexCodeFromMapping("Z")
|
|
|
if err != nil {
|
|
|
fmt.Println("select Code err:", err)
|
|
|
}
|
|
@@ -87,6 +83,7 @@ func SyncRankingFromShangHai() {
|
|
|
//获取新的指标信息
|
|
|
for i := 2; i > 0; i-- {
|
|
|
var message Message
|
|
|
+ var item = new(models.BaseFromTradeShanghaiIndex)
|
|
|
zzUrl := "http://www.shfe.com.cn/data/dailydata/kx/pm%s.dat"
|
|
|
date := time.Now().AddDate(0, 0, -i)
|
|
|
dateStr := date.Format(utils.FormatDateUnSpace)
|
|
@@ -114,63 +111,19 @@ func SyncRankingFromShangHai() {
|
|
|
var itemVerifyCode int
|
|
|
//处理指标
|
|
|
for _, p := range position {
|
|
|
- var item = new(models.BaseFromTradeShanghaiIndex)
|
|
|
if p.Rank > 0 && p.Rank < 40 && p.ParticipantName1 != "" {
|
|
|
if strings.Replace(p.ProductName, " ", "", -1) != "20号胶" && strings.Replace(p.ProductName, " ", "", -1) != "低硫燃料油" {
|
|
|
- contractCode := strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
//成交量
|
|
|
item.Rank = p.Rank
|
|
|
- item.DealShortName = strings.Replace(p.ParticipantName1, " ", "", -1)
|
|
|
- item.BuyShortName = strings.Replace(p.ParticipantName2, " ", "", -1)
|
|
|
- item.SoldShortName = strings.Replace(p.ParticipantName3, " ", "", -1)
|
|
|
+ item.DealShortName = p.ParticipantName1
|
|
|
+ item.BuyShortName = p.ParticipantName2
|
|
|
+ item.SoldShortName = p.ParticipantName3
|
|
|
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 = 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.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)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else if p.Rank == 999 {
|
|
|
- if strings.Replace(p.ProductName, " ", "", -1) != "20号胶" && strings.Replace(p.ProductName, " ", "", -1) != "低硫燃料油" {
|
|
|
- contractCode := strings.Replace(p.ContractCode, " ", "", -1)
|
|
|
- //Top 20
|
|
|
- item.Rank = p.Rank
|
|
|
- item.DealShortName = strings.Replace(p.ParticipantName1, " ", "", -1)
|
|
|
- item.BuyShortName = strings.Replace(p.ParticipantName2, " ", "", -1)
|
|
|
- item.SoldShortName = strings.Replace(p.ParticipantName3, " ", "", -1)
|
|
|
- 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 = shIndexCodeGenerator("top20", item.DealName, contractCode, "deal")
|
|
|
- item.BuyCode = shIndexCodeGenerator("top20", item.BuyName, contractCode, "buy")
|
|
|
- item.SoldCode = shIndexCodeGenerator("top20", item.SoldName, contractCode, "sold")
|
|
|
+ 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
|