WebSocketController.java 1.17 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3
package com.zehong.web.controller.websocket;

import com.alibaba.fastjson.JSONObject;
4
import com.zehong.system.domain.vo.DeviceAlarmVo;
耿迪迪's avatar
耿迪迪 committed
5 6
import com.zehong.system.service.ITDeviceAlarmService;
import com.zehong.system.service.WebSocketServer;
7 8
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
耿迪迪's avatar
耿迪迪 committed
9 10 11 12 13 14 15 16 17
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/websocket")
public class WebSocketController {

18 19
    private static final Logger log = LoggerFactory.getLogger(WebSocketController.class);

耿迪迪's avatar
耿迪迪 committed
20 21 22 23 24 25 26 27 28
    @Autowired
    private WebSocketServer webSocketServer;

    @Autowired
    private ITDeviceAlarmService itDeviceAlarmService;


    @GetMapping("/send")
    public void send(int alarmId){
29 30
        try {
            DeviceAlarmVo alarm = itDeviceAlarmService.selectTDeviceAlarmById(alarmId);
31
            webSocketServer.batchSendMessage(JSONObject.toJSONString(alarm));
32 33
        } catch (Exception e) {
            log.error("wesocket发送失败!");
耿迪迪's avatar
耿迪迪 committed
34
        }
35

耿迪迪's avatar
耿迪迪 committed
36 37
    }
}