Browse Source

fix:edit chat_session/list

jimmyyem 4 months ago
parent
commit
2f37f6c983

+ 1 - 1
desc/wechat/chat_records.api

@@ -46,7 +46,7 @@ type (
     ChatRecordsListReq {
         PageInfo
 
-        SessionId  *uint64 `json:"sessionId,optional"`
+        SessionId  *uint64 `json:"sessionId"`
 		BotId *uint64 `json:"botId,optional"`
 		BotType *uint8  `json:"botType,optional"`
     }

+ 1 - 0
desc/wechat/chat_session.api

@@ -40,6 +40,7 @@ type (
 
 		BotId  *uint64 `json:"botId,optional"`
         BotType  *uint8 `json:"botType,optional"`
+		BotName *string `json:"botName,optional"`
     }
 
     // ChatSession information response | ChatSession信息返回体

+ 4 - 2
internal/logic/chatrecords/get_chat_records_list_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/errorx"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -30,9 +31,10 @@ func NewGetChatRecordsListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 func (l *GetChatRecordsListLogic) GetChatRecordsList(req *types.ChatRecordsListReq) (*types.ChatRecordsListResp, error) {
 	var predicates []predicate.ChatRecords
 
-	if req.SessionId != nil && *req.SessionId > 0 {
-		predicates = append(predicates, chatrecords.SessionID(*req.SessionId))
+	if req.SessionId == nil || *req.SessionId <= 0 {
+		return nil, errorx.NewInvalidArgumentError("会话ID不能为空")
 	}
+	predicates = append(predicates, chatrecords.SessionID(*req.SessionId))
 	if req.BotId != nil && *req.BotId > 0 {
 		predicates = append(predicates, chatrecords.BotID(*req.BotId))
 	}

+ 35 - 3
internal/logic/chatsession/get_chat_session_list_logic.go

@@ -4,8 +4,11 @@ import (
 	"context"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/errorx"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/employee"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/wxcard"
 	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
@@ -28,9 +31,40 @@ func NewGetChatSessionListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *GetChatSessionListLogic) GetChatSessionList(req *types.ChatSessionListReq) (*types.ChatSessionListResp, error) {
+	resp := &types.ChatSessionListResp{}
+	resp.Msg = errormsg.Success
+
 	var predicates []predicate.ChatSession
-	if req.BotType != nil && *req.BotType > 0 {
+	if req.BotType == nil || *req.BotType == 0 {
+		return nil, errorx.NewInvalidArgumentError("BotId cannot be null")
+	}
+	if req.BotName != nil && *req.BotName != "" {
 		predicates = append(predicates, chatsession.BotType(*req.BotType))
+
+		ids := make([]uint64, 0)
+		if *req.BotType == 2 {
+			wxcardList, err := l.svcCtx.DB.WxCard.Query().Where(wxcard.NameContains(*req.BotName)).All(l.ctx)
+			if err != nil {
+				return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+			}
+			for _, val := range wxcardList {
+				ids = append(ids, val.ID)
+			}
+		} else if *req.BotType == 3 {
+			employeeList, err := l.svcCtx.DB.Employee.Query().Where(employee.TitleContains(*req.BotName)).All(l.ctx)
+			if err != nil {
+				return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+			}
+			for _, val := range employeeList {
+				ids = append(ids, val.ID)
+			}
+		}
+
+		if len(ids) > 0 {
+			predicates = append(predicates, chatsession.BotIDIn(ids...))
+		} else {
+			return resp, nil
+		}
 	}
 
 	data, err := l.svcCtx.DB.ChatSession.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
@@ -39,8 +73,6 @@ func (l *GetChatSessionListLogic) GetChatSessionList(req *types.ChatSessionListR
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
-	resp := &types.ChatSessionListResp{}
-	resp.Msg = errormsg.Success
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {

+ 2 - 1
internal/types/types.go

@@ -2270,7 +2270,7 @@ type ChatRecordsListInfo struct {
 // swagger:model ChatRecordsListReq
 type ChatRecordsListReq struct {
 	PageInfo
-	SessionId *uint64 `json:"sessionId,optional"`
+	SessionId *uint64 `json:"sessionId"`
 	BotId     *uint64 `json:"botId,optional"`
 	BotType   *uint8  `json:"botType,optional"`
 }
@@ -2349,6 +2349,7 @@ type ChatSessionListReq struct {
 	PageInfo
 	BotId   *uint64 `json:"botId,optional"`
 	BotType *uint8  `json:"botType,optional"`
+	BotName *string `json:"botName,optional"`
 }
 
 // ChatSession information response | ChatSession信息返回体