zwxi 1 year ago
parent
commit
9da0d26594
9 changed files with 676 additions and 0 deletions
  1. BIN
      eta_data_analysis
  2. 3 0
      go.mod
  3. 6 0
      go.sum
  4. 78 0
      main.go
  5. 485 0
      services/commodity_coal_coastal.go
  6. 81 0
      services/task.go
  7. 6 0
      utils/common.go
  8. 11 0
      utils/config.go
  9. 6 0
      utils/constants.go

BIN
eta_data_analysis


+ 3 - 0
go.mod

@@ -7,7 +7,10 @@ require (
 	github.com/beego/beego/v2 v2.1.4
 	github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b
 	github.com/mozillazg/go-pinyin v0.20.0
+	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
+	github.com/patrickmn/go-cache v2.1.0+incompatible
 	github.com/rdlucklib/rdluck_tools v1.0.3
+	github.com/robfig/cron/v3 v3.0.1
 	github.com/shopspring/decimal v1.3.1
 	github.com/tealeg/xlsx v1.0.5
 )

+ 6 - 0
go.sum

@@ -117,6 +117,10 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
 github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
+github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
+github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
+github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
+github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
 github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc=
@@ -147,6 +151,8 @@ github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+Pymzi
 github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
 github.com/rdlucklib/rdluck_tools v1.0.3 h1:iOtK2QPlPQ6CL6c1htCk5VnFCHzyG6DCfJtunrMswK0=
 github.com/rdlucklib/rdluck_tools v1.0.3/go.mod h1:9Onw9o4w19C8KE5lxb8GyxgRBbZweRVkQSc79v38EaA=
+github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
+github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
 github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=

+ 78 - 0
main.go

@@ -0,0 +1,78 @@
+package models
+
+import (
+	"time"
+)
+
+type BaseFromCoalmineMapping struct {
+	BaseFromCoalmineMappingId int       `orm:"column(base_from_coalmine_mapping_id);pk"`
+	IndexName                 string    `description:"持买单量指标名称"`
+	IndexCode                 string    `description:"持买单量指标编码"`
+	CreateTime                time.Time `description:"时间"`
+}
+
+type BaseFromCoalmineJsmIndex struct {
+	BaseFromCoalmineJsmIndexId int       `orm:"column(base_from_coalmine_jsm_index_id);pk"`
+	IndexName                  string    `description:"持买单量指标名称"`
+	IndexCode                  string    `description:"持买单量指标编码"`
+	Exchange                   string    `description:"样本统计类别"`
+	DealValue                  string    `description:"成交量"`
+	DataTime                   string    `description:"数据日期"`
+	Source                     string    `description:"来源"`
+	Province                   string    `description:"省份"`
+	Description                string    `description:"描述"`
+	Unit                       string    `description:"单位"`
+	Frequency                  string    `description:"频率"`
+	CreateTime                 time.Time `description:"插入时间"`
+	ModifyTime                 time.Time `description:"修改时间"`
+}
+
+type BaseFromCoalmineCompanyIndex struct {
+	BaseFromCoalmineCompanyIndexId int       `orm:"column(base_from_coalmine_company_index_id);pk"`
+	IndexName                      string    `description:"持买单量指标名称"`
+	IndexCode                      string    `description:"持买单量指标编码"`
+	DealValue                      string    `description:"成交量"`
+	DataTime                       string    `description:"数据日期"`
+	Source                         string    `description:"来源"`
+	Province                       string    `description:"省份"`
+	City                           string    `description:"城市"`
+	GroupName                      string    `description:"集团名称"`
+	Unit                           string    `description:"单位"`
+	Frequency                      string    `description:"频率"`
+	CreateTime                     time.Time `description:"插入时间"`
+	ModifyTime                     time.Time `description:"修改时间"`
+}
+
+type SheetData struct {
+	Name        string
+	Rows        []Row
+	Cols        []*Col
+	MaxRow      int
+	MaxCol      int
+	Hidden      bool
+	Selected    bool
+}
+
+
+type Row struct {
+	Cells        []Cell
+	Hidden       bool
+	Height       float64
+	OutlineLevel uint8
+	isCustom     bool
+}
+
+type Col struct {
+	Min             int
+	Max             int
+	Hidden          bool
+	Width           float64
+	Collapsed       bool
+	OutlineLevel    uint8
+	numFmt          string
+}
+
+
+type Cell struct {
+	Value          string
+}

+ 485 - 0
services/commodity_coal_coastal.go

@@ -0,0 +1,485 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_data_analysis/models"
+	"eta/eta_data_analysis/utils"
+	"fmt"
+	"github.com/tealeg/xlsx"
+	"os"
+)
+
+func JsmHistory(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新.xlsx"
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省历史数据/442家晋陕蒙历史数据.xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\442家晋陕蒙历史数据.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
+	}
+
+	//sheetData, err := json.Marshal(xlFile)
+	//if err != nil {
+	//	fmt.Println("json.Marshal err:", err)
+	//	return
+	//}
+
+	sheetDatas := make([]models.SheetData, 0)
+	data := *xlFile.Sheets[0]
+	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_COAL_MINE_JSM_HISTORY)
+	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
+}
+
+func CoastalHistory(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省历史数据/CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).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 < 4 {
+			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_COAL_MINE_COASTAL_HISTORY)
+	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
+}
+
+func InlandHistory(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省历史数据/CⅢ-8-16 25省市库存和日耗情况(CCTD).xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).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 > 3 {
+			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_COAL_MINE_INLAND_HISTORY)
+	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
+}
+
+func PathExists(path string) (bool, error) {
+	_, err := os.Stat(path)
+	if err == nil { //文件或者目录存在
+		return true, nil
+	}
+	if os.IsNotExist(err) {
+		return false, nil
+	}
+	return false, err
+}
+
+func Jsm(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/home/code/python/coal_mail/emailFile/沿海八省动力煤终端用户供耗存数据更新.xlsx"
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/442家晋陕蒙煤矿周度产量数据-20231201.xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\442家晋陕蒙历史数据.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)
+	data := *xlFile.Sheets[0]
+	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_COAL_MINE_JSM)
+	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
+}
+
+func Coastal(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/内陆17省动力煤终端用户供耗存.xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).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 _, sheet := range xlFile.Sheets {
+		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_COAL_MINE_COASTAL)
+	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
+}
+
+func Inland(path string) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("RefreshDataFromCoalCoastal  Err:" + err.Error())
+			utils.FileLog.Info(fmt.Sprintf("RefreshDataFromCoalCoastal, Err: %s", err))
+		}
+	}()
+	//path := "/Users/xi/Desktop/瑞茂通-中国煤炭市场网数据/442家晋陕蒙、沿海8省、内陆17省最新数据/内陆17省动力煤终端用户供耗存.xlsx"
+	//path := "D:\\瑞茂通-中国煤炭市场网数据\\442家晋陕蒙、沿海8省、内陆17省历史数据\\CⅢ-8-16 25省市库存和日耗情况(CCTD).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 _, sheet := range xlFile.Sheets {
+		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_COAL_MINE_INLAND)
+	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
+}

+ 81 - 0
services/task.go

@@ -4,6 +4,14 @@ import (
 	"eta/eta_data_analysis/utils"
 	"fmt"
 	"github.com/beego/beego/v2/task"
+	"github.com/patrickmn/go-cache"
+	"github.com/robfig/cron/v3"
+	"io/fs"
+	"os"
+	"path/filepath"
+	"strings"
+	"syscall"
+	"time"
 )
 
 func Task() {
@@ -25,5 +33,78 @@ func Task() {
 		task.StartTask()
 	}
 
+	if utils.CoalMineOpen == "1" {
+		c := cron.New(cron.WithSeconds())
+		//每2分钟检测一次指标文件是否更新
+		_, err := c.AddFunc("0 */2 * * * *", ReadWatchIndexFile)
+		if err != nil {
+			utils.FileLog.Info("watch.ReadWatchIndexFile err" + err.Error())
+		}
+	}
+
 	fmt.Println("task end")
 }
+
+
+func ReadWatchIndexFile() {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("ReadWatchIndexFile 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.CoalMineFilePath, 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, "442家晋陕蒙煤矿周度产量数据") {
+						err = Jsm(path)
+					} else if strings.Contains(path, "内陆17省动力煤终端用户供耗存") {
+						err = Inland(path)
+					} else if strings.Contains(path, "沿海八省动力煤终端用户供耗存数据更新") {
+						err = Coastal(path)
+					} else if strings.Contains(path, "442家晋陕蒙历史数据") {
+						err = JsmHistory(path)
+					} else if strings.Contains(path, "CⅢ-8-16 25省市库存和日耗情况") {
+						err = CoastalHistory(path)
+						time.Sleep(time.Second*10)
+						err = InlandHistory(path)
+					}
+				}
+			} else {
+				if strings.Contains(path, "442家晋陕蒙煤矿周度产量数据") {
+					err = Jsm(path)
+				} else if strings.Contains(path, "内陆17省动力煤终端用户供耗存") {
+					err = Inland(path)
+				} else if strings.Contains(path, "沿海八省动力煤终端用户供耗存数据更新") {
+					err = Coastal(path)
+				} else if strings.Contains(path, "442家晋陕蒙历史数据") {
+					err = JsmHistory(path)
+				} else if strings.Contains(path, "CⅢ-8-16 25省市库存和日耗情况") {
+					err = CoastalHistory(path)
+					time.Sleep(time.Second*10)
+					err = InlandHistory(path)
+				}
+			}
+			cacheClient.Delete(path)
+			cacheClient.Set(path, modifyTimeStr, 24*time.Hour)
+		}
+		return nil
+	})
+}

+ 6 - 0
utils/common.go

@@ -1231,3 +1231,9 @@ func CheckFrequency(leftFrequency, rightFrequency string) int {
 
 	return frequencyMap[leftFrequency] - frequencyMap[rightFrequency]
 }
+
+// 把秒级的时间戳转为time格式
+func SecondToTime(sec int64) time.Time {
+	return time.Unix(sec, 0)
+}
+

+ 11 - 0
utils/config.go

@@ -42,6 +42,12 @@ var (
 	YongyiOpen     string //是否配置涌益生猪数据源,1已配置
 )
 
+// 中国煤炭网
+var (
+	CoalMineFilePath string //excel文件地址
+	CoalMineOpen     string //是否配置涌益生猪数据源,1已配置
+)
+
 var TerminalCode string
 
 func init() {
@@ -86,6 +92,11 @@ func init() {
 		YongyiFilePath = config["yongyi_file_path"]
 		YongyiOpen = config["yongyi_open"]
 	}
+	//中国煤炭网文件夹配置
+	{
+		CoalMineFilePath = config["coal_mine_file_path"]
+		CoalMineOpen = config["coal_mine_open"]
+	}
 	TerminalCode = config["terminal_code"]
 }
 

+ 6 - 0
utils/constants.go

@@ -231,4 +231,10 @@ var FrequencyDaysMap = map[string]int{
 // edb_index_lib 的接口名称
 const (
 	LIB_ROUTE_YONGYI_HANDLE = "yongyi/handle/excel_data" //涌益咨询处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_JSM_HISTORY = "/coal_mine/jsm/history" //jsm三省煤炭网历史数据处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_COASTAL_HISTORY = "/coal_mine/coastal/history" //沿海煤炭网历史数据处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_INLAND_HISTORY = "/coal_mine/inland/history" //内陆三省煤炭网历史数据处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_JSM = "/coal_mine/jsm" //jsm三省煤炭网历史数据处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_COASTAL = "/coal_mine/coastal" //沿海煤炭网历史数据处理excel数据并入库 数据地址
+	LIB_ROUTE_COAL_MINE_INLAND = "/coal_mine/inland" //内陆三省煤炭网历史数据处理excel数据并入库 数据地址
 )