Explorar el Código

处理偶发性总线请求不回复的问题

zhou.xiaoning hace 2 años
padre
commit
0dd59b0bed
Se han modificado 3 ficheros con 19 adiciones y 13 borrados
  1. 1 1
      initialize/rabbitmq.go
  2. 4 0
      model/account/request/certification.go
  3. 14 12
      service/account/login.go

+ 1 - 1
initialize/rabbitmq.go

@@ -57,7 +57,7 @@ func (t *MQProc) Process(topic, queuename string, msg *[]byte) {
 			// 通知类 或 特殊处理
 			t.onNtf(funcode, sessionId, bytes)
 		} else {
-			// 请求回复W
+			// 请求回复
 			// 尝试获取对应异步任务
 			if c, exists := client.Clients[int(sessionId)]; exists {
 				key := fmt.Sprintf("%v_%v_%v", sessionId, funcode, serialNumber)

+ 4 - 0
model/account/request/certification.go

@@ -14,3 +14,7 @@ type AddUserReq struct {
 type CreateContractAndAddSignerReq struct {
 	TemplateNo string `json:"templateNo" binding:"required"` // 合同模板编号
 }
+
+// type AddAuthReq struct {
+
+// }

+ 14 - 12
service/account/login.go

@@ -238,6 +238,20 @@ func buildRedisLoginInfo(loginaccount accountModel.Loginaccount, addr string, gr
 
 // RestoreLoginWithToken 通过Token检验恢复登录状态失败
 func RestoreLoginWithToken(loginID int, group int, token string) (err error) {
+	// 先判断Clients中是否有对应的对像
+	if client.Clients != nil {
+		targetKeys := make([]int, 0)
+		for key, item := range client.Clients {
+			if item.LoginID == strconv.Itoa(loginID) && item.Group == strconv.Itoa(group) {
+				targetKeys = append(targetKeys, key)
+			}
+		}
+		if len(targetKeys) > 0 {
+			return
+		}
+	}
+
+	// 没有的话重新创建一个
 	// 从Redis获取登录信息
 	j := utils.NewJWT()
 	loginMap, err := j.GetRedisLogin(loginID, group)
@@ -269,17 +283,6 @@ func RestoreLoginWithToken(loginID int, group int, token string) (err error) {
 		global.M2A_LOG.Error("Token检验恢复登录状态失败", zap.Error(err))
 		return
 	}
-	// 这里应该按loginid和group把之前的client删除掉
-	// delete(client.Clients, s)
-	targetKeys := make([]int, 0)
-	for key, item := range client.Clients {
-		if item.LoginID == loginLogin.LoginID && item.Group == loginLogin.Group {
-			targetKeys = append(targetKeys, key)
-		}
-	}
-	for _, k := range targetKeys {
-		delete(client.Clients, k)
-	}
 	client.Clients[s] = &client.Client{LoginRedis: loginLogin}
 
 	return
@@ -298,7 +301,6 @@ func GetClientsByAccountID(accountID uint64) (clients []*client.Client, err erro
 	WHERE a.accountid = %v
 	`, accountID)
 	if err = global.M2A_DB.SQL(sql).Find(&loginIds); err != nil {
-
 		global.M2A_LOG.Info("获取LoginID失败", zap.Error(err))
 		return
 	} else {