Browse Source

Merge branch 'feature/eta_2.5.6_pb_data_deal' into debug

kobe6258 1 tuần trước cách đây
mục cha
commit
2e48755688
2 tập tin đã thay đổi với 51 bổ sung10 xóa
  1. 32 10
      controllers/data_manage/edb_info_refresh.go
  2. 19 0
      services/data/edb_info_relation.go

+ 32 - 10
controllers/data_manage/edb_info_refresh.go

@@ -679,7 +679,7 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 	}
 	edbType := 1 //基础指标
 	switch req.Source {
-	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND: // wind
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_THS, utils.DATA_SOURCE_PB_FINANCE, utils.DATA_SOURCE_PB: // wind
 	case -1:
 		req.Source = 0
 		edbType = 2
@@ -712,12 +712,32 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 			if ok {
 				continue
 			}
-
+			if v.RelationNum > 0 && v.IsSupplierStop == 0 {
+				br.Msg = "保存失败,停用指标已被引用,指标ID:" + v.EdbCode + "指标名称:" + v.EdbName
+				br.ErrMsg = "保存失败,停用指标已被引用,指标ID:" + v.EdbCode + "指标名称:" + v.EdbName
+				return
+			}
 			// 加入到待配置的指标列表id
 			edbIdList = append(edbIdList, v.EdbInfoId)
 		}
 	} else {
 		edbIdList = req.EdbSelectIdList
+		_, edbRelationList, err := data.GetEdbRelationListByIds(edbIdList, req.Source)
+		if err != nil && !utils.IsErrNoRow(err) {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		for _, v := range edbRelationList {
+			if v.RelationNum > 0 && v.IsSupplierStop == 0 {
+				br.Msg = "保存失败,停用指标已被引用,指标ID:" + v.EdbCode + "指标名称:" + v.EdbName
+				br.ErrMsg = "保存失败,停用指标已被引用,指标ID:" + v.EdbCode + "指标名称:" + v.EdbName
+				return
+			}
+			// 加入到待配置的指标列表id
+			// 加入到待配置的指标列表id
+			edbIdList = append(edbIdList, v.EdbInfoId)
+		}
 	}
 
 	if len(edbIdList) <= 0 {
@@ -725,14 +745,8 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 		br.IsSendEmail = false
 		return
 	}
-	//查询指标信息
-	edbList, e := data_manage.GetEdbInfoByIdList(edbIdList)
-	if e != nil && !utils.IsErrNoRow(e) {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取数据失败,Err:" + e.Error()
-		return
-	}
 
+	var edbList []*data_manage.EdbInfo
 	// 如果是钢联化工,那么需要过滤供应商暂停的指标
 	if req.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
 		// 获取未被供应商暂停的指标
@@ -760,13 +774,21 @@ func (c *EdbInfoController) SaveRelationEdbRefreshStatus() {
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
-
 		if len(edbList) <= 0 {
 			br.Ret = 200
 			br.Success = true
 			br.Msg = "保存成功"
 			return
 		}
+	} else {
+		//查询指标信息
+		edbList, err = data_manage.GetEdbInfoByIdList(edbIdList)
+		if err != nil && !utils.IsErrNoRow(err) {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+
 	}
 
 	fromEdbIdList := make([]int, 0)

+ 19 - 0
services/data/edb_info_relation.go

@@ -474,6 +474,25 @@ func GetEdbRelationList(source, edbType int, classifyId, sysUserId, frequency, k
 	return
 }
 
+// GetEdbRelationList 获取指标引用列表
+func GetEdbRelationListByIds(edbIds []int, source int) (total int, list []*data_manage.BaseRelationEdbInfo, err error) {
+	var pars []interface{}
+	var condition string
+	if len(edbIds) == 0 {
+		return
+	}
+	list = make([]*data_manage.BaseRelationEdbInfo, 0)
+	// 关联表语句
+	var addFieldStr, joinTableStr string
+	// 供应商停用
+	if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
+		joinTableStr = ` LEFT JOIN base_from_mysteel_chemical_index z ON e.edb_code = z.index_code `
+		addFieldStr = ` ,z.is_supplier_stop `
+	}
+	total, list, err = data_manage.GetEdbInfoRelationList(condition, pars, addFieldStr, joinTableStr, "", 0, len(edbIds))
+	return
+}
+
 // 查找当前计算指标的所有溯源指标
 func GetEdbListByEdbInfoId(edbInfoList []*data_manage.EdbInfo, needPredict bool) (edbMappingListMap map[int]*data_manage.EdbInfoCalculateMapping, edbInfoMappingRootIdsMap map[int][]int, err error) {
 	if len(edbInfoList) == 0 {