|
@@ -32,9 +32,9 @@ func GetClassifyName() (list trade_analysis.TradeClassifyNameListSort, err error
|
|
|
timeMap := make(map[string]string)
|
|
|
i := 0
|
|
|
var wg sync.WaitGroup
|
|
|
- for k, _ := range exchanges {
|
|
|
+ for k := range exchanges {
|
|
|
wg.Add(1)
|
|
|
- go func(k string,classifyExchangeMap map[string][]trade_analysis.TradeClassifyName) {
|
|
|
+ go func(k string, classifyExchangeMap map[string][]trade_analysis.TradeClassifyName) {
|
|
|
defer wg.Done()
|
|
|
nameList, tmpErr := trade_analysis.GetExchangeClassify(k)
|
|
|
if tmpErr != nil {
|
|
@@ -56,21 +56,23 @@ func GetClassifyName() (list trade_analysis.TradeClassifyNameListSort, err error
|
|
|
}(k, classifyExchangeMap)
|
|
|
}
|
|
|
wg.Wait()
|
|
|
+ currDate := time.Now().Format(utils.FormatDate)
|
|
|
for k, v := range exchanges {
|
|
|
tmp := trade_analysis.TradeClassifyNameList{
|
|
|
Exchange: v,
|
|
|
Items: nil,
|
|
|
- Sort: exchangesSortMap[k],
|
|
|
+ Sort: exchangesSortMap[k],
|
|
|
+ CurrDate: currDate,
|
|
|
}
|
|
|
nameList, ok := classifyExchangeMap[k]
|
|
|
if !ok {
|
|
|
- err = fmt.Errorf( "查询交易所分类信息失败")
|
|
|
+ err = fmt.Errorf("查询交易所分类信息失败")
|
|
|
errMsg = "查询交易所分类信息失败"
|
|
|
return
|
|
|
}
|
|
|
tmp.DataTime, ok = timeMap[k]
|
|
|
if !ok {
|
|
|
- err = fmt.Errorf( "查询交易所最新更新时间失败")
|
|
|
+ err = fmt.Errorf("查询交易所最新更新时间失败")
|
|
|
errMsg = "查询交易所最新更新时间失败"
|
|
|
return
|
|
|
}
|
|
@@ -84,7 +86,7 @@ func GetClassifyName() (list trade_analysis.TradeClassifyNameListSort, err error
|
|
|
}
|
|
|
classifyMap[classifyName] = append(classifyMap[classifyName], tmpItemItem)
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
for _, item := range nameList {
|
|
|
tmpItemItem := trade_analysis.TradeClassifyNameListItemItem{
|
|
|
ClassifyType: item.ClassifyType,
|
|
@@ -99,12 +101,12 @@ func GetClassifyName() (list trade_analysis.TradeClassifyNameListSort, err error
|
|
|
Items: l,
|
|
|
}
|
|
|
tmp.Items = append(tmp.Items, tmpItems)
|
|
|
- tmp.Num ++
|
|
|
+ tmp.Num++
|
|
|
}
|
|
|
}
|
|
|
sort.Sort(trade_analysis.TradeClassifyNameListItemSort(tmp.Items))
|
|
|
list = append(list, tmp)
|
|
|
- i ++
|
|
|
+ i++
|
|
|
}
|
|
|
if len(list) > 0 {
|
|
|
sort.Sort(list)
|
|
@@ -113,100 +115,100 @@ func GetClassifyName() (list trade_analysis.TradeClassifyNameListSort, err error
|
|
|
}
|
|
|
|
|
|
func getZhengzhouClassifyName(code string) (name string) {
|
|
|
- if strings.HasPrefix(code,"PTA") {
|
|
|
+ if strings.HasPrefix(code, "PTA") {
|
|
|
name = "PTA"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"TA") {
|
|
|
+ if strings.HasPrefix(code, "TA") {
|
|
|
name = "PTA"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"ZC") {
|
|
|
- name="动力煤"
|
|
|
+ if strings.HasPrefix(code, "ZC") {
|
|
|
+ name = "动力煤"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"WH") {
|
|
|
- name="强麦"
|
|
|
+ if strings.HasPrefix(code, "WH") {
|
|
|
+ name = "强麦"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"UR") {
|
|
|
- name="尿素"
|
|
|
+ if strings.HasPrefix(code, "UR") {
|
|
|
+ name = "尿素"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"SR") {
|
|
|
- name="白糖"
|
|
|
+ if strings.HasPrefix(code, "SR") {
|
|
|
+ name = "白糖"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"SM") {
|
|
|
- name="锰硅"
|
|
|
+ if strings.HasPrefix(code, "SM") {
|
|
|
+ name = "锰硅"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"SF") {
|
|
|
- name="硅铁"
|
|
|
+ if strings.HasPrefix(code, "SF") {
|
|
|
+ name = "硅铁"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"SA") {
|
|
|
- name="纯碱"
|
|
|
+ if strings.HasPrefix(code, "SA") {
|
|
|
+ name = "纯碱"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"RS") {
|
|
|
- name="油菜籽"
|
|
|
+ if strings.HasPrefix(code, "RS") {
|
|
|
+ name = "油菜籽"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"RM") {
|
|
|
- name="菜籽粕"
|
|
|
+ if strings.HasPrefix(code, "RM") {
|
|
|
+ name = "菜籽粕"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"RI") {
|
|
|
- name="早籼稻"
|
|
|
+ if strings.HasPrefix(code, "RI") {
|
|
|
+ name = "早籼稻"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"PM") {
|
|
|
- name="普麦"
|
|
|
+ if strings.HasPrefix(code, "PM") {
|
|
|
+ name = "普麦"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"PK") {
|
|
|
- name="花生"
|
|
|
+ if strings.HasPrefix(code, "PK") {
|
|
|
+ name = "花生"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"PF") {
|
|
|
- name="涤纶短纤"
|
|
|
+ if strings.HasPrefix(code, "PF") {
|
|
|
+ name = "涤纶短纤"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"OI") {
|
|
|
- name="菜油"
|
|
|
+ if strings.HasPrefix(code, "OI") {
|
|
|
+ name = "菜油"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"MA") {
|
|
|
- name="甲醇"
|
|
|
+ if strings.HasPrefix(code, "MA") {
|
|
|
+ name = "甲醇"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"LR") {
|
|
|
- name="晚籼稻"
|
|
|
+ if strings.HasPrefix(code, "LR") {
|
|
|
+ name = "晚籼稻"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"JR") {
|
|
|
- name="粳稻"
|
|
|
+ if strings.HasPrefix(code, "JR") {
|
|
|
+ name = "粳稻"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"FG") {
|
|
|
- name="玻璃"
|
|
|
+ if strings.HasPrefix(code, "FG") {
|
|
|
+ name = "玻璃"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"CY") {
|
|
|
- name="棉纱"
|
|
|
+ if strings.HasPrefix(code, "CY") {
|
|
|
+ name = "棉纱"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"CJ") {
|
|
|
- name="红枣"
|
|
|
+ if strings.HasPrefix(code, "CJ") {
|
|
|
+ name = "红枣"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"CF") {
|
|
|
- name="棉花"
|
|
|
+ if strings.HasPrefix(code, "CF") {
|
|
|
+ name = "棉花"
|
|
|
return
|
|
|
}
|
|
|
- if strings.HasPrefix(code,"AP") {
|
|
|
- name="苹果"
|
|
|
+ if strings.HasPrefix(code, "AP") {
|
|
|
+ name = "苹果"
|
|
|
return
|
|
|
}
|
|
|
return
|
|
@@ -215,11 +217,11 @@ func getZhengzhouClassifyName(code string) (name string) {
|
|
|
func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analysis.GetPositionTopResp, err error, errMsg string) {
|
|
|
//定义交易所
|
|
|
exchanges := map[string]string{
|
|
|
- "郑商所":"zhengzhou",
|
|
|
- "大商所":"dalian",
|
|
|
- "上期所":"shanghai",
|
|
|
- "中金所":"cffex",
|
|
|
- "上期能源":"ine",
|
|
|
+ "郑商所": "zhengzhou",
|
|
|
+ "大商所": "dalian",
|
|
|
+ "上期所": "shanghai",
|
|
|
+ "中金所": "cffex",
|
|
|
+ "上期能源": "ine",
|
|
|
}
|
|
|
exchange, ok := exchanges[req.Exchange]
|
|
|
if !ok {
|
|
@@ -231,14 +233,14 @@ func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analy
|
|
|
var dataTime time.Time
|
|
|
//查询最新的时间
|
|
|
if dataTimeStr == "" {
|
|
|
- lastItem , tmpErr := trade_analysis.GetTradeTopLastDataTime(exchange, req.ClassifyName, req.ClassifyType)
|
|
|
+ lastItem, tmpErr := trade_analysis.GetTradeTopLastDataTime(exchange, req.ClassifyName, req.ClassifyType)
|
|
|
if tmpErr != nil {
|
|
|
errMsg = "查询最新的榜单信息失败"
|
|
|
err = tmpErr
|
|
|
return
|
|
|
}
|
|
|
dataTime = lastItem.DataTime
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
dataTime, err = time.ParseInLocation(utils.FormatDate, dataTimeStr, time.Local)
|
|
|
if err != nil {
|
|
|
errMsg = "请输入正确的时间格式"
|
|
@@ -290,13 +292,13 @@ func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analy
|
|
|
//统计汇总数据
|
|
|
for _, v := range dataList {
|
|
|
if t, ok1 := totalMap[v.DealType]; ok1 {
|
|
|
- totalMap[v.DealType] = t+v.DealValue
|
|
|
- }else{
|
|
|
+ totalMap[v.DealType] = t + v.DealValue
|
|
|
+ } else {
|
|
|
totalMap[v.DealType] = v.DealValue
|
|
|
}
|
|
|
if t, ok1 := totalChangeMap[v.DealType]; ok1 {
|
|
|
- totalChangeMap[v.DealType] = t+v.DealChange
|
|
|
- }else{
|
|
|
+ totalChangeMap[v.DealType] = t + v.DealChange
|
|
|
+ } else {
|
|
|
totalChangeMap[v.DealType] = v.DealChange
|
|
|
}
|
|
|
}
|
|
@@ -314,13 +316,13 @@ func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analy
|
|
|
for k, v := range dataList {
|
|
|
k++
|
|
|
if t, ok1 := totalTmpMap[v.DealType]; ok1 {
|
|
|
- totalTmpMap[v.DealType] = t+v.DealValue
|
|
|
- }else{
|
|
|
+ totalTmpMap[v.DealType] = t + v.DealValue
|
|
|
+ } else {
|
|
|
totalTmpMap[v.DealType] = v.DealValue
|
|
|
}
|
|
|
if t, ok1 := totalChangeTmpMap[v.DealType]; ok1 {
|
|
|
- totalChangeTmpMap[v.DealType] = t+v.DealChange
|
|
|
- }else{
|
|
|
+ totalChangeTmpMap[v.DealType] = t + v.DealChange
|
|
|
+ } else {
|
|
|
totalChangeTmpMap[v.DealType] = v.DealChange
|
|
|
}
|
|
|
|
|
@@ -333,11 +335,11 @@ func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analy
|
|
|
BeforeAllChange: totalChangeTmpMap[v.DealType],
|
|
|
}
|
|
|
//统计占比
|
|
|
- rate := fmt.Sprintf("%.2f", float64(tmp.DealValue)/float64(totalMap[v.DealType])) // 保留2位小数
|
|
|
+ rate := fmt.Sprintf("%.2f", float64(tmp.DealValue)/float64(totalMap[v.DealType])) // 保留2位小数
|
|
|
beforeAllRate := fmt.Sprintf("%.2f", float64(tmp.BeforeAllValue)/float64(totalMap[v.DealType])) // 保留2位小数
|
|
|
tmp.Rate = rate
|
|
|
tmp.BeforeAllRate = beforeAllRate
|
|
|
- if tmp.DealShortName == "-"{
|
|
|
+ if tmp.DealShortName == "-" {
|
|
|
continue
|
|
|
}
|
|
|
detailList[v.DealType] = append(detailList[v.DealType], tmp)
|
|
@@ -360,4 +362,4 @@ func GetPositionTopDetail(req trade_analysis.GetPositionTopReq) (ret trade_analy
|
|
|
|
|
|
ret.DataTime = dataTimeStr
|
|
|
return
|
|
|
-}
|
|
|
+}
|