From 0ca5490e818089c9cbf36256257a309e615c17bf Mon Sep 17 00:00:00 2001 From: YuleiLan Date: Mon, 19 Apr 2021 16:05:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E5=9B=A0=E6=B5=81=E7=A8=8B=E5=88=A0=E9=99=A4=E8=80=8C=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=98=BE=E7=A4=BA=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/service/process.go | 78 +++++++++++++++++++----------------- pkg/service/userAuthority.go | 15 ++++--- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/pkg/service/process.go b/pkg/service/process.go index c69f4e5..d8e42c7 100644 --- a/pkg/service/process.go +++ b/pkg/service/process.go @@ -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 @@ -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 } } } diff --git a/pkg/service/userAuthority.go b/pkg/service/userAuthority.go index 26c7334..576a8e7 100644 --- a/pkg/service/userAuthority.go +++ b/pkg/service/userAuthority.go @@ -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)