Pārlūkot izejas kodu

初步调通与后端服务

liwei 5 dienas atpakaļ
vecāks
revīzija
40d41a9591

+ 1 - 1
desc/wechat/add_wechat_friend_log.api

@@ -5,7 +5,7 @@ type (
     //add_friend_by_phone api接口请求值
     AddWechatFriendLogInfo {
         Type int `json:"type"`
-        WeChatIds []string `json:"WeChatId,optional,omitempty"`
+        WeChatIds []string `json:"WeChatIds,optional,omitempty"`
         Phone string `json:"phone"`
         Message string `json:"message"`
     }

+ 49 - 1
internal/logic/add_friend/add_friend_by_phone_logic.go

@@ -3,9 +3,13 @@ package add_friend
 import (
 	"context"
 
+	"wechat-api/internal/logic/chat"
+	"wechat-api/internal/service/addfriend"
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
 
+	"github.com/suyuan32/simple-admin-common/enum/errorcode"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -22,8 +26,52 @@ func NewAddFriendByPhoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 		svcCtx: svcCtx}
 }
 
+/*
+func getWeChatIds(ids any) []string {
+	nids := []string{}
+	switch rv := ids.(type) {
+	case []string:
+		nids = rv
+	case string:
+		nids = append(nids, rv)
+	}
+	return nids
+}
+*/
+
 func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddWechatFriendLogInfo) (resp *types.BaseMsgResp, err error) {
 	// todo: add your logic here and delete this line
 
-	return
+	if req.Type != 2 {
+		req.Type = 1
+	}
+	if len(req.WeChatIds) == 0 {
+		req.WeChatIds = append(req.WeChatIds, "")
+	}
+	for _, wechatId := range req.WeChatIds {
+		nreq := &types.AddFriendByPhoneReq{Type: req.Type, WeChatId: wechatId, Phone: req.Phone, Message: req.Message}
+		//fmt.Println(typekit.PrettyPrint(nreq))
+		id, err := chat.AppendWechaFriendAddLog(l.ctx, l.svcCtx, nreq)
+		if err != nil {
+			logx.Errorf("chat.AppendWechaFriendAddLog err : %s", err)
+			continue
+		}
+		logx.Infof("chat.AppendWechaFriendAddLog succ,get id:%d",
+			id)
+
+		if req.Type != 1 {
+			continue //企微忽略后面
+		}
+		ret := addfriend.NewAddWechatFriendService(l.ctx, l.svcCtx).
+			FindFriendByContent(wechatId, req.Phone)
+		if ret {
+			logx.Infof("call addfriend.NewAddWechatFriendService.FindFriendByContent('%s','%s') maybe succ", wechatId, req.Phone)
+		}
+	}
+	resp = &types.BaseMsgResp{
+		Msg:  errormsg.Success,
+		Code: errorcode.OK,
+	}
+
+	return resp, nil
 }

+ 23 - 8
internal/logic/chat/add_friend_by_phone_logic.go

@@ -56,17 +56,32 @@ func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq)
 	return resp, nil
 }
 
-func (l *AddFriendByPhoneLogic) AppendWechaFriendAddReq(apiKeyObj *ent.ApiKey, req *types.AddFriendByPhoneReq) error {
+func AppendWechaFriendAddLog(ctx context.Context, svcCtx *svc.ServiceContext, addLog *types.AddFriendByPhoneReq) (int64, error) {
+
+	isCanAdd := 0
+	if addLog.Type != 1 {
+		isCanAdd = 1
+	}
+	res, err := svcCtx.DB.AddWechatFriendLog.Create().
+		SetNotNilOwnerWxID(&addLog.WeChatId).
+		SetNotNilOwnerWxType(&addLog.Type).
+		SetNotNilFindContent(&addLog.Phone).
+		SetNotNilMessage(&addLog.Message).
+		SetIsCanAdd(isCanAdd).
+		Save(ctx)
+
+	id := int64(0)
+	if err == nil {
+		id = res.ID
+	}
+	return id, err
+}
 
-	res, err := l.svcCtx.DB.AddWechatFriendLog.Create().
-		SetNotNilOwnerWxID(&req.WeChatId).
-		SetNotNilOwnerWxType(&req.Type).
-		SetNotNilFindContent(&req.Phone).
-		SetNotNilMessage(&req.Message).
-		Save(l.ctx)
+func (l *AddFriendByPhoneLogic) AppendWechaFriendAddReq(apiKeyObj *ent.ApiKey, req *types.AddFriendByPhoneReq) error {
 
+	id, err := AppendWechaFriendAddLog(l.ctx, l.svcCtx, req)
 	if err == nil {
-		logx.Infof("AppendWechaFriendAddReq succ,get id:%d", res.ID)
+		logx.Infof("AppendWechaFriendAddReq succ,get id:%d", id)
 	}
 	return err
 }

+ 4 - 3
internal/middleware/authority_middleware.go

@@ -3,11 +3,12 @@ package middleware
 import (
 	"context"
 	"errors"
-	"github.com/suyuan32/simple-admin-core/rpc/coreclient"
-	"github.com/suyuan32/simple-admin-core/rpc/types/core"
 	"net/http"
 	"strings"
 
+	"github.com/suyuan32/simple-admin-core/rpc/coreclient"
+	"github.com/suyuan32/simple-admin-core/rpc/types/core"
+
 	"github.com/casbin/casbin/v2"
 	"github.com/redis/go-redis/v9"
 	"github.com/suyuan32/simple-admin-common/config"
@@ -39,7 +40,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
 		// get the method
 		act := r.Method
 		// get the role id
-		roleIds := r.Context().Value("roleId").(string)
+		roleIds, _ := r.Context().Value("roleId").(string)
 
 		// check jwt blacklist
 		jwtResult, err := m.Rds.Get(context.Background(), config.RedisTokenPrefix+jwt.StripBearerPrefixFromToken(r.Header.Get("Authorization"))).Result()

+ 1 - 1
internal/types/types.go

@@ -4716,7 +4716,7 @@ type LoginResp struct {
 // swagger:model AddWechatFriendLogInfo
 type AddWechatFriendLogInfo struct {
 	Type      int      `json:"type"`
-	WeChatIds []string `json:"WeChatId,optional,omitempty"`
+	WeChatIds []string `json:"WeChatIds,optional,omitempty"`
 	Phone     string   `json:"phone"`
 	Message   string   `json:"message"`
 }