Skip to content

Commit

Permalink
Merge pull request #1724 from actiontech/fix/task-execution
Browse files Browse the repository at this point in the history
fix:task summary wait operation person
  • Loading branch information
ColdWaterLW authored Aug 8, 2023
2 parents aeccd36 + bdffabc commit f3e0244
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
25 changes: 25 additions & 0 deletions sqle/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,28 @@ func (s *Storage) GetUserRoleFromUserGroupByProjectName(projectName string) ([]*
Scan(&userRoles).Error
return userRoles, errors.ConnectStorageErrWrapper(err)
}

func GetDistinctOfUsers(users1, users2 []*User) []*User {
resUsers := users1
for _, user1 := range users1 {
for _, user2 := range users2 {
if user1.ID == user2.ID {
continue
}
resUsers = append(resUsers, user2)
}
}
return resUsers
}

func GetOverlapOfUsers(users1, users2 []*User) []*User {
var res []*User
for _, user1 := range users1 {
for _, user2 := range users2 {
if user1.ID == user2.ID {
res = append(res, user1)
}
}
}
return res
}
37 changes: 21 additions & 16 deletions sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,6 @@ 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{
Expand All @@ -456,8 +450,8 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User,
canOptUsers := allUsers[0]
canExecUsers := allExecutor[0]
for i := 1; i < len(allUsers); i++ {
canOptUsers = getOverlapOfUsers(canOptUsers, allUsers[i])
canExecUsers = getOverlapOfUsers(canExecUsers, allExecutor[i])
canOptUsers = GetOverlapOfUsers(canOptUsers, allUsers[i])
canExecUsers = GetOverlapOfUsers(canExecUsers, allExecutor[i])
}

if len(canOptUsers) == 0 || len(canExecUsers) == 0 {
Expand All @@ -475,6 +469,10 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User,

steps := generateWorkflowStepByTemplate(stepTemplates, canOptUsers, canExecUsers)

// 工单详情概览页面待操作人是流程模版执行上线step的待操作人加上该数据源待操作人
// 如果流程模版制定了待操作人,即指定待操作人上线
UpdateInstanceRecord(stepTemplates, tasks, canExecUsers, instanceRecords, allExecutor)

tx := s.db.Begin()

err := tx.Save(record).Error
Expand Down Expand Up @@ -524,16 +522,23 @@ func (s *Storage) CreateWorkflowV2(subject, workflowId, desc string, user *User,
return errors.New(errors.ConnectStorageError, tx.Commit().Error)
}

func getOverlapOfUsers(users1, users2 []*User) []*User {
var res []*User
for _, user1 := range users1 {
for _, user2 := range users2 {
if user1.ID == user2.ID {
res = append(res, user1)
}
func UpdateInstanceRecord(stepTemplates []*WorkflowStepTemplate, tasks []*Task, stepExecUsers []*User, instanceRecords []*WorkflowInstanceRecord, allExecutor [][]*User) {
executionStep := stepTemplates[len(stepTemplates)-1]
isExecuteByAuthorized := executionStep.ExecuteByAuthorized.Bool
stepTemplateAssignees := executionStep.Users
for i, task := range tasks {
instanceRecords[i] = &WorkflowInstanceRecord{
TaskId: task.ID,
InstanceId: task.InstanceId,
}

if isExecuteByAuthorized {
distinctOfUsers := GetDistinctOfUsers(stepExecUsers, allExecutor[i])
instanceRecords[i].ExecutionAssignees = distinctOfUsers
} else {
instanceRecords[i].ExecutionAssignees = stepTemplateAssignees
}
}
return res
}

func (s *Storage) UpdateWorkflowRecord(w *Workflow, tasks []*Task) error {
Expand Down

0 comments on commit f3e0244

Please sign in to comment.