api.go 875 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package services
  2. import (
  3. "eta/eta_api/models"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. )
  8. func ApiFix() {
  9. //拿到所有的api遍历
  10. list, err := models.GetApiUriTest()
  11. if err != nil {
  12. return
  13. }
  14. apiMap := make(map[int]string, 0)
  15. for _, v := range list {
  16. menuIds := strings.Split(v.MenuId,",")
  17. for _, menuIdStr := range menuIds {
  18. if menuIdStr != "" {
  19. menuId, err := strconv.Atoi(menuIdStr)
  20. if err != nil {
  21. fmt.Println("strconv err:" + err.Error())
  22. return
  23. }
  24. if apis, ok := apiMap[menuId]; ok {
  25. apiMap[menuId] = apis + "&" +v.ApiUri
  26. } else {
  27. apiMap[menuId] = v.ApiUri
  28. }
  29. }
  30. }
  31. }
  32. fmt.Println(apiMap)
  33. //修改每一个按钮的值
  34. for menuId, api := range apiMap {
  35. fmt.Println(menuId, api)
  36. err := models.UpdateApiUriTest(api, menuId)
  37. if err!= nil {
  38. fmt.Println("update err:" + err.Error())
  39. return
  40. }
  41. }
  42. }