Menu.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package controllers
  2. import (
  3. "ERP_user/Nats/NatsServer"
  4. "ERP_user/conf"
  5. "ERP_user/logs"
  6. "ERP_user/models/Account"
  7. "fmt"
  8. beego "github.com/beego/beego/v2/server/web"
  9. menulibs "gogs.baozhida.cn/zoie/ERP_libs/Menu"
  10. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  11. )
  12. type MenuController struct {
  13. beego.Controller
  14. User Account.User
  15. }
  16. func (c *MenuController) Prepare() {
  17. c.User = *Account.User_r
  18. }
  19. // 列表 -
  20. func (c *MenuController) List() {
  21. T_code := c.GetString("T_code")
  22. sysName := Account.Get_Sys_Name(T_code)
  23. if sysName == T_code {
  24. // 不存在这个code
  25. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_code Err!"}
  26. c.ServeJSON()
  27. return
  28. }
  29. var r_jsons lib.R_JSONS
  30. var menu []menulibs.Menu
  31. var err error
  32. switch T_code {
  33. case conf.ERP_ACCOUNT_Sys:
  34. menu, err = Account.Read_Menu_List()
  35. if err != nil {
  36. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取用户系统菜单失败!"}
  37. c.ServeJSON()
  38. return
  39. }
  40. default:
  41. menu, err = NatsServer.ERP_Read_Menu_List(T_code)
  42. if err != nil {
  43. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("获取%s菜单失败!", Account.Get_Sys_Name(T_code))}
  44. c.ServeJSON()
  45. return
  46. }
  47. }
  48. r_jsons.Data = menu
  49. c.Data["json"] = lib.JSONS{Code: 200, Msg: sysName + "ok!", Data: r_jsons}
  50. c.ServeJSON()
  51. return
  52. }
  53. // 列表 -
  54. func (c *MenuController) User_List() {
  55. var r_jsons lib.R_JSONS
  56. var menuList []menulibs.Menu
  57. if r, is := Account.Redis_Menu_Get(c.User.T_power); is {
  58. r_jsons.Data = r
  59. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  60. c.ServeJSON()
  61. return
  62. }
  63. power, err := Account.Read_Power_ByT_id(c.User.T_power)
  64. if err != nil {
  65. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  66. c.ServeJSON()
  67. return
  68. }
  69. menu, err := Account.Read_User_Bind_Menu_List(power.T_menu)
  70. sysName := Account.Get_Sys_Name(conf.ERP_ACCOUNT_Sys)
  71. if err != nil {
  72. logs.Error(lib.FuncName(), Account.Get_Sys_Name(conf.ERP_ACCOUNT_Sys), err)
  73. c.Data["json"] = lib.JSONS{Code: 202, Msg: sysName + "查询失败!"}
  74. c.ServeJSON()
  75. return
  76. }
  77. if len(menu) > 0 {
  78. menuList = append(menuList, menu...)
  79. }
  80. // 获取其他系统菜单
  81. for _, prefix := range Account.ERP_Sys_prefix {
  82. // Nats 发送失败 重试3次
  83. menu, err = NatsServer.ERP_Read_User_Bind_Menu_List(prefix, c.User.T_power)
  84. sysName = Account.Get_Sys_Name(prefix)
  85. if err != nil {
  86. logs.Error(lib.FuncName(), sysName, err)
  87. c.Data["json"] = lib.JSONS{Code: 202, Msg: sysName + "查询失败!"}
  88. c.ServeJSON()
  89. return
  90. }
  91. if len(menu) > 0 {
  92. menuList = append(menuList, menu...)
  93. }
  94. }
  95. if len(menuList) == 0 {
  96. c.Data["json"] = lib.JSONS{Code: 202, Msg: "该用户暂无任务菜单权限!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. r_jsons.Data = menuList
  101. Account.Redis_Munu_Set(c.User.T_power, menuList)
  102. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  103. c.ServeJSON()
  104. return
  105. }