zhifei 1 gadu atpakaļ
vecāks
revīzija
dead61c572

+ 24 - 0
warewms-system/src/main/java/com/warewms/hailiang/contoller/TestContoller.java

@@ -1,5 +1,11 @@
 package com.warewms.hailiang.contoller;
 
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.warewms.common.annotation.Anonymous;
+import com.warewms.common.core.domain.R;
+import com.warewms.hailiang.config.DeviceMessageSocket;
+import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -22,6 +28,9 @@ public class TestContoller {
     @Autowired
     PlcConnectServiceRunner plcConnectServiceRunner;
 
+    @Autowired
+    DeviceMessageSocket deviceMessageSocket;
+
     @GetMapping("/pclTest")
     public Object testPlc(String plcName,String db,String type,String value){
         if (type.equals("1")){
@@ -70,4 +79,19 @@ public class TestContoller {
     public Object getStatus(String plcName){
         return plcConnectServiceRunner.getPlcServer(plcName).checkConnected();
     }
+
+    @GetMapping("/testNotify")
+    @Anonymous
+    public R testNotify(String content,String status) throws InterruptedException {
+        Thread.sleep(3000);
+        DeviceLog deviceLog = new DeviceLog("1","倒角读码器",content,status);
+        deviceLog.setCreateBy("system");
+        deviceLog.setUpdateBy("system");
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type","notify");
+        jsonObject.set("content",JSONUtil.parse(deviceLog));
+        //推送消息
+        deviceMessageSocket.sendAllMessage(jsonObject.toString());
+        return R.ok();
+    }
 }

+ 17 - 1
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceLogServiceImpl.java

@@ -1,6 +1,9 @@
 package com.warewms.hailiang.service.impl;
 
 
+import cn.hutool.json.JSON;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -8,9 +11,11 @@ import com.warewms.common.core.domain.base.page.PageDomain;
 import com.warewms.common.core.domain.base.page.TableDataInfo;
 import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.config.DeviceMessageSocket;
+import com.warewms.hailiang.domain.Device;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.mapper.DeviceLogMapper;
 import com.warewms.hailiang.service.DeviceLogService;
+import com.warewms.hailiang.service.DeviceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.event.EventListener;
 import org.springframework.scheduling.annotation.Async;
@@ -31,6 +36,9 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
     @Autowired
     DeviceLogMapper deviceLogMapper;
 
+    @Autowired
+    DeviceService deviceService;
+
     @Autowired
     DeviceMessageSocket deviceMessageSocket;
 
@@ -56,7 +64,15 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
         deviceLog.setUpdateBy("system");
         deviceLogMapper.insert(deviceLog);
         //推送消息
-        deviceMessageSocket.sendAllMessage(deviceLog.toString());
+        for (Device device : deviceService.getList()) {
+            if (device.getDeviceId().equals(deviceLog.getDeviceId())){
+                deviceLog.setDeviceName(device.getAbbreviation());
+            }
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.set("type","notify");
+        jsonObject.set("content",JSONUtil.parse(deviceLog));
+        deviceMessageSocket.sendAllMessage(jsonObject.toString());
     }
 
 }