package middleground import ( "app.yhyue.com/moapp/jybase/common" "context" "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/datasmt" "jygit.jydev.jianyu360.cn/ApplicationCenter/publicService/rpc/pb" "log" "github.com/zeromicro/go-zero/core/discov" "github.com/zeromicro/go-zero/zrpc" ) type publicService struct { hosts []string key string client zrpc.Client } func newPublicservice(hosts []string, key string) *publicService { r := &publicService{ hosts: hosts, key: key, } r.client = r.NewClient() return r } func (u *publicService) NewClient() zrpc.Client { if u.client != nil && u.client.Conn() != nil { return u.client } client, err := zrpc.NewClient(zrpc.RpcClientConf{ Etcd: discov.EtcdConf{ Hosts: u.hosts, Key: u.key, }, }) if err != nil { log.Println(err) return nil } u.client = client return client } // 列表数据处理 func (p *publicService) List(searchValue, dataType string, pageNum, pageSize int64) map[string]interface{} { client := p.NewClient() if client == nil { return nil } resp, err := datasmt.NewDatasmt(client).List(context.Background(), &pb.DatasmtReqList{ SearchValue: searchValue, DataType: dataType, PageNum: pageNum, PageSize: pageSize, }) if err != nil { log.Println(err) return nil } result := map[string]interface{}{} result["PageCount"] = resp.PageCount arr := []map[string]interface{}{} for _, v := range resp.List { arr = append(arr, map[string]interface{}{ "id": v.Id, "name": v.Name, "format": v.Format, "clearStatus": v.ClearStatus, "clearStatusStr": common.If(v.ClearStatus == "0", "", "人工清洗"), "dataType": v.DataType, }) } result["list"] = arr result["fieldIllustrate"] = resp.FieldIllustrate result["hotKeys"] = resp.HotKeys result["searchValue"] = searchValue result["dataTypeStr"] = resp.DataTypeStr return result } func (p *publicService) Detail(id string) map[string]interface{} { client := p.NewClient() if client == nil { return nil } resp, err := datasmt.NewDatasmt(client).Detail(context.Background(), &pb.DatasmtReqDetail{ Id: id}) if err != nil { log.Println(err) return nil } result := map[string]interface{}{} result["name"] = resp.Name result["dataType"] = resp.FieldIllustrate.Name result["describe"] = resp.FieldIllustrate.Describe result["clearStatusStr"] = common.If(resp.ClearStatus == "0", "", "人工清洗") result["clearStatus"] = resp.ClearStatus result["dataExample"] = resp.DataExample result["introduce"] = resp.Introduce result["format"] = resp.Format result["keyword"] = resp.Keyword result["application"] = resp.FieldIllustrate.Application return result }