123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package v1
- import (
- "context"
- "strconv"
- "google.golang.org/grpc/status"
- v1pb "go-common/app/admin/live/live-admin/api/http/v1"
- "go-common/app/admin/live/live-admin/conf"
- client "go-common/app/service/live/resource/api/grpc/v1"
- "go-common/library/ecode"
- )
- // GaeaService struct
- type GaeaService struct {
- conf *conf.Config
- client *client.Client
- // optionally add other properties here, such as dao
- // dao *dao.Dao
- }
- //NewGaeaService init
- func NewGaeaService(c *conf.Config) (s *GaeaService) {
- s = &GaeaService{
- conf: c,
- }
- s.client, _ = client.NewClient(c.ResourceClient)
- return s
- }
- // GetConfigByKeyword implementation
- // 获取team下某个keyword的配置 `internal:"true"`
- func (s *GaeaService) GetConfigByKeyword(ctx context.Context, req *v1pb.GetConfigReq) (resp *v1pb.GetConfigResp, err error) {
- resp = &v1pb.GetConfigResp{}
- if "" == req.GetKeyword() || 0 == req.GetTeam() {
- err = ecode.Error(1, "参数错误")
- return
- }
- ret, err := s.client.GetConfigByKeyword(ctx, &client.GetConfigReq{
- Team: req.GetTeam(),
- Keyword: req.GetKeyword(),
- })
- if err != nil {
- return
- }
- resp.Team = ret.Team
- resp.Keyword = ret.Keyword
- resp.Name = ret.Name
- resp.Value = ret.Value
- resp.Ctime = ret.Ctime
- resp.Mtime = ret.Mtime
- resp.Status = ret.Status
- resp.Id = ret.Id
- return
- }
- // SetConfigByKeyword implementation
- // 设置team下某个keyword配置 `internal:"true"`
- func (s *GaeaService) SetConfigByKeyword(ctx context.Context, req *v1pb.SetConfigReq) (resp *v1pb.SetConfigResp, err error) {
- resp = &v1pb.SetConfigResp{}
- if "" == req.GetKeyword() || len(req.GetKeyword()) > 16 {
- err = ecode.Error(1, "参数错误")
- return
- }
- ret, err := s.client.SetConfigByKeyword(ctx, &client.SetConfigReq{
- Team: req.GetTeam(),
- Keyword: req.GetKeyword(),
- Value: req.GetValue(),
- Name: req.GetName(),
- Id: req.GetId(),
- Status: req.GetStatus(),
- })
- if err != nil {
- return
- }
- resp.Id = ret.Id
- return
- }
- // GetConfigsByParams implementation
- // 管理后台根据条件获取配置 `internal:"true"`
- func (s *GaeaService) GetConfigsByParams(ctx context.Context, req *v1pb.ParamsConfigReq) (resp *v1pb.ParamsConfigResp, err error) {
- resp = &v1pb.ParamsConfigResp{}
- clientResp, err := s.client.GetConfigsByParams(ctx, &client.ParamsConfigReq{
- Team: req.GetTeam(),
- Keyword: req.GetKeyword(),
- Name: req.GetName(),
- Status: req.GetStatus(),
- Page: req.GetPage(),
- PageSize: req.GetPageSize(),
- Id: req.GetId(),
- })
- resp.TotalNum = clientResp.TotalNum
- resp.List = []*v1pb.List{}
- for _, v := range clientResp.List {
- detail := &v1pb.List{
- Id: v.Id,
- Team: v.Team,
- Keyword: v.Keyword,
- Name: v.Name,
- Value: v.Value,
- Ctime: v.Ctime,
- Mtime: v.Mtime,
- Status: v.Status,
- }
- resp.List = append(resp.List, detail)
- }
- if err != nil {
- return
- }
- return
- }
- // FormatErr format error msg
- func (s *GaeaService) FormatErr(statusCode *status.Status) (code int32, msg string) {
- gCode := statusCode.Code()
- code = 1
- if gCode == 2 {
- code, _ := strconv.Atoi(statusCode.Message())
- switch code {
- case 1:
- msg = "必要参数不正确"
- case 11:
- msg = "索引名称在分组内冲突"
- case -500:
- msg = "内部错误"
- default:
- msg = "内部错误"
- }
- } else {
- msg = "内部错误"
- }
- return
- }
- // GetConfigsByTeam implementation
- // 获取单个team的全部配置 `internal:"true"`
- func (s *GaeaService) GetConfigsByTeam(ctx context.Context, req *v1pb.TeamConfigReq) (resp *v1pb.TeamConfigResp, err error) {
- resp = &v1pb.TeamConfigResp{}
- return
- }
- // GetConfigsByKeyword implementation
- // 通过keyword获取配置 `internal:"true"`
- func (s *GaeaService) GetConfigsByKeyword(ctx context.Context, req *v1pb.GetConfigsReq) (resp *v1pb.GetConfigsResp, err error) {
- resp = &v1pb.GetConfigsResp{}
- return
- }
- // GetConfigsByTeams implementation
- // 获取多个team下的全部配置 `internal:"true"`
- func (s *GaeaService) GetConfigsByTeams(ctx context.Context, req *v1pb.TeamsConfigReq) (resp *v1pb.TeamsConfigResp, err error) {
- resp = &v1pb.TeamsConfigResp{}
- return
- }
|