Skip to content

Commit

Permalink
Merge pull request #1713 from actiontech/issue_1605_1
Browse files Browse the repository at this point in the history
Issue 1605 1
  • Loading branch information
ColdWaterLW authored Jul 31, 2023
2 parents 5f71c83 + 984b740 commit ef2ace1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion sqle/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 32 additions & 25 deletions sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
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 {
Expand Down Expand Up @@ -405,24 +406,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 {
Expand All @@ -435,6 +421,20 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User,
return err
}
allExecutor[i] = executor

instanceRecords[i] = &WorkflowInstanceRecord{
TaskId: task.ID,
InstanceId: task.InstanceId,
ExecutionAssignees: executor,
}
}

record := &WorkflowRecord{
InstanceRecords: instanceRecords,
}

if len(stepTemplates) == 1 {
record.Status = WorkflowStatusWaitForExecution
}

canOptUsers := allUsers[0]
Expand Down Expand Up @@ -467,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("ExecutionAssignees").Replace(instanceRecord.ExecutionAssignees).Error != nil {
tx.Rollback()
return errors.New(errors.ConnectStorageError, err)
}
}

workflow.WorkflowRecordId = record.ID
err = tx.Save(workflow).Error
if err != nil {
Expand Down Expand Up @@ -1351,11 +1358,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) {
Expand All @@ -1376,7 +1383,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"`
}

Expand Down

0 comments on commit ef2ace1

Please sign in to comment.