Przeglądaj źródła

添加websocket预警

hfxc226 2 lat temu
rodzic
commit
ba63054232

+ 6 - 0
platform-dao/pom.xml

@@ -80,6 +80,12 @@
             <version>1.3.50</version>
         </dependency>
 
+        <!-- socket -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-aop</artifactId>

+ 16 - 0
platform-dao/src/main/java/com/platform/dao/config/websocket/WebSocketConfig.java

@@ -0,0 +1,16 @@
+package com.platform.dao.config.websocket;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+@Configuration
+@EnableWebSocket
+public class WebSocketConfig {
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}

+ 129 - 0
platform-dao/src/main/java/com/platform/dao/config/websocket/WebSocketServer.java

@@ -0,0 +1,129 @@
+package com.platform.dao.config.websocket;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.websocket.*;
+import javax.websocket.server.PathParam;
+import javax.websocket.server.ServerEndpoint;
+import java.io.IOException;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+/**
+ * Created with IntelliJ IDEA.
+ * @ Auther: 马超伟
+ * @ Date: 2020/06/16/14:35
+ * @ Description:
+ * @ ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端,
+ * 注解的值将被用于监听用户连接的终端访问URL地址,客户端可以通过这个URL来连接到WebSocket服务器端
+ */
+@Component
+@Slf4j
+@ServerEndpoint(value="/websocket/{sid}")
+public class WebSocketServer {
+    //当前在线连接数
+    private static int onlineCount = 0;
+    //存放每个客户端对应的MyWebSocket对象
+    private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();
+
+    private Session session;
+
+    //接收sid
+    private String sid = "";
+
+    /**
+     * 连接建立成功调用的方法
+     */
+    @OnOpen
+    public void onOpen(Session session, @PathParam("sid") String sid) {
+        log.info("有新窗口开始监听:" + sid + ", 当前在线人数为:" + getOnlineCount());
+        this.session = session;
+        webSocketSet.add(this);     //加入set中
+        this.sid = sid;
+        addOnlineCount();           //在线数加1
+        //sendMessage("连接成功");
+        log.info("有新窗口开始监听:" + sid + ", 当前在线人数为:" + getOnlineCount());
+
+    }
+
+    /**
+     * 连接关闭调用的方法
+     */
+    @OnClose
+    public void onClose() {
+        webSocketSet.remove(this);  //从set中删除
+        subOnlineCount();           //在线数减1
+        log.info("释放的sid为:"+sid);
+        log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
+    }
+
+    /**
+     * 收到客户端消息后调用的方法
+     * @ Param message 客户端发送过来的消息
+     */
+    @OnMessage
+    public void onMessage(String message, Session session) {
+        log.info("收到来自窗口" + sid + "的信息:" + message);
+        //群发消息
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                item.sendMessage(message);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * @ Param session
+     * @ Param error
+     */
+    @OnError
+    public void onError(Session session, Throwable error) {
+        log.error("发生错误");
+        error.printStackTrace();
+    }
+
+    /**
+     * 实现服务器主动推送
+     */
+    public void sendMessage(String message) throws IOException {
+        this.session.getBasicRemote().sendText(message);
+    }
+
+    /**
+     * 群发自定义消息
+     */
+    public static void sendInfo(String message, @PathParam("sid") String sid) throws IOException {
+        log.info("推送消息到窗口" + sid + ",推送内容:" + message);
+        log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
+        for (WebSocketServer item : webSocketSet) {
+            try {
+                //为null则全部推送
+                if (sid == null) {
+                    item.sendMessage(message);
+                } else if (item.sid.equals(sid)) {
+                    item.sendMessage(message);
+                }
+            } catch (IOException e) {
+                continue;
+            }
+        }
+    }
+
+    public static synchronized int getOnlineCount() {
+        return onlineCount;
+    }
+
+    public static synchronized void addOnlineCount() {
+        WebSocketServer.onlineCount++;
+    }
+
+    public static synchronized void subOnlineCount() {
+        WebSocketServer.onlineCount--;
+    }
+
+    public static CopyOnWriteArraySet<WebSocketServer> getWebSocketSet() {
+        return webSocketSet;
+    }
+}

+ 8 - 8
platform-dao/src/main/java/com/platform/dao/dto/remote/RemoteOpcDTO.java

@@ -36,35 +36,35 @@ public class RemoteOpcDTO extends BaseDTO implements Serializable {
      */
     private Integer fetchFlag;
     /**
-     * 最低阈
+     * 低低限
      */
     private BigDecimal warnFirst;
     /**
-     * 低
+     * 低
      */
     private BigDecimal warnSecond;
     /**
-     * 高
+     * 高
      */
     private BigDecimal warnThird;
     /**
-     * 最高阈
+     * 高高限
      */
     private BigDecimal warnFour;
     /**
-     * 最低阈值颜色
+     * 低低限值颜色
      */
     private String warnFirstColor;
     /**
-     * 低值颜色
+     * 低值颜色
      */
     private String warnSecondColor;
     /**
-     * 高值颜色
+     * 高值颜色
      */
     private String warnThirdColor;
     /**
-     * 最高阈值颜色
+     * 高高限值颜色
      */
     private String warnFourColor;
     /**

+ 8 - 8
platform-dao/src/main/java/com/platform/dao/entity/remote/RemoteOpc.java

@@ -34,35 +34,35 @@ public class RemoteOpc implements Serializable {
      */
     private Integer fetchFlag;
     /**
-     * 最低阈
+     * 低低限
      */
     private BigDecimal warnFirst;
     /**
-     * 低
+     * 低
      */
     private BigDecimal warnSecond;
     /**
-     * 高
+     * 高
      */
     private BigDecimal warnThird;
     /**
-     * 最高阈
+     * 高高限
      */
     private BigDecimal warnFour;
     /**
-     * 低低值颜色
+     * 低低值颜色
      */
     private String warnFirstColor;
     /**
-     * 低值颜色
+     * 低值颜色
      */
     private String warnSecondColor;
     /**
-     * 高值颜色
+     * 高值颜色
      */
     private String warnThirdColor;
     /**
-     * 高高值颜色
+     * 高高值颜色
      */
     private String warnFourColor;
     /**

+ 16 - 16
platform-dao/src/main/java/com/platform/dao/vo/export/remote/ExportRemoteOpcVO.java

@@ -112,44 +112,44 @@ public class ExportRemoteOpcVO implements Serializable {
     @Excel(name = "位置宽度")
     private BigDecimal width;
     /**
-     * 低低
+     * 低低
      */
-    @Excel(name = "低低值")
+    @Excel(name = "低低值")
     private BigDecimal warnFirst;
     /**
-     * 低低值颜色
+     * 低低值颜色
      */
-    @Excel(name = "低低值颜色")
+    @Excel(name = "低低值颜色")
     private BigDecimal warnFirstColor;
     /**
-     * 低
+     * 低
      */
-    @Excel(name = "低值")
+    @Excel(name = "低值")
     private BigDecimal warnSecond;
     /**
-     * 低值颜色
+     * 低值颜色
      */
-    @Excel(name = "低值颜色")
+    @Excel(name = "低值颜色")
     private BigDecimal warnSecondColor;
     /**
-     * 高
+     * 高
      */
-    @Excel(name = "高值")
+    @Excel(name = "高值")
     private BigDecimal warnThird;
     /**
-     * 高值颜色
+     * 高值颜色
      */
-    @Excel(name = "高值颜色")
+    @Excel(name = "高值颜色")
     private BigDecimal warnThirdColor;
     /**
-     * 高高
+     * 高高
      */
-    @Excel(name = "高高值")
+    @Excel(name = "高高值")
     private BigDecimal warnFour;
     /**
-     * 高高值颜色
+     * 高高值颜色
      */
-    @Excel(name = "高高值颜色")
+    @Excel(name = "高高值颜色")
     private BigDecimal warnFourColor;
     /**
      * 备注

+ 8 - 8
platform-dao/src/main/java/com/platform/dao/vo/query/remote/RemoteOpcVO.java

@@ -32,35 +32,35 @@ public class RemoteOpcVO extends BaseVO implements Serializable {
      */
     private Integer fetchFlag;
     /**
-     * 最低阈
+     * 低低限
      */
     private BigDecimal warnFirst;
     /**
-     * 低
+     * 低
      */
     private BigDecimal warnSecond;
     /**
-     * 高
+     * 高
      */
     private BigDecimal warnThird;
     /**
-     * 最高阈
+     * 高高限
      */
     private BigDecimal warnFour;
     /**
-     * 最低阈值颜色
+     * 低低限值颜色
      */
     private String warnFirstColor;
     /**
-     * 低值颜色
+     * 低值颜色
      */
     private String warnSecondColor;
     /**
-     * 高值颜色
+     * 高值颜色
      */
     private String warnThirdColor;
     /**
-     * 最高阈值颜色
+     * 高高限值颜色
      */
     private String warnFourColor;
     /**

+ 8 - 0
platform-rest/src/main/java/com/platform/rest/config/security/WebSecurityConfigurer.java

@@ -3,6 +3,7 @@ package com.platform.rest.config.security;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.platform.rest.config.security.handler.LoginSuccessHandler;
 import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -11,6 +12,7 @@ import org.springframework.context.annotation.Primary;
 import org.springframework.core.annotation.Order;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 import org.springframework.security.crypto.factory.PasswordEncoderFactories;
 import org.springframework.security.crypto.password.PasswordEncoder;
@@ -27,6 +29,7 @@ import org.springframework.security.web.authentication.AuthenticationSuccessHand
 @Primary
 @Order(90)
 @Configuration
+@Slf4j
 public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
     @Autowired
     private ObjectMapper objectMapper;
@@ -56,6 +59,11 @@ public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
         return super.authenticationManagerBean();
     }
 
+    @Override
+    public void configure(WebSecurity webSecurity) throws Exception {
+        log.info("webSecurity: ");
+        webSecurity.ignoring().antMatchers("/websocket/**");
+    }
 
     /**
      * BCrypt

+ 29 - 21
platform-rest/src/main/java/com/platform/rest/controller/remote/RemoteOpcController.java

@@ -3,10 +3,8 @@ package com.platform.rest.controller.remote;
 import com.alibaba.fastjson.JSON;
 import com.platform.common.bean.AbstractPageResultBean;
 import com.platform.common.constant.RedisKeyConstants;
-import com.platform.common.util.BeanConverterUtil;
-import com.platform.common.util.R;
-import com.platform.common.util.RedisUtils;
-import com.platform.common.util.StringUtils;
+import com.platform.common.constant.UpmsRedisKeyConstants;
+import com.platform.common.util.*;
 import com.platform.common.validation.group.AddGroup;
 import com.platform.common.validation.group.UpdateGroup;
 import com.platform.dao.dto.remote.RemoteOpcDTO;
@@ -18,12 +16,14 @@ import com.platform.dao.vo.query.remote.RemoteOpcVO;
 import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.remote.RemoteOpcService;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -36,8 +36,9 @@ import java.util.List;
 @RestController
 @AllArgsConstructor
 @RequestMapping("/remote/opcs")
+@Slf4j
 public class RemoteOpcController {
-    private final RemoteOpcService remoteMeasureService;
+    private final RemoteOpcService remoteOpcService;
 
     /**
      * 通过id查询单条记录
@@ -47,7 +48,7 @@ public class RemoteOpcController {
      */
     @GetMapping("/{id}")
     public R<RemoteOpc> getById(@PathVariable("id") String id) {
-        return new R<>(remoteMeasureService.getModelById(id));
+        return new R<>(remoteOpcService.getModelById(id));
     }
 
     /**
@@ -58,7 +59,7 @@ public class RemoteOpcController {
      */
     @GetMapping("/positionNum/{positionNum}/{line}")
     public R<RemoteOpc> getByPositionNum(@PathVariable("positionNum") String positionNum, @PathVariable("line") String line) {
-        return new R<>(remoteMeasureService.getModelByPositionNumAndLine(positionNum, line));
+        return new R<>(remoteOpcService.getModelByPositionNumAndLine(positionNum, line));
     }
 
     /**
@@ -71,7 +72,7 @@ public class RemoteOpcController {
     @PostMapping
     @PreAuthorize("@pms.hasPermission('remote-opcs-add')")
     public R save(@Validated({AddGroup.class}) @RequestBody RemoteOpcDTO remoteMeasureDTO) {
-        return new R<>(remoteMeasureService.saveModelByDTO(remoteMeasureDTO));
+        return new R<>(remoteOpcService.saveModelByDTO(remoteMeasureDTO));
     }
 
     /**
@@ -84,7 +85,7 @@ public class RemoteOpcController {
     @PutMapping("/{id}")
     @PreAuthorize("@pms.hasPermission('remote-opcs-edit')")
     public R update(@PathVariable("id") String id, @Validated({UpdateGroup.class}) @RequestBody RemoteOpcDTO remoteMeasureDTO) {
-        remoteMeasureService.modModelByDTO(remoteMeasureDTO);
+        remoteOpcService.modModelByDTO(remoteMeasureDTO);
         return new R<>();
     }
 
@@ -99,7 +100,7 @@ public class RemoteOpcController {
     @PutMapping("/group/add/{positionNum}")
     @PreAuthorize("@pms.hasPermission('remote-opcs-edit')")
     public R addGroup(@PathVariable("positionNum") String positionNum) {
-        remoteMeasureService.addToGroup(positionNum);
+        remoteOpcService.addToGroup(positionNum);
         return new R<>("已加入待采集列表,10秒后自动采集");
     }
 
@@ -112,7 +113,7 @@ public class RemoteOpcController {
     @PutMapping("/group/addAll")
     @PreAuthorize("@pms.hasPermission('remote-opcs-edit')")
     public R addGroupAll(RemoteOpcDTO remoteMeasureDTO) {
-        remoteMeasureService.addAllToGroup(remoteMeasureDTO);
+        remoteOpcService.addAllToGroup(remoteMeasureDTO);
         return new R<>("已加入待采集列表,10秒后自动采集");
     }
 
@@ -140,7 +141,7 @@ public class RemoteOpcController {
     @PutMapping("/update/batch/{updateType}/{value}")
     @PreAuthorize("@pms.hasPermission('remote-opcs-del')")
     public R updateIds(@RequestBody List<String> ids, @PathVariable("updateType") Integer updateType, @PathVariable("value") Integer value) {
-        remoteMeasureService.updateIds(ids, updateType, value);
+        remoteOpcService.updateIds(ids, updateType, value);
         return new R<>();
     }
 
@@ -154,7 +155,7 @@ public class RemoteOpcController {
     @DeleteMapping("/{id}")
     @PreAuthorize("@pms.hasPermission('remote-opcs-del')")
     public R removeById(@PathVariable String id) {
-        remoteMeasureService.deleteByPrimaryKey(id);
+        remoteOpcService.deleteByPrimaryKey(id);
         return new R<>();
     }
 
@@ -168,7 +169,7 @@ public class RemoteOpcController {
     @DeleteMapping("")
     @PreAuthorize("@pms.hasPermission('remote-opcs-del')")
     public R removeIds(@RequestBody List<String> ids) {
-        remoteMeasureService.batchDelete(ids);
+        remoteOpcService.batchDelete(ids);
         return new R<>();
     }
 
@@ -182,7 +183,7 @@ public class RemoteOpcController {
      */
     @GetMapping("/page")
     public R<AbstractPageResultBean<RemoteOpcVO>> queryPage(RemoteOpcDTO remoteMeasureDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
-        return new R<>(remoteMeasureService.selectPageList(remoteMeasureDTO, pageNum, pageSize));
+        return new R<>(remoteOpcService.selectPageList(remoteMeasureDTO, pageNum, pageSize));
     }
 
     /**
@@ -193,12 +194,13 @@ public class RemoteOpcController {
      */
     @GetMapping("")
     public R query(RemoteOpcDTO remoteMeasureDTO) {
-        return new R<>(remoteMeasureService.selectList(remoteMeasureDTO));
+        return new R<>(remoteOpcService.selectList(remoteMeasureDTO));
     }
 
 
     /**
      * 获取实时数据列表,从redis里面获取
+     * 同时处理判断超阈值的问题,超过最大预警值,就需要弹出消息:异步处理
      *
      * @param remoteMeasureDTO opc点位对应表DTO
      * @return R
@@ -206,11 +208,17 @@ public class RemoteOpcController {
     @GetMapping("/redis")
     public R queryFromRedis(RemoteOpcDTO remoteMeasureDTO) {
         String jsonStr = RedisUtils.getString(RedisKeyConstants.DCS_PREFIX + remoteMeasureDTO.getLine());
+        log.info("jsonStr: " + jsonStr);
+        List<RemoteOpcVO> resultList = new ArrayList<>();
         if (StringUtils.isNotBlank(jsonStr)) {
-            List<RemoteOpcVO> resultList = JSON.parseArray(jsonStr, RemoteOpcVO.class);
-            return new R<>(resultList);
+            resultList = JSON.parseArray(jsonStr, RemoteOpcVO.class);
+        } else {
+            resultList = remoteOpcService.selectList(remoteMeasureDTO);
         }
-        return new R<>(remoteMeasureService.selectList(remoteMeasureDTO));
+        if (BeanUtils.isDev() ) {
+            remoteOpcService.sendWarn(resultList);
+        }
+        return new R<>(resultList);
     }
 
     /**
@@ -223,7 +231,7 @@ public class RemoteOpcController {
     @SysLog("opc点位对应表导出")
     @PreAuthorize("@pms.hasPermission('remote-opcs-export')")
     public void export(HttpServletResponse response, RemoteOpcDTO remoteMeasureDTO) {
-        List<RemoteOpcVO> list = remoteMeasureService.selectList(remoteMeasureDTO);
+        List<RemoteOpcVO> list = remoteOpcService.selectList(remoteMeasureDTO);
         ExcelUtil.exportResponseDict(response, ExportRemoteOpcVO.class, BeanConverterUtil.copyListProperties(list, ExportRemoteOpcVO.class), "opc点位对应表");
     }
 
@@ -236,7 +244,7 @@ public class RemoteOpcController {
     @SysLog("新增opc点位数据导入")
     @PostMapping("/import/{line}")
     public R importExcel(@RequestParam("file") MultipartFile file, @PathVariable("line") String line) throws Exception {
-        String result = remoteMeasureService.importListByAdd(file, line);
+        String result = remoteOpcService.importListByAdd(file, line);
         return new R<>(result);
     }
 

+ 60 - 0
platform-rest/src/main/java/com/platform/rest/controller/websocket/WebSocketController.java

@@ -0,0 +1,60 @@
+package com.platform.rest.controller.websocket;
+
+import com.platform.common.util.R;
+import com.platform.dao.config.websocket.WebSocketServer;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.io.IOException;
+
+/**
+ * 验证码接口
+ *
+ * @author
+ */
+@AllArgsConstructor
+@Slf4j
+@Controller
+@RequestMapping("/socket")
+public class WebSocketController {
+
+    /**
+     * 前台定时发送消息,5分钟发送一次,后台接受到后,发送
+     *
+     * @param cid 短信DTO
+     * @return R
+     */
+    @ResponseBody
+    @PostMapping("/push/{cid}")
+    public R sendMessageSingle(@PathVariable String cid, String message) {
+        try {
+            WebSocketServer.sendInfo(message, cid);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return new R<>("单发成功");
+    }
+
+    /**
+     * 前台定时发送消息,5分钟发送一次,后台接受到后,发送
+     *
+     * @return R
+     */
+    @ResponseBody
+    @PostMapping("/push/all")
+    public R sendMessageSingle(String message) {
+        try {
+            WebSocketServer.sendInfo(message, null);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return new R<>("群发成功");
+    }
+
+}
+

+ 3 - 1
platform-rest/src/main/resources/application-dev.yml

@@ -76,10 +76,12 @@ ignore:
     - /ignores/**
     - /wechat/**
     - /yongyou/**
+    - /sb/measure-logs/generate/init
+    - /operate/customers/*
     - /store/out-store-forms/**
     - /operate/customers/*
     - /repair/application-forms/repair/report
-
+    - /websocket/**
 platform:
   slf4j:
     data: D://xajg

+ 5 - 0
platform-rest/src/main/resources/application-prod.yml

@@ -54,7 +54,12 @@ ignore:
     - /ignores/**
     - /wechat/**
     - /yongyou/**
+    - /sb/measure-logs/generate/init
     - /operate/customers/*
+    - /store/out-store-forms/**
+    - /operate/customers/*
+    - /repair/application-forms/repair/report
+    - /websocket/**
 
 platform:
   slf4j:

+ 4 - 0
platform-rest/src/main/resources/application-test.yml

@@ -56,6 +56,10 @@ ignore:
     - /yongyou/**
     - /sb/measure-logs/generate/init
     - /operate/customers/*
+    - /store/out-store-forms/**
+    - /operate/customers/*
+    - /repair/application-forms/repair/report
+    - /websocket/**
 
 platform:
   slf4j:

+ 9 - 0
platform-service/src/main/java/com/platform/service/remote/RemoteOpcService.java

@@ -25,6 +25,15 @@ public interface RemoteOpcService extends IBaseService<RemoteOpc, RemoteOpcDTO>
      */
     int batchDelete(List<String> ids);
 
+    /**
+     * 判断是否超预警,并发送预警消息
+     * 前端展示预警列表信息*
+     *
+     * @param resultList :
+     * @return :
+     */
+    void sendWarn(List<RemoteOpcVO> resultList);
+
     /**
      * 批量删除
      *

+ 35 - 5
platform-service/src/main/java/com/platform/service/remote/impl/RemoteOpcServiceImpl.java

@@ -6,9 +6,11 @@ import com.platform.common.bean.AbstractPageResultBean;
 import com.platform.common.constant.RedisKeyConstants;
 import com.platform.common.enums.DictTypeEnum;
 import com.platform.common.exception.BusinessException;
+import com.platform.common.util.JsonUtils;
 import com.platform.common.util.RedisUtils;
 import com.platform.common.util.StringUtils;
 import com.platform.dao.bean.MyPage;
+import com.platform.dao.config.websocket.WebSocketServer;
 import com.platform.dao.dto.remote.RemoteOpcDTO;
 import com.platform.dao.entity.remote.RemoteOpc;
 import com.platform.dao.entity.sb.SbInfo;
@@ -22,6 +24,8 @@ import com.platform.dao.vo.query.remote.RemoteOpcVO;
 import com.platform.service.base.impl.BaseServiceImpl;
 import com.platform.service.remote.RemoteOpcService;
 import lombok.AllArgsConstructor;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -29,6 +33,7 @@ import org.springframework.web.multipart.MultipartFile;
 import tk.mybatis.mapper.weekend.Weekend;
 import tk.mybatis.mapper.weekend.WeekendCriteria;
 
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -43,7 +48,7 @@ import java.util.stream.Collectors;
  */
 @AllArgsConstructor
 @Service("remoteOpcService")
-
+@EnableAsync
 public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, RemoteOpc, RemoteOpcDTO>
         implements RemoteOpcService {
 
@@ -126,8 +131,33 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
         return 1;
     }
 
+    @Override
+    @Async
+    public void sendWarn(List<RemoteOpcVO> resultList) {
+        if (!CollectionUtils.isEmpty(resultList)) {
+            List<RemoteOpcVO> warnFirst = new ArrayList<>();// 低低限值
+            List<RemoteOpcVO> warnSecond = new ArrayList<>();// 低限值
+            List<RemoteOpcVO> warnThird = new ArrayList<>();// 高限值
+            List<RemoteOpcVO> warnFour = new ArrayList<>();// 高高限值
+            /*for(RemoteOpcVO vo: resultList){
+            }*/
+            try {
+                WebSocketServer.sendInfo(JsonUtils.objectToJson(resultList.subList(0, 2)), null);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        } else {
+            try {
+                WebSocketServer.sendInfo(JsonUtils.objectToJson(selectPageList(null, 1, 10).getRows()), null);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     /**
      * *
+     *
      * @param positionNum :
      * @return
      */
@@ -138,7 +168,7 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
         weekendCriteria.andEqualTo(RemoteOpc::getPositionNum, positionNum);
         // 同一个点位会存在多个点位值,不同车间绑定了同一个点位,在发起分组的时候,要按照分组来获取数据?
         List<RemoteOpc> remoteOpcList = mapper.selectByExample(weekend);
-        if(!CollectionUtils.isEmpty(remoteOpcList)){
+        if (!CollectionUtils.isEmpty(remoteOpcList)) {
             return remoteOpcList.get(0);
         }
         return null;
@@ -261,7 +291,7 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
     @Override
     public void addToGroup(String positionNum) {
         RemoteOpc remoteOpc = this.selectByPositionNum(positionNum);
-        if(remoteOpc != null){
+        if (remoteOpc != null) {
             updateIds(Arrays.asList(remoteOpc.getId()), 2, YesNoEnum.YES.getValue());
             RedisUtils.setListOne(RedisKeyConstants.redis_opc_wait_add_list, positionNum);
         }
@@ -273,10 +303,10 @@ public class RemoteOpcServiceImpl extends BaseServiceImpl<RemoteOpcMapper, Remot
         List<RemoteOpcVO> voList = mapper.selectList(remoteMeasureDTO);
         List<String> positionNums = voList.stream().map(item -> item.getPositionNum()).collect(Collectors.toList());
         List<String> ids = voList.stream().map(item -> item.getId()).collect(Collectors.toList());
-        if(!CollectionUtils.isEmpty(positionNums)){
+        if (!CollectionUtils.isEmpty(positionNums)) {
             updateIds(ids, 2, YesNoEnum.YES.getValue());
             RedisUtils.setList(RedisKeyConstants.redis_opc_wait_add_list, positionNums);
-        }else{
+        } else {
             throw new BusinessException("无待配置点位");
         }
     }