123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package controllers
- import (
- "ERP_user/Nats/NatsServer"
- "ERP_user/conf"
- "ERP_user/logs"
- "ERP_user/models/Account"
- "fmt"
- beego "github.com/beego/beego/v2/server/web"
- menulibs "gogs.baozhida.cn/zoie/ERP_libs/Menu"
- "gogs.baozhida.cn/zoie/ERP_libs/lib"
- )
- type MenuController struct {
- beego.Controller
- User Account.User
- }
- func (c *MenuController) Prepare() {
- c.User = *Account.User_r
- }
- // 列表 -
- func (c *MenuController) List() {
- T_code := c.GetString("T_code")
- sysName := Account.Get_Sys_Name(T_code)
- if sysName == T_code {
- // 不存在这个code
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_code Err!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- var menu []menulibs.Menu
- var err error
- switch T_code {
- case conf.ERP_ACCOUNT_Sys:
- menu, err = Account.Read_Menu_List()
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取用户系统菜单失败!"}
- c.ServeJSON()
- return
- }
- default:
- menu, err = NatsServer.ERP_Read_Menu_List(T_code)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("获取%s菜单失败!", Account.Get_Sys_Name(T_code))}
- c.ServeJSON()
- return
- }
- }
- r_jsons.Data = menu
- c.Data["json"] = lib.JSONS{Code: 200, Msg: sysName + "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *MenuController) User_List() {
- var r_jsons lib.R_JSONS
- var menuList []menulibs.Menu
- if r, is := Account.Redis_Menu_Get(c.User.T_power); is {
- r_jsons.Data = r
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- power, err := Account.Read_Power_ByT_id(c.User.T_power)
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
- c.ServeJSON()
- return
- }
- menu, err := Account.Read_User_Bind_Menu_List(power.T_menu)
- sysName := Account.Get_Sys_Name(conf.ERP_ACCOUNT_Sys)
- if err != nil {
- logs.Error(lib.FuncName(), Account.Get_Sys_Name(conf.ERP_ACCOUNT_Sys), err)
- c.Data["json"] = lib.JSONS{Code: 202, Msg: sysName + "查询失败!"}
- c.ServeJSON()
- return
- }
- if len(menu) > 0 {
- menuList = append(menuList, menu...)
- }
- // 获取其他系统菜单
- for _, prefix := range Account.ERP_Sys_prefix {
- // Nats 发送失败 重试3次
- menu, err = NatsServer.ERP_Read_User_Bind_Menu_List(prefix, c.User.T_power)
- sysName = Account.Get_Sys_Name(prefix)
- if err != nil {
- logs.Error(lib.FuncName(), sysName, err)
- c.Data["json"] = lib.JSONS{Code: 202, Msg: sysName + "查询失败!"}
- c.ServeJSON()
- return
- }
- if len(menu) > 0 {
- menuList = append(menuList, menu...)
- }
- }
- if len(menuList) == 0 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "该用户暂无任务菜单权限!"}
- c.ServeJSON()
- return
- }
- r_jsons.Data = menuList
- Account.Redis_Munu_Set(c.User.T_power, menuList)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
|