Browse Source

Merge branch 'feature/jingbo' of eta_server/hongtao3_watch into master

xyxie 1 năm trước cách đây
mục cha
commit
2f53f7374e
3 tập tin đã thay đổi với 20 bổ sung3 xóa
  1. 2 0
      config/config.go
  2. 11 1
      init_serve/task.go
  3. 7 2
      services/api_tool.go

+ 2 - 0
config/config.go

@@ -23,6 +23,8 @@ type Serve struct {
 	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:"终端编码"`
+	RefreshTime     string `mapstructure:"refresh_time" json:"refresh_time" yaml:"refresh_time" description:"刷新服务任务更新时间"`
+	RefreshUrl      string `mapstructure:"refresh_url" json:"refresh_url" yaml:"refresh_url" description:"刷新服务任务更新地址"`
 }
 
 // Log 日志配置

+ 11 - 1
init_serve/task.go

@@ -11,8 +11,15 @@ func InitTask() {
 	//services.RefreshExcel()
 	c := cron.New(cron.WithSeconds())
 
+	// 定时统一更新(日度、周度指标)
+	if global.CONFIG.Serve.RefreshTime == "" {
+		//panic("未配置数据统一刷新时间")
+		// 未配置时间的话,那么默认每天17点更新一次
+		global.CONFIG.Serve.RefreshTime = "0 0 17 * * *"
+	}
+	//fmt.Println(global.CONFIG.Serve.RefreshTime)
 	// 每天下午5点开始刷新excel表格
-	_, err := c.AddFunc("0 0 17 * * *", services.RefreshExcel)
+	_, err := c.AddFunc(global.CONFIG.Serve.RefreshTime, services.RefreshExcel)
 	//_, err := c.AddFunc("0 55 13 * * *", services.RefreshExcel)
 	if err != nil {
 		global.LOG.Info("RefreshExcel err" + err.Error())
@@ -21,6 +28,9 @@ func InitTask() {
 	//每2分钟检测一次指标文件是否更新
 	_, err = c.AddFunc("0 */1 * * * *", watch.ReadWatchIndexFile)
 	//_, err = c.AddFunc("*/30 * * * * *", watch.ReadWatchIndexFile)
+	if err != nil {
+		global.LOG.Info("watch.ReadWatchIndexFile err" + err.Error())
+	}
 
 	c.Start()
 

+ 7 - 2
services/api_tool.go

@@ -3,19 +3,24 @@ package services
 import (
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/http"
+	"hongze/hongtao3_watch/global"
 	"net/url"
 )
 
 const (
 	// RefreshUrl 值示例:http://127.0.0.1:7007/hongtao/refresh?FilePath=E:\hz\hongtao3_data\excel\Oneline\%E7%83%A7%E7%A2%B1.xlsx
-	RefreshUrl = "http://127.0.0.1:7007/hongtao/refresh"
+	DefaultRefreshUrl = "http://127.0.0.1:7007/"
 )
 
 // InvokeRefreshServer 调用红桃3刷新数据的服务(目前是python)
 func InvokeRefreshServer(filePath string) {
 	var refreshUrl string
+	refreshUrl = global.CONFIG.Serve.RefreshUrl
+	if global.CONFIG.Serve.RefreshUrl == "" {
+		refreshUrl = DefaultRefreshUrl
+	}
 	//filePathStr:=url.PathEscape(filePath)
-	refreshUrl = RefreshUrl + "?FilePath=" + url.QueryEscape(filePath)
+	refreshUrl = refreshUrl + "hongtao/refresh?FilePath=" + url.QueryEscape(filePath)
 	fmt.Println("红桃3刷新,文件路径:", filePath, ";刷新URL:"+refreshUrl)
 	body, err := http.Get(refreshUrl)
 	if err != nil {