task.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package services
  2. import (
  3. "fmt"
  4. )
  5. func Task() {
  6. fmt.Println("task start")
  7. //手工数据表格导入后的指标库刷新
  8. // go ImportManualDataRefresh()
  9. // // 指标刷新
  10. // go data.HandleEdbRefreshQueue()
  11. // // 进行指标替换操作
  12. // go DealReplaceEdbCache()
  13. // 修复分类LevelPath
  14. //FixClassifyLevelPath()
  15. fmt.Println("task end")
  16. }
  17. // // ImportManualDataRefresh 导入手工数据后的刷新
  18. // func ImportManualDataRefresh() {
  19. // defer func() {
  20. // if err := recover(); err != nil {
  21. // fmt.Println("[ImportManualDataRefresh]", err)
  22. // }
  23. // }()
  24. // for {
  25. // utils.Rc.Brpop(utils.CACHE_IMPORT_MANUAL_DATA, func(b []byte) {
  26. // edbCode := string(b)
  27. // edbCode = strings.TrimPrefix(edbCode, `"`)
  28. // edbCode = strings.TrimSuffix(edbCode, `"`)
  29. // data.RefreshManualData(edbCode)
  30. // })
  31. // }
  32. // }
  33. // func FixClassifyLevelPath() {
  34. // var err error
  35. // defer func() {
  36. // if err != nil {
  37. // fmt.Println(err)
  38. // }
  39. // }()
  40. // classifyOb := new(models.Classify)
  41. // classifies, e := classifyOb.GetItemsByCondition("", []interface{}{}, []string{}, "")
  42. // if e != nil {
  43. // err = fmt.Errorf("获取分类列表失败, %v", e)
  44. // return
  45. // }
  46. // fmt.Println("开始修复")
  47. // // 先更新所有一级分类
  48. // for _, v := range classifies {
  49. // if v.ParentId > 0 {
  50. // continue
  51. // }
  52. // v.LevelPath = strconv.Itoa(v.Id)
  53. // if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
  54. // err = fmt.Errorf("更新LevelPath失败, ID: %d", v.Id)
  55. // return
  56. // }
  57. // }
  58. // // 再更新二级
  59. // parentMap := make(map[int]string)
  60. // for _, v := range classifies {
  61. // if v.Level != 2 {
  62. // continue
  63. // }
  64. // v.LevelPath = fmt.Sprintf("%d,%d", v.ParentId, v.Id)
  65. // if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
  66. // err = fmt.Errorf("更新二级LevelPath失败, ID: %d", v.Id)
  67. // return
  68. // }
  69. // parentMap[v.Id] = v.LevelPath
  70. // }
  71. // // 再更新三级,没四级了
  72. // for _, v := range classifies {
  73. // if v.Level != 3 {
  74. // continue
  75. // }
  76. // str := parentMap[v.ParentId]
  77. // if str == "" {
  78. // err = fmt.Errorf("二级LevelPath为空, ID: %d", v.ParentId)
  79. // return
  80. // }
  81. // v.LevelPath = fmt.Sprintf("%s,%d", str, v.Id)
  82. // if e = v.UpdateClassify([]string{"LevelPath"}); e != nil {
  83. // err = fmt.Errorf("更新三级LevelPath失败, ID: %d", v.Id)
  84. // return
  85. // }
  86. // }
  87. // fmt.Println("修复成功")
  88. // }