hsun hace 8 meses
padre
commit
acb8abb65c

+ 13 - 0
controller/index_data/pcsg_index.go

@@ -47,3 +47,16 @@ func (this *PCSGIndexController) GetBloombergMonthlyIndex(c *gin.Context) {
 	}
 	resp.OkData("获取成功", data, c)
 }
+
+// GetBloombergDailyIndexRun3
+// @Description 获取日度指标Run3
+// @Success 200 {string} string "获取成功"
+// @Router /bloomberg/daily_index_run3 [post]
+func (this *PCSGIndexController) GetBloombergDailyIndexRun3(c *gin.Context) {
+	data, e := indexDataService.GetPCSGBloombergDailyIndexRun3()
+	if e != nil {
+		resp.FailMsg("获取失败", "获取中石油新加坡日度指标(Run3)失败, err: "+e.Error(), c)
+		return
+	}
+	resp.OkData("获取成功", data, c)
+}

+ 9 - 0
models/pcsg/bloomberg.go

@@ -9,6 +9,7 @@ import (
 type PythonBloombergGeneralData struct {
 	IDENTIFIER           string   `json:"IDENTIFIER" description:"指标编码"`
 	PX_LAST_EOD          *float64 `json:"PX_LAST_EOD" description:"数据值, 可能为null"`
+	PX_VOLUME_EOD        *float64 `json:"PX_VOLUME_EOD" description:"数据值(Run3), 可能为null"`
 	LAST_UPDATE_DATE_EOD string   `json:"LAST_UPDATE_DATE_EOD" description:"数据日期, 可能为null"`
 	NAME                 string   `json:"NAME" description:"指标名称, 可能为null"`
 }
@@ -56,5 +57,13 @@ func FormatPythonBloombergGeneralData2Base(origin PythonBloombergGeneralData, fr
 			Value:    *origin.PX_LAST_EOD,
 		})
 	}
+	// 可能是从Run3过来的, 数据值的字段为PX_VOLUME_EOD
+	if origin.LAST_UPDATE_DATE_EOD != "" && origin.PX_VOLUME_EOD != nil {
+		t, _ := time.ParseInLocation(time.DateOnly, origin.LAST_UPDATE_DATE_EOD, time.Local)
+		item.Data = append(item.Data, BaseFromBloombergApiIndexData{
+			DataTime: t,
+			Value:    *origin.PX_VOLUME_EOD,
+		})
+	}
 	return
 }

+ 1 - 0
routers/pcsg.go

@@ -13,4 +13,5 @@ func InitPCSG(r *gin.RouterGroup) {
 	group.POST("bloomberg/daily_index", control.GetBloombergDailyIndex)
 	group.POST("bloomberg/weekly_index", control.GetBloombergWeeklyIndex)
 	group.POST("bloomberg/monthly_index", control.GetBloombergMonthlyIndex)
+	group.POST("bloomberg/daily_index_run3", control.GetBloombergDailyIndexRun3)
 }

+ 62 - 3
services/index_data/pcsg_bloomberg.go

@@ -11,9 +11,10 @@ import (
 )
 
 var (
-	PCSGBloombergPythonApiDaily   = "/api/bloomberg/daily_data"
-	PCSGBloombergPythonApiWeekly  = "/api/bloomberg/weekly_data"
-	PCSGBloombergPythonApiMonthly = "/api/bloomberg/monthly_data"
+	PCSGBloombergPythonApiDaily     = "/api/bloomberg/daily_data"
+	PCSGBloombergPythonApiWeekly    = "/api/bloomberg/weekly_data"
+	PCSGBloombergPythonApiMonthly   = "/api/bloomberg/monthly_data"
+	PCSGBloombergPythonApiDailyRun3 = "/api/bloomberg/daily_data_run3"
 )
 
 // GetPCSGBloombergDailyIndex 获取彭博日度指标
@@ -76,6 +77,26 @@ func GetPCSGBloombergMonthlyIndex() (indexes []pcsg.BaseFromBloombergApiIndexAnd
 	return
 }
 
+// GetPCSGBloombergDailyIndexRun3 获取彭博日度指标(Run3)
+func GetPCSGBloombergDailyIndexRun3() (indexes []pcsg.BaseFromBloombergApiIndexAndData, err error) {
+	apiData, e := CurlPCSGBloombergDailyRun3Api()
+	if e != nil {
+		err = fmt.Errorf("GetPCSGBloombergDailyIndexRun3 err: %s", e.Error())
+		return
+	}
+	if len(apiData) == 0 {
+		return
+	}
+	frequency := "日度"
+	for _, v := range apiData {
+		t := pcsg.FormatPythonBloombergGeneralData2Base(v, frequency)
+		if t.IndexCode != "" {
+			indexes = append(indexes, t)
+		}
+	}
+	return
+}
+
 // CurlPCSGBloombergDailyApi 请求日度指标接口
 func CurlPCSGBloombergDailyApi() (resultData []pcsg.PythonBloombergGeneralData, err error) {
 	if global.CONFIG.PCSG.BloombergApiUrl == "" {
@@ -189,3 +210,41 @@ func CurlPCSGBloombergMonthlyApi() (resultData []pcsg.PythonBloombergGeneralData
 	resultData = result.Data
 	return
 }
+
+// CurlPCSGBloombergDailyRun3Api 请求日度指标(Run3)接口
+func CurlPCSGBloombergDailyRun3Api() (resultData []pcsg.PythonBloombergGeneralData, err error) {
+	if global.CONFIG.PCSG.BloombergApiUrl == "" {
+		err = fmt.Errorf("服务地址为空")
+		return
+	}
+	url := fmt.Sprint(global.CONFIG.PCSG.BloombergApiUrl, PCSGBloombergPythonApiDailyRun3)
+
+	resp, e := http.Post(url, "application/json", bytes.NewBuffer([]byte("")))
+	if e != nil {
+		err = fmt.Errorf("http post err: %s", e.Error())
+		return
+	}
+	defer resp.Body.Close()
+
+	b, e := ioutil.ReadAll(resp.Body)
+	if e != nil {
+		err = fmt.Errorf("resp body read err: %s", e.Error())
+		return
+	}
+	if len(b) == 0 {
+		err = fmt.Errorf("resp body is empty")
+		return
+	}
+
+	result := new(pcsg.PythonBloombergGeneralResult)
+	if e = json.Unmarshal(b, &result); e != nil {
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s", string(b))
+		return
+	}
+	resultData = result.Data
+	return
+}