|
@@ -27,6 +27,7 @@ import (
|
|
|
|
|
|
const (
|
|
|
HZ_DATA_API = "https://hzdataapi.hzinsights.com/hzdataapi/"
|
|
|
+ ClassifyId = 685
|
|
|
)
|
|
|
|
|
|
func InitCalculateIndex() {
|
|
@@ -66,7 +67,7 @@ func InitCalculateIndex() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- method := "edb_index/detail"
|
|
|
+ hzMethod := "edb_index/detail"
|
|
|
edbLibIndexMethod := "/edb_info/detail"
|
|
|
var needAddIndexArr []string
|
|
|
|
|
@@ -90,7 +91,7 @@ func InitCalculateIndex() {
|
|
|
|
|
|
params := make(map[string]interface{})
|
|
|
params["EdbCode"] = indexCode
|
|
|
- result, err := hzDataHttpPost(method, params)
|
|
|
+ result, err := hzDataHttpPost(hzMethod, params)
|
|
|
if err != nil {
|
|
|
fmt.Println("hzDataHttpPost Err:" + err.Error())
|
|
|
return
|
|
@@ -153,8 +154,138 @@ func InitCalculateIndex() {
|
|
|
}
|
|
|
f.Save()
|
|
|
|
|
|
+ hzIndexMethod := "edb_index/item"
|
|
|
+ hzCalculateIndexMethod := "edb_info_calculate/item"
|
|
|
+
|
|
|
+ edbLibIndexMethod = "edb_info/copy/from/hz"
|
|
|
+ edbLibCalculateIndexMethod := "edb_info/copy/from/hz"
|
|
|
+
|
|
|
for k, v := range needAddIndexArr { //需要同步的计算指标
|
|
|
fmt.Println(k, v)
|
|
|
+
|
|
|
+ params := make(map[string]interface{})
|
|
|
+ params["EdbCode"] = v
|
|
|
+ hzResult, err := hzDataHttpPost(hzIndexMethod, params)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("hzDataHttpPost Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hzResp := new(models.EdbInfoItemResp)
|
|
|
+ err = json.Unmarshal([]byte(hzResult), &hzResp)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("json.Unmarshal Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if hzResp.Ret != 200 {
|
|
|
+ fmt.Println("resp Err:" + hzResp.ErrMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ edbInfo := hzResp.Data
|
|
|
+ //新增指标信息
|
|
|
+ indexMap := make(map[string]interface{})
|
|
|
+ indexMap["EdbInfoType"] = edbInfo.EdbInfoType
|
|
|
+ indexMap["SourceName"] = edbInfo.SourceName
|
|
|
+ indexMap["Source"] = edbInfo.Source
|
|
|
+ indexMap["EdbCode"] = edbInfo.EdbCode
|
|
|
+ indexMap["EdbName"] = edbInfo.EdbName
|
|
|
+ indexMap["EdbNameEn"] = edbInfo.EdbNameEn
|
|
|
+ indexMap["EdbNameSource"] = edbInfo.EdbNameSource
|
|
|
+ indexMap["Frequency"] = edbInfo.Frequency
|
|
|
+ indexMap["Unit"] = edbInfo.Unit
|
|
|
+ indexMap["UnitEn"] = edbInfo.UnitEn
|
|
|
+ indexMap["StartDate"] = edbInfo.StartDate
|
|
|
+ indexMap["EndDate"] = edbInfo.EndDate
|
|
|
+ indexMap["ClassifyId"] = ClassifyId
|
|
|
+ indexMap["SysUserId"] = 0
|
|
|
+ indexMap["SysUserRealName"] = ""
|
|
|
+ indexMap["UniqueCode"] = edbInfo.UniqueCode
|
|
|
+ indexMap["CreateTime"] = time.Now()
|
|
|
+ indexMap["ModifyTime"] = time.Now()
|
|
|
+ indexMap["MinValue"] = edbInfo.MinValue
|
|
|
+ indexMap["MaxValue"] = edbInfo.MaxValue
|
|
|
+ indexMap["CalculateFormula"] = edbInfo.CalculateFormula
|
|
|
+ indexMap["EdbType"] = edbInfo.EdbType
|
|
|
+ indexMap["IsUpdate"] = 1
|
|
|
+ indexMap["Sort"] = edbInfo.Sort
|
|
|
+ indexMap["LatestDate"] = edbInfo.LatestDate
|
|
|
+ indexMap["LatestValue"] = edbInfo.LatestValue
|
|
|
+ indexMap["MoveType"] = edbInfo.MoveType
|
|
|
+ indexMap["MoveFrequency"] = edbInfo.MoveFrequency
|
|
|
+ indexMap["NoUpdate"] = edbInfo.NoUpdate
|
|
|
+ indexMap["ServerUrl"] = edbInfo.ServerUrl
|
|
|
+ indexMap["ChartImage"] = edbInfo.ChartImage
|
|
|
+ indexMap["Calendar"] = edbInfo.Calendar
|
|
|
+ indexMap["DataDateType"] = edbInfo.DataDateType
|
|
|
+
|
|
|
+ edbLibResult, err := PostEdbLib(indexMap, edbLibIndexMethod)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("新增计算指标失败:" + err.Error() + " result:" + string(edbLibResult))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ baseResp := new(models.BaseResponse)
|
|
|
+ err = json.Unmarshal([]byte(edbLibResult), &baseResp)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("edbLibResult json.Unmarshal Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if baseResp.Ret != 200 {
|
|
|
+ fmt.Println("PostEdbLib resp Err:" + hzResp.ErrMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增计算指标映射关系
|
|
|
+ calculateParams := make(map[string]interface{})
|
|
|
+ calculateParams["EdbCode"] = v
|
|
|
+ hzResult, err = hzDataHttpPost(hzCalculateIndexMethod, calculateParams)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("hzDataHttpPost calculate Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ hzCalculateResp := new(models.EdbInfoCalculateMappingResp)
|
|
|
+ err = json.Unmarshal([]byte(hzResult), &hzCalculateResp)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("calculate json.Unmarshal Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if hzResp.Ret != 200 {
|
|
|
+ fmt.Println("calculate resp Err:" + hzResp.ErrMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, cv := range hzCalculateResp.Data {
|
|
|
+ //新增指标信息
|
|
|
+ indexCalculateMap := make(map[string]interface{})
|
|
|
+ indexCalculateMap["EdbInfoId"] = cv.EdbInfoId
|
|
|
+ indexCalculateMap["Source"] = cv.Source
|
|
|
+ indexCalculateMap["SourceName"] = cv.SourceName
|
|
|
+ indexCalculateMap["EdbCode"] = cv.EdbCode
|
|
|
+ indexCalculateMap["FromEdbInfoId"] = cv.FromEdbInfoId
|
|
|
+ indexCalculateMap["FromEdbCode"] = cv.FromEdbCode
|
|
|
+ indexCalculateMap["FromEdbName"] = cv.FromEdbName
|
|
|
+ indexCalculateMap["FromSource"] = cv.FromSource
|
|
|
+ indexCalculateMap["FromSourceName"] = cv.FromSourceName
|
|
|
+ indexCalculateMap["MoveValue"] = cv.MoveValue
|
|
|
+ indexCalculateMap["Sort"] = cv.Sort
|
|
|
+ indexCalculateMap["CreateTime"] = time.Now()
|
|
|
+ indexCalculateMap["ModifyTime"] = time.Now()
|
|
|
+ indexCalculateMap["FromTag"] = cv.EdbInfoId
|
|
|
+
|
|
|
+ edbLibResult, err := PostEdbLib(indexCalculateMap, edbLibCalculateIndexMethod)
|
|
|
+ if err != nil {
|
|
|
+ utils.FileLog.Info("新增计算指标映射关系失败:" + err.Error() + " result:" + string(edbLibResult))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ baseResp := new(models.BaseResponse)
|
|
|
+ err = json.Unmarshal([]byte(edbLibResult), &baseResp)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("edbLibResult mapping json.Unmarshal Err:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if baseResp.Ret != 200 {
|
|
|
+ fmt.Println("PostEdbLib mapping resp Err:" + hzResp.ErrMsg)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
}
|
|
|
}
|
|
|
|