Browse Source

计算指标设置启用,禁用

xyxie 8 months ago
parent
commit
dd46fc734d

+ 16 - 11
controllers/data_manage/edb_info_refresh.go

@@ -584,23 +584,27 @@ func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
 	if req.ModifyStatus == `暂停` {
 		isStop = 1
 	}
-	// 查询相关的计算指标
-	calculateEdb, err := data_manage.GetAllCalculateByEdbInfoId(edbInfo.EdbInfoId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			br.Msg = "指标不存在"
+	calculateEdb := make([]*data_manage.EdbInfoCalculateMapping, 0)
+	if edbInfo.EdbInfoType == 0 && edbInfo.EdbType == 1 { //基础指标
+		// 查询相关的计算指标
+		calculateEdb, err = data_manage.GetAllCalculateByEdbInfoId(edbInfo.EdbInfoId)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "指标不存在"
+				return
+			}
+			br.Msg = "查询计算指标失败"
+			br.ErrMsg = "查询计算指标失败,Err:" + err.Error()
 			return
 		}
-		br.Msg = "查询计算指标失败"
-		br.ErrMsg = "查询计算指标失败,Err:" + err.Error()
 	}
+
 	// 遍历指标列表,把计算指标id整理成数组
 	if len(calculateEdb) > 0 {
 		for _, calculateEdbInfo := range calculateEdb {
 			calculateEdbIdList = append(calculateEdbIdList, calculateEdbInfo.EdbInfoId)
 		}
 	}
-	// todo 查询相关的预测指标
 
 	switch edbInfo.Source {
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
@@ -608,7 +612,8 @@ func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
 	case utils.DATA_SOURCE_WIND: // wind
 		err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
 	default:
-		br.Msg = "暂不支持设置其他来源的指标"
+		// todo 支持其他的指标设置
+		err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop)
 		return
 	}
 	if err != nil {
@@ -660,7 +665,7 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 	// 指标id列表
 	if req.IsSelectAll {
 		// 如果是列表全选
-		_, edbList, err := data.GetEdbRelationList(req.Source, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
+		_, edbList, err := data.GetEdbRelationList(req.Source, req.EdbInfoType, req.ClassifyId, req.SysUserId, req.Frequency, req.Keyword, req.Status, 0, 100000, "", "")
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
@@ -736,7 +741,7 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 	case utils.DATA_SOURCE_WIND: // wind
 		err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
 	default:
-		br.Msg = "暂不支持设置其他来源的指标"
+		err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop)
 		return
 	}
 	if err != nil {

+ 2 - 1
controllers/data_manage/edb_info_relation.go

@@ -38,6 +38,7 @@ func (c *EdbInfoRelationController) RelationEdbList() {
 	}()
 
 	source, _ := c.GetInt("Source")
+	edbInfoType, _ := c.GetInt("edbInfoType")
 	classifyId := c.GetString("ClassifyId")
 	sysUserId := c.GetString("SysUserId")
 	frequency := c.GetString("Frequency")
@@ -73,7 +74,7 @@ func (c *EdbInfoRelationController) RelationEdbList() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
-	total, list, err := data.GetEdbRelationList(source, classifyId, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
+	total, list, err := data.GetEdbRelationList(source, edbInfoType, classifyId, sysUserId, frequency, keyword, status, startSize, pageSize, sortParam, sortType)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()

+ 30 - 0
models/data_manage/edb_data_wind.go

@@ -104,3 +104,33 @@ func WindEdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateE
 
 	return
 }
+
+func EdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int) (err error) {
+	o, err := orm.NewOrmUsingDB("data").Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = o.Rollback()
+			return
+		}
+		_ = o.Commit()
+	}()
+
+	// 更改指标的更新状态
+	if len(edbInfoIds) == 1 {
+		sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id=? `
+		_, err = o.Raw(sql, isStop, edbInfoIds[0]).Exec()
+		if err != nil {
+			return
+		}
+	} else {
+		sql := ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
+		_, err = o.Raw(sql, isStop, edbInfoIds).Exec()
+		if err != nil {
+			return
+		}
+	}
+	return
+}

+ 1 - 0
models/data_manage/edb_refresh/request/edb_info_refresh.go

@@ -66,6 +66,7 @@ type SaveRelationEdbRefreshStatusReq struct {
 	SysUserId       string `description:"操作人id,支持多选,用英文,隔开"`
 	Frequency       string `description:"频度,支持多选,用英文,隔开"`
 	Status          string `description:"状态,枚举值:启用、暂停"`
+	EdbInfoType     int    `description:"1计算指标,2预测指标"`
 	Keyword         string `description:"关键字"`
 	IsSelectAll     bool   `description:"是否选择所有指标"`
 	EdbSelectIdList []int  `description:"选择的指标id列表"`

+ 50 - 42
services/data/edb_info_relation.go

@@ -339,7 +339,7 @@ func SaveCalendarEdbInfoRelation(chartPermissionId int, matterDate string, editM
 }
 
 // GetEdbRelationList 获取指标引用列表
-func GetEdbRelationList(source int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
+func GetEdbRelationList(source, edbInfoType int, classifyId, sysUserId, frequency, keyword, status string, startSize, pageSize int, sortParam, sortType string) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
 	var pars []interface{}
 	var condition string
 
@@ -356,57 +356,65 @@ func GetEdbRelationList(source int, classifyId, sysUserId, frequency, keyword, s
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND:
 		condition += ` AND e.source = ? `
 		pars = append(pars, source)
+	}
 
-		if isStop >= 0 {
-			condition += " AND e.no_update = ? "
-			pars = append(pars, isStop)
-		}
+	if edbInfoType == 1 { //预测指标
+		condition += ` AND e.edb_info_type = ? `
+		pars = append(pars, edbInfoType)
+	} else if edbInfoType == 2 { //计算指标
+		condition += ` AND e.edb_type = ? `
+		pars = append(pars, edbInfoType)
+	}
 
-		if classifyId != `` {
-			classifyIdSlice := strings.Split(classifyId, ",")
-			condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
-			pars = append(pars, classifyIdSlice)
-		}
-		if sysUserId != `` {
-			sysUserIdSlice := strings.Split(sysUserId, ",")
-			condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
-			pars = append(pars, sysUserIdSlice)
-		}
-		if frequency != `` {
-			frequencySlice := strings.Split(frequency, ",")
-			condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
-			pars = append(pars, frequencySlice)
-		}
-		if keyword != `` {
-			keywordSlice := strings.Split(keyword, " ")
-			if len(keywordSlice) > 0 {
-				tmpConditionSlice := make([]string, 0)
-				tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
-				pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+	if isStop >= 0 {
+		condition += " AND e.no_update = ? "
+		pars = append(pars, isStop)
+	}
 
-				for _, v := range keywordSlice {
-					if v == ` ` || v == `` {
-						continue
-					}
-					tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
-					pars = utils.GetLikeKeywordPars(pars, v, 2)
-				}
-				condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
+	if classifyId != `` {
+		classifyIdSlice := strings.Split(classifyId, ",")
+		condition += ` AND e.classify_id IN (` + utils.GetOrmInReplace(len(classifyIdSlice)) + `)`
+		pars = append(pars, classifyIdSlice)
+	}
+	if sysUserId != `` {
+		sysUserIdSlice := strings.Split(sysUserId, ",")
+		condition += ` AND e.sys_user_id IN (` + utils.GetOrmInReplace(len(sysUserIdSlice)) + `)`
+		pars = append(pars, sysUserIdSlice)
+	}
+	if frequency != `` {
+		frequencySlice := strings.Split(frequency, ",")
+		condition += ` AND e.frequency IN (` + utils.GetOrmInReplace(len(frequencySlice)) + `)`
+		pars = append(pars, frequencySlice)
+	}
+	if keyword != `` {
+		keywordSlice := strings.Split(keyword, " ")
+		if len(keywordSlice) > 0 {
+			tmpConditionSlice := make([]string, 0)
+			tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+			pars = utils.GetLikeKeywordPars(pars, keyword, 2)
 
-			} else {
-				condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
-				pars = utils.GetLikeKeywordPars(pars, keyword, 2)
+			for _, v := range keywordSlice {
+				if v == ` ` || v == `` {
+					continue
+				}
+				tmpConditionSlice = append(tmpConditionSlice, ` e.edb_name like ? or e.edb_code like ? `)
+				pars = utils.GetLikeKeywordPars(pars, v, 2)
 			}
-		}
+			condition += ` AND (` + strings.Join(tmpConditionSlice, " or ") + `)`
 
-		sortStr := ``
-		if sortParam != `` {
-			sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
+		} else {
+			condition += ` AND (e.edb_name like ? or e.edb_code like ? )`
+			pars = utils.GetLikeKeywordPars(pars, keyword, 2)
 		}
+	}
 
-		total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, sortStr, startSize, pageSize)
+	sortStr := ``
+	if sortParam != `` {
+		sortStr = fmt.Sprintf("%s %s,e.edb_info_id desc ", sortParam, sortType)
 	}
 
+	total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, sortStr, startSize, pageSize)
+
 	return
 }