Răsfoiți Sursa

增加sop执行结果查看功能

boweniac 7 luni în urmă
părinte
comite
3ed3ca3b5a

+ 6 - 0
desc/wechat/message_records.api

@@ -76,6 +76,12 @@ type (
 
         // 发送内容 
         Content  *string `json:"content,optional"`
+
+        // 发送内容
+        SourceType  *int `json:"sourceType,optional"`
+
+        // 发送内容
+        SourceId  *uint64 `json:"sourceId,optional"`
     }
 
     // MessageRecords information response | MessageRecords信息返回体

+ 36 - 0
desc/wechat/sop_task.api

@@ -10,6 +10,38 @@ type (
         Data SopTaskListInfo `json:"data"`
     }
 
+    // The response data of sop task record list | SopTask列表数据
+    SopTaskRecordListResp {
+        BaseDataInfo
+
+        // SopTask list data | SopTask列表数据
+        Data []SopTaskRecordInfo `json:"data"`
+    }
+
+    // SopTask list data | SopTask列表数据
+    SopTaskRecordInfo {
+        // NodeId 节点ID
+        SourceType  *int `json:"sourceType,optional"`
+
+        // NodeId 节点ID
+        SourceId  *uint64 `json:"sourceId,optional"`
+
+        // 节点名称
+        Name  *string `json:"name,optional"`
+
+        // 消息总数
+        TotalCount *int64 `json:"totalCount,optional"`
+
+        // 成功数
+        SuccessCount *int64 `json:"successCount,optional"`
+
+        // 失败数
+        FailureCount *int64 `json:"failureCount,optional"`
+
+        // 成功率
+        SuccessRate *int64 `json:"successRate,optional"`
+    }
+
     // SopTask list data | SopTask列表数据
     SopTaskListInfo {
         BaseListInfo
@@ -69,6 +101,10 @@ service Wechat {
     @handler getSopTaskList
     post /sop_task/list (SopTaskListReq) returns (SopTaskListResp)
 
+    // Get sop task record list | 获取SopTask列表
+    @handler getSopTaskRecordList
+    post /sop_task/record_list (IDReq) returns (SopTaskRecordListResp)
+
     // Get sop task by ID | 通过ID获取SopTask
     @handler getSopTaskById
     post /sop_task (IDReq) returns (SopTaskInfoResp)

+ 5 - 0
internal/handler/routes.go

@@ -329,6 +329,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/sop_task/record_list",
+					Handler: sop_task.GetSopTaskRecordListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/sop_task",
 					Handler: sop_task.GetSopTaskByIdHandler(serverCtx),
 				},

+ 44 - 0
internal/handler/sop_task/get_sop_task_record_list_handler.go

@@ -0,0 +1,44 @@
+package sop_task
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/sop_task"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /sop_task/record_list sop_task GetSopTaskRecordList
+//
+// Get sop task record list | 获取SopTask列表
+//
+// Get sop task record list | 获取SopTask列表
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDReq
+//
+// Responses:
+//  200: SopTaskRecordListResp
+
+func GetSopTaskRecordListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := sop_task.NewGetSopTaskRecordListLogic(r.Context(), svcCtx)
+		resp, err := l.GetSopTaskRecordList(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 7 - 8
internal/logic/message_records/get_message_records_list_logic.go

@@ -41,6 +41,12 @@ func (l *GetMessageRecordsListLogic) GetMessageRecordsList(req *types.MessageRec
 	if req.Content != nil {
 		predicates = append(predicates, messagerecords.ContentContains(*req.Content))
 	}
+	if req.SourceType != nil {
+		predicates = append(predicates, messagerecords.SourceTypeEQ(*req.SourceType))
+	}
+	if req.SourceId != nil {
+		predicates = append(predicates, messagerecords.SourceIDEQ(*req.SourceId))
+	}
 	data, err := l.svcCtx.DB.MessageRecords.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
@@ -55,22 +61,15 @@ func (l *GetMessageRecordsListLogic) GetMessageRecordsList(req *types.MessageRec
 		resp.Data.Data = append(resp.Data.Data,
 			types.MessageRecordsInfo{
 				BaseIDInfo: types.BaseIDInfo{
-					Id:        &v.ID,
-					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
-					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+					Id: &v.ID,
 				},
 				Status:      &v.Status,
 				BotWxid:     &v.BotWxid,
-				ContactId:   &v.ContactID,
-				ContactType: &v.ContactType,
 				ContactWxid: &v.ContactWxid,
 				ContentType: &v.ContentType,
 				Content:     &v.Content,
 				ErrorDetail: &v.ErrorDetail,
 				SendTime:    pointy.GetUnixMilliPointer(v.SendTime.UnixMilli()),
-				SourceType:  &v.SourceType,
-				SourceId:    &v.SourceID,
-				SubSourceId: &v.SubSourceID,
 			})
 	}
 

+ 9 - 8
internal/logic/sop_node/get_sop_node_by_id_logic.go

@@ -55,14 +55,15 @@ func (l *GetSopNodeByIdLogic) GetSopNodeById(req *types.IDReq) (*types.SopNodeIn
 				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
 				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
 			},
-			Status:        &data.Status,
-			StageId:       &data.StageID,
-			ParentId:      &data.ParentID,
-			Name:          &data.Name,
-			ConditionType: &data.ConditionType,
-			ConditionList: data.ConditionList,
-			ActionMessage: actionMessage,
-			ActionLabel:   data.ActionLabel,
+			Status:           &data.Status,
+			StageId:          &data.StageID,
+			ParentId:         &data.ParentID,
+			Name:             &data.Name,
+			ConditionType:    &data.ConditionType,
+			ConditionList:    data.ConditionList,
+			NoReplyCondition: &data.NoReplyCondition,
+			ActionMessage:    actionMessage,
+			ActionLabel:      data.ActionLabel,
 		},
 	}, nil
 }

+ 9 - 8
internal/logic/sop_node/get_sop_node_detail_logic.go

@@ -53,14 +53,15 @@ func (l *GetSopNodeDetailLogic) GetSopNodeDetail(req *types.IDReq) (resp *types.
 				CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
 				UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
 			},
-			Status:        &data.Status,
-			StageId:       &data.StageID,
-			ParentId:      &data.ParentID,
-			Name:          &data.Name,
-			ConditionType: &data.ConditionType,
-			ConditionList: data.ConditionList,
-			ActionMessage: actionMessage,
-			ActionLabel:   data.ActionLabel,
+			Status:           &data.Status,
+			StageId:          &data.StageID,
+			ParentId:         &data.ParentID,
+			Name:             &data.Name,
+			ConditionType:    &data.ConditionType,
+			ConditionList:    data.ConditionList,
+			NoReplyCondition: &data.NoReplyCondition,
+			ActionMessage:    actionMessage,
+			ActionLabel:      data.ActionLabel,
 		},
 	}, nil
 }

+ 9 - 8
internal/logic/sop_node/get_sop_node_list_logic.go

@@ -82,14 +82,15 @@ func GetSopNodeListByParentId(parentId uint64, nodeList []*ent.SopNode) ([]*type
 					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:           &node.Status,
+					StageId:          &node.StageID,
+					ParentId:         &node.ParentID,
+					Name:             &node.Name,
+					ConditionType:    &node.ConditionType,
+					ConditionList:    node.ConditionList,
+					NoReplyCondition: &node.NoReplyCondition,
+					ActionMessage:    actionMessage,
+					ActionLabel:      node.ActionLabel,
 				},
 			}
 			result = append(result, &child)

+ 90 - 0
internal/logic/sop_task/get_sop_task_record_list_logic.go

@@ -0,0 +1,90 @@
+package sop_task
+
+import (
+	"context"
+	"fmt"
+	"wechat-api/ent"
+	"wechat-api/ent/messagerecords"
+	"wechat-api/ent/soptask"
+	"wechat-api/internal/utils/dberrorhandler"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetSopTaskRecordListLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetSopTaskRecordListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSopTaskRecordListLogic {
+	return &GetSopTaskRecordListLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetSopTaskRecordListLogic) GetSopTaskRecordList(req *types.IDReq) (resp *types.SopTaskRecordListResp, err error) {
+	organizationId := l.ctx.Value("organizationId").(uint64)
+	data, err := l.svcCtx.DB.SopTask.Query().
+		Where(soptask.ID(req.Id), soptask.OrganizationIDEQ(organizationId)).
+		WithTaskStages(func(query *ent.SopStageQuery) {
+			query.WithStageNodes()
+		}).
+		Only(l.ctx)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+	fmt.Printf("----------------data1----------------: %+v\n", data.Edges.TaskStages)
+	fmt.Printf("----------------data2----------------: %+v\n", data.Edges.TaskStages[0].Edges.StageNodes)
+	var sopTaskRecordList []types.SopTaskRecordInfo
+	for _, s := range data.Edges.TaskStages {
+		// 在message_records 表中统计 source_type=3, source_id=s.ID的记录数,以及其中status=3的记录数
+		sst, _ := l.SopTaskRecord(3, s.ID, s.Name)
+		fmt.Printf("----------------sst----------------: %+v\n", *sst)
+		sopTaskRecordList = append(sopTaskRecordList, *sst)
+		for _, n := range s.Edges.StageNodes {
+			nst, _ := l.SopTaskRecord(4, n.ID, n.Name)
+			fmt.Printf("----------------nst----------------: %+v\n", *nst)
+			sopTaskRecordList = append(sopTaskRecordList, *nst)
+		}
+	}
+
+	resp = &types.SopTaskRecordListResp{
+		Data: sopTaskRecordList,
+	}
+
+	return resp, nil
+}
+
+func (l *GetSopTaskRecordListLogic) SopTaskRecord(sourceType int, sourceId uint64, name string) (resp *types.SopTaskRecordInfo, err error) {
+	fmt.Printf("----------------sourceType----------------: %d\n", sourceType)
+	fmt.Printf("----------------sourceId----------------: %d\n", sourceId)
+	stageTotalCount, _ := l.svcCtx.DB.MessageRecords.Query().
+		Where(messagerecords.SourceType(sourceType), messagerecords.SourceID(sourceId)).
+		Count(l.ctx)
+	stageSuccessCount, _ := l.svcCtx.DB.MessageRecords.Query().
+		Where(messagerecords.SourceTypeEQ(sourceType), messagerecords.SourceID(sourceId), messagerecords.Status(3)).
+		Count(l.ctx)
+	fmt.Printf("----------------stageTotalCount----------------: %d\n", stageTotalCount)
+	fmt.Printf("----------------stageSuccessCount----------------: %d\n", stageSuccessCount)
+	totalCountInt64 := int64(stageTotalCount)
+	successCountInt64 := int64(stageSuccessCount)
+	failureCount := totalCountInt64 - successCountInt64
+	successRate := int64(0)
+	if totalCountInt64 != 0 {
+		successRate = successCountInt64 * 100 / totalCountInt64
+	}
+	return &types.SopTaskRecordInfo{
+		SourceType:   &sourceType,
+		SourceId:     &sourceId,
+		Name:         &name,
+		TotalCount:   &totalCountInt64,
+		SuccessCount: &successCountInt64,
+		FailureCount: &failureCount,
+		SuccessRate:  &successRate,
+	}, nil
+}

+ 31 - 0
internal/types/types.go

@@ -705,6 +705,33 @@ type SopTaskListResp struct {
 	Data SopTaskListInfo `json:"data"`
 }
 
+// The response data of sop task record list | SopTask列表数据
+// swagger:model SopTaskRecordListResp
+type SopTaskRecordListResp struct {
+	BaseDataInfo
+	// SopTask list data | SopTask列表数据
+	Data []SopTaskRecordInfo `json:"data"`
+}
+
+// SopTask list data | SopTask列表数据
+// swagger:model SopTaskRecordInfo
+type SopTaskRecordInfo struct {
+	// NodeId 节点ID
+	SourceType *int `json:"sourceType,optional"`
+	// NodeId 节点ID
+	SourceId *uint64 `json:"sourceId,optional"`
+	// 节点名称
+	Name *string `json:"name,optional"`
+	// 消息总数
+	TotalCount *int64 `json:"totalCount,optional"`
+	// 成功数
+	SuccessCount *int64 `json:"successCount,optional"`
+	// 失败数
+	FailureCount *int64 `json:"failureCount,optional"`
+	// 成功率
+	SuccessRate *int64 `json:"successRate,optional"`
+}
+
 // SopTask list data | SopTask列表数据
 // swagger:model SopTaskListInfo
 type SopTaskListInfo struct {
@@ -971,6 +998,10 @@ type MessageRecordsListReq struct {
 	ContactWxid *string `json:"contactWxid,optional"`
 	// 发送内容
 	Content *string `json:"content,optional"`
+	// 发送内容
+	SourceType *int `json:"sourceType,optional"`
+	// 发送内容
+	SourceId *uint64 `json:"sourceId,optional"`
 }
 
 // MessageRecords information response | MessageRecords信息返回体