NatsERP_user.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package NatsServer
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "github.com/vmihailenco/msgpack/v5"
  6. powerlibs "gogs.baozhida.cn/zoie/ERP_libs/Power"
  7. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  8. "time"
  9. )
  10. // 验证TOKEY
  11. func (m *NatsImpl) Verification(GetCookie string, GetString string) (userlibs.User, error) {
  12. var user userlibs.User
  13. User_tokey := GetCookie
  14. if len(User_tokey) == 0 {
  15. User_tokey = GetString
  16. }
  17. if len(User_tokey) == 0 {
  18. return user, errors.New("user tokey is null")
  19. }
  20. // 请求-响应, 向 verification 发布一个 `ToKey` 请求数据,设置超时间3秒,如果有多个响应,只接收第一个收到的消息
  21. msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_verification", []byte(User_tokey), 3*time.Second)
  22. if err != nil {
  23. return user, err
  24. }
  25. type T_R struct {
  26. Code int16 `xml:"Code"`
  27. Msg string `xml:"Msg"`
  28. Data userlibs.User `xml:"Data"` // 泛型
  29. }
  30. var t_R T_R
  31. err = msgpack.Unmarshal(msg.Data, &t_R)
  32. if err != nil {
  33. return user, err
  34. }
  35. if t_R.Code != 200 {
  36. return user, errors.New(t_R.Msg)
  37. }
  38. return t_R.Data, nil
  39. }
  40. func (m *NatsImpl) Read_User_List_All() (list []userlibs.User, err error) {
  41. msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_User_List_All", []byte(""), 3*time.Second)
  42. if err != nil {
  43. return list, err
  44. }
  45. type T_R struct {
  46. Code int16 `xml:"Code"`
  47. Msg string `xml:"Msg"`
  48. Data []userlibs.User `xml:"Data"`
  49. }
  50. var t_R T_R
  51. err = msgpack.Unmarshal(msg.Data, &t_R)
  52. if err != nil {
  53. return list, err
  54. }
  55. if t_R.Code != 200 {
  56. return list, errors.New(t_R.Msg)
  57. }
  58. return t_R.Data, nil
  59. }
  60. func (m *NatsImpl) Read_User_List_T_uuid(T_name string, T_uuid_list []string, page, page_z int) (list []userlibs.User, cnt int64, err error) {
  61. type T_S struct {
  62. T_uuid []string
  63. T_name string
  64. Page int
  65. Page_z int
  66. }
  67. b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid_list, T_name: T_name, Page: page, Page_z: page_z})
  68. msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_User_List_T_uuid", b, 3*time.Second)
  69. if err != nil {
  70. return list, cnt, err
  71. }
  72. type T_R struct {
  73. Code int16 `xml:"Code"`
  74. Msg string `xml:"Msg"`
  75. Data []userlibs.User `xml:"Data"`
  76. Num int64 `xml:"Num"`
  77. }
  78. var t_R T_R
  79. err = msgpack.Unmarshal(msg.Data, &t_R)
  80. if err != nil {
  81. return list, cnt, err
  82. }
  83. if t_R.Code != 200 {
  84. return list, cnt, errors.New(t_R.Msg)
  85. }
  86. return t_R.Data, t_R.Num, nil
  87. }
  88. func (m *NatsImpl) Read_Power_List_All() (list []powerlibs.Power_R, err error) {
  89. msg, err := m.nats.Request(m.NatsSubj_Prefix+"ERP_User_Read_Power_List_All", []byte(""), 3*time.Second)
  90. if err != nil {
  91. return list, err
  92. }
  93. type T_R struct {
  94. Code int16 `xml:"Code"`
  95. Msg string `xml:"Msg"`
  96. Data []powerlibs.Power_R `xml:"Data"` // 泛型
  97. }
  98. var t_R T_R
  99. err = msgpack.Unmarshal(msg.Data, &t_R)
  100. if err != nil {
  101. return list, err
  102. }
  103. if t_R.Code != 200 {
  104. return list, errors.New(t_R.Msg)
  105. }
  106. return t_R.Data, nil
  107. }
  108. // 添加系统日志
  109. func (m *NatsImpl) AddSysLogs(T_class, T_title string, T_txt interface{}) {
  110. jsonStu, _ := json.Marshal(T_txt)
  111. type T_S struct {
  112. T_class string
  113. T_title string
  114. T_txt string
  115. }
  116. b, _ := msgpack.Marshal(&T_S{T_class: T_class, T_title: T_title, T_txt: string(jsonStu)})
  117. // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据
  118. _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddSysLogs", b)
  119. }
  120. // 添加用户日志
  121. func (m *NatsImpl) AddUserLogs(T_uuid, T_class, T_title string, T_txt interface{}) {
  122. jsonStu, _ := json.Marshal(T_txt)
  123. type T_S struct {
  124. T_uuid string
  125. T_class string
  126. T_title string
  127. T_txt string
  128. }
  129. b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid, T_class: T_class, T_title: T_title, T_txt: string(jsonStu)})
  130. // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据
  131. _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddUserLogs", b)
  132. }
  133. // 添加用户日志
  134. func (m *NatsImpl) AddNews(T_uuid, T_title, T_Url string) {
  135. type T_S struct {
  136. T_uuid string
  137. T_Title string
  138. T_Url string
  139. }
  140. b, _ := msgpack.Marshal(&T_S{T_uuid: T_uuid, T_Title: T_title, T_Url: T_Url})
  141. // 发布-订阅 模式,向 test1 发布一个 `Hello World` 数据
  142. _ = m.nats.Publish(m.NatsSubj_Prefix+"ERP_AddNews", b)
  143. }