|
@@ -0,0 +1,114 @@
|
|
|
|
+package add_friend
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "context"
|
|
|
|
+ "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
|
+ "github.com/zeromicro/go-zero/core/errorx"
|
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
|
+ "wechat-api/ent/addwechatfriendlog"
|
|
|
|
+ "wechat-api/ent/predicate"
|
|
|
|
+ "wechat-api/ent/wx"
|
|
|
|
+ "wechat-api/internal/svc"
|
|
|
|
+ "wechat-api/internal/types"
|
|
|
|
+ "wechat-api/internal/utils"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type AddFriendListLogic struct {
|
|
|
|
+ logx.Logger
|
|
|
|
+ ctx context.Context
|
|
|
|
+ svcCtx *svc.ServiceContext
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func NewAddFriendListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddFriendListLogic {
|
|
|
|
+ return &AddFriendListLogic{
|
|
|
|
+ Logger: logx.WithContext(ctx),
|
|
|
|
+ ctx: ctx,
|
|
|
|
+ svcCtx: svcCtx}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (l *AddFriendListLogic) AddFriendList(req *types.AddFriendListReq) (resp *types.AddFriendListResp, err error) {
|
|
|
|
+ //获取上下文的组织id
|
|
|
|
+ organizationId := l.ctx.Value("organizationId").(uint64)
|
|
|
|
+ //通过organizationId去wx表拿微信机器人的数
|
|
|
|
+
|
|
|
|
+ query := l.svcCtx.DB.Wx.Query().Where(wx.OrganizationIDEQ(organizationId), wx.StatusEQ(1))
|
|
|
|
+ // 动态添加条件示例:假设 req.OwnerWxId 存在时添加额外的 Where 条件
|
|
|
|
+ if utils.IsNonEmptyString(req.OwnerWxId) {
|
|
|
|
+ query = query.Where(wx.WxidEQ(*req.OwnerWxId))
|
|
|
|
+ }
|
|
|
|
+ wxIds, err := query.Select(wx.FieldWxid).Strings(l.ctx)
|
|
|
|
+ if err != nil {
|
|
|
|
+ //数据库错误,不直接返回错误,防止暴露数据库错误
|
|
|
|
+ return nil, errorx.NewInvalidArgumentError("请联系管理员")
|
|
|
|
+ }
|
|
|
|
+ //机器人列表为空,直接返回
|
|
|
|
+ if len(wxIds) == 0 {
|
|
|
|
+ return nil, errorx.NewInvalidArgumentError("当前组织架构下,没有wx机器人")
|
|
|
|
+ }
|
|
|
|
+ var predicates []predicate.AddWechatFriendLog
|
|
|
|
+
|
|
|
|
+ predicates = append(predicates, addwechatfriendlog.OwnerWxIDIn(wxIds...))
|
|
|
|
+ ownerWxType := req.OwnerWxType
|
|
|
|
+ //查询企业微信机器人加的好友
|
|
|
|
+ if *ownerWxType > 0 {
|
|
|
|
+ predicates = append(predicates, addwechatfriendlog.OwnerWxTypeEQ(*ownerWxType))
|
|
|
|
+ }
|
|
|
|
+ //查找添加好友
|
|
|
|
+ if utils.IsNonEmptyString(req.FindContent) {
|
|
|
|
+ predicates = append(predicates, addwechatfriendlog.FindContent(*req.FindContent))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var IsCanAdd []int
|
|
|
|
+ if req.Status != nil {
|
|
|
|
+ switch *req.Status {
|
|
|
|
+ case 1:
|
|
|
|
+ IsCanAdd = append(IsCanAdd, 0, 1)
|
|
|
|
+ case 2:
|
|
|
|
+ IsCanAdd = append(IsCanAdd, 3, 4)
|
|
|
|
+ default:
|
|
|
|
+ IsCanAdd = append(IsCanAdd, 2)
|
|
|
|
+ }
|
|
|
|
+ predicates = append(predicates, addwechatfriendlog.IsCanAddIn(IsCanAdd...))
|
|
|
|
+ }
|
|
|
|
+ data, err := l.svcCtx.DB.AddWechatFriendLog.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
|
|
|
|
+
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, errorx.NewInvalidArgumentError("请联系管理员")
|
|
|
|
+ }
|
|
|
|
+ resp = &types.AddFriendListResp{}
|
|
|
|
+ resp.Msg = errormsg.Success
|
|
|
|
+ resp.Data.Total = data.PageDetails.Total
|
|
|
|
+ for _, v := range data.List {
|
|
|
|
+ var wxString string
|
|
|
|
+ if v.OwnerWxType == 1 {
|
|
|
|
+ wxString = "个微"
|
|
|
|
+ } else {
|
|
|
|
+ wxString = "企微"
|
|
|
|
+ }
|
|
|
|
+ resp.Data.Data = append(resp.Data.Data,
|
|
|
|
+ types.FriendList{
|
|
|
|
+ Id: v.ID,
|
|
|
|
+ OwnerWxId: &v.OwnerWxID,
|
|
|
|
+ OwnerWxType: &wxString,
|
|
|
|
+ FindContent: &v.FindContent,
|
|
|
|
+ Status: func() *string {
|
|
|
|
+ statusMap := map[int]string{
|
|
|
|
+ 0: "数据准备中",
|
|
|
|
+ 1: "待执行",
|
|
|
|
+ 2: "成功邀请",
|
|
|
|
+ 3: "timeout及其他错误",
|
|
|
|
+ 4: "用户不存在",
|
|
|
|
+ 5: "后台取消",
|
|
|
|
+ }
|
|
|
|
+ statusStr := statusMap[v.IsCanAdd]
|
|
|
|
+ return &statusStr
|
|
|
|
+ }(),
|
|
|
|
+ TaskCount: &v.TaskCount,
|
|
|
|
+ Message: &v.Message,
|
|
|
|
+ CreateTime: utils.UnixTimeToBeijing(v.CreatedAt),
|
|
|
|
+ UpdateTime: utils.UnixTimeToBeijing(v.UpdatedAt),
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ return resp, nil
|
|
|
|
+}
|