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