update create methods

This commit is contained in:
tzwang 2025-07-18 11:44:06 +08:00
parent c6c11f7a70
commit 640eebe868
5 changed files with 55 additions and 55 deletions

View File

@ -16,10 +16,12 @@ package ai
import ( import (
"context" "context"
"errors"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" algorithm "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )
type CreateAlgorithmLogic struct { type CreateAlgorithmLogic struct {
@ -47,6 +49,9 @@ func (l *CreateAlgorithmLogic) CreateAlgorithm(req *algorithm.CreateAlgorithmReq
if err != nil { if err != nil {
return nil, err return nil, err
} }
if create.Code != http.StatusOK {
return nil, errors.New(create.Message)
}
resp = create.Data resp = create.Data
return return
} }

View File

@ -16,12 +16,12 @@ package ai
import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" dataset "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )
type CreateDataSetLogic struct { type CreateDataSetLogic struct {
@ -38,22 +38,21 @@ func NewCreateDataSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
} }
} }
func (l *CreateDataSetLogic) CreateDataSet(req *dataset.CreateDatasetReq) (resp *dataset.CreateDatasetResp, err error) { func (l *CreateDataSetLogic) CreateDataSet(req *dataset.CreateDatasetReq) (resp interface{}, err error) {
param := &participant.CreateParam{
cluster := &types.GetClusterByIdResp{} Name: req.Name,
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&cluster.ClusterInfo) Desc: req.Desc,
if tx.Error != nil { Src: req.Src,
logx.Errorf(tx.Error.Error()) Param: req.Param,
return nil, errors.New("cluster create failed")
} }
create, err := l.svcCtx.Ai.DatasetCreateById(req.ClusterId, param)
httpClient := resty.New().R() if err != nil {
createDatasetResp := &dataset.CreateDatasetResp{} return nil, err
_, err = httpClient.SetHeader("Content-Type", "application/json"). }
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}). if create.Code != http.StatusOK {
SetBody(req). return nil, errors.New(create.Message)
SetResult(&createDatasetResp). }
Post(cluster.ClusterInfo.Server + "/ai/dataset/create") resp = create.Data
return createDatasetResp, err return
} }

View File

@ -16,12 +16,12 @@ package ai
import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
model "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" model "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )
type CreateModelLogic struct { type CreateModelLogic struct {
@ -38,22 +38,20 @@ func NewCreateModelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
} }
} }
func (l *CreateModelLogic) CreateModel(req *model.CreateModelReq) (resp *model.CreateModelResp, err error) { func (l *CreateModelLogic) CreateModel(req *model.CreateModelReq) (resp interface{}, err error) {
param := &participant.CreateParam{
cluster := &types.GetClusterByIdResp{} Name: req.Name,
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&cluster.ClusterInfo) Desc: req.Desc,
if tx.Error != nil { Src: req.Src,
logx.Errorf(tx.Error.Error()) Param: req.Param,
return nil, errors.New("cluster create failed")
} }
create, err := l.svcCtx.Ai.ModelCreateById(req.ClusterId, param)
httpClient := resty.New().R() if err != nil {
createModelResp := &model.CreateModelResp{} return nil, err
_, err = httpClient.SetHeader("Content-Type", "application/json"). }
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}). if create.Code != http.StatusOK {
SetBody(req). return nil, errors.New(create.Message)
SetResult(&createModelResp). }
Post(cluster.ClusterInfo.Server + "/ai/model/create") resp = create.Data
return createModelResp, err return
} }

View File

@ -16,12 +16,12 @@ package ai
import ( import (
"context" "context"
"github.com/go-resty/resty/v2"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/participant"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
sync "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai" sync "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types/ai"
"net/http"
) )
type TaskResultSyncLogic struct { type TaskResultSyncLogic struct {
@ -38,22 +38,20 @@ func NewTaskResultSyncLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ta
} }
} }
func (l *TaskResultSyncLogic) TaskResultSync(req *sync.ResultSyncReq) (resp *sync.ResultSyncResp, err error) { func (l *TaskResultSyncLogic) TaskResultSync(req *sync.ResultSyncReq) (resp interface{}, err error) {
cluster := &types.GetClusterByIdResp{} param := &participant.TaskResultSyncParam{
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where id = ?", req.ClusterId).Scan(&cluster.ClusterInfo) Src: req.Src,
if tx.Error != nil { Param: req.Param,
logx.Errorf(tx.Error.Error())
return nil, errors.New("cluster create failed")
} }
rs, err := l.svcCtx.Ai.TaskResultSync(req.ClusterId, param)
httpClient := resty.New().R() if err != nil {
createModelResp := &sync.ResultSyncResp{} return nil, err
_, err = httpClient.SetHeader("Content-Type", "application/json"). }
SetQueryParams(map[string]string{"pfId": cluster.ClusterInfo.Id}). if rs.Code != http.StatusOK {
SetBody(req). return nil, errors.New(rs.Message)
SetResult(&createModelResp). }
Post(cluster.ClusterInfo.Server + "/ai/task/sync") resp = rs.Data
return createModelResp, err return
} }

View File

@ -7,7 +7,7 @@ type RespErr struct {
type Resp struct { type Resp struct {
Code int32 `json:"code"` Code int32 `json:"code"`
Message string `json:"message"` Message string `json:"msg"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }