pb.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package proto
  2. import (
  3. "context"
  4. "encoding/json"
  5. "bet24.com/log"
  6. "bet24.com/servers/micros/common"
  7. "github.com/smallnest/rpcx/client"
  8. )
  9. const ServiceName = "userlabel"
  10. var consulAddr = common.Default_Consul_Addr
  11. func getClient() client.XClient {
  12. return common.GetClientPool().GetClient(ServiceName, consulAddr)
  13. }
  14. type Request struct {
  15. UserId int `json:",omitempty"`
  16. Name string `json:",omitempty"`
  17. IpAddress string `json:",omitempty"`
  18. }
  19. type Response struct {
  20. RetCode int
  21. Data string
  22. }
  23. func SetConsulAddr(addr string) {
  24. consulAddr = addr
  25. }
  26. func SayHello(name string) string {
  27. xclient := getClient()
  28. //defer xclient.Close()
  29. args := &Request{
  30. Name: name,
  31. }
  32. reply := &Response{}
  33. err := xclient.Call(context.Background(), "SayHello", args, reply)
  34. if err != nil {
  35. log.Debug("userLabel failed to call: %v", err)
  36. common.GetClientPool().RemoveClient(ServiceName)
  37. return ""
  38. }
  39. log.Debug("userLabel return %s", reply.Data)
  40. return reply.Data
  41. }
  42. type Request_GetLabel struct {
  43. UserId int // 用户id
  44. TypeId int // 类型id
  45. }
  46. type Response_GetLabel struct {
  47. Labels []LabelColor
  48. }
  49. type LabelColor struct {
  50. TypeId int // 类型id
  51. TypeName string // 类型名称
  52. LabelId string // 标签ID
  53. LabelName string // 标签名称
  54. Color string // 色值
  55. PoolValue int // 奖池金额
  56. }
  57. type Request_TriggerEvent struct {
  58. UserId int // 用户ID
  59. TypeId int // 类型ID
  60. Scope // 范围
  61. }
  62. // 用户标签触发事件
  63. func TriggerEvent(userId, typeId int, scope Scope) {
  64. xclient := getClient()
  65. //defer xclient.Close()
  66. args := &Request_TriggerEvent{
  67. UserId: userId,
  68. TypeId: typeId,
  69. Scope: scope,
  70. }
  71. err := xclient.Call(context.Background(), "TriggerEvent", args, nil)
  72. if err != nil {
  73. common.GetClientPool().RemoveClient(ServiceName)
  74. log.Debug("userLabel failed to call: %v", err)
  75. }
  76. return
  77. }
  78. // 获取标签列表
  79. func GetLabel(userId, typeId int) []LabelColor {
  80. xclient := getClient()
  81. //defer xclient.Close()
  82. args := &Request_GetLabel{
  83. UserId: userId,
  84. TypeId: typeId,
  85. }
  86. reply := &Response_GetLabel{}
  87. err := xclient.Call(context.Background(), "GetLabel", args, reply)
  88. if err != nil {
  89. common.GetClientPool().RemoveClient(ServiceName)
  90. log.Debug("userLabel failed to call: %v", err)
  91. }
  92. return reply.Labels
  93. }
  94. type LabelUser struct {
  95. UserId int // 用户id
  96. NickName string // 昵称
  97. TypeId int // 类型id
  98. TypeName string // 类型名称
  99. LabelId string // 标签ID
  100. LabelName string // 标签名称
  101. UpdateTime string // 更新时间
  102. }
  103. type Request_GetListByLabelId struct {
  104. LabelId int
  105. PageIndex int
  106. PageSize int
  107. }
  108. type Response_GetListByLabelId struct {
  109. RecordCount int
  110. List []LabelUser
  111. }
  112. // 获取标签列表
  113. func GetListByLabelId(labelId, pageIndex, pageSize int) string {
  114. xclient := getClient()
  115. //defer xclient.Close()
  116. args := &Request_GetListByLabelId{
  117. LabelId: labelId,
  118. PageIndex: pageIndex,
  119. PageSize: pageSize,
  120. }
  121. reply := &Response_GetListByLabelId{}
  122. err := xclient.Call(context.Background(), "GetListByLabelId", args, reply)
  123. if err != nil {
  124. common.GetClientPool().RemoveClient(ServiceName)
  125. log.Debug("userLabel failed to call: %v", err)
  126. }
  127. buf, _ := json.Marshal(reply)
  128. return string(buf)
  129. }
  130. type Response_GetConfigSimpleInfo struct {
  131. List []ConfigSimpleInfo
  132. }
  133. // 获取标签配置简单信息
  134. func GetConfigSimpleInfo() []ConfigSimpleInfo {
  135. xclient := getClient()
  136. //defer xclient.Close()
  137. args := &Request{}
  138. reply := &Response_GetConfigSimpleInfo{}
  139. err := xclient.Call(context.Background(), "GetConfigSimpleInfo", args, reply)
  140. if err != nil {
  141. common.GetClientPool().RemoveClient(ServiceName)
  142. log.Debug("userLabel failed to call: %v", err)
  143. }
  144. return reply.List
  145. }