浏览代码

Merge branch 'task_526_lichangdong_250424' into debug

lichangdong 3 天之前
父节点
当前提交
c1ab84bc6a

+ 8 - 1
crontask/wx_add_friend.go

@@ -121,8 +121,15 @@ func (me *CronTask) getTaskList() ([]*ent.AddWechatFriendLog, error) {
 		WITH RandRanked AS (
     		SELECT %s,ROW_NUMBER() OVER(PARTITION BY owner_wx_id ORDER BY id DESC) as rn
     		FROM add_wechat_friend_log
-		    WHERE is_can_add = 1 AND task_count < 3)
+		    WHERE is_can_add = 1 )
 		SELECT %s FROM RandRanked WHERE rn = 1;`, fieldListStr, fieldListStr)
+	/*
+				rawQuery := fmt.Sprintf(`
+				WITH RandRanked AS (
+		    		SELECT %s,ROW_NUMBER() OVER(PARTITION BY owner_wx_id ORDER BY id DESC) as rn
+		    		FROM add_wechat_friend_log
+				    WHERE is_can_add = 1 AND task_count < 3)
+				SELECT %s FROM RandRanked WHERE rn = 1;`, fieldListStr, fieldListStr)*/
 
 	//fmt.Println(rawQuery)
 	// 执行原始查询

+ 15 - 0
internal/logic/chat/add_friend_by_phone_logic.go

@@ -12,6 +12,7 @@ import (
 	"wechat-api/internal/types"
 	"wechat-api/internal/utils/typekit"
 
+	"github.com/go-sql-driver/mysql"
 	"github.com/suyuan32/simple-admin-common/enum/errorcode"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -157,6 +158,7 @@ func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq)
 		}
 		logx.Infof("chat.AppendWechaFriendAddLog succ,get id:%d", id)
 
+		continue
 		if req.Type != 1 {
 			continue //企微忽略后面
 		}
@@ -171,12 +173,21 @@ func (l *AddFriendByPhoneLogic) AddFriendByPhone(req *types.AddFriendByPhoneReq)
 	return &types.BaseMsgResp{Msg: errormsg.Success, Code: errorcode.OK}, nil
 }
 
+func isDuplicateEntry(err error) bool {
+	var mysqlErr *mysql.MySQLError
+	if errors.As(err, &mysqlErr) {
+		return mysqlErr.Number == 1062
+	}
+	return false
+}
+
 func (l *AddFriendByPhoneLogic) AppendWechaFriendAddInfo(addInfo *AddFriendByPhoneInfo) (int64, error) {
 
 	isCanAdd := 0
 	if addInfo.Type != 1 {
 		isCanAdd = 1
 	}
+	isCanAdd = 1
 	res, err := l.svcCtx.DB.AddWechatFriendLog.Create().
 		SetNotNilOwnerWxID(&addInfo.WeChatId).
 		SetNotNilOwnerWxType(&addInfo.Type).
@@ -189,6 +200,10 @@ func (l *AddFriendByPhoneLogic) AppendWechaFriendAddInfo(addInfo *AddFriendByPho
 	id := int64(0)
 	if err == nil {
 		id = res.ID
+	} else {
+		if isDuplicateEntry(err) {
+			err = errors.New("手机号不能重复绑定")
+		}
 	}
 	return id, err
 }

+ 4 - 4
internal/service/MessageHandlers/find_contact_task_result_notice.go

@@ -91,16 +91,16 @@ func (f *FindContactTaskResultNoticeHandler) Handle(ctx context.Context, msg *we
 
 	if message.ErrMsg != nil {
 		if *message.ErrMsg == "用户不存在" {
-			update = update.SetIsCanAdd(4)
+			update = update.SetIsCanAdd(5)
 		} else {
-			update = update.SetIsCanAdd(3)
+			update = update.SetIsCanAdd(4)
 		}
 	}
 	if message.Success {
 		if message.IsFriend {
-			update = update.SetIsCanAdd(6)
+			update = update.SetIsCanAdd(7)
 		} else {
-			update = update.SetIsCanAdd(1)
+			update = update.SetIsCanAdd(1) //todo 后续这里会发送 添加请求
 		}
 	}
 	if _, err := update.Save(ctx); err != nil {

+ 4 - 4
internal/service/MessageHandlers/task_result_notice.go

@@ -63,16 +63,16 @@ func (f *TaskResultNoticeHandler) Handle(ctx context.Context, msg *wechat_ws.Msg
 
 	if common.Code == "InternalError" {
 		if common.ErrMsg == "timeout" {
-			update.SetIsCanAdd(3) // 重置添加为不能添加好友
-		} else if common.ErrMsg == "该用户不存在" || common.ErrMsg == "用户不存在" {
 			update.SetIsCanAdd(4) // 重置添加为不能添加好友
+		} else if common.ErrMsg == "该用户不存在" || common.ErrMsg == "用户不存在" {
+			update.SetIsCanAdd(5) // 重置添加为不能添加好友
 		} else {
-			update.SetIsCanAdd(3)
+			update.SetIsCanAdd(4)
 		} // 重置添加为不能添加好友
 	}
 
 	if common.Success {
-		update.SetIsCanAdd(2) // 表示任务成功
+		update.SetIsCanAdd(3) // 表示任务成功
 	}
 
 	if _, err := update.Save(ctx); err != nil {

+ 1 - 0
internal/service/addfriend/add_wechat_friend_log.go

@@ -94,6 +94,7 @@ func (l *AddWechatFriendService) AddNewFriend(wechatId, content, message string,
 		SetAddRequest(result).
 		SetTaskID(taskId.Int64()).
 		AddTaskCount(1).
+		SetIsCanAdd(2).
 		SetUpdatedAt(time.Now().Unix())
 	_, err = update.Save(l.ctx)
 	logx.Infof("更新 AddWechatFriendLog-field-add-result成功: %v", result)