Browse Source

睿姿得数据对接联调

gmy 4 months ago
parent
commit
128a375935

+ 5 - 10
controllers/data_manage/base_from_rzd_index_controller.go

@@ -259,17 +259,12 @@ func (this *BaseFromRzdIndexController) RzdIndexAddValidate() {
 		return
 	}
 
-	codeLen := len(req.IndexCodes)
-	var codeMax = 30
-	if codeLen > codeMax {
-		br.Msg = "批量添加指标数量不得超过" + strconv.Itoa(codeMax) + "个"
-		br.ErrMsg = "批量添加指标数量不得超过" + strconv.Itoa(codeMax) + "个"
-		return
-	}
-
 	// 校验指标编码是否存在
-	addValidate, err := data.RzdIndexAddValidate(req.IndexCodes)
+	addValidate, err := data.RzdIndexAddValidate(req)
 	if err != nil {
+		br.Ret = 500
+		br.Success = false
+		br.Msg = fmt.Sprintf("操作失败,Err:%s", err)
 		return
 	}
 	br.Data = addValidate
@@ -377,7 +372,7 @@ func (this *BaseFromRzdIndexController) RzdIndexAdd() {
 		if v.Exist {
 			br.Msg = "指标名称重复"
 			br.Data = nameCheck
-			br.Ret = 200
+			br.Ret = 400
 			br.Success = true
 			return
 		}

+ 27 - 5
models/data_manage/base_from_rzd_index.go

@@ -72,11 +72,13 @@ type RzdIndexCheckData struct {
 
 // BaseFromRzdIndexBatchAddCheckReq 校验编码是否存在请求参数
 type BaseFromRzdIndexBatchAddCheckReq struct {
-	IndexCodes   []string `form:"IndexCodes" description:"指标编码列表"`
-	ClassifyId   int      `description:"分类id"`
-	Frequency    string   `description:"频度"`
-	SearchParams string   `description:"搜索参数 指标编码/指标名称"`
-	IsCheckAll   bool     `form:"IndexCodes" description:"是否全选"`
+	IndexCodes     []string `form:"IndexCodes" description:"指标编码列表"`
+	ClassifyIdList []int    `description:"分类id"`
+	Frequency      string   `description:"频度"`
+	SearchParams   string   `description:"搜索参数 指标编码/指标名称"`
+	IsCheckAll     bool     `description:"是否全选"`
+	CurrentIndex   int      `description:"起始页"`
+	PageSize       int      `description:"每页记录数"`
 }
 
 func init() {
@@ -107,6 +109,26 @@ func GetRzdIndex(condition string, pars interface{}) (items []*BaseFromRzdIndexL
 	return
 }
 
+func GetRzdIndexNotExistEdbInfoCount(condition string, pars interface{}) (count int, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT count(1) FROM base_from_rzd_index WHERE index_code not in (select edb_code from edb_info) `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func GetRzdIndexNotExistEdbInfoPage(condition string, pars interface{}) (items []*BaseFromRzdIndexAndData, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM base_from_rzd_index WHERE index_code not in (select edb_code from edb_info) `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // GetRzdIndexFrequency 获取指标频度
 func GetRzdIndexFrequency(classifyIdList []int) (items []*string, err error) {
 	sql := `SELECT DISTINCT frequency 

+ 72 - 25
services/data/base_from_rzd_index_service.go

@@ -143,27 +143,74 @@ func GetRzdIndexFrequency(classify int) ([]*string, error) {
 }
 
 // RzdIndexAddValidate 指标添加校验
-func RzdIndexAddValidate(indexCodes []string) (*[]data_manage.RzdIndexCheckData, error) {
-	// 根据指标编码获取指标库 指标信息
-	edbInfos, err := data_manage.GetEdbInfoByEdbCodeList(utils.DATA_SOURCE_RZD, indexCodes)
+func RzdIndexAddValidate(req *data_manage.BaseFromRzdIndexBatchAddCheckReq) (*data_manage.BaseFromRzdIndexPage, error) {
+	var condition string
+	var pars []interface{}
+
+	if req.IsCheckAll {
+		if len(req.ClassifyIdList) >= 0 {
+			condition += ` AND base_from_rzd_classify_id in (` + utils.GetOrmInReplace(len(req.ClassifyIdList)) + `)`
+			for _, id := range req.ClassifyIdList {
+				pars = append(pars, id)
+			}
+		}
+		if req.Frequency != "" {
+			condition += ` AND frequency=? `
+			pars = append(pars, req.Frequency)
+		}
+		if req.SearchParams != "" {
+			condition += ` AND index_name like ? or index_code ?`
+			pars = append(pars, "%"+req.SearchParams+"%", "%"+req.SearchParams+"%")
+		}
+		if len(req.IndexCodes) > 0 {
+			condition += ` AND index_code not in (` + utils.GetOrmInReplace(len(req.IndexCodes)) + `)`
+			for _, code := range req.IndexCodes {
+				pars = append(pars, code)
+			}
+		}
+	} else {
+		if len(req.IndexCodes) > 0 {
+			condition += ` AND index_code in (` + utils.GetOrmInReplace(len(req.IndexCodes)) + `)`
+			for _, code := range req.IndexCodes {
+				pars = append(pars, code)
+			}
+		}
+	}
+
+	if req.PageSize <= 0 {
+		req.PageSize = utils.PageSize20
+	}
+	if req.CurrentIndex <= 0 {
+		req.CurrentIndex = 1
+	}
+	startSize := utils.StartIndex(req.CurrentIndex, req.PageSize)
+
+	count, err := data_manage.GetRzdIndexNotExistEdbInfoCount(condition, pars)
 	if err != nil {
 		return nil, err
 	}
-	var respList []data_manage.RzdIndexCheckData
-	if len(edbInfos) > 0 {
-		for _, ebdInfo := range edbInfos {
-			respList = append(respList, data_manage.RzdIndexCheckData{
-				IndexCode:  ebdInfo.EdbCode,
-				IndexName:  ebdInfo.EdbName,
-				Unit:       ebdInfo.Unit,
-				Frequency:  ebdInfo.Frequency,
-				EdbInfoId:  ebdInfo.EdbInfoId,
-				ClassifyId: ebdInfo.ClassifyId,
-				UniqueCode: ebdInfo.UniqueCode,
-			})
-		}
+	page := paging.GetPaging(req.CurrentIndex, req.PageSize, count)
+
+	result := data_manage.BaseFromRzdIndexPage{}
+	result.Paging = page
+
+	if count <= 0 {
+		return &result, nil
+	} else if count > 30 {
+		return &result, fmt.Errorf("批量添加指标数量不得超过30个")
+	}
+
+	condition += ` ORDER BY base_from_rzd_index_id asc`
+
+	condition += ` limit ?, ?`
+	pars = append(pars, startSize, req.PageSize)
+
+	indexList, err := data_manage.GetRzdIndexNotExistEdbInfoPage(condition, pars)
+	if err != nil {
+		return nil, err
 	}
-	return &respList, nil
+	result.List = indexList
+	return &result, nil
 }
 
 // RzdIndexNameCheck 指标名称校验
@@ -268,8 +315,8 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
 	var condition string
 	var pars []interface{}
 	if keyWord != "" {
-		condition += ` AND CONCAT(index_name,index_code) LIKE '%` + keyWord + `%'`
-		pars = append(pars, keyWord)
+		condition += ` AND (index_name like ? or index_code like ?)`
+		pars = append(pars, "%"+keyWord+"%", "%"+keyWord+"%")
 	}
 	if len(classifyIdList) > 0 {
 		condition += ` AND base_from_rzd_classify_id IN (`
@@ -288,12 +335,6 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
 		condition = condition[:len(condition)-1] + `)`
 	}
 
-	condition += ` ORDER BY base_from_rzd_index_id asc`
-
-	// 分页
-	condition += ` LIMIT ?, ?`
-	pars = append(pars, startSize, pageSize)
-
 	count, err := data_manage.GetRzdIndexInfoCount(condition, pars)
 	if err != nil {
 		return nil, err
@@ -305,6 +346,12 @@ func GetRzdIndexInfo(keyWord string, classifyIdList []string, frequencyList []st
 		return &indexPage, nil
 	}
 
+	condition += ` ORDER BY base_from_rzd_index_id asc`
+
+	// 分页
+	condition += ` LIMIT ?, ?`
+	pars = append(pars, startSize, pageSize)
+
 	indexInfoPage, err := data_manage.GetRzdIndexInfoPage(condition, pars)
 	if err != nil {
 		return nil, err