Explorar el Código

优化数据获取

longyu hace 2 años
padre
commit
a4d1f13f97
Se han modificado 5 ficheros con 57 adiciones y 35 borrados
  1. 4 2
      controller/index/index.go
  2. 2 0
      init_serve/task.go
  3. 4 2
      services/api_tool.go
  4. 43 17
      services/index.go
  5. 4 14
      services/index_queue.go

+ 4 - 2
controller/index/index.go

@@ -94,7 +94,8 @@ func (s *IndexController) Create(c *gin.Context) {
 	}
 	time.Sleep(1 * time.Second)
 	fmt.Println("start MysteelChemicalRefresh")
-	services.MysteelChemicalRefresh(filePath)
+	//services.MysteelChemicalRefresh(filePath)
+	services.AddIndexRefreshToLpush(filePath)
 	resp.Ok("保存成功", c)
 	return
 }
@@ -151,7 +152,8 @@ func (s *IndexController) Refresh(c *gin.Context) {
 		resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
 		return
 	}
-	services.MysteelChemicalRefresh(req.MergeFilePath)
+	//services.MysteelChemicalRefresh(req.MergeFilePath)
+	services.AddIndexRefreshToLpush(req.MergeFilePath)
 	resp.Ok("保存成功", c)
 	return
 }

+ 2 - 0
init_serve/task.go

@@ -62,6 +62,8 @@ func InitTask() {
 	//go watch.ListenFolderNew()
 	go watch.ListenFolderNew()
 	go watch.ListenFolderNewMerge()
+
+	//redis 队列刷新指标
 	go services.AutoRefresh()
 
 	//CheckIndexCreate()

+ 4 - 2
services/api_tool.go

@@ -3,6 +3,7 @@ package services
 import (
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/http"
+	"net/url"
 )
 
 const (
@@ -11,8 +12,9 @@ const (
 
 func MysteelChemicalRefresh(filePath string) {
 	var refreshUrl string
-	refreshUrl = RefreshUrl + "?FilePath=" + filePath
-	fmt.Println("MysteelChemicalRefresh URL:"+RefreshUrl)
+	filePathStr:=url.PathEscape(filePath)
+	refreshUrl = RefreshUrl + "?FilePath=" + filePathStr
+	fmt.Println("MysteelChemicalRefresh URL:"+refreshUrl)
 	body, err := http.Get(refreshUrl)
 	if err != nil {
 		fmt.Println("MysteelChemicalRefresh Err:" + err.Error())

+ 43 - 17
services/index.go

@@ -55,7 +55,8 @@ func IndexCreateCheck() (err error) {
 				go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+v.FilePath, 3)
 			}
 			time.Sleep(1 * time.Second)
-			MysteelChemicalRefresh(v.FilePath)
+			//MysteelChemicalRefresh(v.FilePath)
+			AddIndexRefreshToLpush(v.FilePath)
 		} else {
 			fmt.Println("IndexCreate:" + v.IndexCode)
 			saveFilePath, err := IndexCreate(v)
@@ -67,7 +68,8 @@ func IndexCreateCheck() (err error) {
 			fmt.Println("IndexCreate saveFilePath:" + v.FilePath)
 			time.Sleep(1 * time.Second)
 			if utils.FileIsExist(saveFilePath) {
-				MysteelChemicalRefresh(saveFilePath)
+				//MysteelChemicalRefresh(saveFilePath)
+				AddIndexRefreshToLpush(saveFilePath)
 			}
 			fmt.Println("MysteelChemicalRefresh end:" + v.IndexCode)
 		}
@@ -194,23 +196,28 @@ func IndexRefreshAll() {
 		time.Sleep(time.Duration(rn) * time.Second)
 		if v.Frequency == "年度" {
 			if month == 1 && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "季度" {
 			if (month == 1 || month == 4 || month == 7 || month == 10) && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "月度" {
 			if day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "周度" {
 			if week > 2 && week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else {
 			if week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		}
 	}
@@ -239,23 +246,28 @@ func IndexRefreshMethanol() {
 		time.Sleep(3 * time.Second)
 		if v.Frequency == "年度" {
 			if month == 1 && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "季度" {
 			if (month == 1 || month == 4 || month == 7 || month == 10) && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "月度" {
 			if day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "周度" {
 			if week > 2 && week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else {
 			if week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		}
 	}
@@ -288,23 +300,28 @@ func IndexRefreshTimely() {
 		time.Sleep(3 * time.Second)
 		if v.Frequency == "年度" {
 			if month == 1 && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "季度" {
 			if (month == 1 || month == 4 || month == 7 || month == 10) && day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "月度" {
 			if day == 1 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else if v.Frequency == "周度" {
 			if week > 2 && week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		} else {
 			if week < 6 {
-				MysteelChemicalRefresh(v.MergeFilePath)
+				//MysteelChemicalRefresh(v.MergeFilePath)
+				AddIndexRefreshToLpush(v.MergeFilePath)
 			}
 		}
 	}
@@ -415,3 +432,12 @@ func GetComment(filePath string) string {
 	}
 	return ""
 }
+
+var pushLock sync.RWMutex
+//刷新周度指标数据
+func AddIndexRefreshToLpush(filePath string) {
+	pushLock.Lock()
+	cache.IndexAutoRefresh(filePath)
+	pushLock.Unlock()
+	return
+}

+ 4 - 14
services/index_queue.go

@@ -3,9 +3,7 @@ package services
 import (
 	"fmt"
 	"hongze/mysteel_watch/global"
-	"hongze/mysteel_watch/services/alarm_msg"
 	"hongze/mysteel_watch/utils"
-	"strings"
 	"time"
 )
 
@@ -25,18 +23,10 @@ func AutoRefresh() {
 }
 
 func IndexHandle(filePath string) {
-	err := UpdateComment(filePath)
-	if err != nil {
-		go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
-	}
+	//err := UpdateComment(filePath)
+	//if err != nil {
+	//	go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
+	//}
 	time.Sleep(1 * time.Second)
 	MysteelChemicalRefresh(filePath)
-	indexCodeArr := strings.Split(filePath, "_")
-	if len(indexCodeArr) > 1 {
-		indexCode := indexCodeArr[0]
-		key := utils.REFRESH_INDEX_CODE + indexCode
-		if global.Re == nil && global.Rc != nil {
-			global.Rc.Delete(key)
-		}
-	}
 }