pb.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 = "dotservice"
  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("dotservice failed to call: %v", err)
  36. common.GetClientPool().RemoveClient(ServiceName)
  37. return ""
  38. }
  39. //log.Debug("dotservice return %s", reply.Data)
  40. return reply.Data
  41. }
  42. type Request_AddDot struct {
  43. UserId int // 用户id
  44. DotScope // 范围
  45. }
  46. // 添加打点
  47. func AddDot(userId int, scope DotScope) {
  48. xclient := getClient()
  49. //defer xclient.Close()
  50. args := &Request_AddDot{
  51. UserId: userId,
  52. DotScope: scope,
  53. }
  54. reply := &Response{}
  55. err := xclient.Call(context.Background(), "AddDot", args, reply)
  56. if err != nil {
  57. log.Debug("dotservice failed to call: %v", err)
  58. common.GetClientPool().RemoveClient(ServiceName)
  59. return
  60. }
  61. //log.Debug("dotservice return %s", reply.Data)
  62. return
  63. }
  64. type Request_List struct {
  65. BeginTime string // 开始时间
  66. EndTime string // 截止时间
  67. Event string // 事件
  68. }
  69. type Response_StatList struct {
  70. RecordCount int
  71. List interface{}
  72. }
  73. // 获取打点统计
  74. func GetStatList(beginTime, endTime, event string) string {
  75. xclient := getClient()
  76. //defer xclient.Close()
  77. args := &Request_List{
  78. BeginTime: beginTime,
  79. EndTime: endTime,
  80. Event: event,
  81. }
  82. reply := &Response_StatList{}
  83. err := xclient.Call(context.Background(), "GetStatList", args, reply)
  84. if err != nil {
  85. log.Debug("dotservice failed to call: %v", err)
  86. common.GetClientPool().RemoveClient(ServiceName)
  87. }
  88. buf, _ := json.Marshal(reply)
  89. return string(buf)
  90. }
  91. // 获取打点任务统计
  92. func GetTaskStatList(beginTime, endTime string) string {
  93. xclient := getClient()
  94. //defer xclient.Close()
  95. args := &Request_List{
  96. BeginTime: beginTime,
  97. EndTime: endTime,
  98. }
  99. reply := &Response_StatList{}
  100. err := xclient.Call(context.Background(), "GetTaskStatList", args, reply)
  101. if err != nil {
  102. log.Debug("dotservice failed to call: %v", err)
  103. common.GetClientPool().RemoveClient(ServiceName)
  104. }
  105. buf, _ := json.Marshal(reply)
  106. return string(buf)
  107. }
  108. // 打点列表
  109. func GetConfigListNotTask() string {
  110. xclient := getClient()
  111. //defer xclient.Close()
  112. args := &Request{}
  113. reply := &Response_StatList{}
  114. err := xclient.Call(context.Background(), "GetConfigListNotTask", args, reply)
  115. if err != nil {
  116. log.Debug("dotservice failed to call: %v", err)
  117. common.GetClientPool().RemoveClient(ServiceName)
  118. }
  119. buf, _ := json.Marshal(reply)
  120. return string(buf)
  121. }