|
@@ -15,7 +15,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
// GetKplerDataByApi 获取开普勒数据
|
|
// GetKplerDataByApi 获取开普勒数据
|
|
-func GetKplerDataByApi(params models.KplerSearchEdbReq, terminalCode string) (indexes []*models.KplerIndexItem, apiQueryUrl string, terminalInfo *models.EdbTerminal, err error) {
|
|
|
|
|
|
+func GetKplerDataByApi(params models.KplerSearchEdbReq, terminalCode string, isRefresh bool) (indexes []*models.KplerIndexItem, apiQueryUrl string, terminalInfo *models.EdbTerminal, err error) {
|
|
terminal, e := GetApiTerminal(utils.DATA_SOURCE_KPLER, terminalCode)
|
|
terminal, e := GetApiTerminal(utils.DATA_SOURCE_KPLER, terminalCode)
|
|
if e != nil {
|
|
if e != nil {
|
|
err = fmt.Errorf("获取开普勒终端配置失败, %v", e)
|
|
err = fmt.Errorf("获取开普勒终端配置失败, %v", e)
|
|
@@ -29,7 +29,7 @@ func GetKplerDataByApi(params models.KplerSearchEdbReq, terminalCode string) (in
|
|
|
|
|
|
// 走API
|
|
// 走API
|
|
if terminal.IsApi == 1 {
|
|
if terminal.IsApi == 1 {
|
|
- indexes, apiQueryUrl, err = getKplerDataByApi(params, terminal.ServerUrl)
|
|
|
|
|
|
+ indexes, apiQueryUrl, err = getKplerDataByApi(params, terminal.ServerUrl, isRefresh)
|
|
if err != nil {
|
|
if err != nil {
|
|
err = fmt.Errorf("获取开普勒指标数据失败, %v", err)
|
|
err = fmt.Errorf("获取开普勒指标数据失败, %v", err)
|
|
return
|
|
return
|
|
@@ -41,7 +41,7 @@ func GetKplerDataByApi(params models.KplerSearchEdbReq, terminalCode string) (in
|
|
}
|
|
}
|
|
|
|
|
|
// getEdbDataFromThsHfHttp API-获取高频指标数据
|
|
// getEdbDataFromThsHfHttp API-获取高频指标数据
|
|
-func getKplerDataByApi(params models.KplerSearchEdbReq, serverUrl string) (list []*models.KplerIndexItem, apiQueryUrl string, err error) {
|
|
|
|
|
|
+func getKplerDataByApi(params models.KplerSearchEdbReq, serverUrl string, isRefresh bool) (list []*models.KplerIndexItem, apiQueryUrl string, err error) {
|
|
defer func() {
|
|
defer func() {
|
|
if err != nil {
|
|
if err != nil {
|
|
tips := fmt.Sprintf("开普勒指标API-getKplerDataByApi err: %v", err)
|
|
tips := fmt.Sprintf("开普勒指标API-getKplerDataByApi err: %v", err)
|
|
@@ -66,7 +66,7 @@ func getKplerDataByApi(params models.KplerSearchEdbReq, serverUrl string) (list
|
|
libreq.WithIntraRegion = "true"
|
|
libreq.WithIntraRegion = "true"
|
|
libreq.WithForecast = "true"
|
|
libreq.WithForecast = "true"
|
|
libreq.OnlyRealized = "false"
|
|
libreq.OnlyRealized = "false"
|
|
- libreq.StartDate = "2025-01-01"
|
|
|
|
|
|
+ libreq.StartDate = "2013-01-01"
|
|
libreq.EndDate = time.Now().Format(utils.FormatDate)
|
|
libreq.EndDate = time.Now().Format(utils.FormatDate)
|
|
// 请求接口
|
|
// 请求接口
|
|
apiResp, err := getKplerFlowDataLib(serverUrl, libreq)
|
|
apiResp, err := getKplerFlowDataLib(serverUrl, libreq)
|
|
@@ -121,10 +121,10 @@ func getKplerDataByApi(params models.KplerSearchEdbReq, serverUrl string) (list
|
|
for _, v := range existList {
|
|
for _, v := range existList {
|
|
existIndexCodeMap[v.IndexCode] = true
|
|
existIndexCodeMap[v.IndexCode] = true
|
|
}
|
|
}
|
|
- // 过滤已经存在的指标
|
|
|
|
|
|
+ // 过滤已经存在的指标, 如果是刷新指标,则无需过滤
|
|
list = make([]*models.KplerIndexItem, 0)
|
|
list = make([]*models.KplerIndexItem, 0)
|
|
for _, v := range indexes {
|
|
for _, v := range indexes {
|
|
- if _, ok := existIndexCodeMap[v.IndexCode]; !ok {
|
|
|
|
|
|
+ if _, ok := existIndexCodeMap[v.IndexCode]; !ok || isRefresh {
|
|
list = append(list, v)
|
|
list = append(list, v)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -182,6 +182,7 @@ func AddKplerIndexByApi(indexList []*models.KplerIndexItem, req *models.KplerSea
|
|
indexObj.IndexName = indexInfo.IndexName
|
|
indexObj.IndexName = indexInfo.IndexName
|
|
indexObj.Frequency = indexInfo.Frequency
|
|
indexObj.Frequency = indexInfo.Frequency
|
|
indexObj.ClassifyId = int(classifyId)
|
|
indexObj.ClassifyId = int(classifyId)
|
|
|
|
+ indexObj.ProductNames = req.ProductNames
|
|
indexObj.FromZoneId = fromZoneId
|
|
indexObj.FromZoneId = fromZoneId
|
|
indexObj.ToZoneId = toZoneId
|
|
indexObj.ToZoneId = toZoneId
|
|
indexObj.FromZoneName = req.FromZoneNames
|
|
indexObj.FromZoneName = req.FromZoneNames
|
|
@@ -221,7 +222,7 @@ func AddKplerIndexByApi(indexList []*models.KplerIndexItem, req *models.KplerSea
|
|
indexObj.FromZoneName = req.FromZoneNames
|
|
indexObj.FromZoneName = req.FromZoneNames
|
|
indexObj.ToZoneName = req.ToZoneNames
|
|
indexObj.ToZoneName = req.ToZoneNames
|
|
indexObj.FlowDirection = req.FlowDirection
|
|
indexObj.FlowDirection = req.FlowDirection
|
|
- indexObj.Granularity = req.Granularity
|
|
|
|
|
|
+ indexObj.Granularity = GetKplerGranularity(req.Granularity)
|
|
indexObj.Split = req.Split
|
|
indexObj.Split = req.Split
|
|
indexObj.Unit = req.Unit
|
|
indexObj.Unit = req.Unit
|
|
indexObj.ApiQueryUrl = apiQueryUrl
|
|
indexObj.ApiQueryUrl = apiQueryUrl
|
|
@@ -415,9 +416,13 @@ func getKplerFlowDataLib(libUrl string, dataMap *models.KplerFlowDataLibReq) (re
|
|
return resp, nil
|
|
return resp, nil
|
|
}
|
|
}
|
|
|
|
|
|
-func getKplerProductLib(libUrl string) (resp *models.KplerProductLibResp, err error) {
|
|
|
|
|
|
+func getKplerProductLib(libUrl string, req *models.KplerProductLibReq) (resp *models.KplerProductLibResp, err error) {
|
|
postUrl := fmt.Sprintf("%s%s", libUrl, "/v1/kpler/getProductData")
|
|
postUrl := fmt.Sprintf("%s%s", libUrl, "/v1/kpler/getProductData")
|
|
- result, err := HttpPost(postUrl, "", "application/json")
|
|
|
|
|
|
+ postData, err := json.Marshal(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ result, err := HttpPost(postUrl, string(postData), "application/json")
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -781,15 +786,15 @@ func getKplerFrequency(granularity string) (frequency string) {
|
|
|
|
|
|
func GetKplerGranularity(frequency string) (granularity string) {
|
|
func GetKplerGranularity(frequency string) (granularity string) {
|
|
switch frequency {
|
|
switch frequency {
|
|
- case "daily", "Daily":
|
|
|
|
|
|
+ case "daily", "Daily", "days":
|
|
return "days"
|
|
return "days"
|
|
- case "weekly", "Weekly":
|
|
|
|
|
|
+ case "weekly", "Weekly", "weeks":
|
|
return "weeks"
|
|
return "weeks"
|
|
- case "monthly", "Monthly":
|
|
|
|
|
|
+ case "monthly", "Monthly", "months":
|
|
return "months"
|
|
return "months"
|
|
- case "yearly", "Yearly":
|
|
|
|
|
|
+ case "yearly", "Yearly", "years":
|
|
return "years"
|
|
return "years"
|
|
- case "quarterly", "Quarters":
|
|
|
|
|
|
+ case "quarterly", "Quarters", "quarters":
|
|
return "quarters"
|
|
return "quarters"
|
|
}
|
|
}
|
|
return ""
|
|
return ""
|
|
@@ -797,7 +802,18 @@ func GetKplerGranularity(frequency string) (granularity string) {
|
|
|
|
|
|
func InitKplerProduct ()(err error) {
|
|
func InitKplerProduct ()(err error) {
|
|
libUrl := "http://127.0.0.1:8915"
|
|
libUrl := "http://127.0.0.1:8915"
|
|
- libResp, err := getKplerProductLib(libUrl)
|
|
|
|
|
|
+ libResp, err := getKplerProductLib(libUrl, &models.KplerProductLibReq{
|
|
|
|
+ AncestorFamilyIds: "",
|
|
|
|
+ AncestorFamilyNames: "",
|
|
|
|
+ AncestorGroupIds: "",
|
|
|
|
+ AncestorGroupNames: "",
|
|
|
|
+ AncestorProductIds: "",
|
|
|
|
+ AncestorProductNames: "",
|
|
|
|
+ AncestorGradeIds: "",
|
|
|
|
+ AncestorGradeNames: "",
|
|
|
|
+ Products: "",
|
|
|
|
+ ProductIds: "",
|
|
|
|
+ })
|
|
if err != nil {
|
|
if err != nil {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -871,6 +887,77 @@ func InitKplerProduct ()(err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func InitKplerProductGrade ()(err error) {
|
|
|
|
+ libUrl := "http://127.0.0.1:8915"
|
|
|
|
+
|
|
|
|
+ classifyList, err := models.GetAllBaseFromKplerClassifyByClassifyType("subgrade4")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, c := range classifyList {
|
|
|
|
+ c.ModifyTime = time.Now()
|
|
|
|
+ err = c.Update([]string{"ModifyTime"})
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("更新开普勒产品库失败", err)
|
|
|
|
+ utils.FileLog.Info("更新开普勒产品库失败", err)
|
|
|
|
+ }
|
|
|
|
+ // 每个分类都发起分组请求
|
|
|
|
+ libResp, er := getKplerProductLib(libUrl, &models.KplerProductLibReq{
|
|
|
|
+ // AncestorFamilyIds: familyIds,
|
|
|
|
+ // AncestorFamilyNames: familyNames,
|
|
|
|
+ // AncestorGroupIds: groupIds,
|
|
|
|
+ // AncestorGroupNames: groupNames,
|
|
|
|
+ // AncestorProductIds: productIds,
|
|
|
|
+ // AncestorProductNames: productNames,
|
|
|
|
+ AncestorGradeIds: strconv.Itoa(c.ProductId),
|
|
|
|
+ AncestorGradeNames: c.ProductName,
|
|
|
|
+ })
|
|
|
|
+ if er != nil {
|
|
|
|
+ fmt.Println("获取开普勒产品库失败", er)
|
|
|
|
+ utils.FileLog.Info("获取开普勒产品库失败", er)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if libResp.Ret != 200 {
|
|
|
|
+ fmt.Println("获取开普勒产品库失败", libResp.ErrMsg)
|
|
|
|
+ utils.FileLog.Info("获取开普勒产品库失败", libResp.ErrMsg)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ classifyObj := new(models.BaseFromKplerClassify)
|
|
|
|
+ for _, v := range libResp.Data {
|
|
|
|
+ id, _ := strconv.Atoi(v.Id)
|
|
|
|
+ if id == 0 {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if id == c.ProductId {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ // 更新对应的分类等级和父级
|
|
|
|
+ // 查找所有子分类
|
|
|
|
+
|
|
|
|
+ classifyItem, er := classifyObj.GetByProductId(id)
|
|
|
|
+ if er != nil {
|
|
|
|
+ err = fmt.Errorf("子分类不存在 Err:%s", er)
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ classifyItem.Level = c.Level + 1
|
|
|
|
+ classifyItem.ParentId = c.ClassifyId
|
|
|
|
+ classifyItem.ClassifyType = "subgrade5"
|
|
|
|
+ classifyItem.ModifyTime = time.Now()
|
|
|
|
+ err = classifyItem.Update([]string{"Level", "ParentId", "ClassifyType", "ModifyTime"})
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("更新开普勒产品库失败", err)
|
|
|
|
+ utils.FileLog.Info("更新开普勒产品库失败", err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fmt.Println("classifyList:", classifyList)
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
func InitKplerZone() (err error) {
|
|
func InitKplerZone() (err error) {
|
|
libUrl := "http://127.0.0.1:8915"
|
|
libUrl := "http://127.0.0.1:8915"
|