|
@@ -0,0 +1,138 @@
|
|
|
|
+package services
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "eta/eta_data_analysis/models"
|
|
|
|
+ "eta/eta_data_analysis/utils"
|
|
|
|
+ "fmt"
|
|
|
|
+ "github.com/patrickmn/go-cache"
|
|
|
|
+ "github.com/tealeg/xlsx"
|
|
|
|
+ "io/fs"
|
|
|
|
+ "os"
|
|
|
|
+ "path/filepath"
|
|
|
|
+ "strings"
|
|
|
|
+ "syscall"
|
|
|
|
+ "time"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+func clarksonsWatch() {
|
|
|
|
+ fmt.Println("clarksonsWatch start")
|
|
|
|
+ var err error
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("clarksonsWatch Err:" + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ var cacheClient *cache.Cache
|
|
|
|
+ if cacheClient == nil {
|
|
|
|
+ cacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
|
|
|
|
+ }
|
|
|
|
+ err = filepath.Walk(utils.ClarkSonsFilePath, func(path string, info fs.FileInfo, err error) error {
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if !info.IsDir() {
|
|
|
|
+ fileInfo, err := os.Stat(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("os.Stat:", err.Error())
|
|
|
|
+ }
|
|
|
|
+ winFileAttr := fileInfo.Sys().(*syscall.Win32FileAttributeData)
|
|
|
|
+ modifyTimeStr := utils.SecondToTime(winFileAttr.LastWriteTime.Nanoseconds() / 1e9).Format(utils.FormatDateTime)
|
|
|
|
+
|
|
|
|
+ existModifyTime, ok := cacheClient.Get(path)
|
|
|
|
+ if ok {
|
|
|
|
+ existModifyTimeStr := existModifyTime.(string)
|
|
|
|
+ if existModifyTimeStr != modifyTimeStr {
|
|
|
|
+ if strings.Contains(path, "克拉克森") {
|
|
|
|
+ err = Clarksons(path)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if strings.Contains(path, "克拉克森") {
|
|
|
|
+ err = Clarksons(path)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ cacheClient.Delete(path)
|
|
|
|
+ cacheClient.Set(path, modifyTimeStr, 24*time.Hour)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func Clarksons(path string) (err error) {
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("Clarksons Err:" + err.Error())
|
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("Clarksons, Err: %s", err))
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ path = "/Users/xi/Desktop/SIN_Timeseries_20241217022653.xlsx"
|
|
|
|
+
|
|
|
|
+ var xlFile *xlsx.File
|
|
|
|
+ exist, err := PathExists(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if exist {
|
|
|
|
+ xlFile, err = xlsx.OpenFile(path)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("OpenFile err:", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Println("Not Exist")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ sheetDatas := make([]models.SheetData, 0)
|
|
|
|
+ for i, sheet := range xlFile.Sheets {
|
|
|
|
+ if i > 0 {
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ data := sheet
|
|
|
|
+ sheetData := models.SheetData{
|
|
|
|
+ Name: data.Name,
|
|
|
|
+ MaxRow: data.MaxRow,
|
|
|
|
+ MaxCol: data.MaxCol,
|
|
|
|
+ Hidden: data.Hidden,
|
|
|
|
+ Selected: data.Selected,
|
|
|
|
+ }
|
|
|
|
+ rows := make([]models.Row, 0)
|
|
|
|
+ for _, v := range data.Rows {
|
|
|
|
+ cells := make([]models.Cell, 0)
|
|
|
|
+ for _, cell := range v.Cells {
|
|
|
|
+ cells = append(cells, models.Cell{
|
|
|
|
+ Value: cell.String(),
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ row := models.Row{
|
|
|
|
+ Cells: cells,
|
|
|
|
+ }
|
|
|
|
+ rows = append(rows, row)
|
|
|
|
+ }
|
|
|
|
+ sheetData.Rows = rows
|
|
|
|
+ sheetDatas = append(sheetDatas, sheetData)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ params := make(map[string]interface{})
|
|
|
|
+ params["SheetData"] = sheetDatas
|
|
|
|
+ result, e := PostEdbLib(params, utils.LIB_ROUTE_CLARKSONS)
|
|
|
|
+ if e != nil {
|
|
|
|
+ b, _ := json.Marshal(params)
|
|
|
|
+ fmt.Println(e)
|
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("PostEdbLib err: %s, params: %s", e.Error(), string(b)))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp := new(models.BaseEdbLibResponse)
|
|
|
|
+ if e := json.Unmarshal(result, &resp); e != nil {
|
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("json.Unmarshal err: %s", e))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if resp.Ret != 200 {
|
|
|
|
+ utils.FileLog.Info(fmt.Sprintf("Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return
|
|
|
|
+}
|