Browse Source

汾渭更新时间

gmy 2 months ago
parent
commit
39eee0ed9a
2 changed files with 48 additions and 31 deletions
  1. 40 31
      controllers/data_manage/fenwei_data.go
  2. 8 0
      models/data_manage/base_from_fenwei.go

+ 40 - 31
controllers/data_manage/fenwei_data.go

@@ -173,44 +173,53 @@ func (this *EdbInfoController) FenweiIndexData() {
 	}
 
 	resultList := make([]*data_manage.BaseFromFenweiIndexList, 0)
-	for _, v := range indexes {
-		product := new(data_manage.BaseFromFenweiIndexList)
-		product.FenweiIndexId = v.FenweiIndexId
-		product.ClassifyId = v.ClassifyId
-		product.Unit = v.Unit
-		product.IndexCode = v.IndexCode
-		product.IndexName = v.IndexName
-		product.Frequency = v.Frequency
-		product.CreateTime = v.CreateTime
-
+	if indexes != nil {
 		// 获取指标数据最新更新时间
-		modifyTime, err := data_manage.GetFenWeiDataLastModifyTime(v.IndexCode)
+		lastModifyTimeList, err := data_manage.GetFenWeiDataLastModifyTimeList(indexCodes)
 		if err != nil {
-			br.Msg = "获取数据失败"
-			br.ErrMsg = "获取指标数据最新更新时间失败, Err:" + err.Error()
 			return
 		}
-		product.ModifyTime = modifyTime
-
-		edbInfo := edbCodeMap[v.IndexCode]
-		if edbInfo != nil {
-			product.EdbInfoId = edbInfo.EdbInfoId
+		lastModifyTimeMap := make(map[string]string)
+		for _, v := range lastModifyTimeList {
+			lastModifyTimeMap[v.IndexCode] = v.ModifyTime
 		}
 
-		total := countMap[v.IndexCode]
-		page := paging.GetPaging(currentIndex, pageSize, total)
-		dataList, e := data_manage.GetFenweiIndexData(v.IndexCode, startSize, pageSize)
-		if e != nil {
-			br.Msg = "获取数据失败"
-			br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
-			return
-		}
-		if dataList == nil {
-			dataList = make([]*data_manage.BaseFromFenweiData, 0)
+		for _, v := range indexes {
+			product := new(data_manage.BaseFromFenweiIndexList)
+			product.FenweiIndexId = v.FenweiIndexId
+			product.ClassifyId = v.ClassifyId
+			product.Unit = v.Unit
+			product.IndexCode = v.IndexCode
+			product.IndexName = v.IndexName
+			product.Frequency = v.Frequency
+			product.CreateTime = v.CreateTime
+
+			if lastModifyTimeMap[v.IndexCode] != "" {
+				product.ModifyTime = lastModifyTimeMap[v.IndexCode]
+			} else {
+				product.ModifyTime = ""
+			}
+
+			edbInfo := edbCodeMap[v.IndexCode]
+			if edbInfo != nil {
+				product.EdbInfoId = edbInfo.EdbInfoId
+			}
+
+			total := countMap[v.IndexCode]
+			page := paging.GetPaging(currentIndex, pageSize, total)
+			dataList, e := data_manage.GetFenweiIndexData(v.IndexCode, startSize, pageSize)
+			if e != nil {
+				br.Msg = "获取数据失败"
+				br.ErrMsg = "获取指标数据失败,Err:" + e.Error()
+				return
+			}
+			if dataList == nil {
+				dataList = make([]*data_manage.BaseFromFenweiData, 0)
+			}
+			product.DataList = dataList
+			product.Paging = page
+			resultList = append(resultList, product)
 		}
-		product.DataList = dataList
-		product.Paging = page
-		resultList = append(resultList, product)
 	}
 
 	br.Ret = 200

+ 8 - 0
models/data_manage/base_from_fenwei.go

@@ -291,3 +291,11 @@ func GetFenWeiDataLastModifyTime(indexCode string) (lastModifyTime string, err e
 	err = o.Raw(sql, indexCode).QueryRow(&lastModifyTime)
 	return
 }
+
+// GetFenWeiDataLastModifyTimeList 查询指标数据最新更新时间
+func GetFenWeiDataLastModifyTimeList(indexCodes []string) (items []*BaseFromFenweiData, err error) {
+	sql := ` SELECT MAX(modify_time) AS modify_time, index_code FROM base_from_fenwei_data WHERE index_code IN(` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY index_code `
+	o := orm.NewOrmUsingDB("data")
+	_, err = o.Raw(sql, indexCodes).QueryRows(&items)
+	return
+}