package services import ( "eta_gn/eta_api/models" "eta_gn/eta_api/services/data" "eta_gn/eta_api/utils" "fmt" "strconv" "strings" ) func Task() { fmt.Println("task start") //手工数据表格导入后的指标库刷新 go ImportManualDataRefresh() // 指标刷新 go data.HandleEdbRefreshQueue() // 进行指标替换操作 go DealReplaceEdbCache() // 修复分类LevelPath //FixClassifyLevelPath() fmt.Println("task end") } // ImportManualDataRefresh 导入手工数据后的刷新 func ImportManualDataRefresh() { defer func() { if err := recover(); err != nil { fmt.Println("[ImportManualDataRefresh]", err) } }() for { utils.Rc.Brpop(utils.CACHE_IMPORT_MANUAL_DATA, func(b []byte) { edbCode := string(b) edbCode = strings.TrimPrefix(edbCode, `"`) edbCode = strings.TrimSuffix(edbCode, `"`) data.RefreshManualData(edbCode) }) } } func FixClassifyLevelPath() { var err error defer func() { if err != nil { fmt.Println(err) } }() classifyOb := new(models.Classify) classifies, e := classifyOb.GetItemsByCondition("", []interface{}{}, []string{}, "") if e != nil { err = fmt.Errorf("获取分类列表失败, %v", e) return } fmt.Println("开始修复") // 先更新所有一级分类 for _, v := range classifies { if v.ParentId > 0 { continue } v.LevelPath = strconv.Itoa(v.Id) if e = v.UpdateClassify([]string{"LevelPath"}); e != nil { err = fmt.Errorf("更新LevelPath失败, ID: %d", v.Id) return } } // 再更新二级 parentMap := make(map[int]string) for _, v := range classifies { if v.Level != 2 { continue } v.LevelPath = fmt.Sprintf("%d,%d", v.ParentId, v.Id) if e = v.UpdateClassify([]string{"LevelPath"}); e != nil { err = fmt.Errorf("更新二级LevelPath失败, ID: %d", v.Id) return } parentMap[v.Id] = v.LevelPath } // 再更新三级,没四级了 for _, v := range classifies { if v.Level != 3 { continue } str := parentMap[v.ParentId] if str == "" { err = fmt.Errorf("二级LevelPath为空, ID: %d", v.ParentId) return } v.LevelPath = fmt.Sprintf("%s,%d", str, v.Id) if e = v.UpdateClassify([]string{"LevelPath"}); e != nil { err = fmt.Errorf("更新三级LevelPath失败, ID: %d", v.Id) return } } fmt.Println("修复成功") }