|
@@ -2,6 +2,9 @@ package services
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
+ "eta/eta_task/models"
|
|
|
+ "eta/eta_task/models/data_manage"
|
|
|
"eta/eta_task/models/data_manage/edb_refresh"
|
|
|
"eta/eta_task/services/alarm_msg"
|
|
|
"eta/eta_task/services/data"
|
|
@@ -581,3 +584,194 @@ func getPreviousHalfHour(now time.Time) string {
|
|
|
}
|
|
|
return fmt.Sprintf("%02d:%02d", now.Hour(), 0)
|
|
|
}
|
|
|
+
|
|
|
+// 根据配置把钢联化工和wind指标设置成禁止刷新
|
|
|
+func DisableEdbRefresh() (err error) {
|
|
|
+ //设置刷新key,如果没有执行完 报错提示
|
|
|
+ cacheKey := "eta_task:DisableEdbRefresh"
|
|
|
+ deleteCache := true
|
|
|
+ defer func() {
|
|
|
+ if deleteCache {
|
|
|
+ utils.Rc.Delete(cacheKey)
|
|
|
+ }
|
|
|
+ if err != nil {
|
|
|
+ tips := "DisableEdbRefresh-钢联化工和wind指标设置成禁止刷新失败, ErrMsg:\n" + err.Error()
|
|
|
+ utils.FileLog.Info(tips)
|
|
|
+ go alarm_msg.SendAlarmMsg(tips, 3)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ if !utils.Rc.SetNX(cacheKey, 1, 2*time.Minute) {
|
|
|
+ deleteCache = false
|
|
|
+ err = fmt.Errorf("系统处理中,请稍后重试!")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //查询配置,如果未开启自动设置禁止刷新,则无需处理
|
|
|
+ obj := new(models.BusinessConf)
|
|
|
+ conf, err := obj.GetItemByConfKey("EdbStopRefreshRule")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ //将json转为结构体
|
|
|
+ rule := new(models.EdbStopRefreshRule)
|
|
|
+ err = json.Unmarshal([]byte(conf.ConfVal), rule)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //判断是否开启自动设置禁止刷新
|
|
|
+ if rule.IsOpen == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取当前时间
|
|
|
+ now := time.Now()
|
|
|
+ if rule.BaseIndexStopDays > 0 { //设置数据源钢联化工指标禁止更新
|
|
|
+ baseIndexEndDate := now.AddDate(0, 0, -rule.BaseIndexStopDays+1).Format(utils.FormatDate)
|
|
|
+
|
|
|
+ // 查询钢联化工指标,查询创建时间在baseIndexStartDate前,的所有钢联化工指标,分批查询,先查总数,再查列表
|
|
|
+ totalCount, e := data_manage.GetCountRefreshBaseFromMysteelChemicalIndexItemByCreateTime(baseIndexEndDate)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询钢联化工指标总数失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //分页查询
|
|
|
+ pageSize := 100
|
|
|
+ pageNum := (int(totalCount) + 99) / pageSize // 使用整数除法,并添加一页以防有余数
|
|
|
+ stopRefreshIds := make([]int32, 0)
|
|
|
+ for i := 0; i < pageNum; i++ {
|
|
|
+ start := i * pageSize
|
|
|
+ indexItems, e := data_manage.GetRefreshBaseFromMysteelChemicalIndexItemByCreateTime(baseIndexEndDate, start, pageSize)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("分页查询钢联化工指标失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(indexItems) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ indexCodeList := make([]string, 0)
|
|
|
+ for _, indexItem := range indexItems {
|
|
|
+ indexCodeList = append(indexCodeList, indexItem.IndexCode)
|
|
|
+ }
|
|
|
+ condition := ` AND source=? AND edb_code in (` + utils.GetOrmInReplace(len(indexCodeList)) + `)`
|
|
|
+ var pars []interface{}
|
|
|
+ pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, indexCodeList)
|
|
|
+
|
|
|
+ // 查询指标库里这些指标是否已创建
|
|
|
+ edbList, e := data_manage.GetEdbInfoByCondition(condition, pars, 0)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询指标库里这些指标是否被创建失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ edbMap := make(map[string]bool)
|
|
|
+ for _, edb := range edbList {
|
|
|
+ edbMap[edb.EdbCode] = true
|
|
|
+ }
|
|
|
+ for _, indexItem := range indexItems {
|
|
|
+ // 判断指标是否被创建
|
|
|
+ if _, ok := edbMap[indexItem.IndexCode]; !ok {
|
|
|
+ stopRefreshIds = append(stopRefreshIds, indexItem.BaseFromMysteelChemicalIndexId)
|
|
|
+ if len(stopRefreshIds) > 100 {
|
|
|
+ // err = data_manage.SetStopRefreshMysteelChemicalIndex(stopRefreshIds)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("设置禁止刷新失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ stopRefreshIds = make([]int32, 0)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 未被创建,则设置禁止刷新
|
|
|
+ if len(stopRefreshIds) > 0 {
|
|
|
+ //err = data_manage.SetStopRefreshMysteelChemicalIndex(stopRefreshIds)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("设置禁止刷新失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if rule.EdbStopDays > 0 {
|
|
|
+ // 查询钢联和wind来源的指标
|
|
|
+ edbEndDate := now.AddDate(0, 0, -rule.EdbStopDays+1).Format(utils.FormatDate)
|
|
|
+
|
|
|
+ condition := ` AND no_update=0 AND source in (?,?) AND create_time < ?`
|
|
|
+ var pars []interface{}
|
|
|
+ pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL, utils.DATA_SOURCE_WIND, edbEndDate)
|
|
|
+ // 查询钢联化工指标和wind指标 分批查询,先查总数,再查列表
|
|
|
+ totalCount, e := data_manage.GetEdbInfoCountByCondition(condition, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询钢联化工指标总数失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //分页查询
|
|
|
+ pageSize := 100
|
|
|
+ pageNum := (int(totalCount) + 99) / pageSize // 使用整数除法,并添加一页以防有余数
|
|
|
+ stopRefreshIds := make([]int, 0)
|
|
|
+ stopRefreshMysteelCode := make([]string, 0)
|
|
|
+ for i := 0; i < pageNum; i++ {
|
|
|
+ start := i * pageSize
|
|
|
+ edbItems, e := data_manage.GetEdbInfoPageByCondition(condition, pars, start, pageSize)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("分页查询钢联化工指标失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(edbItems) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ edbInfoIds := make([]int, 0)
|
|
|
+ for _, item := range edbItems {
|
|
|
+ edbInfoIds = append(edbInfoIds, item.EdbInfoId)
|
|
|
+ }
|
|
|
+ // 查询指标库里这些指标 引用情况
|
|
|
+ relationList, e := data_manage.GetEdbInfoRelationByEdbInfoIds(edbInfoIds)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("查询指标库里这些指标是否被创建失败:%v", e)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ edbMap := make(map[int]struct{})
|
|
|
+ for _, item := range relationList {
|
|
|
+ edbMap[item] = struct{}{}
|
|
|
+ }
|
|
|
+ for _, item := range edbItems {
|
|
|
+ if _, ok := edbMap[item.EdbInfoId]; !ok {
|
|
|
+ stopRefreshIds = append(stopRefreshIds, item.EdbInfoId)
|
|
|
+ if item.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
|
|
|
+ stopRefreshMysteelCode = append(stopRefreshMysteelCode, item.EdbCode)
|
|
|
+ }
|
|
|
+ // 更新指标禁止刷新状态
|
|
|
+ if len(stopRefreshIds) > 100 {
|
|
|
+ _, tmpErr := data_manage.GetAllCalculateEdbIdsByEdbInfoIds(stopRefreshIds)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = fmt.Errorf("查询计算指标信息失败:%v", tmpErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //err = data_manage.ModifyEdbUpdateStatus(stopRefreshIds, stopRefreshMysteelCode, calculateEdbIds)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("更新指标禁止刷新状态失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ stopRefreshIds = []int{}
|
|
|
+ stopRefreshMysteelCode = []string{}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新指标禁止刷新状态
|
|
|
+ if len(stopRefreshIds) > 0 {
|
|
|
+ _, tmpErr := data_manage.GetAllCalculateEdbIdsByEdbInfoIds(stopRefreshIds)
|
|
|
+ if tmpErr != nil {
|
|
|
+ err = fmt.Errorf("查询计算指标信息失败:%v", tmpErr)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // err = data_manage.ModifyEdbUpdateStatus(stopRefreshIds, stopRefreshMysteelCode, calculateEdbIds)
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("更新指标禁止刷新状态失败:%v", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|