|
@@ -1434,6 +1434,7 @@ func ChartInfoRefreshV2(chartInfoId int) (err error, isAsync bool) {
|
|
|
|
|
|
// 批量刷新
|
|
|
err, isAsync = EdbInfoRefreshAllFromBaseV3(edbIdList, false, false)
|
|
|
+
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -1445,7 +1446,7 @@ func ChartInfoRefreshV2(chartInfoId int) (err error, isAsync bool) {
|
|
|
// @author Roc
|
|
|
// @datetime 2022-09-16 10:15:38
|
|
|
// @description 将原来自己写的一套获取所有关联指标,然后刷新指标逻辑 改成 只获取使用的指标id,然后遍历去调用“指标刷新服务”
|
|
|
-func BatchChartInfoRefreshV2(chartInfoList []*data_manage.ChartInfo) (err error, isAsync bool) {
|
|
|
+func BatchChartInfoRefreshV2(chartInfoList []*data_manage.ChartInfo, redisKey string) (err error, isAsync bool) {
|
|
|
if len(chartInfoList) <= 0 {
|
|
|
return
|
|
|
}
|
|
@@ -1454,15 +1455,28 @@ func BatchChartInfoRefreshV2(chartInfoList []*data_manage.ChartInfo) (err error,
|
|
|
chartInfoIdSlice = append(chartInfoIdSlice, chartInfo.ChartInfoId)
|
|
|
}
|
|
|
|
|
|
- var errmsg string
|
|
|
+ var errMsg string
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
- go alarm_msg.SendAlarmMsg("ChartInfoRefresh:"+errmsg, 3)
|
|
|
+ go alarm_msg.SendAlarmMsg("ChartInfoRefresh:"+errMsg, 3)
|
|
|
//go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "ChartInfoRefresh:"+errmsg, utils.EmailSendToUsers)
|
|
|
- fmt.Println("ChartInfoRefresh Err:" + errmsg)
|
|
|
+ fmt.Println("ChartInfoRefresh Err:" + errMsg)
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ // 是否删除缓存
|
|
|
+ isDeleteCache := true
|
|
|
+ if redisKey != `` {
|
|
|
+ //设置最多10分钟缓存
|
|
|
+ utils.Rc.SetNX(redisKey, 1, time.Minute*10)
|
|
|
+ defer func() {
|
|
|
+ if isDeleteCache {
|
|
|
+ utils.Rc.Delete(redisKey)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取需要刷新的指标信息
|
|
|
edbIdList := make([]int, 0)
|
|
|
edbInfoIdMap := make(map[int]int)
|
|
|
edbMappingList, err := data_manage.GetChartEdbMappingListByIdList(chartInfoIdSlice)
|
|
@@ -1473,10 +1487,88 @@ func BatchChartInfoRefreshV2(chartInfoList []*data_manage.ChartInfo) (err error,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 批量刷新
|
|
|
- err, isAsync = EdbInfoRefreshAllFromBaseV3(edbIdList, false, false)
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
+ // 获取需要刷新的指标列表
|
|
|
+ newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr := getEdbInfoIdList(edbIdList)
|
|
|
+
|
|
|
+ // 需要刷新的指标数量
|
|
|
+ totalEdbInfo := len(newBaseEdbInfoArr) + len(calculateArr) + len(predictCalculateArr)
|
|
|
+
|
|
|
+ if totalEdbInfo > 20 { // 关联指标过多的时候,异步刷新
|
|
|
+ isAsync = true
|
|
|
+ isDeleteCache = false // 不删除缓存
|
|
|
+ go refreshChartEdbInfo(chartInfoList, redisKey, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
|
|
|
+ } else {
|
|
|
+ err = edbInfoRefreshAll(false, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
|
|
|
+
|
|
|
+ //清除图表缓存
|
|
|
+ for _, v := range chartInfoList {
|
|
|
+ key := utils.HZ_CHART_LIB_DETAIL + v.UniqueCode
|
|
|
+ _ = utils.Rc.Delete(key)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// refreshChartEdbInfo
|
|
|
+// @Description: 刷新图表中的质保列表
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2023-12-01 16:05:39
|
|
|
+// @param chartInfoList []*data_manage.ChartInfo
|
|
|
+// @param redisKey string
|
|
|
+// @param newBaseEdbInfoArr []*data_manage.EdbInfo
|
|
|
+// @param newBasePredictEdbInfoArr []*data_manage.EdbInfo
|
|
|
+// @param newCalculateMap map[int]*data_manage.EdbInfo
|
|
|
+// @param newPredictCalculateMap map[int]*data_manage.EdbInfo
|
|
|
+// @param calculateArr []int
|
|
|
+// @param predictCalculateArr []int
|
|
|
+func refreshChartEdbInfo(chartInfoList []*data_manage.ChartInfo, redisKey string, newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) {
|
|
|
+ edbInfoRefreshAll(false, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
|
|
|
+
|
|
|
+ //清除图表缓存
|
|
|
+ for _, v := range chartInfoList {
|
|
|
+ key := utils.HZ_CHART_LIB_DETAIL + v.UniqueCode
|
|
|
+ _ = utils.Rc.Delete(key)
|
|
|
+ }
|
|
|
+ // 如果是有插入redisKey,那么刷新结束后就清除缓存
|
|
|
+ if redisKey != `` {
|
|
|
+ utils.Rc.Delete(redisKey)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// GetBatchChartRefreshKey
|
|
|
+// @Description: 获取批量刷新key
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2023-11-30 13:30:26
|
|
|
+// @param source string
|
|
|
+// @param reportId int
|
|
|
+// @param reportChapterId int
|
|
|
+// @return string
|
|
|
+func GetBatchChartRefreshKey(source string, reportId, reportChapterId int) string {
|
|
|
+ if source == `` {
|
|
|
+ return ``
|
|
|
+ }
|
|
|
+
|
|
|
+ return fmt.Sprint("batch_chart_refresh:", source, ":", reportId, ":", reportChapterId)
|
|
|
+}
|
|
|
+
|
|
|
+// CheckBatchChartRefreshResult
|
|
|
+// @Description: 判断报告中的图表是否刷新完成
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2023-11-30 13:30:26
|
|
|
+// @param source string
|
|
|
+// @param reportId int
|
|
|
+// @param reportChapterId int
|
|
|
+// @return string
|
|
|
+func CheckBatchChartRefreshResult(source string, reportId, reportChapterId int) (refreshResult bool) {
|
|
|
+ refreshResult = true
|
|
|
+ redisKey := GetBatchChartRefreshKey(source, reportId, reportChapterId)
|
|
|
+ if redisKey != `` {
|
|
|
+ // 如果找到了key,那么就是还在更新中
|
|
|
+ isOk := utils.Rc.IsExist(redisKey)
|
|
|
+ if isOk {
|
|
|
+ refreshResult = false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return
|