WH01243 преди 3 седмици
родител
ревизия
a7a836608c
променени са 4 файла, в които са добавени 25 реда и са изтрити 12 реда
  1. 1 1
      client/config.json
  2. 3 0
      client/service/chatClient.go
  3. 1 1
      rpc/main.go
  4. 20 10
      rpc/service/chatServer.go

+ 1 - 1
client/config.json

@@ -1,4 +1,4 @@
 {
-  "serviceAddress": "localhost:50051",
+  "serviceAddress": "jybx3-webtest.jydev.jianyu360.com:50051",
   "informationDelay": 20
 }

+ 3 - 0
client/service/chatClient.go

@@ -297,6 +297,9 @@ func (c *ChatClient) receiveMessages(stream ChatService_JoinChatClient) error {
 			default:
 				log.Printf("[系统通知]: %s", msg.Text)
 			}
+			if msg.Text == "欢迎加入聊天室" {
+				go GetContacts()
+			}
 		}
 	}
 }

+ 1 - 1
rpc/main.go

@@ -130,7 +130,7 @@ func (s *server) setupTimedTasks(ctx context.Context) {
 	}{
 		{1 * time.Minute, "sendTalk"},
 		{1 * time.Hour, "getContacts"},
-		{10 * time.Second, "heartbeat"},
+		{30 * time.Second, "heartbeat"},
 	}
 
 	for _, task := range tasks {

+ 20 - 10
rpc/service/chatServer.go

@@ -50,7 +50,7 @@ func (s *ChatServer) JoinChat(req *JoinRequest, stream ChatService_JoinChatServe
 	// 发送欢迎消息
 	welcomeMsg := &Message{
 		UserId:    "系统",
-		Text:      "欢迎加入聊天室!",
+		Text:      "欢迎加入聊天室",
 		Timestamp: time.Now().Unix(),
 	}
 	if err := stream.Send(welcomeMsg); err != nil {
@@ -87,7 +87,7 @@ func (s *ChatServer) SendMessage(ctx context.Context, msg *Message) (*MessageAck
 	switch msg.Action {
 	case "getContacts":
 		log.Printf("接收%s通讯录信息\n", msg.UserId)
-		//go SynchronousContacts(msg.UserId, msg.Text)
+		go SynchronousContacts(msg.UserId, msg.Text)
 	case "chatHistory":
 		go AddChatRecord(msg.UserId, msg.Text) // 异步处理
 	case "sendTalk":
@@ -248,24 +248,34 @@ func (s *ChatServer) SpecifyAdminMessage(taskId int64, userMap map[string]interf
 		config.WxRobot.Insert("send_record", map[string]interface{}{
 			"task_id":      taskId,
 			"base_user_id": gconv.String(userMap["baseUserId"]),
-			"send_status":  3,
+			"send_status":  1,
 			"create_time":  time.Now().Format(time.DateTime),
 			"batch_code":   batchCode,
+			"remark":       "用户拒绝",
 		})
 		return nil
 	}
 	s.mu.Lock()
 	ch, exists := s.clients[userId] // 直接获取目标用户的 channel
 	s.mu.Unlock()
-	config.WxRobot.Insert("send_record", map[string]interface{}{
-		"task_id":      taskId,
-		"base_user_id": gconv.String(userMap["baseUserId"]),
-		"send_status":  1,
-		"create_time":  time.Now().Format(time.DateTime),
-		"batch_code":   batchCode,
-	})
 	if !exists {
+		config.WxRobot.Insert("send_record", map[string]interface{}{
+			"task_id":      taskId,
+			"base_user_id": gconv.String(userMap["baseUserId"]),
+			"send_status":  1,
+			"create_time":  time.Now().Format(time.DateTime),
+			"batch_code":   batchCode,
+			"remark":       fmt.Sprintf("%s客户端关闭", userId),
+		})
 		return fmt.Errorf("用户 %s 不存在或未连接", userId)
+	} else {
+		config.WxRobot.Insert("send_record", map[string]interface{}{
+			"task_id":      taskId,
+			"base_user_id": gconv.String(userMap["baseUserId"]),
+			"send_status":  1,
+			"create_time":  time.Now().Format(time.DateTime),
+			"batch_code":   batchCode,
+		})
 	}
 	text := gconv.String(map[string]interface{}{
 		"user":          userMap,