package service import ( "context" "finclip-app-manager/domain/entity" "finclip-app-manager/domain/entity/proto" "finclip-app-manager/infrastructure/client/httpcall" "finclip-app-manager/infrastructure/config" pb "finclip-app-manager/infrastructure/protobuf/golang" ) type BoxTool struct{} func NewBoxTool() *BoxTool { return &BoxTool{} } func (b *BoxTool) CovertAppVerToAppRspData(appVer *entity.AppVersion, rspData *pb.AppInfoRspData) { if appVer == nil { return } if rspData == nil { rspData = new(pb.AppInfoRspData) } rspData.AppClass = appVer.AppClass rspData.AppId = appVer.AppID rspData.AppType = appVer.AppType rspData.CoreDescription = appVer.CoreDescription rspData.CorporationId = appVer.CorporationID rspData.Created = appVer.Created rspData.CreatedBy = appVer.CreatedBy rspData.DeveloperId = appVer.DeveloperID rspData.GroupId = appVer.GroupID //rspItem.AppInfo.GroupName = appVer.groupname rspData.InGrayRelease = appVer.InGrayRelease rspData.Logo = appVer.Logo rspData.Name = appVer.Name rspData.Sequence = int32(appVer.Sequence) rspData.Version = appVer.Version rspData.IsTemp = false rspData.Status = new(pb.Status) rspData.Status.Value = appVer.Status.Value rspData.Status.Reason = appVer.Status.Reason rspData.Status.ModifiedBy = appVer.Status.ModifiedBy rspData.Status.LastUpdated = appVer.Status.LastUpdated if rspData.CustomData == nil { rspData.CustomData = new(pb.CustomData) } err, _, customData := ConvertModelCustomDataToPb(context.Background(), appVer.GroupID, appVer.CustomData, nil, "") if err != nil { log.Errorf("openApiGetAppVerInfoFromCache ConvertModelCustomDataToRpc err:[%s]", err.Error()) return } rspData.CustomData = customData return } func (b *BoxTool) PackDomainToAppRspCustom(rspData *pb.AppInfoRspData, domainInfo *httpcall.DomainResponseData) { if rspData.CustomData == nil { rspData.CustomData = new(pb.CustomData) } if rspData.CustomData.AppRuntimeDomain == nil { rspData.CustomData.AppRuntimeDomain = new(pb.AppRuntimeDomain) } if domainInfo != nil { rspData.CustomData.AppRuntimeDomain = new(pb.AppRuntimeDomain) rspData.CustomData.AppRuntimeDomain.Business = new(pb.AppRuntimeDomain_Business) rspData.CustomData.AppRuntimeDomain.Business.Domains = domainInfo.Business.Domains rspData.CustomData.AppRuntimeDomain.Service = new(pb.AppRuntimeDomain_Service) rspData.CustomData.AppRuntimeDomain.Service.Socket = domainInfo.Service.Socket rspData.CustomData.AppRuntimeDomain.Service.Request = domainInfo.Service.Request rspData.CustomData.AppRuntimeDomain.Service.Download = domainInfo.Service.Download rspData.CustomData.AppRuntimeDomain.Service.Upload = domainInfo.Service.Upload rspData.CustomData.AppRuntimeDomain.Whitelist = new(pb.AppRuntimeDomain_Whitelist) rspData.CustomData.AppRuntimeDomain.Whitelist.Domains = domainInfo.Whitelist.Domains rspData.CustomData.AppRuntimeDomain.Blacklist = new(pb.AppRuntimeDomain_Blacklist) rspData.CustomData.AppRuntimeDomain.Blacklist.Domains = domainInfo.Blacklist.Domains } } func (b *BoxTool) PackMenuToAppRspCustom(rspData *pb.AppInfoRspData, menuInfo *proto.MenuInfoRspData) { if rspData.CustomData == nil { rspData.CustomData = new(pb.CustomData) } if menuInfo != nil { rspData.CustomData.MenuInfo = new(pb.MenuInfoRspData) rspData.CustomData.MenuInfo.Total = int32(menuInfo.Total) rspData.CustomData.MenuInfo.List = make([]*pb.MenuInfoRspDataItem, 0) if menuInfo.List != nil { for _, v := range menuInfo.List { item := pb.MenuInfoRspDataItem{} item.Name = v.Name item.Image = v.Image item.Id = v.ID rspData.CustomData.MenuInfo.List = append(rspData.CustomData.MenuInfo.List, &item) } } } } func (b *BoxTool) PackApiInfoToAppRspCustom(rspData *pb.AppInfoRspData, apiInfo *[]proto.ApiInfoRspData) { if rspData.CustomData == nil { rspData.CustomData = new(pb.CustomData) } rspData.CustomData.ApiInfo = nil if apiInfo != nil && config.Cfg.EnableApiManage() { if rspData.CustomData.ApiInfo == nil { rspData.CustomData.ApiInfo = make([]*pb.ApiInfoRspData, 0) } for _, v := range *apiInfo { item := new(pb.ApiInfoRspData) item.Url = v.Url item.ApiName = v.ApiName rspData.CustomData.ApiInfo = append(rspData.CustomData.ApiInfo, item) } } }