diff --git a/pkg/db/icp_canister.go b/pkg/db/icp_canister.go index ddfe133..93e8a22 100644 --- a/pkg/db/icp_canister.go +++ b/pkg/db/icp_canister.go @@ -12,6 +12,7 @@ const ( type IcpCanister struct { Id int `json:"id"` + FkUserId uint `json:"fkUserId"` ProjectId string `json:"projectId"` CanisterId string `json:"canisterId"` CanisterName string `json:"canisterName"` diff --git a/pkg/service/workflow_sync.go b/pkg/service/workflow_sync.go index 9a46a0b..6727ff2 100644 --- a/pkg/service/workflow_sync.go +++ b/pkg/service/workflow_sync.go @@ -781,7 +781,7 @@ func (w *WorkflowService) syncInternetComputerDeploy(projectId uuid.UUID, workfl var icpCanister db.IcpCanister - // 使用First查询满足条件的第一条数据 + // 使用 First 查询满足条件的第一条数据 if err := w.db.Model(db.IcpCanister{}).Where("project_id = ? and canister_id = ?", projectId.String(), canisterId).First(&icpCanister).Error; err != nil { if err == gorm.ErrRecordNotFound { fmt.Println("数据不存在") @@ -789,18 +789,30 @@ func (w *WorkflowService) syncInternetComputerDeploy(projectId uuid.UUID, workfl icpCanister.CreateTime = sql.NullTime{Time: time.Now(), Valid: true} icpCanister.ProjectId = projectId.String() } else { - fmt.Println("查询数据时发生错误:", err) + fmt.Println("查询数据时发生错误:", err) continue } } + var project db.Project + if err := w.db.Model(db.Project{}).Where("id = ?", projectId.String()).First(&project).Error; err != nil { + if err == gorm.ErrRecordNotFound { + fmt.Println("project 数据不存在") + } else { + fmt.Println("查询数据时发生错误:", err) + continue + } + } else { + icpCanister.FkUserId = uint(project.UserId) + } + icpCanister.CanisterName = deploy.Name icpCanister.Status = db.Running icpCanister.Contract = strings.Join([]string{deployPackage.Name, deployPackage.Version}, "_#") icpCanister.Cycles = sql.NullString{Valid: false} icpCanister.UpdateTime = sql.NullTime{Time: time.Now(), Valid: true} if err := w.db.Save(&icpCanister).Error; err != nil { - fmt.Println("保存数据时发生错误:", err) + fmt.Println("保存数据时发生错误:", err) continue }