whyclxw
2025-04-18 4c9b54b3b55e93e4d57685c036165bfce95c9c74
告警实时推送
2个文件已修改
15 ■■■■ 已修改文件
src/main/java/com/whyc/webSocket/LockAlmRtSocket.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/LockAlarmMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/webSocket/LockAlmRtSocket.java
@@ -3,11 +3,13 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.LockAlmDto;
import com.whyc.dto.Response;
import com.whyc.pojo.plus_user.UserInf;
import com.whyc.service.LockAlarmService;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.util.HashMap;
@@ -25,6 +27,8 @@
    private volatile boolean runFlag = true;
    private static HttpSession httpSession;
    private volatile Map<String, Thread> threadMap = new HashMap<>();
    private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>();
@@ -36,12 +40,19 @@
    @OnOpen
    public void onOpen(Session session) {
    public void onOpen(Session session, EndpointConfig config) {
        this.session = session;
        this.httpSession = (HttpSession) config.getUserProperties().get("httpSession");
    }
    @OnMessage
    public void onMessage(Session session, String message) {
        LockAlmDto almDto= ActionUtil.getGson().fromJson(message,LockAlmDto.class);
        if(httpSession!=null){
            UserInf user = (UserInf) httpSession.getAttribute("user");
            almDto.setUid(user.getUid());
        }else{
            almDto.setUid(10001);
        }
        thread = new Thread("Thread_areaLockStateSocket") {
            @Override
            public void run() {
src/main/resources/mapper/LockAlarmMapper.xml
@@ -36,7 +36,7 @@
             select distinct lock_id from plus_user.tb_baojigroup_lock,plus_user.tb_baojigroup_usr
             <where>
                 tb_baojigroup_lock.baoji_id=tb_baojigroup_usr.baoji_id
                 <if test="uid>100">
                 <if test="almDto.uid>100">
                     and tb_baojigroup_usr.uid=#{almDto.uid}
                 </if>
             </where>