Browse Source

项目说明文档以及采集注释

fenze 7 months ago
parent
commit
e0769ecd49

+ 17 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/push/utils/MqttClientUtil.java

@@ -43,25 +43,41 @@ public class MqttClientUtil implements ApplicationRunner {
 
 
     public void sub(ConfigMqtt configMqtt) throws MqttException {
+        //创建mqtt连接url
         StringBuffer url = new StringBuffer();
         url.append("tcp://").append(configMqtt.getIp()).append(":").append(configMqtt.getHost());
+        //根据url从连接缓存池中拿去连接对象
         MqttClient client = mqttClients.get(url.toString());
+        //连接对象是否为空或异常
         if(ObjectUtils.isEmpty(client)||!client.isConnected()){
+            //mqtt连接参数
             MqttConnectOptions options = new MqttConnectOptions();
+            //用户名
             options.setUserName(configMqtt.getUsername());
+            //密码
             options.setPassword(configMqtt.getPassword().toCharArray());
+            //连接超时时间
             options.setConnectionTimeout(100);
+            //心跳检测频率
             options.setKeepAliveInterval(60);
+            //清除会话
             options.setCleanSession(true);
+            //自动重连
             options.setAutomaticReconnect(false);
+            //创建连接对象
             client = new MqttClient(url.toString(), configMqtt.getId(), new MemoryPersistence());
+            //设置回调对象
             client.setCallback(new MqttClientCallback(configMqtt.getId(),client,configMqtt.getTopic()));
+            //建立连接
             client.connect(options);
+            //将连接放入链接缓存池中
             mqttClients.put(url.toString(),client);
         }
+        //获取所有主题
         String[] topics = configMqtt.getTopic().split(",");
         if(topics!=null&&topics.length!=0){
             for (String topic : topics) {
+                //订阅主题
                 client.subscribe(topic);
             }
         }
@@ -150,6 +166,7 @@ public class MqttClientUtil implements ApplicationRunner {
         return true;
     }
 
+    //项目启动时对所有需要订阅的mqtt连接进行订阅
     @Override
     public void run(ApplicationArguments args){
         LambdaQueryWrapper<ConfigMqtt> eq = new LambdaQueryWrapper<ConfigMqtt>().ne(ConfigMqtt::getPushOrSub,"0");

+ 10 - 0
jeecg-module-conn/src/main/java/org/jeecg/modules/watch/MqttGatherWatch.java

@@ -34,19 +34,29 @@ public class MqttGatherWatch {
     }
 
 
+    //mqtt连接状态监测
     public void mqtt(){
+        //获取所有需要订阅的mqtt配置
         LambdaQueryWrapper<ConfigMqtt> eq = new LambdaQueryWrapper<ConfigMqtt>().ne(ConfigMqtt::getPushOrSub,"0");
         List<ConfigMqtt> configMqtts = configMqttMapper.selectList(eq);
+        //遍历
         for (ConfigMqtt configMqtt : configMqtts) {
+            //创建mqtt连接url
             StringBuffer url = new StringBuffer();
             url.append("tcp://").append(configMqtt.getIp()).append(":").append(configMqtt.getHost());
             try {
+                //根据url从连接缓存池中拿去连接对象
                 MqttClient client = mqttClientUtil.mqttClients.get(url.toString());
+                //连接对象为空则说明并未订阅
                 if(client == null){
+                    //mqtt订阅操作
                     mqttClientUtil.sub(configMqtt);
                 }else{
+                    //检测mqtt状态是否正常
                     if(!client.isConnected()){
+                        //从连接缓存池中移除该连接
                         mqttClientUtil.mqttClients.remove(url);
+                        //重新订阅
                         mqttClientUtil.sub(configMqtt);
                     }
                 }

+ 17 - 1
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/DbWatch.java

@@ -27,28 +27,38 @@ public class DbWatch {
     MongoTemplate mongoTemplate;
 
 
+    //mongo点位历史数据集合创建时间索引
     public void createIndex(){
+        //获取所有集合并遍历
         mongoTemplate.getCollectionNames().forEach(name->{
+            //如果为风机运行时间累计以及煤气回收报表则不做处理
             if(name.contains("fansRunTime")||name.contains("gasRecovery")){
                 return;
             }
+            //获取该集合下的所有索引
             ListIndexesIterable<Document> indexList = mongoTemplate
                     .getCollection(name).listIndexes();
+            //是否有时间倒序索引标识
             boolean istimedesc = false;
+            //是否有时间hash索引标识
             boolean istimehash = false;
-            //先检查是否存在索引,特殊业务应用,一般不需要这一步
+            //遍历该集合下的所有索引检测是否已有时间索引
             for (Document document : indexList) {
+                //获取索引名称
                 String key = (String)document.get("name");
                 if (null != key) {
+                    //检测索引是否位时间倒序索引
                     if (key.contains("timedesc")) {
                         istimedesc = true;
                     }
+                    //检测索引是否位时间hash索引
                     if (key.contains("timehash")) {
                         istimehash = true;
                     }
                 }
 
             }
+            //没有索引则进行创建
             if(!istimedesc){
                 mongoTemplate.getCollection(name)
                         .createIndex(new Document("time", -1), new IndexOptions().background(false).name("timedesc"));
@@ -63,15 +73,21 @@ public class DbWatch {
     }
 
 
+    //设备点位历史数据定时清除
     @Scheduled(cron = "0 0 0,12 * * ?")
     public void cleanHisory(){
+        //获取10天前的时间
         Calendar instance = Calendar.getInstance();
         instance.add(Calendar.DATE,-10);
+        //获取所有集合并遍历
         mongoTemplate.getCollectionNames().forEach(name->{
+            //如果为风机运行时间累计以及煤气回收报表则不做处理
             if(name.contains("fansRunTime")||name.contains("gasRecovery")){
                 return;
             }
+            //删除数据的过滤条件  删除10天以前的数据
             Query query = Query.query(Criteria.where("time").lt(instance.getTime()));
+            //删除数据
             mongoTemplate.remove(query,name);
 
         });

+ 20 - 3
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/OpcGatherWatch.java

@@ -71,42 +71,59 @@ public class OpcGatherWatch {
         opc("60000");
     }
 
+
+    //opc数据采集
     public void opc(String freq){
-        //opc数据采集
+        //获取所有运行中设备
         LambdaQueryWrapper<DeviceInformation> opcquery = new LambdaQueryWrapper<DeviceInformation>().eq(DeviceInformation::getStatus, "0").eq(DeviceInformation::getFreq, freq);
         List<DeviceInformation> opclist = deviceInformationService.list(opcquery);
+        //获取当前时间
         Date curentDate = new Date();
+        //遍历设备集合
         opclist.forEach(opcConn -> {
+            //获取设备下所有点位
             List<DevicePoint> opcPoints = devicePointService.list( new LambdaQueryWrapper<DevicePoint>().eq(DevicePoint::getDeviceId,opcConn.getId()));
             OpcUaClient opcUaClient = null;
             String readText = "";
             try {
+                //与设备建立连接
                 opcUaClient = OpcUaServerUtils.connectOpcUaServer(opcConn);
-                //主动获取
+                //遍历设备下所有点位
                  for (DevicePoint opcPoint : opcPoints) {
                     try {
+                        //读取点位数据
                         String nodeValue = OpcUaServerUtils.readNodeValue(opcUaClient, opcPoint.getNameindex(), opcPoint.getItemid());
                         if (oConvertUtils.isEmpty(nodeValue)) {
                             nodeValue = "";
                         }
+                        //处理boolean类型数据 true为1 false为0
                         readText = nodeValue.equals("true")?"1":nodeValue.equals("false")?"0":nodeValue;
+                        //将点位数据存入点位信息对象中
                         opcPoint.setTestResult(nodeValue);
-                        opcConn.setStatus("0");
+                        //设置点位状态为正常
+                        opcPoint.setGatherStatus("0");
+                        //如果点位状态异常则恢复为正常
                         if(opcPoint.getGatherStatus().equals(1)){
                             opcPoint.setGatherStatus("0");
                         }
                     } catch (Exception e) {
+                        //打印点位异常日志
                         log.error(e.getMessage());
+                        //设置点位状态为异常
                         opcPoint.setGatherStatus("1");
                     } finally {
+                        //将点位数据存入mongo中
                         mongoTemplate.insert(new PointData(opcPoint, freq, readText, curentDate),  opcPoint.getId());
+                        //更新数据库点位信息
                         devicePointService.updateById(opcPoint);
                     }
                 }
             } catch (Exception e) {
                 log.error(e.getMessage());
             } finally {
+                //更新数据库设备信息
                 deviceInformationService.updateById(opcConn);
+                //关闭连接
                 if(opcUaClient != null)opcUaClient.disconnect();
             }
         });

+ 19 - 3
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/modBusGatherWatch.java

@@ -71,35 +71,49 @@ public class modBusGatherWatch {
     }
 
 
-
+    //modbus数据采集
     public void modbus(String freq){
-        //modbus数据采集
+        //获取所有运行中设备
         LambdaQueryWrapper<DeviceInformation> modquery = new LambdaQueryWrapper<DeviceInformation>().eq(DeviceInformation::getStatus, "0").eq(DeviceInformation::getFreq, freq);
         List<DeviceInformation> modBusList = deviceInformationService.list(modquery);
+        //获取当前时间
         Date curentDate = new Date();
+        //遍历设备集合
         modBusList.forEach(modBus -> {
+            //与设备建立连接
             ModbusTcp plc = new ModbusTcp(modBus.getModbusDeviceNum(), modBus.getDeviceIp(), Integer.valueOf(modBus.getDevicePort()));
+            //未处理数据
             String read = "";
+            //处理过的数据
             String readText = "";
             try {
+                //获取该设备下的所有设备点位
                 List<DevicePoint> modBusPoints = devicePointService.list( new LambdaQueryWrapper<DevicePoint>().eq(DevicePoint::getDeviceId,modBus.getId()));
+                //遍历设备点位集合
                 for (DevicePoint modBusPoint : modBusPoints) {
                     try {
+                        //读取设备点位数据
                         read = "" + plc.readInt16(Integer.valueOf(modBusPoint.getPointAddr()));
                         if (oConvertUtils.isEmpty(read)) {
                             read = "";
                         }
+                        //处理boolean类型数据 true为1 false为0
                         readText = read.equals("true")?"1":read.equals("false")?"0":read;
+                        //将点位数据存入点位信息对象中
                         modBusPoint.setTestResult(read);
-                        modBus.setStatus("0");
+                        //如果点位状态异常则恢复为正常
                         if(modBusPoint.getGatherStatus().equals(1)){
                             modBusPoint.setGatherStatus("0");
                         }
                     } catch (Exception e) {
+                        //打印点位异常日志
                         log.error(e.getMessage());
+                        //设置点位状态为异常
                         modBusPoint.setGatherStatus("1");
                     }finally {
+                        //将点位数据存入mongo中
                         mongoTemplate.insert(new PointData(modBusPoint, freq, readText , curentDate),  modBusPoint.getId());
+                        //更新数据库点位信息
                         devicePointService.updateById(modBusPoint);
                         readText = "";
                     }
@@ -107,7 +121,9 @@ public class modBusGatherWatch {
             } catch (Exception e) {
                 log.error(e.getMessage());
             }finally {
+                //关闭连接
                 plc.close();
+                //更新数据库设备信息
                 deviceInformationService.updateById(modBus);
             }
         });

+ 21 - 1
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/s7gatherWatch.java

@@ -74,24 +74,36 @@ public class s7gatherWatch {
     }
 
 
-
+    //s7数据采集
     public void s7(String freq){
+        //获取当前时间
         Date curentDate = new Date();
+        //获取所有运行中设备
         LambdaQueryWrapper<DeviceInformation> s7Query = new LambdaQueryWrapper<DeviceInformation>().ne(DeviceInformation::getStatus, "1").eq(DeviceInformation::getFreq, freq);
         List<DeviceInformation> s7List = deviceInformationService.list(s7Query);
+        //遍历设备集合
         s7List.forEach(s7 -> {
             List<DevicePoint> s7Infos = null;
+            //未处理数据
             String read = "";
+            //处理过的数据
             String readText = "";
+            //从连接池中拿取连接
             S7PLC s7PLC = s7PLCmap.get(s7.getId());
+            //连接对象为空则创建
             if(oConvertUtils.isEmpty(s7PLC)){
+                //与设备建立连接
                 s7PLC = new S7PLC(s7.getS7Model(), s7.getDeviceIp(), Integer.valueOf(s7.getDevicePort()), s7.getS7Rack(), Integer.valueOf(s7.getS7Slot()), Integer.valueOf(s7.getS7LongestWidth()));
+                //将连接放入连接池中
                 s7PLCmap.put(s7.getId(),s7PLC);
             }
             try {
+                //获取设备下所有点位
                 s7Infos = devicePointService.list( new LambdaQueryWrapper<DevicePoint>().eq(DevicePoint::getDeviceId,s7.getId()));
+                //遍历点位集合
                 for (DevicePoint s7Info : s7Infos) {
                     try {
+                        //读取点位数据
                         String pointAddr = s7Info.getPointAddr()+"";
                         if (s7Info.getDateType().equals("STRING")){
                             read = "" + s7PLC.readString(pointAddr);
@@ -118,14 +130,21 @@ public class s7gatherWatch {
                         if (oConvertUtils.isEmpty(read)) {
                             read = "";
                         }
+                        //将点位数据存入点位信息对象中
                         s7Info.setTestResult(read);
+                        //如果点位状态异常则恢复为正常
                         if(s7Info.getGatherStatus().equals("1")){
                             s7Info.setGatherStatus("0");
                         }
                     } catch (Exception e) {
+                        //打印点位异常日志
+                        log.error(e.getMessage());
+                        //设置点位状态为异常
                         s7Info.setGatherStatus("1");
                     }finally {
+                        //将点位数据存入mongo中
                         mongoTemplate.insert(new PointData(s7Info, freq, readText, curentDate), s7Info.getId());
+                        //更新数据库点位信息
                         devicePointService.updateById(s7Info);
                         readText = "";
                     }
@@ -135,6 +154,7 @@ public class s7gatherWatch {
         });
     }
 
+    //关闭连接并从连接池中移除
     public void closeS7(String id){
         S7PLC s7PLC = s7PLCmap.get(id);
         if(!oConvertUtils.isEmpty(s7PLC)){

+ 126 - 0
zgztREADME.md

@@ -0,0 +1,126 @@
+------
+
+**一、项目结构**
+
+```
+	|-jeecg-boot-parent(父POM: 项目依赖、modules组织)
+    |    |-jeecg-boot-base-core(共通模块: 工具类、config、杈限、查询过滤器、注解等)
+    |    |-jeecg-module-demo 示例代码
+    |    |-jeecg-module-billet 钢坯模块
+    |    |-jeecg-module-gather 采集以及设备管理模块 
+    |    |-jeecg-module-conn 连接以及推送管理模块
+    |    |-jeecg-module-system System系统管理目录
+    |    |-jeecg-system-bizSvstem系统管理权限等功能
+    |    |    |-jeecg-system-biz System系统管理权限等功能
+    |    |    |-jeecg-system-start System单体启动项目(8080)
+    |    |    |-jeecg-system-api System系统管理模块对外api
+    |    |        |-jeecg-system-cloud-api System模块对外提供的微服务接口
+    |    |        |-jeecg-system-local-api System模块对外提供的单体接口
+    |    ├─jeecg-server-cloud          --微服务模块
+             ├─jeecg-cloud-gateway       --微服务网关模块(9999)
+             ├─jeecg-cloud-nacos         --Nacos服务模块(8848)
+             ├─jeecg-system-cloud-start  --System微服务启动项目(7001)
+             ├─jeecg-demo-cloud-start    --Demo微服务启动项目(7002)
+             ├─jeecg-visual
+                ├─jeecg-cloud-monitor        --微服务监控模块 (9111)
+                ├─jeecg-cloud-xxljob         --微服务xxljob定时任务服务端 (9080)
+                ├─jeecg-cloud-sentinel       --sentinel服务端 (9000)
+                ├─jeecg-cloud-test           -- 微服务测试示例(各种例子)
+                   ├─jeecg-cloud-test-more   -- 微服务测试示例(feign、熔断降级、xxljob、分布式锁)
+                   ├─jeecg-cloud-test-rabbitmq     -- 微服务测试示例(rabbitmq)
+                   ├─jeecg-cloud-test-seata          -- 微服务测试示例(seata分布式事务)
+                   ├─jeecg-cloud-test-shardingsphere    -- 微服务测试示例(分库分表)
+```
+
+  
+
+------
+
+**二、业务模块**
+
+1.jeecg-module-billet 钢坯模块
+
+| 类名                                   | 功能说明              |
+| -------------------------------------- | --------------------- |
+| BilletBasicInfosController             | 铸坯实绩              |
+| CastStreamActualsController            | 铸流实绩              |
+| CastStreamTraceProductActualController | 铸流跟踪生产实绩      |
+| HeatsActualsController                 | 炉次实绩              |
+| HeatsActualProductDescController       | 炉次实绩-生产记录详情 |
+| HeatsActualProductLogController        | 炉次实绩-生产记录     |
+| BilletHotsendBaseController            | 钢坯热送              |
+| RulerDefaultConfigController           | 钢坯热送配置信息      |
+| CarRunLogController                    | 车辆运行记录          |
+| CarRunSummaryController                | 车辆运行汇总          |
+| OperateLogController                   | 操作日志              |
+| RollClubOneController                  | 轧钢棒一              |
+| RollClubThreeController                | 轧钢棒三              |
+| RollClubTwoController                  | 轧钢棒二              |
+| RollHeightController                   | 轧钢高线              |
+| RollOutShippController                 | 轧钢外运              |
+| StackingAndLoadingVehiclesController   | 垛位以及车位钢坯情况  |
+| StorageBillController                  | 钢坯装运单            |
+| StorageBillModelController             | 钢坯装运单模板        |
+| StorageCarConfigController             | 储运车辆配置          |
+| StorageCarLogController                | 储运车运记录          |
+| StorageCastConfigController            | 储运铸机配置          |
+| WebSocketServer                        | websocket服务         |
+
+
+
+2.jeecg-module-conn 连接以及推送管理
+
+| 类名                      | 功能说明             |
+| ------------------------- | -------------------- |
+| ConfigMongoController     | mongo配置            |
+| ConfigMqttController      | mqtt配置             |
+| ConfigRabbitController    | rabbit配置           |
+| ConfigSqlController       | sql配置              |
+| ConfigWebsocketController | websocket配置        |
+| PushController            | 数据推送配置         |
+| DataPushConfigController  | 数据推送配置详情     |
+| MqttGatherWatch           | mqtt订阅监测定时任务 |
+| PushWatch                 | 推送定时任务         |
+
+
+
+3.jeecg-module-gather 设备采集管理
+
+| 类名                        | 功能说明              |
+| --------------------------- | --------------------- |
+| common                      | s7、modbus采集通用类  |
+| exceptions                  | s7、modbus采集异常类  |
+| utils                       | 工具类                |
+| net                         | s7、modbus采集连接类  |
+| RepositoryController        | 数据仓库              |
+| DeviceInformationController | 设备管理信息表        |
+| DeviceRegionController      | 区域管理信息表        |
+| GatherManageController      | 采集管理              |
+| modbus                      | modbus设备连接        |
+| opc                         | opc设备连接           |
+| s7                          | s7设备连接            |
+| DevicePointController       | 设备采集点            |
+| DbWatch                     | mongo历史数据定时清除 |
+| modBusGatherWatch           | modbus定时采集        |
+| OpcGatherWatch              | opc定时采集           |
+| s7gatherWatch               | s7定时采集            |
+
+
+
+**三、swagger访问地址**
+
+http://127.0.0.1:8080/jeecg-boot/#/home
+
+
+
+**四、采集流程**
+
+```
+1.获取所有运行中设备信息
+2.遍历设备信息,与设备建立连接
+3.根据设备信息获取该设备下所有采集点点位
+4.根据点位信息主动获取设备点位数值
+5.根据点位数据类型进行数据处理
+6.处理完的数据保存至mysql的设备点位信息表(用于实时数据查询)以及Mongo数据库(用于历史数据查询)中
+```
+