Browse Source

峰平谷 job

guoqiang 7 months ago
parent
commit
fcd403d45c

+ 122 - 0
jeecg-module-gather/src/main/java/org/jeecg/modules/fpgJob/LeanModelStatistics.java

@@ -0,0 +1,122 @@
+package org.jeecg.modules.fpgJob;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.dataRepository.entity.PointData;
+import org.jeecg.modules.device.entity.DeviceInformation;
+import org.jeecg.modules.device.service.IDeviceInformationService;
+import org.jeecg.modules.deviceConn.opc.utils.OpcUaServerUtils;
+import org.jeecg.modules.devicePoint.entity.DevicePoint;
+import org.jeecg.modules.devicePoint.service.IDevicePointService;
+import org.jeecg.modules.events.service.ILeanEventsHostService;
+import org.jeecg.modules.gatherData.entity.FpgGatherData;
+import org.jeecg.modules.gatherData.service.IFpgGatherDataService;
+import org.jeecg.modules.leanEventWarn.service.ILeanEventWarnInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@EnableAsync
+@Component
+//@EnableScheduling
+public class LeanModelStatistics {
+
+    @Autowired
+    IDeviceInformationService deviceInformationService;
+
+    @Autowired
+    IDevicePointService devicePointService;
+
+    @Autowired
+    IFpgGatherDataService fpgGatherDataService;
+
+    @Autowired
+    MongoTemplate mongoTemplate;
+
+    @Autowired
+    RedisTemplate redisTemplate;
+
+    @Autowired
+    ILeanEventsHostService leanEventsHostService;
+
+    @Autowired
+    ILeanEventWarnInfoService leanEventWarnInfoService;
+
+    // 精益模型统计数据
+    public void opc(String freq){
+        // 获取所有运行中设备(峰平谷)
+        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);
+                        //设置点位状态为正常
+                        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);
+                        // 存入采集设备
+                        FpgGatherData fpgGatherData = new FpgGatherData();
+                        fpgGatherData.setDeviceInformationId(opcConn.getId()); // 设备ID
+                        fpgGatherData.setDeviceRegionId(opcConn.getDeviceRegionId()); // 区域id
+                        fpgGatherData.setDevicePointId(opcPoint.getId()); // 采集点ID
+                        fpgGatherData.setCreateTime(curentDate); // 创建时间
+                        fpgGatherDataService.addC(fpgGatherData);
+                        if(oConvertUtils.isEmpty(opcConn.getId())){
+                            return;
+                        }
+                        String deviceInformationId = opcConn.getId();
+                    }
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage());
+            } finally {
+                //更新数据库设备信息
+                deviceInformationService.updateById(opcConn);
+                //关闭连接
+                if(opcUaClient != null) {
+                    opcUaClient.disconnect();
+                }
+            }
+        });
+    }
+}

+ 0 - 1
jeecg-module-gather/src/main/java/org/jeecg/modules/gatherData/entity/FpgStatiscsModelData.java

@@ -118,6 +118,5 @@ public class FpgStatiscsModelData{
         this.dates = dates;
         this.createTime = createTime;
         this.updateTime = updateTime;
-
     }
 }