hz_edb_classify.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package services
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. const (
  7. MethodClassifyReset = "edb_info/classify_reset"
  8. )
  9. func ResetHzEdbClassify() {
  10. fmt.Println("start ResetHzEdbClassify")
  11. for _, v := range []string{"ETA基础指标0821整理", "ETA计算指标0821整理"} {
  12. time.Sleep(5 * time.Second)
  13. ResetEdbClassify(v)
  14. }
  15. fmt.Println("end ResetHzEdbClassify")
  16. }
  17. // ResetEdbClassify 重置指标分类
  18. func ResetEdbClassify(fileName string) {
  19. /*var err error
  20. defer func() {
  21. if err != nil {
  22. fmt.Println("ResetBaseEdbAndClassify Err: " + err.Error())
  23. }
  24. }()
  25. path, e := filepath.Abs(os.Args[0])
  26. if e != nil {
  27. err = fmt.Errorf("path abs err: %s", e.Error())
  28. return
  29. }
  30. dir := filepath.Dir(path)
  31. //dataPath := dir + "/docs/ETA计算指标0821整理.xlsx"
  32. dataPath := fmt.Sprintf("%s/docs/%s.xlsx", dir, fileName)
  33. fmt.Println("dataPath:" + dataPath)
  34. f, e := excelize.OpenFile(dataPath)
  35. if e != nil {
  36. err = fmt.Errorf("open file err: %s", e.Error())
  37. return
  38. }
  39. defer func() {
  40. if e = f.Close(); e != nil {
  41. fmt.Println("file close err: " + e.Error())
  42. }
  43. }()
  44. rows, e := f.GetRows("Sheet1")
  45. if e != nil {
  46. err = fmt.Errorf("get rows err: %s", e.Error())
  47. return
  48. }
  49. if len(rows) == 0 {
  50. err = fmt.Errorf("empty rows")
  51. return
  52. }
  53. // 读取行
  54. utils.FileLog.Info("开始初始化")
  55. for rk, row := range rows {
  56. if rk == 0 {
  57. continue
  58. }
  59. var indexCode, classifyFirst, classifySecond, classifyThird string
  60. // 读取单元格
  61. for ck, cell := range row {
  62. switch ck {
  63. case 2:
  64. indexCode = strings.TrimSpace(cell)
  65. case 7:
  66. classifyFirst = strings.TrimSpace(cell)
  67. case 8:
  68. classifySecond = strings.TrimSpace(cell)
  69. case 9:
  70. classifyThird = strings.TrimSpace(cell)
  71. }
  72. }
  73. if indexCode == "" || classifyFirst == "" || classifySecond == "" || classifyThird == "" {
  74. utils.FileLog.Info("忽略第%d行, IndexCode: %s, ClassifyFirst: %s, ClassifySecond: %s, ClassifyThird: %s", rk+1, indexCode, classifyFirst, classifySecond, classifyThird)
  75. continue
  76. }
  77. utils.FileLog.Info("第%d行, IndexCode: %s", rk+1, indexCode)
  78. params := make(map[string]interface{})
  79. params["IndexCode"] = indexCode
  80. params["ClassifyFirst"] = classifyFirst
  81. params["ClassifySecond"] = classifySecond
  82. params["ClassifyThird"] = classifyThird
  83. result, e := PostEdbLib(params, MethodClassifyReset)
  84. if e != nil {
  85. b, _ := json.Marshal(params)
  86. utils.FileLog.Info("重置指标分类失败, err: %s, params: %s", e.Error(), string(b))
  87. return
  88. }
  89. resp := new(models.EdbInfoResp)
  90. if e := json.Unmarshal(result, &resp); e != nil {
  91. utils.FileLog.Info("MethodClassifyReset Unmarshal err: %s", e.Error())
  92. return
  93. }
  94. if resp.Ret != 200 {
  95. utils.FileLog.Info("重置指标分类失败, Msg: %s, ErrMsg: %s", resp.Msg, resp.ErrMsg)
  96. continue
  97. }
  98. }
  99. utils.FileLog.Info("初始化结束")*/
  100. }