Parcourir la source

添加指标列表 逻辑调整

gmy il y a 4 mois
Parent
commit
dec94d6f1f

+ 2 - 2
controllers/data_manage/base_from_rzd_index_controller.go

@@ -274,7 +274,7 @@ func (this *BaseFromRzdIndexController) RzdIndexAddValidate() {
 	// 校验指标编码是否存在
 	addValidate, err := data.RzdIndexAddValidate(req)
 	if err != nil {
-		br.Ret = 500
+		br.Ret = 403
 		br.Success = false
 		br.Msg = fmt.Sprintf("操作失败,Err:%s", err)
 		return
@@ -526,7 +526,7 @@ func (this *BaseFromRzdIndexController) RzdIndexDataExport() {
 	}
 
 	for _, frequency := range frequencies {
-		fenWeiIndices, err := data_manage.GetRzdIndexByCodeAndClassify(indexCode, classifyId, frequency)
+		fenWeiIndices, err := data_manage.GetRzdIndexByCodeAndClassify(indexCode, classifyIdList, frequency)
 		if err != nil {
 			return
 		}

+ 8 - 8
models/data_manage/base_from_rzd_data.go

@@ -4,7 +4,6 @@ package data_manage
 import (
 	"eta/eta_api/utils"
 	"github.com/beego/beego/v2/client/orm"
-	"strings"
 )
 
 type BaseFromRzdData struct {
@@ -97,14 +96,15 @@ func GetRzdDataListByIndexCodes(IndexCodes string) (items []string, err error) {
 func GetRzdLastUpdateTimeLastByIndexCode(indexCodes []string) (items []*BaseFromRzdData, err error) {
 	o := orm.NewOrmUsingDB("data")
 
-	// 将 indexCodes 切片转换为逗号分隔的字符串
-	placeholders := strings.Repeat("?,", len(indexCodes)-1) + "?"
-
 	// 构造 SQL 查询
-	sql := `SELECT index_code, MAX(modify_time) AS modify_time
-            FROM base_from_rzd_data
-            WHERE index_code IN (` + placeholders + `)
-            GROUP BY index_code`
+	sql := `SELECT t1.index_code, t1.data_time, t2.value
+			FROM (
+    			SELECT index_code, MAX(data_time) AS data_time
+   				 FROM base_from_rzd_data
+    			WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `)
+    			GROUP BY index_code
+			) AS t1
+			JOIN base_from_rzd_data AS t2 ON t1.index_code = t2.index_code AND t1.data_time = t2.data_time`
 
 	// 执行 SQL 查询
 	_, err = o.Raw(sql, indexCodes).QueryRows(&items)

+ 6 - 4
models/data_manage/base_from_rzd_index.go

@@ -151,7 +151,7 @@ func GetRzdIndexFrequency(classifyIdList []int) (items []*string, err error) {
 }
 
 // GetRzdIndexByCodeAndClassify 根据指标编码和分类查询 indexCode非必传
-func GetRzdIndexByCodeAndClassify(indexCode string, classifyId int, frequency *string) (items []*BaseFromRzdIndex, err error) {
+func GetRzdIndexByCodeAndClassify(indexCode string, classifyIdList []int, frequency *string) (items []*BaseFromRzdIndex, err error) {
 	o := orm.NewOrmUsingDB("data")
 
 	// SQL 查询语句
@@ -162,9 +162,11 @@ func GetRzdIndexByCodeAndClassify(indexCode string, classifyId int, frequency *s
 
 	var params []interface{}
 
-	if classifyId != 0 {
-		sql += ` AND a.base_from_rzd_classify_id = ?`
-		params = append(params, classifyId)
+	if len(classifyIdList) > 0 {
+		sql += ` AND a.base_from_rzd_classify_id in (` + utils.GetOrmInReplace(len(classifyIdList)) + `)`
+		for _, id := range classifyIdList {
+			params = append(params, id)
+		}
 	}
 
 	// 如果 indexCode 不为空,增加过滤条件

+ 2 - 2
services/data/base_from_rzd_index_service.go

@@ -161,7 +161,7 @@ func RzdIndexAddValidate(req *data_manage.BaseFromRzdIndexBatchAddCheckReq) ([]*
 			}
 		}
 		if req.SearchParams != "" {
-			condition += ` AND index_name like ? or index_code ?`
+			condition += ` AND (index_name like ? or index_code like ?)`
 			pars = append(pars, "%"+req.SearchParams+"%", "%"+req.SearchParams+"%")
 		}
 		if len(req.IndexCodes) > 0 {
@@ -356,7 +356,7 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
 		if indexDataMap[indexInfo.IndexCode] == nil {
 			continue
 		}
-		indexInfo.ModifyTimeMax = indexDataMap[indexInfo.IndexCode].ModifyTime
+		indexInfo.ModifyTimeMax = indexDataMap[indexInfo.IndexCode].DataTime
 		indexInfo.Value = indexDataMap[indexInfo.IndexCode].Value
 	}