|
@@ -1,6 +1,7 @@
|
|
package services
|
|
package services
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"eta/eta_data_analysis/models"
|
|
"eta/eta_data_analysis/models"
|
|
"eta/eta_data_analysis/services/kpler"
|
|
"eta/eta_data_analysis/services/kpler"
|
|
@@ -16,19 +17,18 @@ import (
|
|
"github.com/patrickmn/go-cache"
|
|
"github.com/patrickmn/go-cache"
|
|
)
|
|
)
|
|
|
|
|
|
-func ExcelDataWatch() {
|
|
|
|
|
|
+func KplerExcelDataWatch(cont context.Context) (err error) {
|
|
fmt.Println("kplerExcelWatch start")
|
|
fmt.Println("kplerExcelWatch start")
|
|
utils.FileLog.Info("kplerExcelWatch start")
|
|
utils.FileLog.Info("kplerExcelWatch start")
|
|
- var err error
|
|
|
|
defer func() {
|
|
defer func() {
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("kplerExcelDataWatch Err:" + err.Error())
|
|
fmt.Println("kplerExcelDataWatch Err:" + err.Error())
|
|
utils.FileLog.Info(fmt.Sprintf("kplerExcelDataWatch, Err: %s", err))
|
|
utils.FileLog.Info(fmt.Sprintf("kplerExcelDataWatch, Err: %s", err))
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
- var cacheClient *cache.Cache
|
|
|
|
|
|
+ cacheClient := utils.CacheClient
|
|
if cacheClient == nil {
|
|
if cacheClient == nil {
|
|
- cacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
|
|
|
|
|
|
+ utils.CacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
|
|
}
|
|
}
|
|
err = filepath.Walk(utils.KplerExcelFilePath, func(path string, info fs.FileInfo, err error) error {
|
|
err = filepath.Walk(utils.KplerExcelFilePath, func(path string, info fs.FileInfo, err error) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -44,8 +44,9 @@ func ExcelDataWatch() {
|
|
}
|
|
}
|
|
winFileAttr := fileInfo.Sys().(*syscall.Win32FileAttributeData)
|
|
winFileAttr := fileInfo.Sys().(*syscall.Win32FileAttributeData)
|
|
modifyTimeStr := utils.SecondToTime(winFileAttr.LastWriteTime.Nanoseconds() / 1e9).Format(utils.FormatDateTime)
|
|
modifyTimeStr := utils.SecondToTime(winFileAttr.LastWriteTime.Nanoseconds() / 1e9).Format(utils.FormatDateTime)
|
|
-
|
|
|
|
|
|
+ fmt.Println("文件的修改时间modifyTimeStr:", modifyTimeStr)
|
|
existModifyTime, ok := cacheClient.Get(path)
|
|
existModifyTime, ok := cacheClient.Get(path)
|
|
|
|
+ fmt.Println("缓存里的时间existModifyTime:", existModifyTime)
|
|
if ok {
|
|
if ok {
|
|
existModifyTimeStr := existModifyTime.(string)
|
|
existModifyTimeStr := existModifyTime.(string)
|
|
if existModifyTimeStr != modifyTimeStr {
|
|
if existModifyTimeStr != modifyTimeStr {
|
|
@@ -59,11 +60,12 @@ func ExcelDataWatch() {
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
})
|
|
})
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Main function for standalone testing
|
|
// Main function for standalone testing
|
|
func GetKplerDataByExcel(filePath string) (err error) {
|
|
func GetKplerDataByExcel(filePath string) (err error) {
|
|
- filePath = "services/kpler/crude.xlsx"
|
|
|
|
|
|
+ //filePath = "services/kpler/crude.xlsx"
|
|
fmt.Println("Starting Kpler data processing...")
|
|
fmt.Println("Starting Kpler data processing...")
|
|
|
|
|
|
// Process the Excel data
|
|
// Process the Excel data
|