Browse Source

修改包名、指标重新分类

hsun 1 year ago
parent
commit
9f6baa2dd8

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 /rdlucklog
 /binlog
 /conf
+/*.exe

BIN
docs/ETA基础指标0821整理.xlsx


BIN
docs/ETA计算指标0821整理.xlsx


+ 1 - 4
go.mod

@@ -1,4 +1,4 @@
-module hongze/hz_eta_data
+module eta/eta_data_init
 
 go 1.19
 
@@ -7,7 +7,6 @@ require (
 	github.com/beego/beego/v2 v2.1.0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/gonum/stat v0.0.0-20181125101827-41a0da705a5b
-	github.com/olivere/elastic/v7 v7.0.32
 	github.com/shopspring/decimal v1.3.1
 	github.com/xuri/excelize/v2 v2.7.1
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
@@ -24,9 +23,7 @@ require (
 	github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 // indirect
 	github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9 // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect
-	github.com/josharian/intern v1.0.0 // indirect
 	github.com/kr/text v0.2.0 // indirect
-	github.com/mailru/easyjson v0.7.7 // indirect
 	github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
 	github.com/mitchellh/mapstructure v1.5.0 // indirect
 	github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect

+ 0 - 7
go.sum

@@ -13,7 +13,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
 github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
 github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
-github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
 github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
 github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@@ -37,21 +36,15 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
 github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
-github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
-github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
 github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
 github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
-github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
-github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
 github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
 github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
 github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
 github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
-github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E=
-github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

+ 2 - 2
main.go

@@ -1,8 +1,8 @@
 package main
 
 import (
-	_ "hongze/hz_eta_data/routers"
-	"hongze/hz_eta_data/services"
+	_ "eta/eta_data_init/routers"
+	"eta/eta_data_init/services"
 
 	beego "github.com/beego/beego/v2/server/web"
 )

+ 1 - 1
routers/router.go

@@ -8,7 +8,7 @@
 package routers
 
 import (
-	"hongze/hz_eta_data/controllers"
+	"eta/eta_data_init/controllers"
 
 	beego "github.com/beego/beego/v2/server/web"
 )

+ 1 - 1
services/base.go

@@ -2,8 +2,8 @@ package services
 
 import (
 	"encoding/json"
+	"eta/eta_data_init/utils"
 	"fmt"
-	"hongze/hz_eta_data/utils"
 	"io/ioutil"
 	"net/http"
 	"strings"

+ 117 - 0
services/hz_edb_classify.go

@@ -0,0 +1,117 @@
+package services
+
+import (
+	"encoding/json"
+	"eta/eta_data_init/models"
+	"eta/eta_data_init/utils"
+	"fmt"
+	"github.com/xuri/excelize/v2"
+	"os"
+	"path/filepath"
+	"strings"
+	"time"
+)
+
+const (
+	MethodClassifyReset = "edb_info/classify_reset"
+)
+
+func ResetHzEdbClassify() {
+	fmt.Println("start ResetHzEdbClassify")
+	for _, v := range []string{"ETA基础指标0821整理", "ETA计算指标0821整理"} {
+		time.Sleep(5 * time.Second)
+		ResetEdbClassify(v)
+	}
+	fmt.Println("end ResetHzEdbClassify")
+}
+
+// ResetEdbClassify 重置指标分类
+func ResetEdbClassify(fileName string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("ResetBaseEdbAndClassify Err: " + err.Error())
+		}
+	}()
+
+	path, e := filepath.Abs(os.Args[0])
+	if e != nil {
+		err = fmt.Errorf("path abs err: %s", e.Error())
+		return
+	}
+	dir := filepath.Dir(path)
+	//dataPath := dir + "/docs/ETA计算指标0821整理.xlsx"
+	dataPath := fmt.Sprintf("%s/docs/%s.xlsx", dir, fileName)
+	fmt.Println("dataPath:" + dataPath)
+
+	f, e := excelize.OpenFile(dataPath)
+	if e != nil {
+		err = fmt.Errorf("open file err: %s", e.Error())
+		return
+	}
+	defer func() {
+		if e = f.Close(); e != nil {
+			fmt.Println("file close err: " + e.Error())
+		}
+	}()
+
+	rows, e := f.GetRows("Sheet1")
+	if e != nil {
+		err = fmt.Errorf("get rows err: %s", e.Error())
+		return
+	}
+	if len(rows) == 0 {
+		err = fmt.Errorf("empty rows")
+		return
+	}
+
+	// 读取行
+	utils.FileLog.Info("开始初始化")
+	for rk, row := range rows {
+		if rk == 0 {
+			continue
+		}
+
+		var indexCode, classifyFirst, classifySecond, classifyThird string
+		// 读取单元格
+		for ck, cell := range row {
+			switch ck {
+			case 2:
+				indexCode = strings.TrimSpace(cell)
+			case 7:
+				classifyFirst = strings.TrimSpace(cell)
+			case 8:
+				classifySecond = strings.TrimSpace(cell)
+			case 9:
+				classifyThird = strings.TrimSpace(cell)
+			}
+		}
+		if indexCode == "" || classifyFirst == "" || classifySecond == "" || classifyThird == "" {
+			utils.FileLog.Info("忽略第%d行, IndexCode: %s, ClassifyFirst: %s, ClassifySecond: %s, ClassifyThird: %s", rk+1, indexCode, classifyFirst, classifySecond, classifyThird)
+			continue
+		}
+		utils.FileLog.Info("第%d行, IndexCode: %s", rk+1, indexCode)
+
+		params := make(map[string]interface{})
+		params["IndexCode"] = indexCode
+		params["ClassifyFirst"] = classifyFirst
+		params["ClassifySecond"] = classifySecond
+		params["ClassifyThird"] = classifyThird
+		result, e := PostEdbLib(params, MethodClassifyReset)
+		if e != nil {
+			b, _ := json.Marshal(params)
+			utils.FileLog.Info("重置指标分类失败, err: %s, params: %s", e.Error(), string(b))
+			return
+		}
+		resp := new(models.EdbInfoResp)
+		if e := json.Unmarshal(result, &resp); e != nil {
+			utils.FileLog.Info("MethodClassifyReset Unmarshal err: %s", e.Error())
+			return
+		}
+		if resp.Ret != 200 {
+			utils.FileLog.Info("重置指标分类失败, Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg)
+			continue
+		}
+	}
+	utils.FileLog.Info("初始化结束")
+}

+ 2 - 2
services/init_base_index.go

@@ -2,10 +2,10 @@ package services
 
 import (
 	"encoding/json"
+	"eta/eta_data_init/models"
+	"eta/eta_data_init/utils"
 	"fmt"
 	"github.com/xuri/excelize/v2"
-	"hongze/hz_eta_data/models"
-	"hongze/hz_eta_data/utils"
 	"os"
 	"path/filepath"
 	"strings"

+ 2 - 2
services/init_calculate_index.go

@@ -5,11 +5,11 @@ import (
 	"crypto/md5"
 	"encoding/json"
 	"errors"
+	"eta/eta_data_init/models"
+	"eta/eta_data_init/utils"
 	"fmt"
 	"github.com/shopspring/decimal"
 	"github.com/xuri/excelize/v2"
-	"hongze/hz_eta_data/models"
-	"hongze/hz_eta_data/utils"
 	"io/ioutil"
 	"net/http"
 	"os"

+ 2 - 2
services/init_edb_classify.go

@@ -2,10 +2,10 @@ package services
 
 import (
 	"encoding/json"
+	"eta/eta_data_init/models"
+	"eta/eta_data_init/utils"
 	"fmt"
 	"github.com/xuri/excelize/v2"
-	"hongze/hz_eta_data/models"
-	"hongze/hz_eta_data/utils"
 	"os"
 	"path/filepath"
 )

+ 2 - 2
services/init_mysteel_index.go

@@ -2,10 +2,10 @@ package services
 
 import (
 	"encoding/json"
+	"eta/eta_data_init/models"
+	"eta/eta_data_init/utils"
 	"fmt"
 	"github.com/xuri/excelize/v2"
-	"hongze/hz_eta_data/models"
-	"hongze/hz_eta_data/utils"
 	"os"
 	"path/filepath"
 	"strings"

+ 1 - 1
services/task.go

@@ -1,8 +1,8 @@
 package services
 
 import (
+	"eta/eta_data_init/utils"
 	"fmt"
-	"hongze/hz_eta_data/utils"
 	"time"
 )
 

+ 1 - 1
utils/logs.go

@@ -11,7 +11,7 @@ var Binlog *logs.BeeLogger
 
 func init() {
 	FileLog = logs.NewLogger(1000000)
-	FileLog.SetLogger(logs.AdapterFile, `{"filename":"./rdlucklog/hz_eta_data.log"}`)
+	FileLog.SetLogger(logs.AdapterFile, `{"filename":"./rdlucklog/eta_data_init.log"}`)
 	FileLog.EnableFuncCallDepth(true)
 
 	initBinlog()