puzhibing
2026-04-24 7ea060d3acfdee74d24e2207e746c2061ee78a48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.xiaopeng.pushMessage.webSocket.handler;
 
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xiaopeng.api.feignClient.maintenance.XpTaskClient;
import com.xiaopeng.api.model.maintenance.XpTask;
import com.xiaopeng.pushMessage.webSocket.service.WebSocketUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
 
//@Component
@Slf4j
//public class TestMsgHandler implements BusinessMsgHandler{
public class TestMsgSchedule  {
 
 
    @Resource
    XpTaskClient xpTaskClient;
 
    @Autowired
    private WebSocketUserService webSocketUserService;
 
    @PostConstruct
    public void setup() {
        Executors.newSingleThreadScheduledExecutor()
                .scheduleWithFixedDelay(this::send, 10, 1, TimeUnit.MINUTES);
    }
 
    public void send() {
        String msg;
        XpTask xpTask = xpTaskClient.queryInfoByVehicleId(20L).getData();
        HashMap<String, Object> ret = new HashMap<>();
        ret.put("type", "task");
        ret.put("data", xpTask);
        try {
            msg = om.writeValueAsString(ret);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("Message serialization failed", e);
        }
        webSocketUserService.broadcastMessage(msg);
    }
    @Autowired ObjectMapper om;
    @Autowired MongoTemplate mongoTemplate;
 
 
}