Power.go 844 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package controllers
  2. import (
  3. "ERP_project/Nats/NatsServer"
  4. "github.com/beego/beego/v2/adapter/orm"
  5. powerlibs "gogs.baozhida.cn/zoie/ERP_libs/Power"
  6. )
  7. // 检查角色是否与User一致,不存在则添加
  8. func CheckPowerUniformity() {
  9. o := orm.NewOrm()
  10. // 也可以直接使用 Model 结构体作为表名
  11. powerDao := powerlibs.NewPower(o)
  12. userPowerList, _ := NatsServer.Read_Power_List_All()
  13. powerList, _ := powerDao.Read_Power_List("", 0, 9999)
  14. if len(userPowerList) == len(powerList) {
  15. return
  16. }
  17. powerMap := make(map[string]string)
  18. for _, r := range powerList {
  19. powerMap[r.T_id] = r.T_name
  20. }
  21. for _, r := range userPowerList {
  22. _, ok := powerMap[r.T_id]
  23. if !ok {
  24. p := powerlibs.Power{
  25. T_id: r.T_id,
  26. T_name: r.T_name,
  27. }
  28. if r.T_menu == "*" {
  29. p.T_menu = "*"
  30. }
  31. powerDao.Add_Power(p)
  32. }
  33. }
  34. }