|
@@ -0,0 +1,179 @@
|
|
|
|
+package services
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "fmt"
|
|
|
|
+ "github.com/xuri/excelize/v2"
|
|
|
|
+ "hongze/hz_eta_data/models"
|
|
|
|
+ "hongze/hz_eta_data/utils"
|
|
|
|
+ "os"
|
|
|
|
+ "path/filepath"
|
|
|
|
+ "strings"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// 初始化钢联指标
|
|
|
|
+func InitMysteelIndex() {
|
|
|
|
+ var err error
|
|
|
|
+
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("InitBaseIndexData Err:" + err.Error())
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ //读取excel
|
|
|
|
+ path, err := filepath.Abs(os.Args[0])
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dir := filepath.Dir(path)
|
|
|
|
+ fmt.Println("dir:" + dir)
|
|
|
|
+ dataPath := dir + "/docs/逸诺钢联数据录入.xlsx"
|
|
|
|
+ fmt.Println("dataPath:" + dataPath)
|
|
|
|
+ f, err := excelize.OpenFile(dataPath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer func() {
|
|
|
|
+ // Close the spreadsheet.
|
|
|
|
+ if err := f.Close(); err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ rows, err := f.GetRows("Sheet1")
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ fmt.Println("rows len:", len(rows))
|
|
|
|
+ for rk, row := range rows {
|
|
|
|
+ if rk > 0 {
|
|
|
|
+ var classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source string
|
|
|
|
+ for ck, colCell := range row {
|
|
|
|
+ switch ck {
|
|
|
|
+ case 0:
|
|
|
|
+ classifyFirst = colCell
|
|
|
|
+ case 1:
|
|
|
|
+ classifySecond = colCell
|
|
|
|
+ case 2:
|
|
|
|
+ classifyThree = colCell
|
|
|
|
+ case 3:
|
|
|
|
+ indexCode = colCell
|
|
|
|
+ case 4:
|
|
|
|
+ indexName = colCell
|
|
|
|
+ case 5:
|
|
|
|
+ frequency = colCell
|
|
|
|
+ case 6:
|
|
|
|
+ unit = colCell
|
|
|
|
+ case 7:
|
|
|
|
+ source = colCell
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if classifySecond != "" &&
|
|
|
|
+ classifyThree != "" &&
|
|
|
|
+ indexCode != "" &&
|
|
|
|
+ indexName != "" &&
|
|
|
|
+ unit != "" &&
|
|
|
|
+ frequency != "" {
|
|
|
|
+
|
|
|
|
+ method := "mysteel_classify/get_or_add"
|
|
|
|
+ //classifyFirstMap := make(map[string]interface{})
|
|
|
|
+ //classifyFirstMap["ClassifyName"] = classifyFirst
|
|
|
|
+ //classifyFirstMap["ParentId"] = 0
|
|
|
|
+ //classifyFirstMap["Level"] = 0
|
|
|
|
+ //result, err := PostEdbLib(classifyFirstMap, method)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // utils.FileLog.Info("初始化分类1失败:" + err.Error())
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //
|
|
|
|
+ //resp := new(models.ClassifyResp)
|
|
|
|
+ //err = json.Unmarshal(result, &resp)
|
|
|
|
+ //if err != nil {
|
|
|
|
+ // utils.FileLog.Info("初始化分类1失败:" + err.Error())
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+ //
|
|
|
|
+ //if resp.Ret != 200 {
|
|
|
|
+ // utils.FileLog.Info("初始化分类1失败:" + resp.Msg + ";" + resp.ErrMsg)
|
|
|
|
+ // return
|
|
|
|
+ //}
|
|
|
|
+
|
|
|
|
+ classifySecondMap := make(map[string]interface{})
|
|
|
|
+ classifySecondMap["ClassifyName"] = classifySecond
|
|
|
|
+ classifySecondMap["ParentId"] = 0
|
|
|
|
+ classifySecondMap["Level"] = 0
|
|
|
|
+ result, err := PostEdbLib(classifySecondMap, method)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化分类2失败:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp := new(models.MysteelClassifyResp)
|
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化分类2失败:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if resp.Ret != 200 {
|
|
|
|
+ utils.FileLog.Info("初始化分类2失败:" + resp.Msg + ";" + resp.ErrMsg)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ classifyThreeMap := make(map[string]interface{})
|
|
|
|
+ classifyThreeMap["ClassifyName"] = classifyThree
|
|
|
|
+ classifyThreeMap["ParentId"] = resp.Data.BaseFromMysteelChemicalClassifyId
|
|
|
|
+ classifyThreeMap["Level"] = 1
|
|
|
|
+ result, err = PostEdbLib(classifyThreeMap, method)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化分类3失败:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ resp = new(models.MysteelClassifyResp)
|
|
|
|
+ err = json.Unmarshal(result, &resp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化分类3失败:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if resp.Ret != 200 {
|
|
|
|
+ utils.FileLog.Info("初始化分类3失败:" + resp.Msg + ";" + resp.ErrMsg)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ method = "mysteel_chemical/handle/mysteel/index"
|
|
|
|
+ indexMap := make(map[string]interface{})
|
|
|
|
+ indexMap["EdbCode"] = indexCode
|
|
|
|
+ indexMap["BaseFromMysteelChemicalClassifyId"] = resp.Data.BaseFromMysteelChemicalClassifyId
|
|
|
|
+ result, err = PostEdbLib(indexMap, method)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化指标失败:" + err.Error() + " result:" + string(result))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ indexResp := new(models.EdbInfoResp)
|
|
|
|
+ err = json.Unmarshal(result, &indexResp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ utils.FileLog.Info("初始化分类2失败:" + err.Error())
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if indexResp.Ret != 200 {
|
|
|
|
+ if strings.Contains(indexResp.Msg, "新增指标失败") {
|
|
|
|
+ continue
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Println("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
|
|
|
|
+ utils.FileLog.Info("初始化指标失败:" + indexResp.Msg + ";" + indexResp.ErrMsg)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fmt.Println("add index success:" + indexCode)
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Println("data is empty")
|
|
|
|
+ fmt.Println(classifyFirst, classifySecond, classifyThree, indexCode, indexName, frequency, unit, source)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|