package services import ( "eta/eta_api/models" "fmt" "strconv" "strings" ) func ApiFix() { //拿到所有的api遍历 list, err := models.GetApiUriTest() if err != nil { return } apiMap := make(map[int]string, 0) for _, v := range list { menuIds := strings.Split(v.MenuId,",") for _, menuIdStr := range menuIds { if menuIdStr != "" { menuId, err := strconv.Atoi(menuIdStr) if err != nil { fmt.Println("strconv err:" + err.Error()) return } if apis, ok := apiMap[menuId]; ok { apiMap[menuId] = apis + "&" +v.ApiUri } else { apiMap[menuId] = v.ApiUri } } } } fmt.Println(apiMap) //修改每一个按钮的值 for menuId, api := range apiMap { fmt.Println(menuId, api) err := models.UpdateApiUriTest(api, menuId) if err!= nil { fmt.Println("update err:" + err.Error()) return } } }