소스 검색

去掉预测指标,修改同花顺刷新逻辑

xyxie 8 달 전
부모
커밋
50324e83cb

+ 94 - 50
controllers/data_manage/edb_info_refresh.go

@@ -519,13 +519,54 @@ func (c *EdbInfoController) SaveEdbRefreshStatus() {
 		isStop = 1
 	}
 
+	if len(edbIdList) <= 0 {
+		br.Msg = "指标不能为空"
+		br.IsSendEmail = false
+		return
+	}
+	//查询计算指标信息
+	calculateEdbIdList := make([]int, 0)
+	if isStop == 1 {
+		edbInfoList := make([]*data_manage.EdbInfo, 0)
+		edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + e.Error()
+			return
+		}
+		for _, v := range edbList {
+			if v.EdbInfoType == 0 && v.EdbType == 2 {
+				edbInfoList = append(edbInfoList, v)
+			}
+		}
+
+		calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := data.GetEdbListByEdbInfoId(edbInfoList)
+		if e != nil {
+			br.Msg = "查询计算指标信息失败"
+			br.ErrMsg = "查询计算指标信息失败, Err" + e.Error()
+			return
+		}
+		for _, v := range edbInfoList {
+			childEdbMappingIds, ok := calculateEdbMappingIdsMap[v.EdbInfoId]
+			if ok {
+				for _, childEdbMappingId := range childEdbMappingIds {
+					childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
+					if !ok2 {
+						continue
+					}
+					calculateEdbIdList = append(calculateEdbIdList, childEdbMapping.EdbInfoId)
+				}
+			}
+		}
+	}
+
 	switch req.Source {
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
 		err = data_manage.ModifyMysteelChemicalUpdateStatus(edbIdList, edbCodeList, isStop)
 	case utils.DATA_SOURCE_YS: // 有色
 		err = data_manage.ModifySmmUpdateStatus(edbIdList, edbCodeList, isStop)
 	default:
-		err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop)
+		err = data_manage.ModifyEdbInfoUpdateStatus(edbIdList, isStop, calculateEdbIdList)
 	}
 	if err != nil {
 		br.Msg = `保存失败`
@@ -584,37 +625,34 @@ func (c *EdbInfoController) SaveEdbRefreshStatusSingle() {
 	if req.ModifyStatus == `暂停` {
 		isStop = 1
 	}
-	calculateEdb := make([]*data_manage.EdbInfoCalculateMapping, 0)
-	if edbInfo.EdbInfoType == 0 && edbInfo.EdbType == 1 { //基础指标
+
+	if isStop == 1 && 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()
+		// 查询间接引用的指标信息
+		edbInfoList := make([]*data_manage.EdbInfo, 0)
+		edbInfoList = append(edbInfoList, edbInfo)
+		calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := data.GetEdbListByEdbInfoId(edbInfoList)
+		if e != nil {
+			err = fmt.Errorf("查询计算指标信息失败,%s", e.Error())
 			return
 		}
-	}
-
-	// 遍历指标列表,把计算指标id整理成数组
-	if len(calculateEdb) > 0 {
-		for _, calculateEdbInfo := range calculateEdb {
-			calculateEdbIdList = append(calculateEdbIdList, calculateEdbInfo.EdbInfoId)
+		childEdbMappingIds, ok := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
+		if ok {
+			for _, childEdbMappingId := range childEdbMappingIds {
+				childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
+				if !ok2 {
+					continue
+				}
+				calculateEdbIdList = append(calculateEdbIdList, childEdbMapping.EdbInfoId)
+			}
 		}
 	}
 
 	switch edbInfo.Source {
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联
 		err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoId(edbInfo.EdbInfoId, isStop, edbInfo.EdbCode, calculateEdbIdList)
-	case utils.DATA_SOURCE_WIND: // wind
-		err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
-	default:
-		// todo 支持其他的指标设置
-		err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop)
-		return
+	default: // wind
+		err = data_manage.EdbInfoUpdateStatusByEdbInfoId([]int{edbInfo.EdbInfoId}, isStop, calculateEdbIdList)
 	}
 	if err != nil {
 		br.Msg = `保存失败`
@@ -668,6 +706,7 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 	// todo 批量设置刷新状态修改
 	edbIdList := make([]int, 0)
 	edbCodeList := make([]string, 0)
+	edbInfoList := make([]*data_manage.EdbInfo, 0)
 	// 指标id列表
 	if req.IsSelectAll {
 		// 如果是列表全选
@@ -693,22 +732,9 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 
 			// 加入到待配置的指标列表id
 			edbIdList = append(edbIdList, v.EdbInfoId)
-			edbCodeList = append(edbCodeList, v.EdbCode)
 		}
 	} else {
 		edbIdList = req.EdbSelectIdList
-		if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
-			//查询指标信息
-			edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
-			if e != nil && e.Error() != utils.ErrNoRow() {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取数据失败,Err:" + e.Error()
-				return
-			}
-			for _, v := range edbList {
-				edbCodeList = append(edbCodeList, v.EdbCode)
-			}
-		}
 	}
 
 	if len(edbIdList) <= 0 {
@@ -716,6 +742,21 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 		br.IsSendEmail = false
 		return
 	}
+	//查询指标信息
+	edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + e.Error()
+		return
+	}
+	for _, v := range edbList {
+		if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+			edbCodeList = append(edbCodeList, v.EdbCode)
+		}
+		if v.EdbInfoType == 0 && v.EdbType == 2 {
+			edbInfoList = append(edbInfoList, v)
+		}
+	}
 
 	isStop := 0
 	if req.ModifyStatus == `暂停` {
@@ -725,29 +766,32 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 	// 查询计算指标ID
 	// 查询相关的计算指标
 	calculateEdbIdList := make([]int, 0)
-	calculateEdb, err := data_manage.GetAllCalculateByEdbInfoIds(edbIdList)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			br.Msg = "指标不存在"
+	if isStop == 1 {
+		calculateEdbMappingListMap, calculateEdbMappingIdsMap, e := data.GetEdbListByEdbInfoId(edbInfoList)
+		if e != nil {
+			br.Msg = "查询计算指标信息失败"
+			br.ErrMsg = "查询计算指标信息失败, Err" + e.Error()
 			return
 		}
-		br.Msg = "查询计算指标失败"
-		br.ErrMsg = "查询计算指标失败,Err:" + err.Error()
-	}
-	// 遍历指标列表,把计算指标id整理成数组
-	if len(calculateEdb) > 0 {
-		for _, calculateEdbInfo := range calculateEdb {
-			calculateEdbIdList = append(calculateEdbIdList, calculateEdbInfo.EdbInfoId)
+		for _, v := range edbInfoList {
+			childEdbMappingIds, ok := calculateEdbMappingIdsMap[v.EdbInfoId]
+			if ok {
+				for _, childEdbMappingId := range childEdbMappingIds {
+					childEdbMapping, ok2 := calculateEdbMappingListMap[childEdbMappingId]
+					if !ok2 {
+						continue
+					}
+					calculateEdbIdList = append(calculateEdbIdList, childEdbMapping.EdbInfoId)
+				}
+			}
 		}
 	}
 
 	switch req.Source {
 	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL: // 钢联化工
 		err = data_manage.ModifyMysteelChemicalUpdateStatusByEdbInfoIds(edbIdList, isStop, edbCodeList, calculateEdbIdList)
-	case utils.DATA_SOURCE_WIND: // wind
-		err = data_manage.WindEdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
 	default:
-		err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop)
+		err = data_manage.EdbInfoUpdateStatusByEdbInfoId(edbIdList, isStop, calculateEdbIdList)
 		return
 	}
 	if err != nil {

+ 5 - 35
models/data_manage/edb_data_wind.go

@@ -65,7 +65,7 @@ type EdbDataFromWind struct {
 	ErrMsg string
 }
 
-func WindEdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateEdbInfoIds []int) (err error) {
+func EdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateEdbInfoIds []int) (err error) {
 	o, err := orm.NewOrmUsingDB("data").Begin()
 	if err != nil {
 		return
@@ -80,14 +80,14 @@ func WindEdbInfoUpdateStatusByEdbInfoId(edbInfoIds []int, isStop int, calculateE
 
 	// 更改指标的更新状态
 	if len(edbInfoIds) == 1 {
-		sql := ` UPDATE edb_info SET no_update = ? WHERE source = ? AND edb_info_id=? `
-		_, err = o.Raw(sql, isStop, utils.DATA_SOURCE_WIND, edbInfoIds[0]).Exec()
+		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 source = ? AND edb_info_id IN (` + utils.GetOrmInReplace(len(edbInfoIds)) + `) `
-		_, err = o.Raw(sql, isStop, utils.DATA_SOURCE_WIND, edbInfoIds).Exec()
+		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
 		}
@@ -104,33 +104,3 @@ 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
-}

+ 9 - 2
models/data_manage/edb_info.go

@@ -1647,7 +1647,7 @@ func GetEdbBaseInfoList(condition string, pars []interface{}, orderBy string, st
 // @param indexCodeList []string
 // @param isStop int
 // @return err error
-func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int) (err error) {
+func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int, calculateEdbInfoIds []int) (err error) {
 	idNum := len(edbIdList)
 	if idNum <= 0 {
 		return
@@ -1670,7 +1670,14 @@ func ModifyEdbInfoUpdateStatus(edbIdList []int, isStop int) (err error) {
 	if err != nil {
 		return
 	}
-
+	if len(calculateEdbInfoIds) > 0 {
+		// 批量更新相关联的指标ID
+		sql = ` UPDATE edb_info SET no_update = ? WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(calculateEdbInfoIds)) + `) `
+		_, err = o.Raw(sql, isStop, calculateEdbInfoIds).Exec()
+		if err != nil {
+			return
+		}
+	}
 	return
 }
 

+ 7 - 7
models/data_manage/edb_info_relation.go

@@ -103,9 +103,9 @@ func AddOrUpdateEdbInfoRelation(objectId, objectType int, relationList []*EdbInf
 	}
 
 	if len(refreshEdbInfoIds) > 0 {
-		//更新指标的刷新状态
-		sql := ` UPDATE edb_info SET no_update = 0 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND  no_update = 1`
-		_, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, refreshEdbInfoIds).Exec()
+		//todo 是否需要所有指标的刷新状态
+		sql := ` UPDATE edb_info SET no_update = 0 WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND  no_update = 1`
+		_, err = o.Raw(sql, refreshEdbInfoIds).Exec()
 		if err != nil {
 			return
 		}
@@ -172,8 +172,8 @@ func AddOrUpdateEdbInfoRelationMulti(relationList []*EdbInfoRelation, refreshEdb
 
 	if len(refreshEdbInfoIds) > 0 {
 		// todo 更新指标的刷新状态
-		sql := ` UPDATE edb_info SET no_update = 0 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
-		_, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, refreshEdbInfoIds).Exec()
+		sql := ` UPDATE edb_info SET no_update = 0 WHERE edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
+		_, err = o.Raw(sql, refreshEdbInfoIds).Exec()
 		if err != nil {
 			return
 		}
@@ -397,8 +397,8 @@ func ReplaceRelationEdbInfoId(oldEdbInfo, newEdbInfo *EdbInfo, edbRelationIds []
 
 	if len(refreshEdbInfoIds) > 0 {
 		// todo 更新指标的刷新状态
-		sql := ` UPDATE edb_info SET no_update = 0 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
-		_, err = o.Raw(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, refreshEdbInfoIds).Exec()
+		sql := ` UPDATE edb_info SET no_update = 0 WHERE  edb_info_id IN (` + utils.GetOrmInReplace(len(refreshEdbInfoIds)) + `) AND no_update = 1`
+		_, err = o.Raw(sql, refreshEdbInfoIds).Exec()
 		if err != nil {
 			return
 		}

+ 4 - 4
services/data/edb_info_relation.go

@@ -97,7 +97,7 @@ func saveEdbInfoRelation(edbInfoIds []int, objectId, objectType, objectSubType i
 			}
 			tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
 			addList = append(addList, tmp)
-			if edbInfo.EdbType == 2 || edbInfo.EdbInfoType == 1 {
+			if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
 				childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
 				if !ok1 {
 					continue
@@ -293,7 +293,7 @@ func SaveCalendarEdbInfoRelation(chartPermissionId int, matterDate string, editM
 			tmp.RelationCode = fmt.Sprintf("%d_%d_%d_%d", tmp.EdbInfoId, tmp.ReferObjectId, tmp.ReferObjectType, tmp.ReferObjectSubType)
 			addList = append(addList, tmp)
 			//添加指标间接引用
-			if edbInfo.EdbType == 2 || edbInfo.EdbInfoType == 1 {
+			if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
 				childEdbMappingIds, ok1 := calculateEdbMappingIdsMap[edbInfo.EdbInfoId]
 				if !ok1 {
 					continue
@@ -424,7 +424,7 @@ func GetEdbListByEdbInfoId(edbInfoList []*data_manage.EdbInfo) (edbMappingListMa
 	}
 	edbInfoIds := make([]int, 0)
 	for _, v := range edbInfoList {
-		if v.EdbType == 2 || v.EdbInfoType == 1 {
+		if v.EdbType == 2 && v.EdbInfoType == 0 { //普通计算指标,排除预算指标
 			edbInfoIds = append(edbInfoIds, v.EdbInfoId)
 		}
 	}
@@ -454,7 +454,7 @@ func GetEdbListByEdbInfoId(edbInfoList []*data_manage.EdbInfo) (edbMappingListMa
 	edbInfoMappingRootIdsMap = make(map[int][]int, 0)
 	edbMappingMap := make(map[int]struct{})
 	for _, edbInfo := range edbInfoList {
-		if edbInfo.EdbType == 2 || edbInfo.EdbInfoType == 1 {
+		if edbInfo.EdbType == 2 && edbInfo.EdbInfoType == 0 {
 			edbInfoId := edbInfo.EdbInfoId
 			edbMappingList, err = getCalculateEdbInfoByEdbInfoId(allEdbMappingMap, edbInfoId, hasFindMap, edbInfoIdMap, edbMappingList, edbMappingMap, edbInfoMappingRootIdsMap, edbInfoId)
 			if err != nil {