存算联动类型转换更新

Former-commit-id: 07fc2e447b89c8a45e779a24d5d7bdc3a77e9450
This commit is contained in:
tzwang 2023-09-15 17:56:24 +08:00
parent 65b8f21dd7
commit 4a82cfa159
1 changed files with 56 additions and 3 deletions

View File

@ -41,15 +41,27 @@ func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, partId int64)
func ConvertType[T any](in *T) (interface{}, error) {
switch (interface{})(in).(type) {
case *octopus.UploadImageResp:
var resp types.UploadLinkImageResp
inresp := (interface{})(in).(*octopus.UploadImageResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *octopus.GetUserImageListResp:
var resp types.GetLinkImageListResp
inresp := (interface{})(in).(*octopus.GetUserImageListResp)
resp.Success = inresp.Success
if inresp.Error == nil {
resp.ErrorMsg = ""
} else {
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
resp.Images = nil
return resp, nil
}
for _, v := range inresp.Payload.Images {
var image types.ImageSl
image.ImageId = v.Image.Id
@ -58,18 +70,59 @@ func ConvertType[T any](in *T) (interface{}, error) {
resp.Images = append(resp.Images, image)
}
return resp, nil
case *octopus.DeleteImageResp:
var resp types.DeleteLinkImageResp
inresp := (interface{})(in).(*octopus.DeleteImageResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *octopus.CreateTrainJobResp:
var resp types.SubmitLinkTaskResp
inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.TaskId = inresp.Payload.JobId
return resp, nil
case *octopus.GetTrainJobResp:
var resp types.GetLinkTaskResp
inresp := (interface{})(in).(*octopus.GetTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.Task.TaskId = inresp.Payload.TrainJob.Id
resp.Task.TaskName = inresp.Payload.TrainJob.Name
resp.Task.StartedAt = inresp.Payload.TrainJob.StartedAt
resp.Task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
resp.Task.TaskStatus = inresp.Payload.TrainJob.Status
return resp, nil
case *octopus.DeleteTrainJobResp:
var resp types.DeleteLinkTaskResp
inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
default:
return nil, errors.New("type convert fail")
}