Bläddra i källkod

优化小程序后台相关功能

boweniac 3 månader sedan
förälder
incheckning
b39bfe6b7f

+ 3 - 0
desc/wechat/chat_records.api

@@ -11,6 +11,9 @@ type (
         // 内容类型:1-提问 2-回答 
         ContentType  *uint8 `json:"contentType,optional"`
 
+        // 角色类型:1-用户 2-智能体
+        RoleType  *string `json:"roleType,optional"`
+
         // 会话ID 
         SessionId  *uint64 `json:"sessionId,optional"`
 

+ 8 - 0
desc/wechat/chat_session.api

@@ -11,11 +11,19 @@ type (
         // 用户ID 
         UserId  *uint64 `json:"userId,optional"`
 
+        UserName  *string `json:"userName,optional"`
+
         // 聊天ID 
         BotId  *uint64 `json:"botId,optional"`
 
+        // 主体名称
+        BotName  *string `json:"botName,optional"`
+
         // 类型:1-微信 2-小程序card 3-智能体 
         BotType  *uint8 `json:"botType,optional"`
+
+        // 类型:1-微信 2-小程序card 3-智能体
+        BotTypeStr  *string `json:"botTypeStr,optional"`
     }
 
     // The response data of chat session list | ChatSession列表数据

+ 3 - 1
desc/wechat/wx_card.api

@@ -48,7 +48,7 @@ type (
         // 个人介绍 
         Intro  *string `json:"intro,optional"`
 	
-		ShowChat *bool `json:"showChat,optioal"`
+		ShowChat *bool `json:"showChat,optional"`
 		ShowAi *bool `json:"showAi,optional"`
 		IsVip *bool `json:"isVip,optional"`
     }
@@ -60,6 +60,8 @@ type (
 
 		// 名称
 		Name  *string `json:"name,optional"`
+
+		Type *string `json:"type,optional"`
 	}
 
     // The response data of wx card list | WxCard列表数据

+ 3 - 0
desc/wechat/wx_card_user.api

@@ -64,6 +64,9 @@ type (
 
         // 头像 
         Avatar  *string `json:"avatar,optional"`
+
+        // 昵称
+        Nickname  *string `json:"nickname,optional"`
     }
 
     // WxCardUser information response | WxCardUser信息返回体

+ 10 - 1
desc/wechat/wx_card_visit.api

@@ -9,12 +9,18 @@ type (
         // user表ID 
         UserId  *uint64 `json:"userId,optional"`
 
+        // user名
+        UserName  *string `json:"userName,optional"`
+
         // 被访ID 
         BotId  *uint64 `json:"botId,optional"`
 
-        // 类型:1-微信 2-小程序 3-智能体 
+        // 类型:1-微信 2-小程序 3-智能体
         BotType  *uint8 `json:"botType,optional"`
 
+        // 类型:1-微信 2-小程序 3-智能体
+        BotTypeStr  *string `json:"botTypeStr,optional"`
+
 		CardInfo WxCardSimpleInfo `json:"cardInfo,optional,omitempty"`
     }
 
@@ -65,6 +71,9 @@ type (
     // Get wx card visit list request params | WxCardVisit列表请求参数
     WxCardVisitListReq {
         PageInfo
+        BotId  *uint64 `json:"botId,optional"`
+        BotType  *uint8 `json:"botType,optional"`
+        BotName *string `json:"botName,optional"`
     }
 
     // WxCardVisit information response | WxCardVisit信息返回体

+ 9 - 1
internal/logic/chatrecords/get_chat_records_list_logic.go

@@ -5,6 +5,7 @@ import (
 	"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"
 	"wechat-api/ent/chatrecords"
 	"wechat-api/ent/predicate"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -42,7 +43,7 @@ func (l *GetChatRecordsListLogic) GetChatRecordsList(req *types.ChatRecordsListR
 		predicates = append(predicates, chatrecords.BotType(*req.BotType))
 	}
 
-	data, err := l.svcCtx.DB.ChatRecords.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+	data, err := l.svcCtx.DB.ChatRecords.Query().Where(predicates...).Order(ent.Asc("created_at")).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -53,6 +54,12 @@ func (l *GetChatRecordsListLogic) GetChatRecordsList(req *types.ChatRecordsListR
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
+		roleType := ""
+		if v.ContentType == 1 {
+			roleType = "用户"
+		} else if v.ContentType == 2 {
+			roleType = "智能体"
+		}
 		resp.Data.Data = append(resp.Data.Data,
 			types.ChatRecordsInfo{
 				BaseIDInfo: types.BaseIDInfo{
@@ -62,6 +69,7 @@ func (l *GetChatRecordsListLogic) GetChatRecordsList(req *types.ChatRecordsListR
 				},
 				Content:     &v.Content,
 				ContentType: &v.ContentType,
+				RoleType:    &roleType,
 				SessionId:   &v.SessionID,
 				UserId:      &v.UserID,
 				BotId:       &v.BotID,

+ 31 - 4
internal/logic/chatsession/get_chat_session_list_logic.go

@@ -2,10 +2,14 @@ package chatsession
 
 import (
 	"context"
+	"fmt"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"wechat-api/ent/chatsession"
+	"wechat-api/ent/employee"
 	"wechat-api/ent/predicate"
+	"wechat-api/ent/wxcard"
+	"wechat-api/ent/wxcarduser"
 	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
@@ -91,6 +95,26 @@ func (l *GetChatSessionListLogic) GetChatSessionList(req *types.ChatSessionListR
 	resp.Data.Total = data.PageDetails.Total
 
 	for _, v := range data.List {
+		botType := ""
+		botName := ""
+		userName := ""
+		if v.BotType == 1 {
+			botType = "微信"
+		} else if v.BotType == 2 {
+			botType = "名片"
+			cardInfo, _ := l.svcCtx.DB.WxCard.Query().Where(wxcard.ID(v.BotID)).First(l.ctx)
+			botName = cardInfo.Name
+		} else if v.BotType == 3 {
+			botType = "数字员工"
+			employeeInfo, _ := l.svcCtx.DB.Employee.Query().Where(employee.ID(v.BotID)).First(l.ctx)
+			botName = employeeInfo.Title
+		}
+		userInfo, _ := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(v.UserID)).First(l.ctx)
+		if userInfo != nil {
+			userName = userInfo.Nickname
+		} else {
+			userName = fmt.Sprintf("用户_%d", v.UserID)
+		}
 		resp.Data.Data = append(resp.Data.Data,
 			types.ChatSessionInfo{
 				BaseIDInfo: types.BaseIDInfo{
@@ -98,10 +122,13 @@ func (l *GetChatSessionListLogic) GetChatSessionList(req *types.ChatSessionListR
 					CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
-				Name:    &v.Name,
-				UserId:  &v.UserID,
-				BotId:   &v.BotID,
-				BotType: &v.BotType,
+				Name:       &v.Name,
+				UserId:     &v.UserID,
+				UserName:   &userName,
+				BotId:      &v.BotID,
+				BotName:    &botName,
+				BotType:    &v.BotType,
+				BotTypeStr: &botType,
 			})
 	}
 

+ 3 - 0
internal/logic/wxcarduser/get_wx_card_user_list_logic.go

@@ -36,6 +36,9 @@ func (l *GetWxCardUserListLogic) GetWxCardUserList(req *types.WxCardUserListReq)
 	if req.Account != nil && *req.Account != "" {
 		predicates = append(predicates, wxcarduser.AccountContains(*req.Account))
 	}
+	if req.Nickname != nil && *req.Nickname != "" {
+		predicates = append(predicates, wxcarduser.NicknameContains(*req.Nickname))
+	}
 
 	data, err := l.svcCtx.DB.WxCardUser.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 	if err != nil {

+ 30 - 5
internal/logic/wxcardvisit/get_wx_card_visit_list_logic.go

@@ -2,12 +2,16 @@ package wxcardvisit
 
 import (
 	"context"
+	"fmt"
 	"github.com/alibabacloud-go/tea/tea"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/suyuan32/simple-admin-common/utils/pointy"
 	"wechat-api/ent"
-	"wechat-api/ent/agent"
+	"wechat-api/ent/employee"
+	"wechat-api/ent/predicate"
 	"wechat-api/ent/wxcard"
+	"wechat-api/ent/wxcarduser"
+	"wechat-api/ent/wxcardvisit"
 	"wechat-api/internal/utils/dberrorhandler"
 
 	"wechat-api/internal/svc"
@@ -30,7 +34,15 @@ func NewGetWxCardVisitListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 }
 
 func (l *GetWxCardVisitListLogic) GetWxCardVisitList(req *types.WxCardVisitListReq) (*types.WxCardVisitListResp, error) {
-	data, err := l.svcCtx.DB.WxCardVisit.Query().Page(l.ctx, req.Page, req.PageSize)
+	var predicates []predicate.WxCardVisit
+	if req.BotType != nil && *req.BotType > 0 {
+		predicates = append(predicates, wxcardvisit.BotType(*req.BotType))
+	}
+
+	if req.BotId != nil && *req.BotId > 0 {
+		predicates = append(predicates, wxcardvisit.BotID(*req.BotId))
+	}
+	data, err := l.svcCtx.DB.WxCardVisit.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
 
 	if err != nil {
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
@@ -42,7 +54,7 @@ func (l *GetWxCardVisitListLogic) GetWxCardVisitList(req *types.WxCardVisitListR
 
 	wxIds, cardIds, agentIds := make([]uint64, 0), make([]uint64, 0), make([]uint64, 0)
 	wxCardList := make(map[uint64]*ent.WxCard)
-	wxAgentList := make(map[uint64]*ent.Agent)
+	wxAgentList := make(map[uint64]*ent.Employee)
 	for _, v := range data.List {
 		if v.BotType == 1 {
 			wxIds = append(wxIds, v.BotID)
@@ -59,7 +71,7 @@ func (l *GetWxCardVisitListLogic) GetWxCardVisitList(req *types.WxCardVisitListR
 		}
 	}
 	if len(agentIds) > 0 {
-		agentList, _ := l.svcCtx.DB.Agent.Query().Where(agent.IDIn(agentIds...)).All(l.ctx)
+		agentList, _ := l.svcCtx.DB.Employee.Query().Where(employee.IDIn(agentIds...)).All(l.ctx)
 		for _, val := range agentList {
 			wxAgentList[val.ID] = val
 		}
@@ -67,19 +79,31 @@ func (l *GetWxCardVisitListLogic) GetWxCardVisitList(req *types.WxCardVisitListR
 
 	for _, v := range data.List {
 		cardInfo := types.WxCardSimpleInfo{}
+		botType := ""
 		if v.BotType == 1 {
 
 		} else if v.BotType == 2 {
 			if card, ok := wxCardList[v.BotID]; ok {
 				cardInfo.Name = &card.Name
 				cardInfo.Avatar = &card.Avatar
+				botType = "名片"
+				cardInfo.Type = &botType
 			}
 		} else {
 			if agentItem, ok := wxAgentList[v.BotID]; ok {
-				cardInfo.Name = &agentItem.Name
+				cardInfo.Name = &agentItem.Title
 				cardInfo.Avatar = tea.String("")
+				botType = "数字员工"
+				cardInfo.Type = &botType
 			}
 		}
+		userName := ""
+		userInfo, _ := l.svcCtx.DB.WxCardUser.Query().Where(wxcarduser.ID(v.UserID)).First(l.ctx)
+		if userInfo != nil {
+			userName = userInfo.Nickname
+		} else {
+			userName = fmt.Sprintf("用户_%d", v.UserID)
+		}
 		resp.Data.Data = append(resp.Data.Data,
 			types.WxCardVisitInfo{
 				BaseIDInfo: types.BaseIDInfo{
@@ -88,6 +112,7 @@ func (l *GetWxCardVisitListLogic) GetWxCardVisitList(req *types.WxCardVisitListR
 					UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
 				},
 				UserId:   &v.UserID,
+				UserName: &userName,
 				BotId:    &v.BotID,
 				BotType:  &v.BotType,
 				CardInfo: cardInfo,

+ 21 - 4
internal/types/types.go

@@ -2242,6 +2242,8 @@ type ChatRecordsInfo struct {
 	Content *string `json:"content,optional"`
 	// 内容类型:1-提问 2-回答
 	ContentType *uint8 `json:"contentType,optional"`
+	// 角色类型:1-用户 2-智能体
+	RoleType *string `json:"roleType,optional"`
 	// 会话ID
 	SessionId *uint64 `json:"sessionId,optional"`
 	// 用户ID
@@ -2323,11 +2325,16 @@ type ChatSessionInfo struct {
 	// 名称
 	Name *string `json:"name,optional"`
 	// 用户ID
-	UserId *uint64 `json:"userId,optional"`
+	UserId   *uint64 `json:"userId,optional"`
+	UserName *string `json:"userName,optional"`
 	// 聊天ID
 	BotId *uint64 `json:"botId,optional"`
+	// 主体名称
+	BotName *string `json:"botName,optional"`
 	// 类型:1-微信 2-小程序card 3-智能体
 	BotType *uint8 `json:"botType,optional"`
+	// 类型:1-微信 2-小程序card 3-智能体
+	BotTypeStr *string `json:"botTypeStr,optional"`
 }
 
 // The response data of chat session list | ChatSession列表数据
@@ -2396,7 +2403,7 @@ type WxCardInfo struct {
 	AiInfo *string `json:"aiInfo,optional"`
 	// 个人介绍
 	Intro    *string `json:"intro,optional"`
-	ShowChat *bool   `json:"showChat,optioal"`
+	ShowChat *bool   `json:"showChat,optional"`
 	ShowAi   *bool   `json:"showAi,optional"`
 	IsVip    *bool   `json:"isVip,optional"`
 }
@@ -2408,6 +2415,7 @@ type WxCardSimpleInfo struct {
 	Avatar *string `json:"avatar,optional"`
 	// 名称
 	Name *string `json:"name,optional"`
+	Type *string `json:"type,optional"`
 }
 
 // The response data of wx card list | WxCard列表数据
@@ -2505,6 +2513,8 @@ type WxCardUserListReq struct {
 	Account *string `json:"account,optional"`
 	// 头像
 	Avatar *string `json:"avatar,optional"`
+	// 昵称
+	Nickname *string `json:"nickname,optional"`
 }
 
 // WxCardUser information response | WxCardUser信息返回体
@@ -2521,11 +2531,15 @@ type WxCardVisitInfo struct {
 	BaseIDInfo
 	// user表ID
 	UserId *uint64 `json:"userId,optional"`
+	// user名
+	UserName *string `json:"userName,optional"`
 	// 被访ID
 	BotId *uint64 `json:"botId,optional"`
 	// 类型:1-微信 2-小程序 3-智能体
-	BotType  *uint8           `json:"botType,optional"`
-	CardInfo WxCardSimpleInfo `json:"cardInfo,optional,omitempty"`
+	BotType *uint8 `json:"botType,optional"`
+	// 类型:1-微信 2-小程序 3-智能体
+	BotTypeStr *string          `json:"botTypeStr,optional"`
+	CardInfo   WxCardSimpleInfo `json:"cardInfo,optional,omitempty"`
 }
 
 // swagger:model WxCardVisitReq
@@ -2571,6 +2585,9 @@ type WxCardVisitListInfo struct {
 // swagger:model WxCardVisitListReq
 type WxCardVisitListReq struct {
 	PageInfo
+	BotId   *uint64 `json:"botId,optional"`
+	BotType *uint8  `json:"botType,optional"`
+	BotName *string `json:"botName,optional"`
 }
 
 // WxCardVisit information response | WxCardVisit信息返回体