From ab07bc28a40489c0e92064f4e9060133ecc6b755 Mon Sep 17 00:00:00 2001 From: taolx0 Date: Thu, 27 Jul 2023 13:18:04 +0800 Subject: [PATCH 1/5] refactor:extract public logic --- sqle/model/workflow.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index bdcc52277c..e0eefeb657 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -405,24 +405,9 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, Mode: workflowMode, } - instanceRecords := make([]*WorkflowInstanceRecord, len(tasks)) - for i, task := range tasks { - instanceRecords[i] = &WorkflowInstanceRecord{ - TaskId: task.ID, - InstanceId: task.InstanceId, - } - } - - record := &WorkflowRecord{ - InstanceRecords: instanceRecords, - } - - if len(stepTemplates) == 1 { - record.Status = WorkflowStatusWaitForExecution - } - allUsers := make([][]*User, len(tasks)) allExecutor := make([][]*User, len(tasks)) + instanceRecords := make([]*WorkflowInstanceRecord, len(tasks)) for i, task := range tasks { users, err := s.GetCanAuditWorkflowUsers(task.Instance) if err != nil { @@ -435,6 +420,19 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, return err } allExecutor[i] = executor + + instanceRecords[i] = &WorkflowInstanceRecord{ + TaskId: task.ID, + InstanceId: task.InstanceId, + } + } + + record := &WorkflowRecord{ + InstanceRecords: instanceRecords, + } + + if len(stepTemplates) == 1 { + record.Status = WorkflowStatusWaitForExecution } canOptUsers := allUsers[0] From 07e9ffc3c6bd52bcb4936ccb12e06c0e9e6d80af Mon Sep 17 00:00:00 2001 From: taolx0 Date: Thu, 27 Jul 2023 14:26:31 +0800 Subject: [PATCH 2/5] fix:format code --- sqle/model/workflow.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index e0eefeb657..15d3192b8a 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -1349,11 +1349,11 @@ func (s *Storage) GetWorkflowNamesByIDs(ids []string) ([]string, error) { } type WorkflowStatusDetail struct { - Subject string `json:"subject"` - WorkflowId string `json:"workflow_id"` - Status string `json:"status"` - LoginName string `json:"login_name"` - UpdatedAt *time.Time `json:"updated_at"` + Subject string `json:"subject"` + WorkflowId string `json:"workflow_id"` + Status string `json:"status"` + LoginName string `json:"login_name"` + UpdatedAt *time.Time `json:"updated_at"` } func (s *Storage) GetProjectWorkflowStatusDetail(projectName string, queryStatus []string) ([]WorkflowStatusDetail, error) { @@ -1374,7 +1374,7 @@ func (s *Storage) GetProjectWorkflowStatusDetail(projectName string, queryStatus } type SqlCountAndTriggerRuleCount struct { - SqlCount uint `json:"sql_count"` + SqlCount uint `json:"sql_count"` TriggerRuleCount uint `json:"trigger_rule_count"` } From 339cc8e0d72bddeff4630648ba5afeda382c0b1d Mon Sep 17 00:00:00 2001 From: taolx0 Date: Thu, 27 Jul 2023 14:27:04 +0800 Subject: [PATCH 3/5] chore:add model --- sqle/model/user.go | 3 ++- sqle/model/workflow.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sqle/model/user.go b/sqle/model/user.go index a2b260e9f6..f37a8e9f4e 100644 --- a/sqle/model/user.go +++ b/sqle/model/user.go @@ -43,7 +43,8 @@ type User struct { Stat uint `json:"stat" gorm:"not null; default: 0; comment:'0:正常 1:被禁用'"` ThirdPartyUserID string `json:"third_party_user_id"` - WorkflowStepTemplates []*WorkflowStepTemplate `gorm:"many2many:workflow_step_template_user"` + WorkflowStepTemplates []*WorkflowStepTemplate `gorm:"many2many:workflow_step_template_user"` + WorkflowInstanceRecords []*WorkflowInstanceRecord `gorm:"many2many:workflow_instance_record_user"` } func (u *User) IsDisabled() bool { diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index 15d3192b8a..824e5b31d0 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -212,9 +212,10 @@ type WorkflowInstanceRecord struct { IsSQLExecuted bool ExecutionUserId uint - Instance *Instance `gorm:"foreignkey:InstanceId"` - Task *Task `gorm:"foreignkey:TaskId"` - User *User `gorm:"foreignkey:ExecutionUserId"` + ExecutorUserList []*User `gorm:"many2many:workflow_instance_record_user"` + Instance *Instance `gorm:"foreignkey:InstanceId"` + Task *Task `gorm:"foreignkey:TaskId"` + User *User `gorm:"foreignkey:ExecutionUserId"` } func (wir *WorkflowInstanceRecord) ExecuteUserName() string { From 3af45c77fba5810b746a0859be0b93faa96b9fb4 Mon Sep 17 00:00:00 2001 From: taolx0 Date: Thu, 27 Jul 2023 14:27:12 +0800 Subject: [PATCH 4/5] chore:store task executor user list --- sqle/model/workflow.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index 824e5b31d0..6767f2a7e5 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -423,8 +423,9 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, allExecutor[i] = executor instanceRecords[i] = &WorkflowInstanceRecord{ - TaskId: task.ID, - InstanceId: task.InstanceId, + TaskId: task.ID, + InstanceId: task.InstanceId, + ExecutorUserList: executor, } } @@ -466,6 +467,13 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, return errors.New(errors.ConnectStorageError, err) } + for _, instanceRecord := range record.InstanceRecords { + if tx.Model(instanceRecord).Association("ExecutorUserList").Replace(instanceRecord.ExecutorUserList).Error != nil { + tx.Rollback() + return errors.New(errors.ConnectStorageError, err) + } + } + workflow.WorkflowRecordId = record.ID err = tx.Save(workflow).Error if err != nil { From 984b7401a20499a24154d29aa3a735f1543170df Mon Sep 17 00:00:00 2001 From: taolx0 Date: Mon, 31 Jul 2023 16:04:02 +0800 Subject: [PATCH 5/5] chore:rename --- sqle/model/workflow.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sqle/model/workflow.go b/sqle/model/workflow.go index 6767f2a7e5..5c0d97c52c 100644 --- a/sqle/model/workflow.go +++ b/sqle/model/workflow.go @@ -212,10 +212,10 @@ type WorkflowInstanceRecord struct { IsSQLExecuted bool ExecutionUserId uint - ExecutorUserList []*User `gorm:"many2many:workflow_instance_record_user"` - Instance *Instance `gorm:"foreignkey:InstanceId"` - Task *Task `gorm:"foreignkey:TaskId"` - User *User `gorm:"foreignkey:ExecutionUserId"` + ExecutionAssignees []*User `gorm:"many2many:workflow_instance_record_user"` + Instance *Instance `gorm:"foreignkey:InstanceId"` + Task *Task `gorm:"foreignkey:TaskId"` + User *User `gorm:"foreignkey:ExecutionUserId"` } func (wir *WorkflowInstanceRecord) ExecuteUserName() string { @@ -423,9 +423,9 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, allExecutor[i] = executor instanceRecords[i] = &WorkflowInstanceRecord{ - TaskId: task.ID, - InstanceId: task.InstanceId, - ExecutorUserList: executor, + TaskId: task.ID, + InstanceId: task.InstanceId, + ExecutionAssignees: executor, } } @@ -468,7 +468,7 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User, } for _, instanceRecord := range record.InstanceRecords { - if tx.Model(instanceRecord).Association("ExecutorUserList").Replace(instanceRecord.ExecutorUserList).Error != nil { + if tx.Model(instanceRecord).Association("ExecutionAssignees").Replace(instanceRecord.ExecutionAssignees).Error != nil { tx.Rollback() return errors.New(errors.ConnectStorageError, err) }