|
@@ -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 {
|