api.go 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package services
  2. import (
  3. "eta_gn/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. }