浏览代码

更改 sop node列表返回格式

boweniac 10 月之前
父节点
当前提交
d4007f9365
共有 3 个文件被更改,包括 116 次插入35 次删除
  1. 12 1
      desc/wechat/sop_node.api
  2. 93 33
      internal/logic/sop_node/get_sop_node_list_logic.go
  3. 11 1
      internal/types/types.go

+ 12 - 1
desc/wechat/sop_node.api

@@ -7,7 +7,18 @@ type (
         BaseDataInfo
 
         // SopNode list data | SopNode列表数据
-        Data SopNodeListInfo `json:"data"`
+        Data []*SopChildNodeInfo `json:"data"`
+    }
+
+    // SopNode list data | SopNode列表数据
+    SopChildNodeInfo {
+        NodeName *string `json:"nodeName,optional"`
+        ChildNode *SopChildNodeInfo `json:"childNode,optional"`
+
+        // The API list data | SopNode列表数据
+        ConditionNodes  []*SopChildNodeInfo  `json:"conditionNodes"`
+
+        SopNodeInfo
     }
 
     // SopNode list data | SopNode列表数据

+ 93 - 33
internal/logic/sop_node/get_sop_node_list_logic.go

@@ -3,17 +3,14 @@ package sop_node
 import (
 	"context"
 	"fmt"
-
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/logx"
+	"wechat-api/ent"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/sopnode"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/dberrorhandler"
-
-	"github.com/suyuan32/simple-admin-common/msg/errormsg"
-
-	"github.com/suyuan32/simple-admin-common/utils/pointy"
-	"github.com/zeromicro/go-zero/core/logx"
 )
 
 type GetSopNodeListLogic struct {
@@ -46,35 +43,98 @@ func (l *GetSopNodeListLogic) GetSopNodeList(req *types.SopNodeListReq) (*types.
 	resp := &types.SopNodeListResp{}
 	resp.Msg = errormsg.Success
 
-	for _, v := range data {
-		var actionMessage []types.Action
-		if len(v.ActionMessage) > 0 {
-			actionMessage = make([]types.Action, len(v.ActionMessage))
-			for i, condition := range v.ActionMessage {
-				actionMessage[i] = types.Action{
-					Type:    condition.Type,
-					Content: condition.Content,
+	childNodeList, _ := GetSopNodeListByParentId(0, data)
+
+	resp.Data = childNodeList
+
+	return resp, nil
+}
+
+// 从node列表中找到指定 ParentId 的所有节点
+func GetSopNodeListByParentId(parentId uint64, nodeList []*ent.SopNode) ([]*types.SopChildNodeInfo, error) {
+	// 遍历 nodeList 找到 ParentId 为指定 parentId 的所有节点
+	var result []*types.SopChildNodeInfo
+	for _, node := range nodeList {
+		if node.ParentID == parentId {
+			childNodeList, _ := GetSopNodeListByParentId(node.ID, nodeList)
+			var actionMessage []types.Action
+			if len(node.ActionMessage) > 0 {
+				actionMessage = make([]types.Action, len(node.ActionMessage))
+				for i, condition := range node.ActionMessage {
+					actionMessage[i] = types.Action{
+						Type:    condition.Type,
+						Content: condition.Content,
+					}
 				}
 			}
-		}
-
-		resp.Data.Data = append(resp.Data.Data,
-			types.SopNodeInfo{
-				BaseIDInfo: types.BaseIDInfo{
-					Id:        &v.ID,
-					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
-					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+			child := types.SopChildNodeInfo{
+				NodeName:       &node.Name,
+				ConditionNodes: childNodeList,
+				SopNodeInfo: types.SopNodeInfo{
+					BaseIDInfo: types.BaseIDInfo{
+						Id: &node.ID,
+					},
+					Status:        &node.Status,
+					StageId:       &node.StageID,
+					ParentId:      &node.ParentID,
+					Name:          &node.Name,
+					ConditionType: &node.ConditionType,
+					ConditionList: node.ConditionList,
+					ActionMessage: actionMessage,
+					ActionLabel:   node.ActionLabel,
 				},
-				Status:        &v.Status,
-				StageId:       &v.StageID,
-				ParentId:      &v.ParentID,
-				Name:          &v.Name,
-				ConditionType: &v.ConditionType,
-				ConditionList: v.ConditionList,
-				ActionMessage: actionMessage,
-				ActionLabel:   v.ActionLabel,
-			})
+			}
+			result = append(result, &child)
+		}
 	}
-
-	return resp, nil
+	return result, nil
 }
+
+//func (l *GetSopNodeListLogic) GetSopNodeList(req *types.SopNodeListReq) (*types.SopNodeListResp, error) {
+//	var predicates []predicate.SopNode
+//	if req.StageId != nil {
+//		predicates = append(predicates, sopnode.StageID(*req.StageId))
+//	} else {
+//		return nil, dberrorhandler.DefaultEntError(l.Logger, fmt.Errorf("StageId 不能为空"), req)
+//	}
+//	data, err := l.svcCtx.DB.SopNode.Query().Where(predicates...).All(l.ctx)
+//
+//	if err != nil {
+//		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+//	}
+//
+//	resp := &types.SopNodeListResp{}
+//	resp.Msg = errormsg.Success
+//
+//	for _, v := range data {
+//		var actionMessage []types.Action
+//		if len(v.ActionMessage) > 0 {
+//			actionMessage = make([]types.Action, len(v.ActionMessage))
+//			for i, condition := range v.ActionMessage {
+//				actionMessage[i] = types.Action{
+//					Type:    condition.Type,
+//					Content: condition.Content,
+//				}
+//			}
+//		}
+//
+//		resp.Data.Data = append(resp.Data.Data,
+//			types.SopNodeInfo{
+//				BaseIDInfo: types.BaseIDInfo{
+//					Id:        &v.ID,
+//					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
+//					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+//				},
+//				Status:        &v.Status,
+//				StageId:       &v.StageID,
+//				ParentId:      &v.ParentID,
+//				Name:          &v.Name,
+//				ConditionType: &v.ConditionType,
+//				ConditionList: v.ConditionList,
+//				ActionMessage: actionMessage,
+//				ActionLabel:   v.ActionLabel,
+//			})
+//	}
+//
+//	return resp, nil
+//}

+ 11 - 1
internal/types/types.go

@@ -851,7 +851,17 @@ type SopStageMoveReq struct {
 type SopNodeListResp struct {
 	BaseDataInfo
 	// SopNode list data | SopNode列表数据
-	Data SopNodeListInfo `json:"data"`
+	Data []*SopChildNodeInfo `json:"data"`
+}
+
+// SopNode list data | SopNode列表数据
+// swagger:model SopChildNodeInfo
+type SopChildNodeInfo struct {
+	NodeName  *string           `json:"nodeName,optional"`
+	ChildNode *SopChildNodeInfo `json:"childNode,optional"`
+	// The API list data | SopNode列表数据
+	ConditionNodes []*SopChildNodeInfo `json:"conditionNodes"`
+	SopNodeInfo
 }
 
 // SopNode list data | SopNode列表数据