瀏覽代碼

新增日度周度刷新星期的配置

hsun 1 年之前
父節點
當前提交
eb6f1c9559
共有 3 個文件被更改,包括 52 次插入16 次删除
  1. 16 14
      config/config.go
  2. 14 2
      services/index_merge_v2.go
  3. 22 0
      utils/common.go

+ 16 - 14
config/config.go

@@ -8,20 +8,22 @@ type Config struct {
 
 // Serve gin服务配置
 type Serve struct {
-	Port               int      `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
-	RunMode            string   `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
-	UseRedis           bool     `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
-	AppName            string   `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
-	StaticDir          string   `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
-	IndexSaveDir       string   `mapstructure:"index-save-dir" json:"index-save-dir" yaml:"index-save-dir" description:"监听文件夹的路径"`
-	IndexMergeSaveDir  string   `mapstructure:"index-merge-save-dir" json:"index-merge-save-dir" yaml:"index-merge-save-dir" description:"监听合并文件夹的路径"`
-	Frequency          string   `mapstructure:"frequency" json:"frequency" yaml:"frequency" description:"频度"`
-	EdbLibUrl          string   `mapstructure:"edb-lib-url" json:"edb-lib-url" yaml:"edb-lib-url" description:"公共指标库的地址"`
-	AppEdbLibNameEn    string   `mapstructure:"app_edb_lib_name_en" json:"app_edb_lib_name_en" yaml:"app_edb_lib_name_en" description:"指标库的英文名称"`
-	EdbLibMd5Key       string   `mapstructure:"edb_lib_md5_key" json:"edb_lib_md5_key" yaml:"edb_lib_md5_key" description:"指标库服务秘钥"`
-	TerminalCode       string   `mapstructure:"terminal_code" json:"terminal_code" yaml:"terminal_code" description:"终端编码"`
-	IsCheckIndexUpdate bool     `mapstructure:"is_check_index_update" json:"is_check_index_update" yaml:"is_check_index_update" description:"是否检测指标更新状态"`
-	RefreshTimeList    []string `mapstructure:"refresh_time_list" json:"refresh_time_list" yaml:"refresh_time_list" description:"刷新服务任务更新时间列表"`
+	Port                int      `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
+	RunMode             string   `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
+	UseRedis            bool     `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
+	AppName             string   `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
+	StaticDir           string   `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
+	IndexSaveDir        string   `mapstructure:"index-save-dir" json:"index-save-dir" yaml:"index-save-dir" description:"监听文件夹的路径"`
+	IndexMergeSaveDir   string   `mapstructure:"index-merge-save-dir" json:"index-merge-save-dir" yaml:"index-merge-save-dir" description:"监听合并文件夹的路径"`
+	Frequency           string   `mapstructure:"frequency" json:"frequency" yaml:"frequency" description:"频度"`
+	EdbLibUrl           string   `mapstructure:"edb-lib-url" json:"edb-lib-url" yaml:"edb-lib-url" description:"公共指标库的地址"`
+	AppEdbLibNameEn     string   `mapstructure:"app_edb_lib_name_en" json:"app_edb_lib_name_en" yaml:"app_edb_lib_name_en" description:"指标库的英文名称"`
+	EdbLibMd5Key        string   `mapstructure:"edb_lib_md5_key" json:"edb_lib_md5_key" yaml:"edb_lib_md5_key" description:"指标库服务秘钥"`
+	TerminalCode        string   `mapstructure:"terminal_code" json:"terminal_code" yaml:"terminal_code" description:"终端编码"`
+	IsCheckIndexUpdate  bool     `mapstructure:"is_check_index_update" json:"is_check_index_update" yaml:"is_check_index_update" description:"是否检测指标更新状态"`
+	RefreshTimeList     []string `mapstructure:"refresh_time_list" json:"refresh_time_list" yaml:"refresh_time_list" description:"刷新服务任务更新时间列表"`
+	DayRefreshWeekdays  []int    `mapstructure:"day_refresh_weekdays" json:"day_refresh_weekdays" yaml:"day_refresh_weekdays" description:"日度指标刷新星期"`
+	WeekRefreshWeekdays []int    `mapstructure:"week_refresh_weekdays" json:"week_refresh_weekdays" yaml:"week_refresh_weekdays" description:"周度指标刷新星期"`
 }
 
 // Log 日志配置

+ 14 - 2
services/index_merge_v2.go

@@ -21,13 +21,25 @@ func MergeDayAndWeek() {
 	fmt.Println("MergeDayAndWeek start")
 	now := time.Now()
 	week := int(now.Weekday())
+
+	dayArr := []int{1, 2, 3, 4, 5, 6} // 日度默认1-6
+	weekArr := []int{3, 4, 5, 6}      // 周度默认3-6
+	// 有配置则取配置中的时间
+	if len(global.CONFIG.Serve.DayRefreshWeekdays) > 0 {
+		dayArr = global.CONFIG.Serve.DayRefreshWeekdays
+	}
+	if len(global.CONFIG.Serve.WeekRefreshWeekdays) > 0 {
+		weekArr = global.CONFIG.Serve.WeekRefreshWeekdays
+	}
+
 	//日度
-	if week >= 1 && week <= 6 {
+	if utils.InArrayByInt(dayArr, week) {
 		IndexDayMergeV2()
 	}
 	time.Sleep(1 * time.Minute)
+
 	//周度
-	if week >= 3 && week <= 6 {
+	if utils.InArrayByInt(weekArr, week) {
 		IndexWeekMergeV2()
 	}
 	fmt.Println("MergeV2 end")

+ 22 - 0
utils/common.go

@@ -1073,3 +1073,25 @@ func GetWeekDay() (string, string) {
 func SecondToTime(sec int64) time.Time {
 	return time.Unix(sec, 0)
 }
+
+// InArrayByInt php中的in_array(判断Int类型的切片中是否存在该int值)
+func InArrayByInt(idIntList []int, searchId int) (has bool) {
+	for _, id := range idIntList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}
+
+// InArrayByStr php中的in_array(判断String类型的切片中是否存在该string值)
+func InArrayByStr(idStrList []string, searchId string) (has bool) {
+	for _, id := range idStrList {
+		if id == searchId {
+			has = true
+			return
+		}
+	}
+	return
+}