浏览代码

Merge remote-tracking branch 'origin/feature/eta_2.5.6_pb_data_deal'

Roc 2 天之前
父节点
当前提交
c0225a6e12
共有 3 个文件被更改,包括 88 次插入8 次删除
  1. 10 2
      models/data_manage/edb_info.go
  2. 16 1
      services/data/edb_info.go
  3. 62 5
      services/edb_refresh.go

+ 10 - 2
models/data_manage/edb_info.go

@@ -371,8 +371,8 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
 	}()
 	}()
 
 
 	// 更改指标的更新状态
 	// 更改指标的更新状态
-	sql := ` UPDATE edb_info SET no_update = 1 WHERE source in (?, ?) AND edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) AND  no_update = 0`
-	err = tx.Exec(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbIdList).Error
+	sql := ` UPDATE edb_info SET no_update = 1 WHERE source in (?,?,?,?,?) AND edb_info_id IN (` + utils.GetOrmInReplace(idNum) + `) AND  no_update = 0`
+	err = tx.Exec(sql, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_PB_FINANCE, utils.DATA_SOURCE_PB, utils.DATA_SOURCE_THS, edbIdList).Error
 	if err != nil {
 	if err != nil {
 		return
 		return
 	}
 	}
@@ -399,6 +399,14 @@ func ModifyEdbUpdateStatus(edbIdList []int, indexCodeList []string, calculateEdb
 	return
 	return
 }
 }
 
 
+//func StopRefreshCalculateEdbIndex(edbInfoId int) (err error) {
+//	o := global.DbMap[utils.DbNameIndex]
+//	// 更改指标的更新状态
+//	sql := ` UPDATE edb_info SET no_update = 1,set_update_time=? WHERE edb_type =2 AND edb_info_id = ? AND  no_update = 0`
+//	err = o.Exec(sql, time.Now(), edbInfoId).Error
+//	return
+//}
+
 // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
 // GetEdbInfoByIdList 根据指标id集合 获取 指标列表
 func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
 func GetEdbInfoByIdList(edbInfoIdList []int) (items []*EdbInfo, err error) {
 	num := len(edbInfoIdList)
 	num := len(edbInfoIdList)

+ 16 - 1
services/data/edb_info.go

@@ -297,7 +297,22 @@ func RefreshDataFromCalculateAll() (err error) {
 			continue
 			continue
 		}
 		}
 		fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
 		fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
-
+		////对依赖指标是基础指标的且基础指标停用,停用当前计算指标,因为item是按照edb_Info_id升序,所以默认层级关系是由低而上,所以不需要考虑嵌套,只要考虑当前的下一级依赖即可
+		//mappings, err := data_manage.GetEdbInfoCalculateMappingListByEdbInfoId(v.EdbInfoId)
+		//if err != nil {
+		//	utils.FileLog.Error("[获取计算指标的依赖指标失败,不刷新指标,CODE:" + v.EdbCode + "],err:" + err.Error())
+		//	continue
+		//}
+		//for _, mapping := range mappings {
+		//	if mapping.FromEdbInfoId > 0 && mapping.NoUpdate == 1 {
+		//		utils.FileLog.Info("依赖指标停用,依赖指标ID:" + mapping.FromEdbCode + ",停用当前计算指标,CODE:" + v.EdbCode)
+		//		stopErr := data_manage.StopRefreshCalculateEdbIndex(v.EdbInfoId)
+		//		if stopErr != nil {
+		//			utils.FileLog.Error(fmt.Sprintf("停用计算指标失败,ID:%d;指标编码:%s;err:%s", mapping.EdbInfoId, mapping.EdbCode, stopErr.Error()))
+		//		}
+		//		continue
+		//	}
+		//}
 		fmt.Println("RefreshEdbCalculateData", v.EdbInfoId, v.EdbCode, startDate)
 		fmt.Println("RefreshEdbCalculateData", v.EdbInfoId, v.EdbCode, startDate)
 		result, tmpErr := RefreshEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
 		result, tmpErr := RefreshEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
 		if tmpErr != nil {
 		if tmpErr != nil {

+ 62 - 5
services/edb_refresh.go

@@ -366,6 +366,61 @@ func getConfigRefreshData(now time.Time) (sourceEdbInfoListMap map[string][]*edb
 	fmt.Println("Get ConfigRefreshData End")
 	fmt.Println("Get ConfigRefreshData End")
 	return
 	return
 }
 }
+func needForUpdate(date time.Time, frequency string) bool {
+	//如果当前已经更新最新的数据则停止更新
+	today := time.Now()
+	switch frequency {
+	case "日度":
+		return !date.Equal(today)
+	case "周度":
+		// 获取本周的开始日期(周一)
+		startOfWeek := today.AddDate(0, 0, int(time.Monday-today.Weekday()))
+		return date.Before(startOfWeek)
+	case "旬度":
+		day := today.Day()
+		var beginOfTenDays time.Time
+		if day <= 10 {
+			beginOfTenDays = time.Date(today.Year(), today.Month(), 1, 0, 0, 0, 0, time.Local)
+			return date.Before(beginOfTenDays)
+		} else if day <= 20 {
+			beginOfTenDays = time.Date(today.Year(), today.Month(), 11, 0, 0, 0, 0, time.Local)
+			return date.Before(beginOfTenDays)
+		} else {
+			beginOfTenDays = time.Date(today.Year(), today.Month(), 21, 0, 0, 0, 0, time.Local)
+			return date.Before(beginOfTenDays)
+		}
+	case "月度":
+		beginOfMonth := time.Date(today.Year(), today.Month(), 1, 0, 0, 0, 0, time.Local)
+		return date.Before(beginOfMonth)
+	case "季度":
+		month := today.Month()
+		var beginOfQuarter time.Time
+		if month <= 3 {
+			beginOfQuarter = time.Date(today.Year(), 1, 1, 0, 0, 0, 0, time.Local)
+		} else if month <= 6 {
+			beginOfQuarter = time.Date(today.Year(), 4, 1, 0, 0, 0, 0, time.Local)
+		} else if month <= 9 {
+			beginOfQuarter = time.Date(today.Year(), 7, 1, 0, 0, 0, 0, time.Local)
+		} else {
+			beginOfQuarter = time.Date(today.Year(), 10, 1, 0, 0, 0, 0, time.Local)
+		}
+		return date.Before(beginOfQuarter)
+	case "半年度":
+		month := today.Month()
+		var beginOfHalfYear time.Time
+		if month <= 6 {
+			beginOfHalfYear = time.Date(today.Year(), 1, 1, 0, 0, 0, 0, time.Local)
+		} else {
+			beginOfHalfYear = time.Date(today.Year(), 7, 1, 0, 0, 0, 0, time.Local)
+		}
+		return date.Before(beginOfHalfYear)
+	case "年度":
+		startOfYear := time.Date(today.Year(), 1, 1, 0, 0, 0, 0, time.Local)
+		return date.Before(startOfYear)
+	default:
+		return true
+	}
+}
 
 
 // BaseRefreshData
 // BaseRefreshData
 // @Description: 基础数据刷新
 // @Description: 基础数据刷新
@@ -399,6 +454,9 @@ func BaseRefreshData(wg *sync.WaitGroup, source, subSource int, items []*edb_ref
 			if v.NoUpdate == 1 {
 			if v.NoUpdate == 1 {
 				continue
 				continue
 			}
 			}
+			if !needForUpdate(v.EndDate, v.Frequency) {
+				continue
+			}
 			if v.DataRefreshNum > 0 {
 			if v.DataRefreshNum > 0 {
 				dataRefreshNum = v.DataRefreshNum
 				dataRefreshNum = v.DataRefreshNum
 			}
 			}
@@ -426,7 +484,6 @@ func BaseRefreshData(wg *sync.WaitGroup, source, subSource int, items []*edb_ref
 				}
 				}
 			}
 			}
 			fmt.Println(startDate)
 			fmt.Println(startDate)
-
 			// 数据更新
 			// 数据更新
 			resp, tmpErr := data.RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
 			resp, tmpErr := data.RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
 			if tmpErr != nil {
 			if tmpErr != nil {
@@ -682,7 +739,7 @@ func DisableEdbRefresh(cont context.Context) (err error) {
 			utils.Rc.Delete(cacheKey)
 			utils.Rc.Delete(cacheKey)
 		}
 		}
 		if err != nil {
 		if err != nil {
-			tips := "DisableEdbRefresh-钢联化工和wind指标设置成禁止刷新失败, ErrMsg:\n" + err.Error()
+			tips := "DisableEdbRefresh-钢联化工、wind、彭博、彭博财务、同花顺指标设置成禁止刷新失败, ErrMsg:\n" + err.Error()
 			utils.FileLog.Info(tips)
 			utils.FileLog.Info(tips)
 			go alarm_msg.SendAlarmMsg(tips, 3)
 			go alarm_msg.SendAlarmMsg(tips, 3)
 		}
 		}
@@ -791,12 +848,12 @@ func DisableEdbRefresh(cont context.Context) (err error) {
 	}
 	}
 
 
 	if rule.EdbStopDays > 0 {
 	if rule.EdbStopDays > 0 {
-		// 查询钢联和wind来源的指标
+		// 查询钢联和wind、彭博、彭博财务、同花顺来源的指标
 		edbEndDate := now.AddDate(0, 0, -rule.EdbStopDays+1).Format(utils.FormatDate)
 		edbEndDate := now.AddDate(0, 0, -rule.EdbStopDays+1).Format(utils.FormatDate)
 
 
-		condition := ` AND no_update=0 AND source in (?,?) AND ((create_time < ? and set_update_time is null) or set_update_time < ? )`
+		condition := ` AND no_update=0 AND source in (?,?,?,?,?) AND ((create_time < ? and set_update_time is null) or set_update_time < ? )`
 		var pars []interface{}
 		var pars []interface{}
-		pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbEndDate, edbEndDate)
+		pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, utils.DATA_SOURCE_PB_FINANCE, utils.DATA_SOURCE_PB, utils.DATA_SOURCE_THS, edbEndDate, edbEndDate)
 		// 查询钢联化工指标和wind指标 分批查询,先查总数,再查列表
 		// 查询钢联化工指标和wind指标 分批查询,先查总数,再查列表
 		totalCount, e := data_manage.GetEdbInfoCountByCondition(condition, pars)
 		totalCount, e := data_manage.GetEdbInfoCountByCondition(condition, pars)
 		if e != nil {
 		if e != nil {