Browse Source

Merge branch 'yhg_240730'

jimmyyem 4 months ago
parent
commit
47d0c946ae

+ 9 - 1
desc/wechat/sop_node.api

@@ -10,6 +10,14 @@ type (
         Data []*SopChildNodeInfo `json:"data"`
     }
 
+	// The response data of sop node list | SopNode列表数据
+	SopNodeListResp2 {
+		BaseDataInfo
+
+		// SopNode list data | SopNode列表数据
+		Data []*SopNodeInfo `json:"data"`
+	}
+
     // SopNode list data | SopNode列表数据
     SopChildNodeInfo {
         NodeName *string `json:"nodeName,optional"`
@@ -63,7 +71,7 @@ type (
 service Wechat {
 	// Get api sop node list | 获取SopNode列表
 	@handler getApiSopNodeList
-	post /api/sop_node/list (BatchSopNodeListReq) returns (SopNodeListResp)
+	post /api/sop_node/list (BatchSopNodeListReq) returns (SopNodeListResp2)
 }
 
 @server(

+ 61 - 4
internal/logic/sop_node/get_api_sop_node_list_logic.go

@@ -6,6 +6,7 @@ import (
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/errorx"
 	"net/http"
+	"wechat-api/ent"
 	"wechat-api/ent/predicate"
 	"wechat-api/ent/sopnode"
 	"wechat-api/hook"
@@ -30,7 +31,7 @@ func NewGetApiSopNodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 		svcCtx: svcCtx}
 }
 
-func (l *GetApiSopNodeListLogic) GetApiSopNodeList(req *types.BatchSopNodeListReq, r *http.Request) (*types.SopNodeListResp, error) {
+func (l *GetApiSopNodeListLogic) GetApiSopNodeList(req *types.BatchSopNodeListReq, r *http.Request) (*types.SopNodeListResp2, error) {
 	tokenStr := r.Header.Get("Authorization")
 	_, err := hook.CheckDesktopAuth(tokenStr, l.svcCtx.DB)
 	if err != nil {
@@ -49,12 +50,68 @@ func (l *GetApiSopNodeListLogic) GetApiSopNodeList(req *types.BatchSopNodeListRe
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	resp := &types.SopNodeListResp{}
+	resp := &types.SopNodeListResp2{}
 	resp.Msg = errormsg.Success
 
-	childNodeList, _ := GetSopNodeListByParentId(0, data)
-
+	childNodeList, _ := getSopNodeList(data)
 	resp.Data = childNodeList
 
 	return resp, nil
 }
+
+// 从node列表中找到指定 ParentId 的所有节点
+func getSopNodeList(nodeList []*ent.SopNode) ([]*types.SopNodeInfo, error) {
+	// 遍历 nodeList 找到 ParentId 为指定 parentId 的所有节点
+	var result []*types.SopNodeInfo
+	for _, node := range 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,
+				}
+			}
+		}
+
+		var actionForward *types.ActionForward
+		if node.ActionForward != nil {
+			actionForward = &types.ActionForward{}
+			actionForward.Wxid = node.ActionForward.Wxid
+			if len(node.ActionForward.Action) > 0 {
+				forwardAction := make([]types.Action, len(node.ActionForward.Action))
+				for i, condition := range node.ActionForward.Action {
+					forwardAction[i] = types.Action{
+						Type:    condition.Type,
+						Content: condition.Content,
+					}
+				}
+				actionForward.Action = forwardAction
+			}
+		} else {
+			actionForward = nil
+		}
+
+		child := 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,
+			NoReplyCondition: &node.NoReplyCondition,
+			NoReplyUnit:      &node.NoReplyUnit,
+			ActionMessage:    actionMessage,
+			ActionLabelAdd:   node.ActionLabelAdd,
+			ActionLabelDel:   node.ActionLabelDel,
+			ActionForward:    actionForward,
+		}
+		result = append(result, &child)
+
+	}
+	return result, nil
+}

+ 1 - 0
internal/logic/sop_stage/get_api_sop_stage_list_logic.go

@@ -44,6 +44,7 @@ func (l *GetApiSopStageListLogic) GetApiSopStageList(req *types.BatchSopStageLis
 
 	resp := &types.SopStageListResp{}
 	resp.Msg = errormsg.Success
+	resp.Data.Total = uint64(len(data))
 
 	for _, v := range data {
 		var conditionList []types.Condition

+ 7 - 0
internal/types/types.go

@@ -1366,6 +1366,13 @@ type SopNodeListResp struct {
 	Data []*SopChildNodeInfo `json:"data"`
 }
 
+// The response data of sop node list | SopNode列表数据
+type SopNodeListResp2 struct {
+	BaseDataInfo
+	// SopNode list data | SopNode列表数据
+	Data []*SopNodeInfo `json:"data"`
+}
+
 // SopNode list data | SopNode列表数据
 // swagger:model SopChildNodeInfo
 type SopChildNodeInfo struct {