From ba84c312a32b0777a22b868f08a1567c716ed492 Mon Sep 17 00:00:00 2001 From: jagger Date: Wed, 5 Jun 2024 17:56:59 +0800 Subject: [PATCH] fix bug Signed-off-by: jagger Former-commit-id: ac8e28da5b7851f03b2fe1207fcbc83f0eee255e --- api/desc/core/pcm-core.api | 30 +++++++++++++------ .../logic/cloud/commitgeneraltasklogic.go | 1 + api/internal/logic/core/taskdetailslogic.go | 17 +++++++---- api/internal/svc/servicecontext.go | 2 +- api/internal/types/types.go | 10 +++++++ pkg/models/cloud/task_cloud.go | 1 + 6 files changed, 45 insertions(+), 16 deletions(-) diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index e5e144d44..bd43ffc84 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -1234,12 +1234,24 @@ type TaskStatusResp { Saved int `json:"Saved"` } -type TaskDetailsResp { - Name string `json:"name"` - description string `json:"description"` - StartTime string `json:"startTime"` - EndTime string `json:"endTime"` - Strategy int64 `json:"strategy"` - SynergyStatus int64 `json:"synergyStatus"` - ClusterInfos []*ClusterInfo `json:"clusterInfos"` -} \ No newline at end of file +type ( + TaskDetailsResp { + Name string `json:"name"` + description string `json:"description"` + StartTime string `json:"startTime"` + EndTime string `json:"endTime"` + Strategy int64 `json:"strategy"` + SynergyStatus int64 `json:"synergyStatus"` + ClusterInfos []*ClusterInfo `json:"clusterInfos"` + SubTaskInfos []*SubTaskInfo `json:"subTaskInfos"` + } + + SubTaskInfo{ + Id string `json:"id" db:"id"` + Name string `json:"name" db:"name"` + ClusterId string `json:"clusterId" db:"cluster_id"` + ClusterName string `json:"clusterName" db:"cluster_name"` + Status string `json:"status" db:"status"` + Remark string `json:"remark" db:"remark"` + } +) \ No newline at end of file diff --git a/api/internal/logic/cloud/commitgeneraltasklogic.go b/api/internal/logic/cloud/commitgeneraltasklogic.go index 14240bc0d..ac35e1b8b 100644 --- a/api/internal/logic/cloud/commitgeneraltasklogic.go +++ b/api/internal/logic/cloud/commitgeneraltasklogic.go @@ -106,6 +106,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er sStruct := UnMarshalK8sStruct(s, int64(r.Replica)) unString, _ := sStruct.MarshalJSON() taskCloud.Id = utils.GenSnowflakeIDUint() + taskCloud.Name = sStruct.GetName() + "-" + sStruct.GetKind() taskCloud.TaskId = uint(taskModel.Id) clusterId, _ := strconv.ParseUint(r.ClusterId, 10, 64) taskCloud.AdapterId = uint(adapterId) diff --git a/api/internal/logic/core/taskdetailslogic.go b/api/internal/logic/core/taskdetailslogic.go index c08edaaad..0a8c7dbd0 100644 --- a/api/internal/logic/core/taskdetailslogic.go +++ b/api/internal/logic/core/taskdetailslogic.go @@ -32,18 +32,22 @@ func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsR if errors.Is(l.svcCtx.DbEngin.Where("id", req.Id).First(&task).Error, gorm.ErrRecordNotFound) { return nil, errors.New("记录不存在") } - clusterIds := make([]int64, 0) + clusterIds := make([]string, 0) var cList []*types.ClusterInfo + var subList []*types.SubTaskInfo switch task.AdapterTypeDict { case 0: - l.svcCtx.DbEngin.Table("task_cloud").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds) - if len(clusterIds) <= 0 { - l.svcCtx.DbEngin.Table("task_vm").Select("cluster_id").Where("task_id", task.Id).Find(&clusterIds) + l.svcCtx.DbEngin.Table("task_cloud").Where("task_id", task.Id).Scan(&subList) + if len(subList) <= 0 { + l.svcCtx.DbEngin.Table("task_vm").Where("task_id", task.Id).Find(&subList) } case 1: - l.svcCtx.DbEngin.Table("task_ai").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds) + l.svcCtx.DbEngin.Table("task_ai").Where("task_id", task.Id).Scan(&subList) case 2: - l.svcCtx.DbEngin.Table("task_hpc").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds) + l.svcCtx.DbEngin.Table("task_hpc").Where("task_id", task.Id).Scan(&subList) + } + for _, sub := range subList { + clusterIds = append(clusterIds, sub.ClusterId) } err = l.svcCtx.DbEngin.Table("t_cluster").Where("id in ?", clusterIds).Scan(&cList).Error if err != nil { @@ -51,5 +55,6 @@ func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsR } utils.Convert(&task, &resp) resp.ClusterInfos = cList + resp.SubTaskInfos = subList return } diff --git a/api/internal/svc/servicecontext.go b/api/internal/svc/servicecontext.go index 5460862d1..8241b9d98 100644 --- a/api/internal/svc/servicecontext.go +++ b/api/internal/svc/servicecontext.go @@ -91,7 +91,7 @@ func NewServiceContext(c config.Config) *ServiceContext { NamingStrategy: schema.NamingStrategy{ SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user` }, - Logger: logger.Default.LogMode(logger.Error), + Logger: logger.Default.LogMode(logger.Info), }) if err != nil { logx.Errorf("数据库连接失败, err%v", err) diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 1539f520e..75d23b445 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -1166,6 +1166,16 @@ type TaskDetailsResp struct { Strategy int64 `json:"strategy"` SynergyStatus int64 `json:"synergyStatus"` ClusterInfos []*ClusterInfo `json:"clusterInfos"` + SubTaskInfos []*SubTaskInfo `json:"subTaskInfos"` +} + +type SubTaskInfo struct { + Id string `json:"id" db:"id"` + Name string `json:"name" db:"name"` + ClusterId string `json:"clusterId" db:"cluster_id"` + ClusterName string `json:"clusterName" db:"cluster_name"` + Status string `json:"status" db:"status"` + Remark string `json:"remark" db:"remark"` } type CommitHpcTaskReq struct { diff --git a/pkg/models/cloud/task_cloud.go b/pkg/models/cloud/task_cloud.go index 5cb1e1c91..39a51afe6 100644 --- a/pkg/models/cloud/task_cloud.go +++ b/pkg/models/cloud/task_cloud.go @@ -7,6 +7,7 @@ import ( type TaskCloudModel struct { Id uint `json:"id" gorm:"primarykey;not null;comment:id"` + Name string `json:"name" gorm:"null;comment:名称"` TaskId uint `json:"taskId" gorm:"not null;comment:task表id"` AdapterId uint `json:"adapterId" gorm:"not null;comment:适配器id"` AdapterName string `json:"adapterName" gorm:"not null;comment:适配器名称"`