publicservice.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package middleground
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/datasmt"
  6. "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/pb"
  7. "log"
  8. "github.com/zeromicro/go-zero/core/discov"
  9. "github.com/zeromicro/go-zero/zrpc"
  10. )
  11. type publicService struct {
  12. hosts []string
  13. key string
  14. client zrpc.Client
  15. }
  16. func newPublicservice(hosts []string, key string) *publicService {
  17. r := &publicService{
  18. hosts: hosts,
  19. key: key,
  20. }
  21. r.client = r.NewClient()
  22. return r
  23. }
  24. func (u *publicService) NewClient() zrpc.Client {
  25. if u.client != nil && u.client.Conn() != nil {
  26. return u.client
  27. }
  28. client, err := zrpc.NewClient(zrpc.RpcClientConf{
  29. Etcd: discov.EtcdConf{
  30. Hosts: u.hosts,
  31. Key: u.key,
  32. },
  33. })
  34. if err != nil {
  35. log.Println(err)
  36. return nil
  37. }
  38. u.client = client
  39. return client
  40. }
  41. // 列表数据处理
  42. func (p *publicService) List(searchValue, dataType string, pageNum, pageSize int64) map[string]interface{} {
  43. client := p.NewClient()
  44. if client == nil {
  45. return nil
  46. }
  47. resp, err := datasmt.NewDatasmt(client).List(context.Background(), &pb.DatasmtReqList{
  48. SearchValue: searchValue,
  49. DataType: dataType,
  50. PageNum: pageNum,
  51. PageSize: pageSize,
  52. })
  53. if err != nil {
  54. log.Println(err)
  55. return nil
  56. }
  57. result := map[string]interface{}{}
  58. result["PageCount"] = resp.PageCount
  59. arr := []map[string]interface{}{}
  60. for _, v := range resp.List {
  61. arr = append(arr, map[string]interface{}{
  62. "id": v.Id,
  63. "name": v.Name,
  64. "format": v.Format,
  65. "clearStatus": v.ClearStatus,
  66. "clearStatusStr": common.If(v.ClearStatus == "0", "", "人工清洗"),
  67. "dataType": v.DataType,
  68. })
  69. }
  70. result["list"] = arr
  71. result["fieldIllustrate"] = resp.FieldIllustrate
  72. result["hotKeys"] = resp.HotKeys
  73. result["searchValue"] = searchValue
  74. result["dataTypeStr"] = resp.DataTypeStr
  75. return result
  76. }
  77. func (p *publicService) Detail(id string) map[string]interface{} {
  78. client := p.NewClient()
  79. if client == nil {
  80. return nil
  81. }
  82. resp, err := datasmt.NewDatasmt(client).Detail(context.Background(), &pb.DatasmtReqDetail{
  83. Id: id})
  84. if err != nil {
  85. log.Println(err)
  86. return nil
  87. }
  88. result := map[string]interface{}{}
  89. result["name"] = resp.Name
  90. result["dataType"] = resp.FieldIllustrate.Name
  91. result["describe"] = resp.FieldIllustrate.Describe
  92. result["clearStatusStr"] = common.If(resp.ClearStatus == "0", "", "人工清洗")
  93. result["clearStatus"] = resp.ClearStatus
  94. result["dataExample"] = resp.DataExample
  95. result["introduce"] = resp.Introduce
  96. result["format"] = resp.Format
  97. result["keyword"] = resp.Keyword
  98. result["application"] = resp.FieldIllustrate.Application
  99. return result
  100. }