Browse Source

代码 备注

guoqiang 7 months ago
parent
commit
e8ce3a619c

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

@@ -35,15 +35,16 @@ public class OpcGatherWatch {
     @Autowired
     MongoTemplate mongoTemplate;
 
+    // 采集频率设置值(数据库字典匹配,否则不执行查询不到设备)
     @Scheduled(fixedDelay = 500)
     public void t1(){
         opc("500");
-    }
+    } // 0.5ms
 
     @Scheduled(fixedDelay = 1000)
     public void t2(){
         opc("1000");
-    }
+    } // 1ms
 
     @Scheduled(fixedDelay = 2000)
     public void t3(){
@@ -60,7 +61,6 @@ public class OpcGatherWatch {
         opc("10000");
     }
 
-
     @Scheduled(fixedDelay = 30000)
     public void t6(){
         opc("30000");

+ 0 - 146
jeecg-module-gather/src/main/java/org/jeecg/modules/watch/s7gatherWatch.java

@@ -1,146 +0,0 @@
-package org.jeecg.modules.watch;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import io.netty.util.internal.StringUtil;
-import lombok.extern.slf4j.Slf4j;
-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.s7.service.S7PLC;
-import org.jeecg.modules.devicePoint.entity.DevicePoint;
-import org.jeecg.modules.devicePoint.service.IDevicePointService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.mongodb.core.MongoTemplate;
-import org.springframework.scheduling.annotation.EnableAsync;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-
-@EnableScheduling
-@EnableAsync
-@Component
-@Slf4j
-public class s7gatherWatch {
-
-    @Autowired
-    IDeviceInformationService deviceInformationService;
-
-    @Autowired
-    IDevicePointService devicePointService;
-
-    @Autowired
-    MongoTemplate mongoTemplate;
-
-    HashMap<String, S7PLC> s7PLCmap = new HashMap<>();
-
-    @Scheduled(fixedDelay = 500)
-    public void t1(){
-        s7("500");
-    }
-
-    @Scheduled(fixedDelay = 1000)
-    public void t2(){
-        s7("1000");
-    }
-
-    @Scheduled(fixedDelay = 2000)
-    public void t3(){
-        s7("2000");
-    }
-
-    @Scheduled(fixedDelay = 5000)
-    public void t4(){
-        s7("5000");
-    }
-
-    @Scheduled(fixedDelay = 10000)
-    public void t5(){
-        s7("10000");
-    }
-
-    @Scheduled(fixedDelay = 30000)
-    public void t6(){
-        s7("30000");
-    }
-
-    @Scheduled(fixedDelay = 60000)
-    public void t7(){
-        s7("60000");
-    }
-
-
-
-    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);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("REAL")){
-                            read = "" + s7PLC.readFloat32(pointAddr);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("DINT")){
-                            read = "" + s7PLC.readInt32(pointAddr);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("INT")){
-                            read = "" + s7PLC.readInt16(pointAddr);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("DWORD")){
-                            read = "" + s7PLC.readInt32(pointAddr);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("WORD")){
-                            read = "" + s7PLC.readInt16(pointAddr);
-                            readText = read;
-                        }else if (s7Info.getDateType().equals("BOOL")){
-                            read = "" + s7PLC.readBoolean(pointAddr);
-                            if(!StringUtil.isNullOrEmpty(read))readText = read.equals("true")?"1":"0";
-                        }
-                        if (oConvertUtils.isEmpty(read)) {
-                            read = "";
-                        }
-                        s7Info.setTestResult(read);
-                        if(s7Info.getGatherStatus().equals("1")){
-                            s7Info.setGatherStatus("0");
-                        }
-                    } catch (Exception e) {
-                        s7Info.setGatherStatus("1");
-                    }finally {
-                        mongoTemplate.insert(new PointData(s7Info, freq, readText, curentDate), s7Info.getId());
-                        devicePointService.updateById(s7Info);
-                        readText = "";
-                    }
-                }
-            } catch (Exception e) {
-            }
-        });
-    }
-
-    public void closeS7(String id){
-        S7PLC s7PLC = s7PLCmap.get(id);
-        if(!oConvertUtils.isEmpty(s7PLC)){
-            s7PLC.close();
-            s7PLCmap.remove(id);
-        }
-    }
-
-}