powercheckcenter.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package middleground
  2. import (
  3. "context"
  4. "log"
  5. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
  6. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/powercheck"
  7. "github.com/zeromicro/go-zero/core/discov"
  8. "github.com/zeromicro/go-zero/zrpc"
  9. )
  10. type powerCheckCenter struct {
  11. hosts []string
  12. key string
  13. client zrpc.Client
  14. }
  15. func newPowerCheckCenter(hosts []string, key string) *powerCheckCenter {
  16. r := &powerCheckCenter{
  17. hosts: hosts,
  18. key: key,
  19. }
  20. r.client = r.NewClient()
  21. return r
  22. }
  23. func (p *powerCheckCenter) NewClient() zrpc.Client {
  24. if p.client != nil && p.client.Conn() != nil {
  25. return p.client
  26. }
  27. client, err := zrpc.NewClient(zrpc.RpcClientConf{
  28. Etcd: discov.EtcdConf{
  29. Hosts: p.hosts,
  30. Key: p.key,
  31. },
  32. })
  33. if err != nil {
  34. log.Println(err)
  35. return nil
  36. }
  37. p.client = client
  38. return client
  39. }
  40. func (p *powerCheckCenter) Check(appid, userId string, baseUserId, accountId, entId, positionType, positionId int64) *pb.CheckResp {
  41. client := p.NewClient()
  42. if client == nil {
  43. return nil
  44. }
  45. //defer client.Conn().Close()
  46. resp, err := powercheck.NewPowerCheck(client).Check(context.Background(), &pb.CheckReq{
  47. Appid: appid,
  48. Userid: userId,
  49. BaseUserId: baseUserId,
  50. AccountId: accountId,
  51. EntId: entId,
  52. PositionType: positionType,
  53. PositionId: positionId,
  54. })
  55. if err != nil {
  56. log.Println(err)
  57. return nil
  58. }
  59. return resp
  60. }
  61. func (p *powerCheckCenter) DelCheckRedis(appid string, positionId int64) *pb.PowerCheckResp {
  62. client := p.NewClient()
  63. if client == nil {
  64. return nil
  65. }
  66. //defer client.Conn().Close()
  67. resp, err := powercheck.NewPowerCheck(client).DelCheckRedis(context.Background(), &pb.CheckReq{
  68. Appid: appid,
  69. PositionId: positionId,
  70. })
  71. if err != nil {
  72. log.Println(err)
  73. return nil
  74. }
  75. return resp
  76. }