Browse Source

博海数据同步发送测试

lloyd 2 months ago
parent
commit
2f1403b1a7

+ 3 - 1
.gitignore

@@ -12,4 +12,6 @@ target
12
 
12
 
13
 logs
13
 logs
14
 !**/nacos/target
14
 !**/nacos/target
15
-data/gtcvr.db
15
+data/gtcvr.db
16
+/data/dump/
17
+/data/

BIN
release/gtcvr.db


+ 0 - 2
src/main/java/com/gct/edge/entity/BhRtuData.java

@@ -19,8 +19,6 @@ import lombok.experimental.Accessors;
19
 @Accessors(chain = true)
19
 @Accessors(chain = true)
20
 public class BhRtuData extends Model<BhRtuData> {
20
 public class BhRtuData extends Model<BhRtuData> {
21
 
21
 
22
-    private static final long serialVersionUID=1L;
23
-    
24
     private String wellId;
22
     private String wellId;
25
     
23
     
26
     private String prodDate;
24
     private String prodDate;

+ 1 - 0
src/main/java/com/gct/edge/service/excutor/DataSendService.java

@@ -3,6 +3,7 @@ package com.gct.edge.service.excutor;
3
 import com.alibaba.fastjson.JSONObject;
3
 import com.alibaba.fastjson.JSONObject;
4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
 import com.baomidou.mybatisplus.extension.service.IService;
5
 import com.baomidou.mybatisplus.extension.service.IService;
6
+import com.gct.edge.entity.BhRtuData;
6
 import com.gct.edge.entity.DumpRecord;
7
 import com.gct.edge.entity.DumpRecord;
7
 import com.gct.edge.service.abst.DumpRecordService;
8
 import com.gct.edge.service.abst.DumpRecordService;
8
 import com.gct.edge.service.abst.AoidProdStateService;
9
 import com.gct.edge.service.abst.AoidProdStateService;

+ 13 - 10
src/main/java/com/gct/edge/service/excutor/ModbusReadService.java

@@ -67,7 +67,15 @@ public class ModbusReadService {
67
                 List<List<Double>> sgt = readBody.card;
67
                 List<List<Double>> sgt = readBody.card;
68
                 Double s = readBody.s;
68
                 Double s = readBody.s;
69
                 Double n = readBody.n;
69
                 Double n = readBody.n;
70
-                String prodTime = readBody.prodTime;
70
+                String prodTime = LocalDateTime.now().format(df);
71
+                String checkTime = readBody.prodTime;
72
+                //bh  data read save
73
+                BHModbusDataBody bhModbusDataBody = ModbusRTUReader.readBHBody();
74
+                BhRtuData data = JSONObject.toJavaObject((JSON) JSONObject.toJSON(bhModbusDataBody), BhRtuData.class);
75
+                data.setWellId(aoidConfigData.getJh());
76
+                data.setProdDate(prodTime);
77
+                bhRtuDataService.save(data);
78
+
71
                 if (Objects.isNull(sgt) || Objects.isNull(s) || Objects.isNull(n) ||Objects.isNull(prodTime) || s < 1e-6 || n < 1e-6) {
79
                 if (Objects.isNull(sgt) || Objects.isNull(s) || Objects.isNull(n) ||Objects.isNull(prodTime) || s < 1e-6 || n < 1e-6) {
72
                     log.error("read Rtu modbus failed, sgt: {},s: {},n: {},prodTime: {}", sgt, s, n, prodTime);
80
                     log.error("read Rtu modbus failed, sgt: {},s: {},n: {},prodTime: {}", sgt, s, n, prodTime);
73
                     continue;
81
                     continue;
@@ -78,12 +86,12 @@ public class ModbusReadService {
78
                 if (Objects.isNull(lastDumpRecord)){
86
                 if (Objects.isNull(lastDumpRecord)){
79
                     lastDumpRecord = new DumpRecord();
87
                     lastDumpRecord = new DumpRecord();
80
                     lastDumpRecord.setTableName(aoidConfigData.getJh());
88
                     lastDumpRecord.setTableName(aoidConfigData.getJh());
81
-                    lastDumpRecord.setDumpTime(prodTime);
89
+                    lastDumpRecord.setDumpTime(checkTime);
82
                     dumpRecordService.save(lastDumpRecord);
90
                     dumpRecordService.save(lastDumpRecord);
83
                 }else {
91
                 }else {
84
-                    if (lastDumpRecord.getDumpTime().equals(prodTime))continue;
92
+                    if (lastDumpRecord.getDumpTime().equals(checkTime))continue;
85
                     else {
93
                     else {
86
-                        lastDumpRecord.setDumpTime(prodTime);
94
+                        lastDumpRecord.setDumpTime(checkTime);
87
                         dumpRecordService.update(lastDumpRecord,new QueryWrapper<DumpRecord>().eq("table_name", aoidConfigData.getJh()));
95
                         dumpRecordService.update(lastDumpRecord,new QueryWrapper<DumpRecord>().eq("table_name", aoidConfigData.getJh()));
88
                     }
96
                     }
89
                 }
97
                 }
@@ -97,12 +105,7 @@ public class ModbusReadService {
97
                 executor.submit(new CalculateInputData(aoidConfigData.getJh(), LocalDateTime.parse(prodTime, df), s, n, sgtDouble));
105
                 executor.submit(new CalculateInputData(aoidConfigData.getJh(), LocalDateTime.parse(prodTime, df), s, n, sgtDouble));
98
 
106
 
99
 
107
 
100
-                //bh  data read save
101
-                BHModbusDataBody bhModbusDataBody = ModbusRTUReader.readBHBody();
102
-                BhRtuData data = JSONObject.toJavaObject((JSON) JSONObject.toJSON(bhModbusDataBody), BhRtuData.class);
103
-                data.setWellId(aoidConfigData.getJh());
104
-                data.setProdDate(prodTime);
105
-                bhRtuDataService.save(data);
108
+
106
             } catch (Exception e) {
109
             } catch (Exception e) {
107
                 log.error("readDataAndSubmitTask error, detail: {}, cause: {}", e.getMessage(),e.getCause());
110
                 log.error("readDataAndSubmitTask error, detail: {}, cause: {}", e.getMessage(),e.getCause());
108
             }
111
             }

+ 4 - 2
src/main/java/com/gct/etl/ModbusRTUReader.java

@@ -186,6 +186,8 @@ public class ModbusRTUReader {
186
     }
186
     }
187
 
187
 
188
     private static void connect() {
188
     private static void connect() {
189
+        regConfig.serial.serialName = "COM3";
190
+        regConfig.serial.baudRate = 115200;//232口使用115200,485口注释此行
189
         System.out.printf("serial: %s, baudRate: %d, is485mode: %s%n", regConfig.serial.serialName, regConfig.serial.baudRate, regConfig.serial.isRs485);
191
         System.out.printf("serial: %s, baudRate: %d, is485mode: %s%n", regConfig.serial.serialName, regConfig.serial.baudRate, regConfig.serial.isRs485);
190
         ModbusSerialMaster master = masterCache.get(regConfig.serial);
192
         ModbusSerialMaster master = masterCache.get(regConfig.serial);
191
         if (Objects.nonNull(master) && master.isConnected()) return;
193
         if (Objects.nonNull(master) && master.isConnected()) return;
@@ -283,8 +285,8 @@ public class ModbusRTUReader {
283
                 String setMethodName = "set" + filedName;
285
                 String setMethodName = "set" + filedName;
284
                 ModbusReadConfig.Section regConfig = (ModbusReadConfig.Section) BHModbusReadConfig.class.getMethod(getMethodName).invoke(readConfig);
286
                 ModbusReadConfig.Section regConfig = (ModbusReadConfig.Section) BHModbusReadConfig.class.getMethod(getMethodName).invoke(readConfig);
285
                 if (Objects.isNull(regConfig)) continue;
287
                 if (Objects.isNull(regConfig)) continue;
286
-                if (element.getType().equals(Double.class)) {
287
-                    BHModbusDataBody.class.getMethod(setMethodName,Double.class).invoke(body, readFloatSingle(regConfig, new ByteToFloat()));
288
+                if (element.getType().equals(Float.class)) {
289
+                    BHModbusDataBody.class.getMethod(setMethodName,Float.class).invoke(body, readFloatSingle(regConfig, new ByteToFloat()));
288
                 } else if (element.getType().equals(Integer.class)) {
290
                 } else if (element.getType().equals(Integer.class)) {
289
                     BHModbusDataBody.class.getMethod(setMethodName,Integer.class).invoke(body, readIntegerSingle(regConfig, new DefaultParser()));
291
                     BHModbusDataBody.class.getMethod(setMethodName,Integer.class).invoke(body, readIntegerSingle(regConfig, new DefaultParser()));
290
                 }
292
                 }