Roc 1 year ago
parent
commit
4e4e531b95
6 changed files with 311 additions and 416 deletions
  1. 15 13
      config/config.go
  2. 75 0
      init_serve/task.go
  3. 1 18
      models/index/index.go
  4. 12 298
      services/index_merge.go
  5. 207 0
      watch/edb_lib.go
  6. 1 87
      watch/watch.go

+ 15 - 13
config/config.go

@@ -3,21 +3,23 @@ package config
 import "time"
 
 type Config struct {
-	Log    Log    `mapstructure:"log" json:"log" yaml:"log"`
-	Serve  Serve  `mapstructure:"serve" json:"serve" yaml:"serve"`
-	Mysql  Mysql  `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
-	Redis  Redis  `mapstructure:"redis" json:"redis" yaml:"redis"`
-	AliOss AliOss `mapstructure:"ali-oss" json:"ali-oss" yaml:"ali-oss"`
-	EsClient     EsClient `mapstructure:"es_client" json:"es_client" yaml:"es_client"`
+	Log      Log      `mapstructure:"log" json:"log" yaml:"log"`
+	Serve    Serve    `mapstructure:"serve" json:"serve" yaml:"serve"`
+	Mysql    Mysql    `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
+	Redis    Redis    `mapstructure:"redis" json:"redis" yaml:"redis"`
+	AliOss   AliOss   `mapstructure:"ali-oss" json:"ali-oss" yaml:"ali-oss"`
+	EsClient EsClient `mapstructure:"es_client" json:"es_client" yaml:"es_client"`
 }
 
 // Serve gin服务配置
 type Serve struct {
-	Port      int    `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
-	RunMode   string `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
-	UseRedis  bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
-	AppName   string `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
-	StaticDir string `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
+	Port            int    `mapstructure:"port" json:"port" yaml:"port" description:"gin开启监听http服务的端口"`
+	RunMode         string `mapstructure:"run-mode" json:"run-mode" yaml:"run-mode" description:"gin运行模式的默认,枚举值:debug,release"`
+	UseRedis        bool   `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis" description:"是否使用redis"`
+	AppName         string `mapstructure:"app-name" json:"app-name" yaml:"app-name" description:"项目名称"`
+	StaticDir       string `mapstructure:"static-dir" json:"static-dir" yaml:"static-dir" description:"上传的文件存储目录地址"`
+	EdbLibUrl       string `mapstructure:"edb-lib-url" json:"edb-lib-url" yaml:"edb-lib-url" description:"公共指标库的地址"`
+	ListenExcelPath string `mapstructure:"listen-excel-path" json:"listen-excel-path" yaml:"listen-excel-path" description:"监听文件夹的路径"`
 }
 
 // Log 日志配置
@@ -81,5 +83,5 @@ type EsClient struct {
 	// es日志目录
 	Log string `json:"log" yaml:"log"`
 	// 索引前缀
-	Prefix  string `json:"prefix" yaml:"prefix"`
-}
+	Prefix string `json:"prefix" yaml:"prefix"`
+}

+ 75 - 0
init_serve/task.go

@@ -2,6 +2,7 @@ package init_serve
 
 import (
 	"fmt"
+	"github.com/robfig/cron/v3"
 	"hongze/mysteel_watch/services"
 	"hongze/mysteel_watch/utils"
 	"hongze/mysteel_watch/watch"
@@ -96,3 +97,77 @@ func CheckIndexCreate() {
 	}()
 	err = services.IndexCreateCheck()
 }
+
+func InitTask2() {
+
+	c := cron.New(cron.WithSeconds())
+
+	//每5分钟检测一次,指标生成
+	_, err := c.AddFunc("0 */1 * * * *", CheckIndexCreate)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+	}
+
+	////每30分钟检测一次,周度指标刷新
+	//_, err = c.AddFunc("0 */30 * * * *", services.IndexRefreshWeek)
+	//if err != nil {
+	//	global.LOG.Info("DownloadCvTask err" + err.Error())
+	//	panic("DownloadCvTask err" + err.Error())
+	//}
+
+	_, err = c.AddFunc("0 40 17 * * *", services.IndexRefreshAll)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+	}
+
+	//单独刷新甲醇指标
+	_, err = c.AddFunc("0 00 18 * * *", services.IndexRefreshMethanol)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+	}
+
+	_, err = c.AddFunc("0 */10 * * * *", services.Merge)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+	}
+
+	//检测需要及时刷新的指标
+	_, err = c.AddFunc("0 30 17 * * *", services.IndexRefreshTimely)
+	if err != nil {
+		global.LOG.Info("DownloadCvTask err" + err.Error())
+	}
+	//
+	////其他指标刷新
+	//_, err = c.AddFunc("0 30 12 * * *", services.IndexRefreshAll)
+	//if err != nil {
+	//	global.LOG.Info("DownloadCvTask err" + err.Error())
+	//	panic("DownloadCvTask err" + err.Error())
+	//}
+
+	//服务检测
+	_, err = c.AddFunc("0 */1 * * * *", services.ServerCheck)
+	if err != nil {
+		global.LOG.Info("ServerCheck err" + err.Error())
+	}
+
+	c.Start()
+
+	//go watch.ListenFolderNew()
+	go watch.ListenFolderNew()
+	go watch.ListenFolderNewMerge()
+
+	//redis 队列刷新指标
+	go services.AutoRefresh()
+
+	//CheckIndexCreate()
+	fmt.Println("start services.Merge")
+	//services.Merge()
+	//yearFile="year.xlsx"
+
+	//filePath := utils.IndexMsergeSaveDir + "season.xlsx"
+	//services.DataAnalysis(filePath)
+
+	//services.Merge()
+
+	fmt.Println("end services.Merge")
+}

+ 1 - 18
models/index/index.go

@@ -122,15 +122,6 @@ func (d *BaseFromMysteelChemicalIndex) GetIndexByFrequencyCount(frequency string
 	return
 }
 
-// GetNoMergeIndexByFrequencyCount 获取未合并的指标总数量
-func (d *BaseFromMysteelChemicalIndex) GetNoMergeIndexByFrequencyCount(frequency string) (total int64, err error) {
-	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).
-		//Where("frequency=? ", frequency).
-		Where("frequency=? AND merge_file_path = ? AND index_name NOT LIKE '%停%' ", frequency, "").
-		Count(&total).Error
-	return
-}
-
 func (d *BaseFromMysteelChemicalIndex) GetIndexByFrequencyPage(frequency string, offset, limit int) (item []*BaseFromMysteelChemicalIndex, err error) {
 	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).
 		Where("frequency=? ", frequency).
@@ -173,14 +164,6 @@ func (d *BaseFromMysteelChemicalIndex) GetIndexLatestMergeFilePath(frequency str
 	return
 }
 
-func (d *BaseFromMysteelChemicalIndex) GetMaxFileIndex(frequency string) (item *BaseFromMysteelChemicalIndex, err error) {
-	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).
-		Where("frequency=? AND index_name NOT LIKE '%停%' ", frequency).
-		Order("file_index DESC").
-		First(&item).Error
-	return
-}
-
 type IndexRefreshReq struct {
 	MergeFilePath string `json:"MergeFilePath" binding:"required"` //指标编码
 }
@@ -197,4 +180,4 @@ func (d *BaseFromMysteelChemicalIndex) GetIndexRefreshMethanolByTimely() (item [
 	err = global.MYSQL["hzdata"].WithContext(context.TODO()).Model(d).Where("merge_file_path != ? AND is_refresh=1 ", "").
 		Group("merge_file_path").Find(&item).Error
 	return
-}
+}

+ 12 - 298
services/index_merge.go

@@ -3,12 +3,11 @@ package services
 import (
 	"encoding/json"
 	"fmt"
-	"hongze/mysteel_watch/global"
 	"hongze/mysteel_watch/models/index"
 	"hongze/mysteel_watch/utils"
+	"hongze/mysteel_watch/watch"
 	"strconv"
 	"strings"
-	"sync"
 	"time"
 
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -38,7 +37,7 @@ func Merge() {
 	fmt.Println("merge end")
 }
 
-//年度
+// 年度
 func IndexYearMerge() {
 	frequency := "年度"
 	fileName := "year" + ".xlsx" //保存的文件名称
@@ -98,7 +97,7 @@ func IndexYearMerge() {
 	AddIndexRefreshToLpush(yearIndexFilePath)
 }
 
-//季度
+// 季度
 func IndexSeasonMerge() {
 	frequency := "季度"
 	fileName := "season" + ".xlsx" //保存的文件名称
@@ -528,8 +527,11 @@ func indexMerge(frequency, filePre string, pageSize int) (err error) {
 	firstIndexCount := pageSize //第一个添加的excel表需要的指标数
 	indexObj := new(index.BaseFromMysteelChemicalIndex)
 
+	frequencyReq := watch.GetMaxFileIndexReq{
+		Frequency: frequency,
+	}
 	// 获取未合并的指标总数量
-	total, err := indexObj.GetNoMergeIndexByFrequencyCount(frequency)
+	total, err := watch.GetNoMergeIndexByFrequencyCount(frequencyReq)
 	if err != nil {
 		fmt.Println("GetIndexByFrequencyCount Err:" + err.Error())
 		return
@@ -540,11 +542,7 @@ func indexMerge(frequency, filePre string, pageSize int) (err error) {
 	}
 
 	// 获取最大的文件编号下标
-	maxFileIndexItem, err := indexObj.GetMaxFileIndex(frequency)
-	if err != nil {
-		fmt.Println("GetMaxFileIndex Err:" + err.Error())
-		return
-	}
+	maxFileIndexItem, err := watch.GetMaxFileIndex(frequencyReq)
 
 	maxFileIndex := maxFileIndexItem.FileIndex
 	if maxFileIndex <= 0 {
@@ -561,14 +559,14 @@ func indexMerge(frequency, filePre string, pageSize int) (err error) {
 		return
 	}
 
-	fmt.Println("当前待合并的文件名:",maxMergeIndexFilePath)
-	fmt.Println("当前文件中指标的最大数量:",indexTotal)
+	fmt.Println("当前待合并的文件名:", maxMergeIndexFilePath)
+	fmt.Println("当前文件中指标的最大数量:", indexTotal)
 	fmt.Println("maxFileIndex:", maxFileIndex)
 	// 如果最近的excel表的指标数量 少于 每页需要的指标数
 	if int(indexTotal) < pageSize {
 		// 最近的excel表的待添加指标数 = 每页需要的指标数 - 已经添加的指标
 		firstIndexCount = pageSize - int(indexTotal)
-	}else{
+	} else {
 		firstIndexCount = pageSize
 		maxFileIndex++
 	}
@@ -609,7 +607,7 @@ func indexMerge(frequency, filePre string, pageSize int) (err error) {
 		//fmt.Println(offset, pageSize)
 
 		// 当下需要合并到excel的指标
-		pageList, tmpErr := indexObj.GetNoMergeIndexByFrequencyPage(frequency, size)
+		pageList, tmpErr := watch.GetNoMergeIndexByFrequencyPage(frequency, size)
 		if tmpErr != nil {
 			fmt.Println("GetIndexByFrequency Err:" + tmpErr.Error())
 			err = tmpErr
@@ -826,287 +824,3 @@ type IndexModels struct {
 	PointValue       int64  `json:"PointValue"`
 	UnionStart       string `json:"UnionStart"`
 }
-
-func DataAnalysis(filePath string) {
-
-	runMode := "debug"
-	//runMode = "release"
-
-	fmt.Println("filePath:", filePath)
-	time.Sleep(1 * time.Second)
-	if !utils.FileIsExist(filePath) {
-		fmt.Println("filePath is not exist:" + filePath)
-		return
-	}
-	//读取文件内容
-	global.LOG.Info("WatchFile:" + filePath)
-	f, err := excelize.OpenFile(filePath)
-	global.LOG.Info("OpenFile:" + filePath)
-	if err != nil {
-		fmt.Println("OpenFile:" + filePath + ",Err:" + err.Error())
-		return
-	}
-	defer func() {
-		if err := f.Close(); err != nil {
-			fmt.Println("FileClose Err:" + err.Error())
-			return
-		}
-	}()
-
-	indexObj := new(index.BaseFromMysteelChemicalIndex)
-	var wg = sync.WaitGroup{}
-	wg.Add(1)
-	go func() {
-		sheetList := f.GetSheetList()
-		for _, sv := range sheetList {
-			rows, err := f.GetRows(sv)
-			if err != nil {
-				fmt.Println("f.GetRows:err:" + err.Error())
-				return
-			}
-			var nameArr []string
-			unitArr := make([]string, 0)
-			sourceArr := make([]string, 0)
-			codeArr := make([]string, 0)
-			frequencyArr := make([]string, 0)
-			dateArr := make([]string, 0)
-			describeArr := make([]string, 0)
-			endDateArr := make([]string, 0)
-			updateArr := make([]string, 0)
-			indexDateArr := make([]string, 0)
-
-			dataMap := make(map[string][]string)
-
-			var nameLen int
-			for rk, row := range rows {
-				if rk == 0 {
-					continue
-				}
-				if rk == 1 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							nameArr = append(nameArr, colCell)
-						}
-					}
-					nameLen = len(nameArr)
-					unitArr = make([]string, nameLen)
-					sourceArr = make([]string, nameLen)
-					codeArr = make([]string, nameLen)
-					frequencyArr = make([]string, nameLen)
-					dateArr = make([]string, nameLen)
-					describeArr = make([]string, nameLen)
-					endDateArr = make([]string, nameLen)
-					updateArr = make([]string, nameLen)
-				} else if rk == 2 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							unitArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 3 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//sourceArr = append(sourceArr, colCell)
-							sourceArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 4 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//codeArr = append(codeArr, colCell)
-							codeArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 5 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//frequencyArr = append(frequencyArr, colCell)
-							frequencyArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 6 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//dateArr = append(dateArr, colCell)
-							dateArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 7 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//describeArr = append(describeArr, colCell)
-							describeArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 8 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//endDateArr = append(endDateArr, colCell)
-							endDateArr[ck-1] = colCell
-						}
-					}
-				} else if rk == 9 {
-					for ck, colCell := range row {
-						if ck >= 1 {
-							//updateArr = append(updateArr, colCell)
-							updateArr[ck-1] = colCell
-						}
-					}
-				} else {
-					var date string
-					dataArr := make([]string, nameLen)
-					for ck, colCell := range row {
-						if ck == 0 {
-							date = colCell
-							indexDateArr = append(indexDateArr, date)
-						} else {
-							if colCell != "" {
-								dataArr[ck-1] = colCell
-							}
-						}
-					}
-					dataMap[date] = dataArr
-				}
-			}
-
-			var indexId int64
-			existDataMap := make(map[string]string)
-			for k, v := range nameArr {
-				indexName := v
-				indexCode := codeArr[k]
-				unit := unitArr[k]
-				source := sourceArr[k]
-				describe := describeArr[k]
-				dateStr := dateArr[k]
-				frequency := frequencyArr[k]
-				//判断指标是否存在
-				var isAdd int
-				item, err := indexObj.GetIndexItem(runMode, indexCode)
-				if err != nil {
-					if err.Error() == "record not found" {
-						isAdd = 1
-					} else {
-						isAdd = -1
-						fmt.Println("GetIndexItem Err:" + err.Error())
-						return
-					}
-				}
-				if item != nil && item.BaseFromMysteelChemicalIndexId > 0 {
-					fmt.Println("item:", item)
-					isAdd = 2
-				} else {
-					isAdd = 1
-				}
-
-				var startDate, endDate string
-				startEndArr := strings.Split(dateStr, "~")
-				if len(startEndArr) >= 2 {
-					startDate = startEndArr[0]
-					endDate = startEndArr[1]
-				}
-
-				if !strings.Contains(frequency, "度") {
-					frequency = frequency + "度"
-				}
-
-				indexItem := new(index.BaseFromMysteelChemicalIndex)
-				if isAdd == 1 {
-					indexItem.IndexCode = indexCode
-					indexItem.IndexName = indexName
-					indexItem.Unit = unit
-					indexItem.Source = source
-					indexItem.Describe = describe
-					indexItem.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
-					indexItem.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
-					indexItem.Frequency = frequency
-					indexItem.FilePath = filePath
-					indexItem.MergeFilePath = filePath
-					err = indexItem.Add(runMode)
-					if err != nil {
-						fmt.Println("indexItem.add err:" + err.Error())
-						return
-					}
-					indexId = indexObj.BaseFromMysteelChemicalIndexId
-				} else if isAdd == 2 {
-					indexItem.IndexCode = indexCode
-					indexItem.IndexName = indexName
-					indexItem.Unit = unit
-					indexItem.Source = source
-					indexItem.Describe = describe
-					indexItem.StartDate, _ = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
-					indexItem.EndDate, _ = time.ParseInLocation(utils.FormatDate, endDate, time.Local)
-					indexItem.Frequency = frequency
-					indexItem.FilePath = filePath
-					indexItem.ModifyTime = time.Now()
-					indexId = item.BaseFromMysteelChemicalIndexId
-					//修改数据
-					updateColsArr := make([]string, 0)
-					updateColsArr = append(updateColsArr, "index_name")
-					updateColsArr = append(updateColsArr, "unit")
-					updateColsArr = append(updateColsArr, "source")
-					updateColsArr = append(updateColsArr, "frequency")
-					updateColsArr = append(updateColsArr, "start_date")
-					updateColsArr = append(updateColsArr, "end_date")
-					updateColsArr = append(updateColsArr, "describe")
-					updateColsArr = append(updateColsArr, "end_date")
-					updateColsArr = append(updateColsArr, "modify_time")
-					updateColsArr = append(updateColsArr, "file_path")
-
-					err = indexItem.Update(runMode, updateColsArr)
-					if err != nil {
-						fmt.Println("indexObj.Update err:" + err.Error())
-						return
-					}
-
-					dataObj := new(index.BaseFromMysteelChemicalData)
-					//获取已存在的所有数据
-					dataList, err := dataObj.GetIndexDataList(runMode, indexCode)
-					if err != nil {
-						fmt.Println("GetIndexDataList Err:" + err.Error())
-						return
-					}
-					fmt.Println("dataListLen:", len(dataList))
-					for _, v := range dataList {
-						dateStr := v.DataTime.Format(utils.FormatDate)
-						existDataMap[dateStr] = v.Value
-					}
-				}
-
-				dataList := make([]index.BaseFromMysteelChemicalData, 0)
-				for _, dv := range indexDateArr {
-					dataArr := dataMap[dv]
-					dataVal := dataArr[k]
-					updateDate := updateArr[k]
-					if dataVal != "" {
-						if _, ok := existDataMap[dv]; !ok {
-							dateTime, err := time.ParseInLocation(utils.FormatDate, dv, time.Local)
-							if err != nil {
-								fmt.Println("time.ParseInLocation Err:" + err.Error())
-								return
-							}
-							dataItem := new(index.BaseFromMysteelChemicalData)
-							dataItem.BaseFromMysteelChemicalIndexId = indexId
-							dataItem.IndexCode = indexCode
-							dataItem.DataTime = dateTime
-							dataItem.Value = dataVal
-							dataItem.UpdateDate = updateDate
-							dataItem.CreateTime = time.Now()
-							dataItem.ModifyTime = time.Now()
-							dataList = append(dataList, *dataItem)
-						}
-					}
-				}
-				if len(dataList) > 0 {
-					dataObj := new(index.BaseFromMysteelChemicalData)
-					err = dataObj.Add(runMode, dataList)
-					if err != nil {
-						fmt.Println("dataObj.Add() Err:" + err.Error())
-						return
-					}
-				}
-			}
-		}
-		wg.Done()
-	}()
-	wg.Wait()
-}

+ 207 - 0
watch/edb_lib.go

@@ -0,0 +1,207 @@
+package watch
+
+import (
+	"encoding/json"
+	"errors"
+	"fmt"
+	"hongze/mysteel_watch/global"
+	"hongze/mysteel_watch/models/index"
+	"hongze/mysteel_watch/utils"
+	"io/ioutil"
+	"net/http"
+	"strings"
+)
+
+type BaseResponse struct {
+	Ret         int
+	Msg         string
+	ErrMsg      string
+	ErrCode     string
+	Data        interface{}
+	Success     bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
+	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
+}
+
+// postRefreshEdbData 刷新指标数据
+func postRefreshEdbData(param map[string]interface{}) (resp *BaseResponse, err error) {
+	urlStr := "mysteel_chemical/refresh"
+
+	if global.CONFIG.Serve.EdbLibUrl == `` {
+		err = errors.New("刷新未配置")
+		return
+	}
+	postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
+	postData, err := json.Marshal(param)
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+	if result != nil {
+		global.LOG.Info(" Refresh Result: " + string(result))
+		err = json.Unmarshal(result, &resp)
+		if err != nil {
+			return
+		}
+		return resp, nil
+	}
+	return nil, err
+}
+
+// postRefreshEdbData 刷新指标数据
+func postHandleMysteelIndex(req *HandleMysteelIndexReq) (resp *BaseResponse, err error) {
+	urlStr := "/mysteel_chemical/handle/mysteel/index"
+
+	if global.CONFIG.Serve.EdbLibUrl == `` {
+		err = errors.New("刷新未配置")
+		return
+	}
+	postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
+	postData, err := json.Marshal(req)
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+	if result != nil {
+		global.LOG.Info(" Refresh Result: " + string(result))
+		err = json.Unmarshal(result, &resp)
+		if err != nil {
+			return
+		}
+		return resp, nil
+	}
+	return nil, err
+}
+
+// GetMaxFileIndexReq 获取最大文件数请求
+type GetMaxFileIndexReq struct {
+	Frequency string
+}
+
+// GetNoMergeIndexByFrequencyCount 获取未合并的指标总数量
+func GetNoMergeIndexByFrequencyCount(req GetMaxFileIndexReq) (total int, err error) {
+	urlStr := "/mysteel_chemical/getNoMergeIndexByFrequencyCount"
+
+	if global.CONFIG.Serve.EdbLibUrl == `` {
+		err = errors.New("刷新未配置")
+		return
+	}
+	postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
+	postData, err := json.Marshal(req)
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+
+	var resp BaseResponse
+	global.LOG.Info(" Refresh Result: " + string(result))
+	err = json.Unmarshal(result, &resp)
+	if err != nil {
+		return
+	}
+
+	total = resp.Data.(int)
+
+	return
+}
+
+// GetMaxFileIndex 获取最大的文件编号下标
+func GetMaxFileIndex(req GetMaxFileIndexReq) (baseFromMysteelChemicalIndex index.BaseFromMysteelChemicalIndex, err error) {
+	urlStr := "/mysteel_chemical/getMaxFileIndex"
+
+	if global.CONFIG.Serve.EdbLibUrl == `` {
+		err = errors.New("刷新未配置")
+		return
+	}
+	postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
+	postData, err := json.Marshal(req)
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+
+	var resp BaseResponse
+	global.LOG.Info(" Refresh Result: " + string(result))
+	err = json.Unmarshal(result, &resp)
+	if err != nil {
+		return
+	}
+
+	baseFromMysteelChemicalIndex = resp.Data.(index.BaseFromMysteelChemicalIndex)
+
+	return
+}
+
+// GetNoMergeIndexByFrequencyPageReq 获取最大文件数请求
+type GetNoMergeIndexByFrequencyPageReq struct {
+	Frequency string
+	Limit     int
+}
+
+// GetNoMergeIndexByFrequencyPage 当下需要合并到excel的指标
+func GetNoMergeIndexByFrequencyPage(frequency string, limit int) (item []index.BaseFromMysteelChemicalIndex, err error) {
+	urlStr := "/mysteel_chemical/getNoMergeIndexByFrequencyPage"
+
+	if global.CONFIG.Serve.EdbLibUrl == `` {
+		err = errors.New("刷新未配置")
+		return
+	}
+	postUrl := global.CONFIG.Serve.EdbLibUrl + urlStr
+	postData, err := json.Marshal(GetNoMergeIndexByFrequencyPageReq{
+		Frequency: frequency,
+		Limit:     limit,
+	})
+	if err != nil {
+		return
+	}
+	result, err := HttpPost(postUrl, string(postData), "application/json")
+	if err != nil {
+		return
+	}
+
+	var resp BaseResponse
+	global.LOG.Info(" Refresh Result: " + string(result))
+	err = json.Unmarshal(result, &resp)
+	if err != nil {
+		return
+	}
+
+	item = resp.Data.([]index.BaseFromMysteelChemicalIndex)
+
+	return
+}
+
+func HttpPost(url, postData string, params ...string) ([]byte, error) {
+	body := ioutil.NopCloser(strings.NewReader(postData))
+	client := &http.Client{}
+	req, err := http.NewRequest("POST", url, body)
+	if err != nil {
+		return nil, err
+	}
+	contentType := "application/x-www-form-urlencoded;charset=utf-8"
+	if len(params) > 0 && params[0] != "" {
+		contentType = params[0]
+	}
+	req.Header.Set("Content-Type", contentType)
+	req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
+	resp, err := client.Do(req)
+	if resp != nil {
+		defer resp.Body.Close()
+		b, err := ioutil.ReadAll(resp.Body)
+		fmt.Println("HttpPost:" + string(b))
+		return b, err
+	}
+	return nil, err
+}

+ 1 - 87
watch/watch.go

@@ -1,15 +1,12 @@
 package watch
 
 import (
-	"encoding/json"
 	"fmt"
 	"hongze/mysteel_watch/global"
 	"hongze/mysteel_watch/models"
 	"hongze/mysteel_watch/models/index"
 	"hongze/mysteel_watch/utils"
-	"io/ioutil"
 	"log"
-	"net/http"
 	"os"
 	"path/filepath"
 	"strings"
@@ -41,6 +38,7 @@ func ListenFolderNew() {
 					!strings.Contains(event.Name, ".TMP") &&
 					!strings.Contains(event.Name, "~") &&
 					(strings.Contains(event.Name, "xlsx") || strings.Contains(event.Name, "xls")) {
+					// 监听文件变更事件
 					WatchIndexFile(event.Name)
 				}
 			case err := <-watcher.Errors:
@@ -705,90 +703,6 @@ func syncEdbDataMysteelChemical(runMode, indexCode string) {
 	postRefreshEdbData(param)
 }
 
-type BaseResponse struct {
-	Ret         int
-	Msg         string
-	ErrMsg      string
-	ErrCode     string
-	Data        interface{}
-	Success     bool `description:"true 执行成功,false 执行失败"`
-	IsSendEmail bool `json:"-" description:"true 发送邮件,false 不发送邮件"`
-	IsAddLog    bool `json:"-" description:"true 新增操作日志,false 不新增操作日志" `
-}
-
-// postRefreshEdbData 刷新指标数据
-func postRefreshEdbData(param map[string]interface{}) (resp *BaseResponse, err error) {
-	urlStr := "mysteel_chemical/refresh"
-	EDB_LIB_URL := "http://47.102.213.75:8300/edbapi/"
-
-	postUrl := EDB_LIB_URL + urlStr
-	postData, err := json.Marshal(param)
-	if err != nil {
-		return
-	}
-	result, err := HttpPost(postUrl, string(postData), "application/json")
-	if err != nil {
-		return
-	}
-	if result != nil {
-		global.LOG.Info(" Refresh Result: " + string(result))
-		err = json.Unmarshal(result, &resp)
-		if err != nil {
-			return
-		}
-		return resp, nil
-	}
-	return nil, err
-}
-
-// postRefreshEdbData 刷新指标数据
-func postHandleMysteelIndex(req *HandleMysteelIndexReq) (resp *BaseResponse, err error) {
-	urlStr := "/mysteel_chemical/handle/mysteel/index"
-	EDB_LIB_URL := "http://127.0.0.1:8300/edbapi/"
-
-	postUrl := EDB_LIB_URL + urlStr
-	postData, err := json.Marshal(req)
-	if err != nil {
-		return
-	}
-	result, err := HttpPost(postUrl, string(postData), "application/json")
-	if err != nil {
-		return
-	}
-	if result != nil {
-		global.LOG.Info(" Refresh Result: " + string(result))
-		err = json.Unmarshal(result, &resp)
-		if err != nil {
-			return
-		}
-		return resp, nil
-	}
-	return nil, err
-}
-
-func HttpPost(url, postData string, params ...string) ([]byte, error) {
-	body := ioutil.NopCloser(strings.NewReader(postData))
-	client := &http.Client{}
-	req, err := http.NewRequest("POST", url, body)
-	if err != nil {
-		return nil, err
-	}
-	contentType := "application/x-www-form-urlencoded;charset=utf-8"
-	if len(params) > 0 && params[0] != "" {
-		contentType = params[0]
-	}
-	req.Header.Set("Content-Type", contentType)
-	req.Header.Set("authorization", utils.MD5(utils.APP_EDB_LIB_NAME_EN+utils.EDB_LIB_Md5_KEY))
-	resp, err := client.Do(req)
-	if resp != nil {
-		defer resp.Body.Close()
-		b, err := ioutil.ReadAll(resp.Body)
-		fmt.Println("HttpPost:" + string(b))
-		return b, err
-	}
-	return nil, err
-}
-
 /*
 CREATE动作即临时文件的创建
 WRITE写文件动作