cache_queue.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_bridge/global"
  5. "eta/eta_bridge/utils"
  6. "fmt"
  7. )
  8. // ListenSyncRole 同步角色
  9. func ListenSyncRole() {
  10. defer func() {
  11. if err := recover(); err != nil {
  12. fmt.Println("[ListenSyncRole]", err)
  13. }
  14. }()
  15. for {
  16. global.Rc.Brpop(utils.CACHE_SYNC_ROLE, func(b []byte) {
  17. var d SyncRoleData
  18. _ = json.Unmarshal(b, &d)
  19. _ = HandleSyncRole(d)
  20. })
  21. }
  22. }
  23. // ListenSyncAdmin 同步用户
  24. func ListenSyncAdmin() {
  25. defer func() {
  26. if err := recover(); err != nil {
  27. fmt.Println("[ListenSyncAdmin]", err)
  28. }
  29. }()
  30. for {
  31. global.Rc.Brpop(utils.CACHE_SYNC_ADMIN, func(b []byte) {
  32. var d SyncAdminData
  33. _ = json.Unmarshal(b, &d)
  34. _ = HandleSyncAdmin(d)
  35. })
  36. }
  37. }
  38. // ListenSyncDepartment 同步部门
  39. func ListenSyncDepartment() {
  40. defer func() {
  41. if err := recover(); err != nil {
  42. fmt.Println("[ListenSyncDepartment]", err)
  43. }
  44. }()
  45. for {
  46. global.Rc.Brpop(utils.CACHE_SYNC_DEPARTMENT, func(b []byte) {
  47. var d SyncDepartmentData
  48. _ = json.Unmarshal(b, &d)
  49. _ = HandleSyncDepartment(d)
  50. })
  51. }
  52. }
  53. // ListenSyncGroup 同步分组
  54. func ListenSyncGroup() {
  55. defer func() {
  56. if err := recover(); err != nil {
  57. fmt.Println("[ListenSyncGroup]", err)
  58. }
  59. }()
  60. for {
  61. global.Rc.Brpop(utils.CACHE_SYNC_GROUP, func(b []byte) {
  62. var d SyncGroupData
  63. _ = json.Unmarshal(b, &d)
  64. _ = HandleSyncGroup(d)
  65. })
  66. }
  67. }
  68. // ListenSyncUserEnRole 同步用户英文权限角色
  69. func ListenSyncUserEnRole() {
  70. defer func() {
  71. if err := recover(); err != nil {
  72. fmt.Println("[ListenSyncUserEnRole]", err)
  73. }
  74. }()
  75. for {
  76. global.Rc.Brpop(utils.CACHE_SYNC_USER_EN_ROLE, func(b []byte) {
  77. var d SyncAdminEnRole
  78. _ = json.Unmarshal(b, &d)
  79. fmt.Println("读到了")
  80. fmt.Println(d.AdminName)
  81. fmt.Println(d.RoleCodes)
  82. _ = HandleSyncUserEnRole(d)
  83. })
  84. }
  85. }