Skip to content

Commit

Permalink
Merge pull request lanyulei#177 from lanyulei/dev
Browse files Browse the repository at this point in the history
fix: 修复工单因流程删除而无法显示的bug。
  • Loading branch information
lanyulei authored Apr 19, 2021
2 parents f1dddea + 0ca5490 commit 4f713d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 43 deletions.
78 changes: 41 additions & 37 deletions pkg/service/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,40 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
)

err = orm.Eloquent.Model(&processValue).Where("id = ?", processId).Find(&processValue).Error
if err != nil {
err = fmt.Errorf("查询流程失败,%v", err.Error())
return
}
//if err != nil {
// err = fmt.Errorf("查询流程失败,%v", err.Error())
// return
//}

err = json.Unmarshal([]byte(processValue.Structure), &processStructureDetails)
if err != nil {
err = fmt.Errorf("json转map失败,%v", err.Error())
return
}
if processValue.Structure != nil && len(processValue.Structure) > 0 {
err = json.Unmarshal([]byte(processValue.Structure), &processStructureDetails)
if err != nil {
err = fmt.Errorf("json转map失败,%v", err.Error())
return
}

// 排序,使用冒泡
p := processStructureDetails["nodes"].([]interface{})
if len(p) > 1 {
for i := 0; i < len(p); i++ {
for j := 1; j < len(p)-i; j++ {
if p[j].(map[string]interface{})["sort"] == nil || p[j-1].(map[string]interface{})["sort"] == nil {
return nil, errors.New("流程未定义顺序属性,请确认")
}
leftInt, _ := strconv.Atoi(p[j].(map[string]interface{})["sort"].(string))
rightInt, _ := strconv.Atoi(p[j-1].(map[string]interface{})["sort"].(string))
if leftInt < rightInt {
//交换
p[j], p[j-1] = p[j-1], p[j]
// 排序,使用冒泡
p := processStructureDetails["nodes"].([]interface{})
if len(p) > 1 {
for i := 0; i < len(p); i++ {
for j := 1; j < len(p)-i; j++ {
if p[j].(map[string]interface{})["sort"] == nil || p[j-1].(map[string]interface{})["sort"] == nil {
return nil, errors.New("流程未定义顺序属性,请确认")
}
leftInt, _ := strconv.Atoi(p[j].(map[string]interface{})["sort"].(string))
rightInt, _ := strconv.Atoi(p[j-1].(map[string]interface{})["sort"].(string))
if leftInt < rightInt {
//交换
p[j], p[j-1] = p[j-1], p[j]
}
}
}
for _, node := range processStructureDetails["nodes"].([]interface{}) {
processNode = append(processNode, node.(map[string]interface{}))
}
} else {
processNode = processStructureDetails["nodes"].([]map[string]interface{})
}
for _, node := range processStructureDetails["nodes"].([]interface{}) {
processNode = append(processNode, node.(map[string]interface{}))
}
} else {
processNode = processStructureDetails["nodes"].([]map[string]interface{})
}

processValue.Structure = nil
Expand Down Expand Up @@ -141,18 +143,20 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
if len(stateList) > 0 {
breakStateTag:
for _, stateValue := range stateList {
for _, processNodeValue := range processStructureDetails["nodes"].([]interface{}) {
if stateValue["id"].(string) == processNodeValue.(map[string]interface{})["id"] {
if _, ok := stateValue["processor"]; ok {
for _, userId := range stateValue["processor"].([]interface{}) {
if int(userId.(float64)) == tools.GetUserId(c) {
workOrderInfo.CurrentState = stateValue["id"].(string)
break breakStateTag
if processStructureDetails["nodes"] != nil {
for _, processNodeValue := range processStructureDetails["nodes"].([]interface{}) {
if stateValue["id"].(string) == processNodeValue.(map[string]interface{})["id"] {
if _, ok := stateValue["processor"]; ok {
for _, userId := range stateValue["processor"].([]interface{}) {
if int(userId.(float64)) == tools.GetUserId(c) {
workOrderInfo.CurrentState = stateValue["id"].(string)
break breakStateTag
}
}
} else {
err = errors.New("未查询到对应的处理人字段,请确认。")
return
}
} else {
err = errors.New("未查询到对应的处理人字段,请确认。")
return
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/service/userAuthority.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ func JudgeUserAuthority(c *gin.Context, workOrderId int, currentState string) (s

// 获取流程信息
err = orm.Eloquent.Model(&process.Info{}).Where("id = ?", workOrderInfo.Process).Find(&processInfo).Error
if err != nil {
return
}
err = json.Unmarshal(processInfo.Structure, &processState.Structure)
if err != nil {
return
//if err != nil {
// return
//}

if processInfo.Structure != nil && len(processInfo.Structure) > 0 {
err = json.Unmarshal(processInfo.Structure, &processState.Structure)
if err != nil {
return
}
}

stateValue, err = processState.GetNode(currentState)
Expand Down

0 comments on commit 4f713d9

Please sign in to comment.