|
@@ -2,11 +2,18 @@ package pcsg
|
|
|
|
|
|
import (
|
|
|
"eta/eta_bridge/global"
|
|
|
+ "eta/eta_bridge/utils"
|
|
|
"fmt"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+const (
|
|
|
+ TaskKey0000 = "IDpcsgDailySnap0000"
|
|
|
+ SubOneDayTaskKey = "IDpcsgDailySnap0330" // 日期-1的key
|
|
|
+ TaskKey0345 = "IDpcsgDailySnap0345"
|
|
|
+)
|
|
|
+
|
|
|
// PythonBloombergGeneralData 通用数据格式(有空改成Map吧...然后做成配置方便加新字段...)
|
|
|
type PythonBloombergGeneralData struct {
|
|
|
NAME string `json:"NAME" description:"指标名称, 可能为null"`
|
|
@@ -31,9 +38,9 @@ type PythonBloombergGeneralData struct {
|
|
|
|
|
|
// PythonBloombergGeneralResult API响应体
|
|
|
type PythonBloombergGeneralResult struct {
|
|
|
- Code int `json:"code"`
|
|
|
- Msg string `json:"msg"`
|
|
|
- Data []map[string]interface{} `json:"data"`
|
|
|
+ Code int `json:"code"`
|
|
|
+ Msg string `json:"msg"`
|
|
|
+ Data []PythonBloombergGeneralData `json:"data"`
|
|
|
}
|
|
|
|
|
|
// BaseFromBloombergApiIndexAndData Bloomberg原始指标及数据
|
|
@@ -55,123 +62,71 @@ type BaseFromBloombergApiIndexData struct {
|
|
|
Value float64 `description:"数据值"`
|
|
|
}
|
|
|
|
|
|
-// TaskConfPCSGBloomberg 配置
|
|
|
-type TaskConfPCSGBloomberg struct {
|
|
|
- TaskKey string `json:"TaskKey" description:"任务名称"`
|
|
|
- IndexCodeField string `json:"IndexCodeField" description:"指标编码字段名"`
|
|
|
- IndexNameField string `json:"IndexNameField" description:"指标名称字段名"`
|
|
|
- FrequencyVal string `json:"FrequencyVal" description:"频度"`
|
|
|
- UnitVal string `json:"UnitVal" description:"单位"`
|
|
|
- DataTimeField string `json:"DataTimeField" description:"数据日期字段名"`
|
|
|
- DataTimeFormat string `json:"DataTimeFormat" description:"数据日期格式"`
|
|
|
- DataTimeMoveDays int `json:"DataTimeMoveDays" description:"数据日期位移天数"`
|
|
|
- DataValField string `json:"DataValField" description:"数据值字段名"`
|
|
|
- CheckDataTimeField string `json:"CheckDataTimeField" description:"需要校验的数据日期字段名"`
|
|
|
- CheckDataTimeFormat string `json:"CheckDataTimeFormat" description:"需要校验的数据日期格式"`
|
|
|
-}
|
|
|
-
|
|
|
-func FormatPythonBloombergGeneralData2Base(origin map[string]interface{}, conf *TaskConfPCSGBloomberg) (item BaseFromBloombergApiIndexAndData) {
|
|
|
- // 指标编码
|
|
|
- if v, ok := origin[conf.IndexCodeField]; ok {
|
|
|
- indexCode, yes := v.(string)
|
|
|
- if !yes {
|
|
|
- return
|
|
|
- }
|
|
|
- item.IndexCode = strings.TrimSpace(indexCode)
|
|
|
+func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, frequency, taskKey string) (item BaseFromBloombergApiIndexAndData) {
|
|
|
+ if origin.IDENTIFIER == "" {
|
|
|
+ return
|
|
|
}
|
|
|
+ item.IndexCode = strings.TrimSpace(origin.IDENTIFIER)
|
|
|
+ item.IndexName = strings.TrimSpace(origin.NAME)
|
|
|
+ item.Frequency = frequency
|
|
|
+ item.Unit = "无"
|
|
|
+ item.Data = make([]BaseFromBloombergApiIndexData, 0)
|
|
|
|
|
|
- // 指标名称/频率/单位
|
|
|
- if v, ok := origin[conf.IndexNameField]; ok {
|
|
|
- indexName, yes := v.(string)
|
|
|
- if yes {
|
|
|
- item.IndexName = strings.TrimSpace(indexName)
|
|
|
- }
|
|
|
+ // 数据来源的值和日期对应字段不同
|
|
|
+ var dataTime time.Time
|
|
|
+ var val *float64
|
|
|
+ if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_LAST_EOD != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.LAST_UPDATE_DATE_EOD, time.Local)
|
|
|
+ val = origin.PX_LAST_EOD
|
|
|
}
|
|
|
- item.Frequency = conf.FrequencyVal
|
|
|
- item.Unit = conf.UnitVal
|
|
|
-
|
|
|
- // 校验一下指定字段的日期格式, 如果格式不对那么不处理
|
|
|
- checkTimeFunc := func(dataMap map[string]interface{}) (pass bool) {
|
|
|
- pass = true // 默认处理
|
|
|
- f, ok := dataMap[conf.CheckDataTimeField]
|
|
|
- if !ok {
|
|
|
- return
|
|
|
- }
|
|
|
- checkField, yes := f.(string)
|
|
|
- if !yes {
|
|
|
- return
|
|
|
- }
|
|
|
- f, ok = dataMap[conf.CheckDataTimeFormat]
|
|
|
- if !ok {
|
|
|
- return
|
|
|
- }
|
|
|
- checkFormat, yes := f.(string)
|
|
|
- if !yes {
|
|
|
- return
|
|
|
- }
|
|
|
- f, ok = dataMap[checkField]
|
|
|
- if !ok {
|
|
|
- return
|
|
|
- }
|
|
|
- fieldVal, yes := f.(string)
|
|
|
- if !yes {
|
|
|
- return
|
|
|
- }
|
|
|
- // 格式不一致, 那么不处理
|
|
|
- _, e := time.ParseInLocation(checkFormat, fieldVal, time.Local)
|
|
|
- if e != nil {
|
|
|
- pass = false
|
|
|
- return
|
|
|
- }
|
|
|
- return
|
|
|
+ if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_VOLUME_EOD != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.LAST_UPDATE_DATE_EOD, time.Local)
|
|
|
+ val = origin.PX_VOLUME_EOD
|
|
|
}
|
|
|
- if !checkTimeFunc(origin) {
|
|
|
- return
|
|
|
+ if origin.DATE != "" && origin.PX_LAST != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.DATE, time.Local)
|
|
|
+ val = origin.PX_LAST
|
|
|
}
|
|
|
-
|
|
|
- // 数据日期
|
|
|
- item.Data = make([]BaseFromBloombergApiIndexData, 0)
|
|
|
- var dataTime time.Time
|
|
|
- if v, ok := origin[conf.DataTimeField]; ok {
|
|
|
- strTime, yes := v.(string)
|
|
|
- if !yes {
|
|
|
- return
|
|
|
- }
|
|
|
- if strTime == "" {
|
|
|
- return
|
|
|
- }
|
|
|
- d, e := time.ParseInLocation(conf.DataTimeFormat, strTime, time.Local)
|
|
|
+ if origin.DATE != "" && origin.PX_VOLUME != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.DATE, time.Local)
|
|
|
+ val = origin.PX_VOLUME
|
|
|
+ }
|
|
|
+ if origin.PX_SETTLE_LAST_DT != "" && origin.PX_SETTLE != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.PX_SETTLE_LAST_DT, time.Local)
|
|
|
+ val = origin.PX_SETTLE
|
|
|
+ }
|
|
|
+ if origin.OPEN_INT_DATE != "" && origin.OPEN_INT != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.OPEN_INT_DATE, time.Local)
|
|
|
+ val = origin.OPEN_INT
|
|
|
+ }
|
|
|
+ if taskKey == TaskKey0345 && origin.PX_CLOSE_DT != "" && origin.PX_LAST != nil {
|
|
|
+ dataTime, _ = time.ParseInLocation(utils.FormatDate, origin.PX_CLOSE_DT, time.Local)
|
|
|
+ val = origin.PX_LAST
|
|
|
+ }
|
|
|
+ if (taskKey == TaskKey0000 || taskKey == SubOneDayTaskKey) && origin.DL_SNAPSHOT_START_TIME != "" && origin.PX_LAST != nil {
|
|
|
+ // 根据LAST_UPDATE的格式进行判断, 仅加入格式为hh:mm:ss的
|
|
|
+ _, e := time.ParseInLocation("15:04:05", origin.LAST_UPDATE, time.Local)
|
|
|
if e != nil {
|
|
|
- global.LOG.Info(fmt.Sprintf("数据日期解析失败, %s, err: %v", strTime, e))
|
|
|
return
|
|
|
}
|
|
|
- if d.IsZero() {
|
|
|
- global.LOG.Info(fmt.Sprintf("数据日期解析为空, %s", strTime))
|
|
|
- return
|
|
|
- }
|
|
|
- if conf.DataTimeMoveDays != 0 {
|
|
|
- d = d.AddDate(0, 0, conf.DataTimeMoveDays)
|
|
|
- }
|
|
|
- dataTime = d
|
|
|
- }
|
|
|
|
|
|
- // 数据值
|
|
|
- var dataVal *float64
|
|
|
- if v, ok := origin[conf.DataValField]; ok {
|
|
|
- val, yes := v.(*float64)
|
|
|
- if !yes {
|
|
|
- global.LOG.Info(fmt.Sprintf("数据float断言失败, %v", v))
|
|
|
- return
|
|
|
+ d, e := time.ParseInLocation("2006-01-02T15:04:05", origin.DL_SNAPSHOT_START_TIME, time.Local)
|
|
|
+ if e != nil {
|
|
|
+ global.LOG.Info(fmt.Sprintf("DL_SNAPSHOT_START_TIME日期解析失败, %s", origin.DL_SNAPSHOT_START_TIME))
|
|
|
}
|
|
|
- if val == nil {
|
|
|
- return
|
|
|
+ dataTime = d
|
|
|
+ // 这个任务日期需要-1
|
|
|
+ if taskKey == SubOneDayTaskKey {
|
|
|
+ dataTime = dataTime.AddDate(0, 0, -1)
|
|
|
}
|
|
|
- dataVal = val
|
|
|
+ val = origin.PX_LAST
|
|
|
+ }
|
|
|
+ if !dataTime.IsZero() && val != nil {
|
|
|
+ item.Data = append(item.Data, BaseFromBloombergApiIndexData{
|
|
|
+ DataTime: dataTime,
|
|
|
+ Value: *val,
|
|
|
+ })
|
|
|
}
|
|
|
- item.Data = append(item.Data, BaseFromBloombergApiIndexData{
|
|
|
- DataTime: dataTime,
|
|
|
- Value: *dataVal,
|
|
|
- })
|
|
|
return
|
|
|
}
|
|
|
|