Menu.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package Account
  2. import (
  3. "ERP_ams/conf"
  4. "ERP_ams/logs"
  5. "fmt"
  6. menulibs "git.baozhida.cn/ERP_libs/Menu"
  7. "git.baozhida.cn/ERP_libs/lib"
  8. "github.com/astaxie/beego/cache"
  9. _ "github.com/astaxie/beego/cache/redis"
  10. "github.com/beego/beego/v2/adapter/orm"
  11. )
  12. var RedisCache_API cache.Cache
  13. func init() {
  14. orm.RegisterModel(new(menulibs.Menu))
  15. orm.RegisterModel(new(menulibs.API))
  16. var err error
  17. apiConfig := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
  18. "redis_ERP_AMS_API", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
  19. fmt.Println(apiConfig)
  20. RedisCache_API, err = cache.NewCache("redis", apiConfig)
  21. if err != nil || RedisCache_API == nil {
  22. errMsg := "failed to init redis api"
  23. logs.Error(errMsg, err)
  24. panic(errMsg)
  25. }
  26. }
  27. // 获取列表
  28. func Read_API_List_ByPower(T_power_id string, Menu_Bind string) (maps []menulibs.API) {
  29. if len(Menu_Bind) == 0 {
  30. return
  31. }
  32. o := orm.NewOrm()
  33. APIDao := menulibs.NewAPI(o, RedisCache_API)
  34. maps, err := APIDao.Read_API_List_ByPower(T_power_id, Menu_Bind)
  35. if err != nil {
  36. logs.Error(lib.FuncName(), err)
  37. return
  38. }
  39. return maps
  40. }