Explorar el Código

将由后端获取实时信息的功能大部分都挪到前端执行,后端只保留首次加载获取曲线、报警信息推送的功能。

dongjh hace 7 meses
padre
commit
a6fd004fbb

+ 2 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/message/websocket/WebSocket.java

@@ -49,7 +49,7 @@ public class WebSocket {
     public void onClose(@PathParam("userId") String userId) {
         try {
             sessionPool.remove(userId);
-            log.info("【系统 WebSocket】连接断开,总数为:" + sessionPool.size());
+            log.warn("【系统 WebSocket】连接断开,总数为:" + sessionPool.size());
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -89,6 +89,7 @@ public class WebSocket {
             for (Map.Entry<String, Session> item : sessionPool.entrySet()) {
                 try {
                     item.getValue().getAsyncRemote().sendText(message);
+                    log.info("【系统 WebSocket】推送消息:" + message);
                 } catch (Exception e) {
                     log.error(e.getMessage(), e);
                 }

+ 2 - 2
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -56,8 +56,8 @@ spring:
     initialize-schema: embedded
     #定时任务启动开关,true-开  false-关
     auto-startup: true
-    #延迟1秒启动定时任务(改成30秒,为binlog缓存数据留出足够的时间)
-    startup-delay: 30s
+    #延迟1秒启动定时任务(改成10秒,为binlog缓存数据留出足够的时间)
+    startup-delay: 10s
     #用于指定Quartz调度器在添加任务时是否覆盖已经存在的同名任务,此处启动时更新己存在的Job
     overwrite-existing-jobs: true
     properties:

+ 2 - 2
jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml

@@ -56,8 +56,8 @@ spring:
     initialize-schema: embedded
     #定时任务启动开关,true-开  false-关
     auto-startup: true
-    #延迟1秒启动定时任务(改成30秒,为binlog缓存数据留出足够的时间)
-    startup-delay: 30s
+    #延迟1秒启动定时任务(改成10秒,为binlog缓存数据留出足够的时间)
+    startup-delay: 10s
     #用于指定Quartz调度器在添加任务时是否覆盖已经存在的同名任务,此处启动时更新己存在的Job
     overwrite-existing-jobs: true
     properties:

+ 40 - 30
module-guan/src/main/java/org/jeecg/modules/MysqlBinLogClient.java

@@ -75,16 +75,21 @@ public class MysqlBinLogClient implements ApplicationRunner {
     private WebSocket webSocket;
 
     // 不知道正式库是否是这个值
-    private Long guanralarmid = 1228L; // 报警信息
-    private Long guananachglogid = 1030L; // 设备状态
-    private Long bwanalogtableid = 286L; // 实时数据信息
+//    private Long guanralarmid = 1228L; // 报警信息
+//    private Long guananachglogid = 1030L; // 设备状态
+//    private Long bwanalogtableid = 286L; // 实时数据信息
 
+//    打包时修改该配置
+    private Long guanralarmid = 99L; // 报警信息
+    private Long guananachglogid = 90L; // 设备状态
+    private Long bwanalogtableid = 86L; // 实时数据信息
 
     @Async
     @Override
     @Order
     public void run(ApplicationArguments args) throws Exception {
-        initRedisCache();
+        //所有信息都从前端获取,不需要从后端获取啦
+//        initRedisCache();
 
         //项目启动完成连接bin-log
         new Thread(() -> {
@@ -124,7 +129,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
                 //只要连接的MySQL发生的增删改的操作,则都会进入这里,无论哪个数据库
                 TableMapEventData tableMapEventData = (TableMapEventData) data;
                 if (schema.equals(tableMapEventData.getDatabase())) {
-//                    log.error("不是错误,只是想查询binlog对应的表ID:" + tableMapEventData.getTableId() + ",表名:" + tableMapEventData.getTable());
+//                    log.info("binlog对应的表ID:" + tableMapEventData.getTableId() + ",表名:" + tableMapEventData.getTable());
                     if ("guan_ralarm".equals(tableMapEventData.getTable())) {
                         guanralarmid = tableMapEventData.getTableId();
                     } else if ("bwanalogtable".equals(tableMapEventData.getTable())) {
@@ -143,7 +148,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
 
                 if (guanralarmid == currTableId) {
                     // 打包时修改该配置 屏蔽下面的语句
-                    log.info("guan_ralarm Insert");
+//                    log.info("guan_ralarm Insert");
 
                     WriteRowsEventData writeRowsEventData = (WriteRowsEventData) data;
                     List<GuanRAlarm> alarmList = alarmService.selectAlarm24h(false);
@@ -189,28 +194,31 @@ public class MysqlBinLogClient implements ApplicationRunner {
 
                 if (guananachglogid == currTableId) {
                     // 打包时修改该配置 屏蔽下面的语句
-                    log.info("guan_anachglog Insert");
+//                    log.info("guan_anachglog Insert");
 
                     Object[] obj = Arrays.stream(((WriteRowsEventData) data).getRows().get(0)).toArray();
-                    GuanAnachglog anachglog = new GuanAnachglog();
-                    anachglog.setId((Integer) obj[0]);
-                    anachglog.setProjnodeid((Integer) obj[1]);
-                    anachglog.setTagname(obj[2].toString());
-                    anachglog.setLogdate(obj[3].toString());
-                    anachglog.setLogtime(obj[4].toString());
-                    anachglog.setLogmillisecond((Integer) obj[5]);
-                    anachglog.setLogvalue((Double) obj[6]);
-                    anachglog.setAlarm((Integer) obj[7]);
-
-                    // 2.1 缓存设备状态
-                    if (redisUtil.hasKey(GuanCommonConstant.GUAN_EQUIPMENT_STATUS)) {
-                        redisUtil.del(GuanCommonConstant.GUAN_EQUIPMENT_STATUS);
-                    }
-                    redisUtil.set(GuanCommonConstant.GUAN_EQUIPMENT_STATUS, anachglog);
+                    if ("设备状态".equals(obj[2].toString())) {
+                        GuanAnachglog anachglog = new GuanAnachglog();
+                        anachglog.setId((Integer) obj[0]);
+                        anachglog.setProjnodeid((Integer) obj[1]);
+                        anachglog.setTagname(obj[2].toString());
+                        anachglog.setLogdate(obj[3].toString());
+                        anachglog.setLogtime(obj[4].toString());
+                        anachglog.setLogmillisecond((Integer) obj[5]);
+                        anachglog.setLogvalue((Double) obj[6]);
+                        anachglog.setAlarm((Integer) obj[7]);
+
+                        // 2.1 缓存设备状态
+                        if (redisUtil.hasKey(GuanCommonConstant.GUAN_EQUIPMENT_STATUS)) {
+                            redisUtil.del(GuanCommonConstant.GUAN_EQUIPMENT_STATUS);
+                        }
+                        redisUtil.set(GuanCommonConstant.GUAN_EQUIPMENT_STATUS, anachglog);
 
-                    // 如果设备状态的LogValue=1,代表设备开始运行,则更新曲线信息
-                    if (anachglog.getLogvalue() == 1) {
-                        refreshCurve();
+                        // 如果设备状态的LogValue=1,代表设备开始运行,则更新曲线信息
+                        if (anachglog.getLogvalue() == 1) {
+                            // 改成通过前端判断是否获取新的曲线
+//                            refreshCurve();
+                        }
                     }
                 }
 
@@ -245,6 +253,8 @@ public class MysqlBinLogClient implements ApplicationRunner {
 
                         // 实时数据存入redis中
                         redisUtil.set(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + bwanalogtable.getTagname(), bwanalogtable);
+//                        log.info(bwanalogtable.getTagname() + ":" + redisUtil.hasKey(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + bwanalogtable.getTagname()));
+//                        log.info(redisUtil.get(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + bwanalogtable.getTagname()).toString());
                     }
                 }
 
@@ -261,7 +271,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
                 // 1、报警信息
                 if (guanralarmid == currTableId) {
                     // 打包时修改该配置 屏蔽下面的语句
-                    log.info("guan_ralarm Update");
+//                    log.info("guan_ralarm Update");
 //                    log.info("guan_ralarm Update:" + data.toString());
 
                     DeleteRowsEventData deleteRowsEventData = (DeleteRowsEventData) data;
@@ -306,7 +316,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
      * 刷新所有曲线(设备启动)
      */
     private void refreshCurve() {
-        log.info(String.format("设备启动,推送新曲线 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
+//        log.info(String.format("设备启动,推送新曲线 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
         // 1 更新预制曲线
         List<String> duans = new ArrayList<>();
         List<CirculateDTO> yzqxList = webAccessService.getYzqx(duans);
@@ -351,7 +361,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
 
         webSocket.pushMessage(jsonObject.toString());
 
-        log.info(String.format("设备启动,推送新曲线 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
+//        log.info(String.format("设备启动,推送新曲线 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
     }
 
 
@@ -388,7 +398,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
      * 刷新预制曲线
      */
     private void refreshPrepareCurve() {
-        log.info(String.format("刷新预制曲线 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
+//        log.info(String.format("刷新预制曲线 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
         // 1 更新预制曲线
         List<String> duans = new ArrayList<>();
         List<CirculateDTO> yzqxList = webAccessService.getYzqx(duans);
@@ -413,7 +423,7 @@ public class MysqlBinLogClient implements ApplicationRunner {
 
         webSocket.pushMessage(jsonObject.toString());
 
-        log.info(String.format("刷新预制曲线 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
+//        log.info(String.format("刷新预制曲线 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
     }
 }
 

+ 15 - 0
module-guan/src/main/java/org/jeecg/modules/webaccess/controller/GuanTestController.java

@@ -118,6 +118,21 @@ public class GuanTestController extends JeecgController<GuanTest, IGuanTestServi
     }
 
     /**
+     * 获取最新的试验信息
+     *
+     * @return
+     */
+    @ApiOperation(value="获取最新的试验信息", notes="获取最新的试验信息")
+    @GetMapping(value = "/queryTop1")
+    public Result<GuanTest> queryTop1() {
+        GuanTest guanTest = guanTestService.selectTop1Test();
+        if(guanTest==null) {
+            return Result.error("未找到对应数据");
+        }
+        return Result.OK(guanTest);
+    }
+
+    /**
      * 导出excel
      *
      * @param request

+ 1 - 0
module-guan/src/main/java/org/jeecg/modules/webaccess/controller/WebAccessController.java

@@ -136,6 +136,7 @@ public class WebAccessController {
     @ApiOperation(value = "获取大屏展示数据", notes = "获取大屏展示数据")
     @RequestMapping(value = "/getDashBoardData", method = RequestMethod.GET)
     public Result getDashBoardData() {
+        webAccessService.loadCacheData(true);
         String rtn = webAccessService.firstLoadData();
 
         return Result.OK("获取成功", rtn);

+ 3 - 1
module-guan/src/main/java/org/jeecg/modules/webaccess/dto/CurveSubDTO.java

@@ -2,6 +2,7 @@ package org.jeecg.modules.webaccess.dto;
 
 import lombok.Data;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.StringJoiner;
 
@@ -28,7 +29,8 @@ public class CurveSubDTO {
     @Override
     public String toString() {
         final StringBuilder sb = new StringBuilder("{");
-        sb.append("transtime='").append(transtime).append('\'');
+        sb.append("logtime='").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(logtime)).append('\'');
+        sb.append(", transtime='").append(transtime).append('\'');
         sb.append(", tagvalue='").append(tagvalue).append('\'');
         sb.append('}');
         return sb.toString();

+ 47 - 15
module-guan/src/main/java/org/jeecg/modules/webaccess/service/WebAccessService.java

@@ -68,18 +68,18 @@ public class WebAccessService {
      * @return
      */
     private String getDictItemDesc(String itemtext, String type) {
-        SysDictItem uriIictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", "webaccess地址");
-        SysDictItem projIictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", "webaccess工程名");
+        SysDictItem uriDictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", "webaccess地址");
+        SysDictItem projDictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", "webaccess工程名");
         SysDictItem dictItem = sysDictItemService.selectItemsByDictcodeAndItemtext("webaccess", itemtext);
 
         if ("group".equals(type)) {
-            return uriIictItem.getDescription() + "/" + dictItem.getDescription() + "/" + projIictItem.getDescription();
+            return uriDictItem.getDescription() + "/" + dictItem.getDescription() + "/" + projDictItem.getDescription();
         }
         else if ("single".equals(type)) {
             return dictItem.getDescription();
         }
         else if ("login".equals(type)) {
-            return uriIictItem.getDescription() + "/" + dictItem.getDescription();
+            return uriDictItem.getDescription() + "/" + dictItem.getDescription();
         }
         else {
             return "";
@@ -659,6 +659,8 @@ public class WebAccessService {
             for (GuanDashboardParam param : dashboardParamList) {
                 if (param.getTagName() != null && !"".equals(param.getTagName())) {
                     JSONObject js = new JSONObject();
+//                    log.info(param.getTagName() + ":" + redisUtil.hasKey(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + param.getTagName()));
+//                    log.info(redisUtil.get(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + param.getTagName()).toString());
                     Bwanalogtable bwanalogtable = (Bwanalogtable) redisUtil.get(GuanCommonConstant.GUAN_TAGVALUE_PREFIX + param.getTagName());
                     if (bwanalogtable != null) {
                         js.put("Name", param.getTagName());
@@ -666,7 +668,7 @@ public class WebAccessService {
                         js.put("Quality", 1);
                     }
                     else {
-                        log.info("此点位未配置:", param.getTagName());
+//                        log.info("此点位未配置:" + param.getTagName());
                     }
 
                     resJsonArray.add(js);
@@ -2371,10 +2373,22 @@ public class WebAccessService {
      */
     public String firstLoadData() {
 
-//        log.info(String.format(" 前端首次加载值! 开始时间 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
+        log.warn(String.format(" 前端首次加载值! 开始时间 ↓↓↓↓↓↓↓↓↓↓:" + DateUtils.getTimestamp()));
 
         JSONObject jsonObject = new JSONObject();
 
+        // 设备实时值 从数据库获取
+        JSONArray testArray = getTestInfo();
+        jsonObject.put("设备实时值", testArray);
+
+        // 预制曲线 从redis中获取
+        if (redisUtil.hasKey(GuanCommonConstant.GUAN_PREPARE_CURVE)) {
+            List<CirculateDTO> yzqxList = (List<CirculateDTO>) redisUtil.get(GuanCommonConstant.GUAN_PREPARE_CURVE);
+            List<String> duans = (List<String>) redisUtil.get(GuanCommonConstant.GUAN_PREPARE_CURVE_SECTION);
+            jsonObject.put("预制曲线", yzqxList);
+            jsonObject.put("预制曲线线段", duans);
+        }
+
         // 实时曲线 从redis中获取
         if (redisUtil.hasKey(GuanCommonConstant.GUAN_REALTIME_CURVE)) {
             List<CurveDTO> realtimeCurveList = (List<CurveDTO>) redisUtil.get(GuanCommonConstant.GUAN_REALTIME_CURVE);
@@ -2387,24 +2401,42 @@ public class WebAccessService {
             jsonObject.put("全程曲线", wholeCurveList.toString());
         }
 
-        // 预制曲线 从redis中获取
-        if (redisUtil.hasKey(GuanCommonConstant.GUAN_PREPARE_CURVE)) {
-            List<CirculateDTO> yzqxList = (List<CirculateDTO>) redisUtil.get(GuanCommonConstant.GUAN_PREPARE_CURVE);
-            List<String> duans = (List<String>) redisUtil.get(GuanCommonConstant.GUAN_PREPARE_CURVE_SECTION);
-            jsonObject.put("预制曲线", yzqxList);
-            jsonObject.put("预制曲线线段", duans);
-        }
-
         // 最近24H报警信息 从redis中获取
         if (redisUtil.hasKey(GuanCommonConstant.GUAN_ALARMS_24H)) {
             List<GuanRAlarm> alarmList = (List<GuanRAlarm>) redisUtil.get(GuanCommonConstant.GUAN_ALARMS_24H);
             jsonObject.put("最近24H报警信息", alarmList.toString());
         }
 
-//        log.info(String.format(" 前端首次加载值! 结束时间 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
+        log.warn(String.format(" 前端首次加载值! 结束时间 ↑↑↑↑↑↑↑↑↑↑:" + DateUtils.getTimestamp()));
 
         return jsonObject.toString();
     }
+
+    /**
+     * 增加需要计算的值
+     * @return
+     */
+    private JSONArray getTestInfo() {
+        JSONArray jsonArray = new JSONArray();
+        // 需要计算的信息
+        JSONObject addObject = new JSONObject();
+        // 试验信息
+        GuanTest guanTest = guanTestMapper.selectTop1Test();
+        if (guanTest != null) {
+            addObject.put("Name", "试验名称");
+            addObject.put("Value", guanTest.getTestname());
+            addObject.put("Quality", 0);
+            jsonArray.add(addObject);
+
+            addObject.put("Name", "试验类型");
+            addObject.put("Value", guanTest.getTesttype());
+            addObject.put("Quality", 0);
+            jsonArray.add(addObject);
+        }
+
+        return jsonArray;
+    }
+
     //endregion
 
     // region <<获取工艺流程图地址>>