Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #118

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/db/icp_canister.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 15 additions & 3 deletions pkg/service/workflow_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,26 +781,38 @@ 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("数据不存在")
icpCanister.CanisterId = canisterId
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
}

Expand Down
Loading