|
@@ -7,6 +7,7 @@ import (
|
|
|
"hongze/hongze_data_crawler/utils"
|
|
|
"rdluck_tools/http"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -30,7 +31,11 @@ var cffexIndexCode string
|
|
|
var cffexIndexCodeMap = make(map[string]string)
|
|
|
var cffexActionCodeMap = make(map[string]map[string]int)
|
|
|
|
|
|
-func cffexIndexCodeGenerator(indexName, suffix string) string {
|
|
|
+func cffexIndexCodeGenerator(shortName, indexName, suffix string) string {
|
|
|
+ if shortName == ""{
|
|
|
+ cffexIndexCode = ""
|
|
|
+ return cffexIndexCode
|
|
|
+ }
|
|
|
cffexIndexCode, _ := cffexIndexCodeMap[indexName]
|
|
|
if cffexIndexCode == "" {
|
|
|
cffexIndexCode = fmt.Sprintf("CFFEX%s", time.Now().Format(utils.FormatDateTimeUnSpace)+strconv.Itoa(utils.GetRandInt(1, 100))+suffix)
|
|
@@ -77,8 +82,12 @@ func SyncRankingFromCffex() {
|
|
|
existDealMap[v.DealName] = v.BaseFromTradeCffexIndexId
|
|
|
existBuyMap[v.BuyName] = v.BaseFromTradeCffexIndexId
|
|
|
existSoldMap[v.SoldName] = v.BaseFromTradeCffexIndexId
|
|
|
+ cffexIndexCodeMap[v.DealName] = v.DealCode
|
|
|
+ cffexIndexCodeMap[v.BuyName] = v.BuyCode
|
|
|
+ cffexIndexCodeMap[v.SoldName] = v.SoldCode
|
|
|
sRank = fmt.Sprintf("%d", v.Rank)
|
|
|
- cffexActionCodeMap[sRank+v.ClassifyType] = map[string]int{"0": v.DealValue, "1": v.BuyValue, "2": v.SoldValue, "id": v.BaseFromTradeCffexIndexId}
|
|
|
+ time := strings.Replace(v.DataTime, "-", "", -1)
|
|
|
+ cffexActionCodeMap[sRank+v.ClassifyType+time] = map[string]int{"0": v.DealValue, "1": v.BuyValue, "2": v.SoldValue, "id": v.BaseFromTradeCffexIndexId}
|
|
|
}
|
|
|
shortNameColum := map[string]string{"0": "deal_short_name", "1": "buy_short_name", "2": "sold_short_name"}
|
|
|
nameColum := map[string]string{"0": "deal_name", "1": "buy_name", "2": "sold_name"}
|
|
@@ -92,12 +101,15 @@ func SyncRankingFromCffex() {
|
|
|
for _, xmlItem := range xmlItems {
|
|
|
for _, i := range xmlItem.Data {
|
|
|
var item = new(models.BaseFromTradeCffexIndex)
|
|
|
+ item.DealValue = -1
|
|
|
+ item.BuyValue = -1
|
|
|
+ item.SoldValue = -1
|
|
|
item.Rank = i.Rank
|
|
|
switch i.Value {
|
|
|
case "0":
|
|
|
item.DealShortName = i.ShortName
|
|
|
item.DealName = fmt.Sprintf("%s", i.ShortName+"_成交量_"+i.ContractCode)
|
|
|
- item.DealCode = cffexIndexCodeGenerator(item.DealName, "deal")
|
|
|
+ item.DealCode = cffexIndexCodeGenerator(item.DealShortName, item.DealName, "deal")
|
|
|
item.DealValue = i.Volume
|
|
|
item.DealChange = i.Varvolume
|
|
|
|
|
@@ -106,7 +118,7 @@ func SyncRankingFromCffex() {
|
|
|
case "1":
|
|
|
item.BuyShortName = i.ShortName
|
|
|
item.BuyName = fmt.Sprintf("%s", i.ShortName+"_持买单量_"+i.ContractCode)
|
|
|
- item.BuyCode = cffexIndexCodeGenerator(item.BuyName, "buy")
|
|
|
+ item.BuyCode = cffexIndexCodeGenerator(item.BuyShortName, item.BuyName, "buy")
|
|
|
item.BuyValue = i.Volume
|
|
|
item.BuyChange = i.Varvolume
|
|
|
|
|
@@ -115,7 +127,7 @@ func SyncRankingFromCffex() {
|
|
|
case "2":
|
|
|
item.SoldShortName = i.ShortName
|
|
|
item.SoldName = fmt.Sprintf("%s", i.ShortName+"_持卖单量_"+i.ContractCode)
|
|
|
- item.SoldCode = cffexIndexCodeGenerator(item.SoldName, "sold")
|
|
|
+ item.SoldCode = cffexIndexCodeGenerator(item.SoldShortName, item.SoldName, "sold")
|
|
|
item.SoldValue = i.Volume
|
|
|
item.SoldChange = i.Varvolume
|
|
|
|
|
@@ -133,24 +145,19 @@ func SyncRankingFromCffex() {
|
|
|
|
|
|
valueMap := map[string]int{"0": item.DealValue, "1": item.BuyValue, "2": item.SoldValue}
|
|
|
//检查在actionCodeMap中是否已经有了
|
|
|
- indexKey = fmt.Sprintf("%d", item.Rank) + item.ClassifyType
|
|
|
+ indexKey = fmt.Sprintf("%d", item.Rank) + item.ClassifyType + item.DataTime
|
|
|
+
|
|
|
if existMap, ok := cffexActionCodeMap[indexKey]; !ok {
|
|
|
- if _, ok := existDealMap[item.DealName]; !ok {
|
|
|
- if _, ok := existBuyMap[item.BuyName]; !ok {
|
|
|
- if _, ok := existSoldMap[item.SoldName]; !ok {
|
|
|
- //没有,新增
|
|
|
- newID, err := models.AddBaseFromTradeCffexIndex(item)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("insert error:", err)
|
|
|
- }
|
|
|
- fmt.Println("insert new indexID:", newID)
|
|
|
- existMap = make(map[string]int)
|
|
|
- existMap[i.Value] = i.Volume
|
|
|
- existMap["id"] = int(newID)
|
|
|
- cffexActionCodeMap[indexKey] = existMap
|
|
|
- }
|
|
|
- }
|
|
|
+ //没有,新增
|
|
|
+ newID, err := models.AddBaseFromTradeCffexIndex(item)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("insert error:", err)
|
|
|
}
|
|
|
+ fmt.Println("insert new indexID:", newID)
|
|
|
+ existMap = make(map[string]int)
|
|
|
+ existMap[i.Value] = i.Volume
|
|
|
+ existMap["id"] = int(newID)
|
|
|
+ cffexActionCodeMap[indexKey] = existMap
|
|
|
} else if existMap != nil && existMap[i.Value] != i.Volume {
|
|
|
//更新
|
|
|
var columnList = [5]string{
|
|
@@ -172,6 +179,69 @@ func SyncRankingFromCffex() {
|
|
|
fmt.Println("data update err:", err)
|
|
|
}
|
|
|
cffexActionCodeMap[indexKey][i.Value] = i.Volume
|
|
|
+ } else if _, ok := existDealMap[item.DealName]; !ok {
|
|
|
+ //更新
|
|
|
+ var columnList = [5]string{
|
|
|
+ shortNameColum[i.Value],
|
|
|
+ nameColum[i.Value],
|
|
|
+ codeColum[i.Value],
|
|
|
+ valueColum[i.Value],
|
|
|
+ changeColum[i.Value],
|
|
|
+ }
|
|
|
+ var dataList = [5]interface{}{
|
|
|
+ i.ShortName,
|
|
|
+ dataName,
|
|
|
+ dataCode,
|
|
|
+ valueMap[i.Value],
|
|
|
+ i.Varvolume,
|
|
|
+ }
|
|
|
+ err := models.ModifyBaseFromTradeCffexIndex(columnList, dataList, existMap["id"])
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("data update err:", err)
|
|
|
+ }
|
|
|
+ cffexActionCodeMap[indexKey][i.Value] = i.Volume
|
|
|
+ } else if _, ok := existBuyMap[item.BuyName]; !ok {
|
|
|
+ //更新
|
|
|
+ var columnList = [5]string{
|
|
|
+ shortNameColum[i.Value],
|
|
|
+ nameColum[i.Value],
|
|
|
+ codeColum[i.Value],
|
|
|
+ valueColum[i.Value],
|
|
|
+ changeColum[i.Value],
|
|
|
+ }
|
|
|
+ var dataList = [5]interface{}{
|
|
|
+ i.ShortName,
|
|
|
+ dataName,
|
|
|
+ dataCode,
|
|
|
+ valueMap[i.Value],
|
|
|
+ i.Varvolume,
|
|
|
+ }
|
|
|
+ err := models.ModifyBaseFromTradeCffexIndex(columnList, dataList, existMap["id"])
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("data update err:", err)
|
|
|
+ }
|
|
|
+ cffexActionCodeMap[indexKey][i.Value] = i.Volume
|
|
|
+ } else if _, ok := existSoldMap[item.SoldName]; !ok {
|
|
|
+ //更新
|
|
|
+ var columnList = [5]string{
|
|
|
+ shortNameColum[i.Value],
|
|
|
+ nameColum[i.Value],
|
|
|
+ codeColum[i.Value],
|
|
|
+ valueColum[i.Value],
|
|
|
+ changeColum[i.Value],
|
|
|
+ }
|
|
|
+ var dataList = [5]interface{}{
|
|
|
+ i.ShortName,
|
|
|
+ dataName,
|
|
|
+ dataCode,
|
|
|
+ valueMap[i.Value],
|
|
|
+ i.Varvolume,
|
|
|
+ }
|
|
|
+ err := models.ModifyBaseFromTradeCffexIndex(columnList, dataList, existMap["id"])
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("data update err:", err)
|
|
|
+ }
|
|
|
+ cffexActionCodeMap[indexKey][i.Value] = i.Volume
|
|
|
}
|
|
|
}
|
|
|
}
|