浏览代码

Merge branch 'ETA_1.4.5' into debug

zwxi 1 年之前
父节点
当前提交
69014a4dec
共有 1 个文件被更改,包括 50 次插入18 次删除
  1. 50 18
      controllers/data_manage/edb_info.go

+ 50 - 18
controllers/data_manage/edb_info.go

@@ -5641,31 +5641,64 @@ func (this *EdbInfoController) EdbInfoSmmSearch() {
 		br.Msg = "无符合指标或指标代码错误"
 		return
 	}
+	searchItemList := make([]*data_manage.EdbInfoSearch, 0)
 
 	resp := new(data_manage.EdbInfoSearchResp)
+	needAddCodeArr := make([]string, 0)
+	for _, edbCode := range edbCodeArr {
+		dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.DATA_SUB_SOURCE_EDB, utils.EDB_DATA_LIMIT)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
+			return
+		}
 
-	edbCode = strings.Join(edbCodeArr, ",")
-	respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode)
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
-		return
-	}
-	if respItem.Ret != 200 {
-		if respItem.Ret == 421 {
-			br.Msg = "该渠道已超过添加上限"
-		} else if respItem.Ret == 4052 {
-			br.Msg = "该指标已下架"
+		fmt.Println("dataItems:", len(dataItems))
+		if len(dataItems) > 0 {
+			searchItem := new(data_manage.EdbInfoSearch)
+			searchItem.EdbCode = edbCode
+			minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
+				return
+			}
+			searchItem.DataList = dataItems
+			searchItem.StartDate = minDate
+			searchItem.EndDate = maxDate
+
+			searchItem.DataList = dataItems
+
+			searchItemList = append(searchItemList, searchItem)
 		} else {
-			br.Msg = "未搜索到该指标"
+			// 把需要新加的code添加到needAddCodeArr数组中,一起批量请求
+			needAddCodeArr = append(needAddCodeArr, edbCode)
+		}
+	}
+	if len(needAddCodeArr) > 0 {
+		edbCode = strings.Join(needAddCodeArr, ",")
+		respItem, err := data.AddEdbData(utils.DATA_SOURCE_YS, edbCode)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if respItem.Ret != 200 {
+			if respItem.Ret == 421 {
+				br.Msg = "该渠道已超过添加上限"
+			} else if respItem.Ret == 4052 {
+				br.Msg = "该指标已下架"
+			} else {
+				br.Msg = "未搜索到该指标"
+			}
+			br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
+			return
 		}
-		br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
-		return
 	}
 
 	edbCodeStr := ""
 	for i, _ := range edbCodeArr {
-		edbCodeStr += "'"+edbCodeArr[i]+"'" + ","
+		edbCodeStr += "'" + edbCodeArr[i] + "'" + ","
 	}
 	edbCodeStr = strings.Trim(edbCodeStr, ",")
 	smmInfoList, err := data_manage.GetBaseFromSmmIndexByIndexCodes(edbCodeStr)
@@ -5674,7 +5707,6 @@ func (this *EdbInfoController) EdbInfoSmmSearch() {
 		br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
 		return
 	}
-	searchItemList := make([]*data_manage.EdbInfoSearch, 0)
 	for _, smmInfo := range smmInfoList {
 		if smmInfo != nil {
 			searchItem := new(data_manage.EdbInfoSearch)
@@ -5852,4 +5884,4 @@ func (this *EdbInfoController) SmmEdbInfoBatchAdd() {
 	br.Msg = "保存成功"
 	br.Data = resp
 	br.IsAddLog = true
-}
+}