2 Commits 339ca96723 ... f702a6dbd3

Autor SHA1 Mensagem Data
  xiziwen f702a6dbd3 Merge branch 'ETA_2.3.2' 1 dia atrás
  xiziwen 9125e9191b first 1 dia atrás
4 arquivos alterados com 172 adições e 12 exclusões
  1. 138 0
      services/clarksons_watch.go
  2. 11 0
      services/task.go
  3. 12 0
      utils/config.go
  4. 11 12
      utils/constants.go

+ 138 - 0
services/clarksons_watch.go

@@ -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
+}

+ 11 - 0
services/task.go

@@ -139,6 +139,17 @@ func Task() {
 		task.AddTask("泛糖科技", hisugarData)
 	}
 
+	if utils.ClarkSonsOpen == "1" {
+		c := cron.New(cron.WithSeconds())
+		//每2分钟检测一次指标文件是否更新
+		_, err := c.AddFunc("0 */2 * * * *", clarksonsWatch)
+		if err != nil {
+			fmt.Println("watch.clarksonsWatch err" + err.Error())
+			utils.FileLog.Info("watch.clarksonsWatch err" + err.Error())
+		}
+		c.Start()
+	}
+
 	task.StartTask()
 
 	fmt.Println("task end")

+ 12 - 0
utils/config.go

@@ -122,6 +122,12 @@ var (
 
 var TerminalCode string
 
+// 克拉克森
+var (
+	ClarkSonsFilePath string //excel文件地址
+	ClarkSonsOpen     string //是否配置克拉克森数据源,1已配置
+)
+
 func init() {
 	tmpRunMode, err := web.AppConfig.String("run_mode")
 	if err != nil {
@@ -259,6 +265,12 @@ func init() {
 		HisugarPassword = config["hisugar_password"]
 		HisugarOpen = config["hisugar_open"]
 	}
+
+	//克拉克森文件夹配置
+	{
+		ClarkSonsFilePath = config["clarksons_file_path"]
+		ClarkSonsOpen = config["clarksons_open"]
+	}
 }
 
 //修改接口文档

+ 11 - 12
utils/constants.go

@@ -266,18 +266,17 @@ const (
 	GET_LY_INDEX_BY_CODE                              = "/ly/get/ly/index/by/code"                              // 根据指标编码获取指标
 	GET_EDB_INFO_BY_INDEX_CODE                        = "/ly/get/edb/info/by/index/code"                        // 根据指标code获取指标信息
 	ADD_BATCH_LY_EDB_DATA                             = "/ly/add/batch/ly/edb/data"                             // 批量增加粮油指标库数据
-
-	ADD_RZD_INDEX                       = "/rzd/add/rzd/index"                       // 新增睿咨得指标
-	ADD_BATCH_RZD_DATA                  = "/rzd/add/batch/rzd/data"                  // 新增数据源指标数据列表
-	GET_RZD_INDEX_DATA_BY_CODE_AND_TIME = "/rzd/get/rzd/index/data/by/code/and/time" // 根据指标编码和日期获取指标数据
-	GET_EDB_RZD_DATA_BY_CODE_AND_TIME   = "/rzd/get/edb/rzd/data/by/code/and/time"   // 根据指标编码和日期获取指标数据
-	GET_RZD_INDEX_BY_CODE               = "/rzd/get/rzd/index/by/code"               // 根据指标编码获取指标
-	GET_RZD_CLASSIFY_BY_NAME            = "/rzd/get/rzd/classify/by/name"            // 根据分类名称查询分类
-	ADD_RZD_CLASSIFY                    = "/rzd/add/rzd/classify"                    // 新增睿咨得分类
-	ADD_BATCH_RZD_EDB_DATA              = "/rzd/add/batch/rzd/edb/data"              // 批量增加指标库指标数据
-	GET_RZD_EDB_INFO_BY_INDEX_CODE      = "/rzd/get/rzd/edb/info/by/code"            // 根据指标code获取指标信息
-	UPDATE_RZD_EDB_DATA                 = "/rzd/update/rzd/edb/data"                 // 修改指标库指标数据
-
+	ADD_RZD_INDEX                                     = "/rzd/add/rzd/index"                                    // 新增睿咨得指标
+	ADD_BATCH_RZD_DATA                                = "/rzd/add/batch/rzd/data"                               // 新增数据源指标数据列表
+	GET_RZD_INDEX_DATA_BY_CODE_AND_TIME               = "/rzd/get/rzd/index/data/by/code/and/time"              // 根据指标编码和日期获取指标数据
+	GET_EDB_RZD_DATA_BY_CODE_AND_TIME                 = "/rzd/get/edb/rzd/data/by/code/and/time"                // 根据指标编码和日期获取指标数据
+	GET_RZD_INDEX_BY_CODE                             = "/rzd/get/rzd/index/by/code"                            // 根据指标编码获取指标
+	GET_RZD_CLASSIFY_BY_NAME                          = "/rzd/get/rzd/classify/by/name"                         // 根据分类名称查询分类
+	ADD_RZD_CLASSIFY                                  = "/rzd/add/rzd/classify"                                 // 新增睿咨得分类
+	ADD_BATCH_RZD_EDB_DATA                            = "/rzd/add/batch/rzd/edb/data"                           // 批量增加指标库指标数据
+	GET_RZD_EDB_INFO_BY_INDEX_CODE                    = "/rzd/get/rzd/edb/info/by/code"                         // 根据指标code获取指标信息
+	UPDATE_RZD_EDB_DATA                               = "/rzd/update/rzd/edb/data"                              // 修改指标库指标数据
+	LIB_ROUTE_CLARKSONS                               = "/clarksons/data"                                       // 克拉克森
 )
 
 const (