fix: 修复工单因流程删除而无法显示的bug。

This commit is contained in:
YuleiLan 2021-04-19 16:05:54 +08:00
parent 6595acb5d4
commit 0ca5490e81
2 changed files with 50 additions and 43 deletions

View File

@ -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 err = orm.Eloquent.Model(&processValue).Where("id = ?", processId).Find(&processValue).Error
if err != nil { //if err != nil {
err = fmt.Errorf("查询流程失败,%v", err.Error()) // err = fmt.Errorf("查询流程失败,%v", err.Error())
return // return
} //}
err = json.Unmarshal([]byte(processValue.Structure), &processStructureDetails) if processValue.Structure != nil && len(processValue.Structure) > 0 {
if err != nil { err = json.Unmarshal([]byte(processValue.Structure), &processStructureDetails)
err = fmt.Errorf("json转map失败%v", err.Error()) if err != nil {
return err = fmt.Errorf("json转map失败%v", err.Error())
} return
}
// 排序,使用冒泡 // 排序,使用冒泡
p := processStructureDetails["nodes"].([]interface{}) p := processStructureDetails["nodes"].([]interface{})
if len(p) > 1 { if len(p) > 1 {
for i := 0; i < len(p); i++ { for i := 0; i < len(p); i++ {
for j := 1; j < len(p)-i; j++ { for j := 1; j < len(p)-i; j++ {
if p[j].(map[string]interface{})["sort"] == nil || p[j-1].(map[string]interface{})["sort"] == nil { if p[j].(map[string]interface{})["sort"] == nil || p[j-1].(map[string]interface{})["sort"] == nil {
return nil, errors.New("流程未定义顺序属性,请确认") return nil, errors.New("流程未定义顺序属性,请确认")
} }
leftInt, _ := strconv.Atoi(p[j].(map[string]interface{})["sort"].(string)) leftInt, _ := strconv.Atoi(p[j].(map[string]interface{})["sort"].(string))
rightInt, _ := strconv.Atoi(p[j-1].(map[string]interface{})["sort"].(string)) rightInt, _ := strconv.Atoi(p[j-1].(map[string]interface{})["sort"].(string))
if leftInt < rightInt { if leftInt < rightInt {
//交换 //交换
p[j], p[j-1] = p[j-1], p[j] 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 processValue.Structure = nil
@ -141,18 +143,20 @@ func ProcessStructure(c *gin.Context, processId int, workOrderId int) (result ma
if len(stateList) > 0 { if len(stateList) > 0 {
breakStateTag: breakStateTag:
for _, stateValue := range stateList { for _, stateValue := range stateList {
for _, processNodeValue := range processStructureDetails["nodes"].([]interface{}) { if processStructureDetails["nodes"] != nil {
if stateValue["id"].(string) == processNodeValue.(map[string]interface{})["id"] { for _, processNodeValue := range processStructureDetails["nodes"].([]interface{}) {
if _, ok := stateValue["processor"]; ok { if stateValue["id"].(string) == processNodeValue.(map[string]interface{})["id"] {
for _, userId := range stateValue["processor"].([]interface{}) { if _, ok := stateValue["processor"]; ok {
if int(userId.(float64)) == tools.GetUserId(c) { for _, userId := range stateValue["processor"].([]interface{}) {
workOrderInfo.CurrentState = stateValue["id"].(string) if int(userId.(float64)) == tools.GetUserId(c) {
break breakStateTag workOrderInfo.CurrentState = stateValue["id"].(string)
break breakStateTag
}
} }
} else {
err = errors.New("未查询到对应的处理人字段,请确认。")
return
} }
} else {
err = errors.New("未查询到对应的处理人字段,请确认。")
return
} }
} }
} }

View File

@ -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 err = orm.Eloquent.Model(&process.Info{}).Where("id = ?", workOrderInfo.Process).Find(&processInfo).Error
if err != nil { //if err != nil {
return // return
} //}
err = json.Unmarshal(processInfo.Structure, &processState.Structure)
if err != nil { if processInfo.Structure != nil && len(processInfo.Structure) > 0 {
return err = json.Unmarshal(processInfo.Structure, &processState.Structure)
if err != nil {
return
}
} }
stateValue, err = processState.GetNode(currentState) stateValue, err = processState.GetNode(currentState)