|
@@ -19,26 +19,28 @@ import java.util.*;
|
19
|
19
|
|
20
|
20
|
/**
|
21
|
21
|
* class name: CamelJDBCCofRealTimeConfiguration.java
|
22
|
|
- * 实时导数据类
|
|
22
|
+ * 实时导数据类
|
|
23
|
+ *
|
23
|
24
|
* @author lloyd
|
24
|
25
|
* @version 1.0
|
25
|
26
|
* @since 2021/4/14 下午3:16
|
26
|
27
|
*/
|
27
|
|
-//@Configuration
|
28
|
|
-public class CamelJDBCCofRealTimeConfiguration {
|
|
28
|
+@Configuration
|
|
29
|
+public class CamelJDBCCofRealTimeConfiguration {
|
29
|
30
|
|
30
|
|
- private static long sendMsgRunTime=0;
|
|
31
|
+ private static long sendMsgRunTime = 0;
|
31
|
32
|
|
32
|
|
- public Double min(String[] strings){
|
|
33
|
+ public Double min(String[] strings) {
|
33
|
34
|
double[] doubles = new double[strings.length];
|
34
|
35
|
for (int i = 0; i < strings.length; i++) {
|
35
|
36
|
doubles[i] = Double.parseDouble(strings[i]);
|
36
|
37
|
}
|
37
|
38
|
OptionalDouble min = Arrays.stream(doubles).min();
|
38
|
|
- return min.isPresent()? min.getAsDouble() : null;
|
|
39
|
+ return min.isPresent() ? min.getAsDouble() : null;
|
39
|
40
|
}
|
|
41
|
+
|
40
|
42
|
//获取最大载荷
|
41
|
|
- public Double max(String[] strings){
|
|
43
|
+ public Double max(String[] strings) {
|
42
|
44
|
double[] doubles = new double[strings.length];
|
43
|
45
|
for (int i = 0; i < strings.length; i++) {
|
44
|
46
|
doubles[i] = Double.parseDouble(strings[i]);
|
|
@@ -48,16 +50,16 @@ public class CamelJDBCCofRealTimeConfiguration {
|
48
|
50
|
}
|
49
|
51
|
|
50
|
52
|
|
51
|
|
- public String getDate(){
|
52
|
|
- return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
53
|
+ public String getDate() {
|
|
54
|
+ return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
53
|
55
|
}
|
54
|
56
|
|
55
|
57
|
|
56
|
58
|
/***
|
57
|
59
|
* 异步发送 RunTime 消息到MQ中
|
58
|
60
|
* */
|
59
|
|
- // @Async
|
60
|
|
- public void sendDataToRocketMQ(String wellName, String wellId, String prodDate, Double stroke_length , Double stroke_frequency, String sgt){
|
|
61
|
+ // @Async
|
|
62
|
+ public void sendDataToRocketMQ(String wellName, String wellId, String prodDate, Double stroke_length, Double stroke_frequency, String sgt) {
|
61
|
63
|
String orgId = "0";
|
62
|
64
|
DiagnoseMsg diagnoseMsg = new DiagnoseMsg(wellId, wellName, orgId, prodDate, sgt, LocalDateTime.now().toString(), stroke_length, stroke_frequency);
|
63
|
65
|
sendMsgRunTime++;
|
|
@@ -66,6 +68,7 @@ public class CamelJDBCCofRealTimeConfiguration {
|
66
|
68
|
|
67
|
69
|
@Resource(name = "diagnoseMessageProducer")
|
68
|
70
|
private MessageProducer producer;
|
|
71
|
+
|
69
|
72
|
@Bean
|
70
|
73
|
public RouteBuilder routeBuilderWithRealTime() {
|
71
|
74
|
return new RouteBuilder() {
|
|
@@ -77,86 +80,87 @@ public class CamelJDBCCofRealTimeConfiguration {
|
77
|
80
|
.to("jdbc:centralbase")
|
78
|
81
|
.split(body()).process(exchange -> {
|
79
|
82
|
HashMap body = exchange.getIn().getBody(HashMap.class);
|
80
|
|
- exchange.getIn().setHeader("well_id",body.get("well_id"));
|
81
|
|
- exchange.getIn().setHeader("sgt_last_time",body.get("sgt_last_time"));
|
|
83
|
+ exchange.getIn().setHeader("well_id", body.get("well_id"));
|
|
84
|
+ exchange.getIn().setHeader("sgt_last_time", body.get("sgt_last_time"));
|
82
|
85
|
})
|
83
|
|
- .setBody(simple("select distinct well_name,dyna_create_time,check_date,displacement,disp_load,stroke,frequency,susp_max_load,susp_min_load from public.pc_fd_pumpjack_dyna_dia_t where well_name='${header.well_id}' and dyna_create_time >= '${header.sgt_last_time}' limit 50 "))
|
|
86
|
+ .setBody(simple("select distinct well_name,dyna_create_time,check_date,displacement,disp_load,stroke,frequency,susp_max_load,susp_min_load" +
|
|
87
|
+ " from DEFAULT_GONGTU where well_name='${header.well_id}' and dyna_create_time >= '${header.sgt_last_time}' limit 50 "))
|
84
|
88
|
.to("jdbc:oracle")
|
85
|
89
|
.process(exchange -> {
|
86
|
90
|
sendMsgRunTime = 0;
|
87
|
91
|
})
|
88
|
92
|
.split(body()).process(exchange -> {
|
89
|
|
- Message in = exchange.getIn();
|
90
|
|
- HashMap<String, Object> aRow = in.getBody(HashMap.class);
|
91
|
|
- String prod_date = aRow.get("dyna_create_time").toString().split("\\+")[0];
|
92
|
|
- aRow.put("dyna_create_time", prod_date);
|
93
|
|
- aRow.put("sgt", "");
|
94
|
|
- if (!StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))) {
|
95
|
|
- String[] displacements = aRow.get("displacement").toString().split(";");//10 四舍五入
|
96
|
|
- String[] disp_loads = aRow.get("disp_load").toString().split(";");
|
97
|
|
- Double susp_max_load = max(disp_loads);
|
98
|
|
- Double susp_min_load = min(disp_loads);
|
99
|
|
- String sgt = "";
|
100
|
|
- for (int i = 0; i < displacements.length; i++) {
|
101
|
|
- sgt = sgt + displacements[i] + "," + disp_loads[i] + ",";
|
102
|
|
- }
|
103
|
|
- String[] s = sgt.split(",");
|
104
|
|
- String w = "";
|
105
|
|
- for (int i = 0; i < s.length; i++) {
|
106
|
|
- w += new BigDecimal(Math.round(Double.parseDouble(s[i]) * 100)).stripTrailingZeros().toPlainString() + ",";
|
107
|
|
- }
|
108
|
|
- Double[][] doubles = SGTUtil.encodeToDoubleArray(w);
|
109
|
|
- aRow.put("sgt", SGTUtil.encodeToString(doubles));
|
110
|
|
- aRow.put("susp_max_load",susp_max_load);
|
111
|
|
- aRow.put("susp_min_load",susp_min_load);
|
112
|
|
- }
|
113
|
|
- //对于位移没有数据,所有数据都在载荷中的特殊数据做特别处理
|
114
|
|
- if (StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))){
|
115
|
|
- String disp_load = aRow.get("disp_load").toString().replaceAll(";", ",");
|
116
|
|
- Double[][] doubles = SGTUtil.encodeToDoubleArray(disp_load);
|
117
|
|
- aRow.put("sgt", SGTUtil.encodeToString(doubles));
|
118
|
|
- String[] split = disp_load.split(",");
|
119
|
|
- List<String> list = new ArrayList<>();
|
120
|
|
- for (int i = 0; i < split.length; i++) {
|
121
|
|
- if (i%2 != 0){
|
122
|
|
- BigDecimal bigDecimal = new BigDecimal(split[i]).divide(new BigDecimal("100.0"));
|
123
|
|
- list.add(bigDecimal.toString());
|
|
93
|
+ Message in = exchange.getIn();
|
|
94
|
+ HashMap<String, Object> aRow = in.getBody(HashMap.class);
|
|
95
|
+ String prod_date = aRow.get("dyna_create_time").toString().split("\\+")[0];
|
|
96
|
+ aRow.put("dyna_create_time", prod_date);
|
|
97
|
+ aRow.put("sgt", "");
|
|
98
|
+ if (!StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))) {
|
|
99
|
+ String[] displacements = aRow.get("displacement").toString().split(";");//10 四舍五入
|
|
100
|
+ String[] disp_loads = aRow.get("disp_load").toString().split(";");
|
|
101
|
+ Double susp_max_load = max(disp_loads);
|
|
102
|
+ Double susp_min_load = min(disp_loads);
|
|
103
|
+ String sgt = "";
|
|
104
|
+ for (int i = 0; i < displacements.length; i++) {
|
|
105
|
+ sgt = sgt + displacements[i] + "," + disp_loads[i] + ",";
|
|
106
|
+ }
|
|
107
|
+ String[] s = sgt.split(",");
|
|
108
|
+ String w = "";
|
|
109
|
+ for (int i = 0; i < s.length; i++) {
|
|
110
|
+ w += new BigDecimal(Math.round(Double.parseDouble(s[i]) * 100)).stripTrailingZeros().toPlainString() + ",";
|
|
111
|
+ }
|
|
112
|
+ Double[][] doubles = SGTUtil.encodeToDoubleArray(w);
|
|
113
|
+ aRow.put("sgt", SGTUtil.encodeToString(doubles));
|
|
114
|
+ aRow.put("susp_max_load", susp_max_load);
|
|
115
|
+ aRow.put("susp_min_load", susp_min_load);
|
124
|
116
|
}
|
125
|
|
- }
|
126
|
|
- String[] loads = list.toArray(new String[0]);
|
127
|
|
- Double susp_max_load =null;
|
128
|
|
- Double susp_min_load =null;
|
129
|
|
- if (loads.length>0 ) {
|
130
|
|
- susp_max_load = max(loads);
|
131
|
|
- susp_min_load = min(loads);
|
132
|
|
- }
|
133
|
|
- aRow.put("susp_max_load",susp_max_load);
|
134
|
|
- aRow.put("susp_min_load",susp_min_load);
|
135
|
|
- }
|
136
|
|
- aRow.putIfAbsent("stroke", "0.0");
|
137
|
|
- aRow.putIfAbsent("frequency", "0.0");
|
138
|
|
- aRow.putIfAbsent("susp_max_load", "0.0");
|
139
|
|
- aRow.putIfAbsent("susp_min_load", "0.0");
|
140
|
|
- if (!StringUtils.isEmpty(aRow.get("frequency"))){
|
141
|
|
- BigDecimal bd=new BigDecimal(aRow.get("frequency").toString());
|
142
|
|
- double frequency=bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
|
143
|
|
- aRow.put("frequency",frequency);
|
144
|
|
- }
|
145
|
|
- if (!StringUtils.isEmpty(aRow.get("stroke"))){
|
146
|
|
- double stroke1 = Double.parseDouble(aRow.get("stroke").toString());
|
147
|
|
- BigDecimal bd=new BigDecimal(stroke1);
|
148
|
|
- double stroke=bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
|
149
|
|
- aRow.put("stroke",stroke);
|
150
|
|
- }
|
151
|
|
- String wellName =aRow.get("well_name").toString();
|
152
|
|
- String wellId =aRow.get("well_name").toString();
|
153
|
|
- String prodDate = aRow.get("dyna_create_time").toString().substring(0,19);
|
|
117
|
+ //对于位移没有数据,所有数据都在载荷中的特殊数据做特别处理
|
|
118
|
+ if (StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))) {
|
|
119
|
+ String disp_load = aRow.get("disp_load").toString().replaceAll(";", ",");
|
|
120
|
+ Double[][] doubles = SGTUtil.encodeToDoubleArray(disp_load);
|
|
121
|
+ aRow.put("sgt", SGTUtil.encodeToString(doubles));
|
|
122
|
+ String[] split = disp_load.split(",");
|
|
123
|
+ List<String> list = new ArrayList<>();
|
|
124
|
+ for (int i = 0; i < split.length; i++) {
|
|
125
|
+ if (i % 2 != 0) {
|
|
126
|
+ BigDecimal bigDecimal = new BigDecimal(split[i]).divide(new BigDecimal("100.0"));
|
|
127
|
+ list.add(bigDecimal.toString());
|
|
128
|
+ }
|
|
129
|
+ }
|
|
130
|
+ String[] loads = list.toArray(new String[0]);
|
|
131
|
+ Double susp_max_load = null;
|
|
132
|
+ Double susp_min_load = null;
|
|
133
|
+ if (loads.length > 0) {
|
|
134
|
+ susp_max_load = max(loads);
|
|
135
|
+ susp_min_load = min(loads);
|
|
136
|
+ }
|
|
137
|
+ aRow.put("susp_max_load", susp_max_load);
|
|
138
|
+ aRow.put("susp_min_load", susp_min_load);
|
|
139
|
+ }
|
|
140
|
+ aRow.putIfAbsent("stroke", "0.0");
|
|
141
|
+ aRow.putIfAbsent("frequency", "0.0");
|
|
142
|
+ aRow.putIfAbsent("susp_max_load", "0.0");
|
|
143
|
+ aRow.putIfAbsent("susp_min_load", "0.0");
|
|
144
|
+ if (!StringUtils.isEmpty(aRow.get("frequency"))) {
|
|
145
|
+ BigDecimal bd = new BigDecimal(aRow.get("frequency").toString());
|
|
146
|
+ double frequency = bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
|
|
147
|
+ aRow.put("frequency", frequency);
|
|
148
|
+ }
|
|
149
|
+ if (!StringUtils.isEmpty(aRow.get("stroke"))) {
|
|
150
|
+ double stroke1 = Double.parseDouble(aRow.get("stroke").toString());
|
|
151
|
+ BigDecimal bd = new BigDecimal(stroke1);
|
|
152
|
+ double stroke = bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
|
|
153
|
+ aRow.put("stroke", stroke);
|
|
154
|
+ }
|
|
155
|
+ String wellName = aRow.get("well_name").toString();
|
|
156
|
+ String wellId = aRow.get("well_name").toString();
|
|
157
|
+ String prodDate = aRow.get("dyna_create_time").toString().substring(0, 19);
|
154
|
158
|
Double strokeLength = Double.valueOf(aRow.get("stroke").toString());
|
155
|
159
|
Double strokeFrequency = Double.valueOf(aRow.get("frequency").toString());
|
156
|
160
|
String sgt = aRow.get("sgt").toString();
|
157
|
|
- in.setHeader("sgt_last_time",prodDate);
|
158
|
|
- in.setHeader("well_id",wellId);
|
159
|
|
- sendDataToRocketMQ(wellName,wellId,prodDate,strokeLength,strokeFrequency,sgt);
|
|
161
|
+ in.setHeader("sgt_last_time", prodDate);
|
|
162
|
+ in.setHeader("well_id", wellId);
|
|
163
|
+ sendDataToRocketMQ(wellName, wellId, prodDate, strokeLength, strokeFrequency, sgt);
|
160
|
164
|
})
|
161
|
165
|
.setBody(simple("insert into centralbase.cb_temp_well_mech_runtime(well_id,prod_date,susp_max_load,susp_min_load,sgt) " +
|
162
|
166
|
"select '${body[well_name]}','${body[dyna_create_time]}','${body[susp_max_load]}','${body[susp_min_load]}','${body[sgt]}' " +
|
|
@@ -166,46 +170,46 @@ public class CamelJDBCCofRealTimeConfiguration {
|
166
|
170
|
.to("jdbc:centralbase")
|
167
|
171
|
.end();
|
168
|
172
|
|
169
|
|
- from("timer:mytimer-update-avg-mech_daily?period=10800000")
|
|
173
|
+ from("timer:mytimer-update-avg-mech_daily?period=10800000")
|
170
|
174
|
.routeId("update-avg-mech_daily")
|
171
|
|
- .process(exchange -> {
|
172
|
|
- Message in = exchange.getIn();
|
173
|
|
- in.setHeader("date",getDate());
|
174
|
|
- })
|
|
175
|
+ .process(exchange -> {
|
|
176
|
+ Message in = exchange.getIn();
|
|
177
|
+ in.setHeader("date", getDate());
|
|
178
|
+ })
|
175
|
179
|
.setBody(simple("select well_id,avg(stroke_length) stroke_length ,avg(stroke_frequency) stroke_frequency from centralbase.cb_temp_well_mech_runtime where prod_date::date='${header.date}' group by well_id"))
|
176
|
180
|
.to("jdbc:centralbase")
|
177
|
181
|
.split(body()).process(exchange -> {
|
178
|
|
- Message in = exchange.getIn();
|
179
|
|
- HashMap<String, Object> aRow = in.getBody(HashMap.class);
|
180
|
|
- if (aRow.get("stroke_length")!=null && aRow.get("stroke_frequency")!=null){
|
181
|
|
- double stroke_length=Double.parseDouble(aRow.get("stroke_length").toString());
|
182
|
|
- double stroke_frequency=Double.parseDouble(aRow.get("stroke_frequency").toString());
|
183
|
|
- BigDecimal bd=new BigDecimal(stroke_length);
|
184
|
|
- double stroke_lengt1=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
185
|
|
- BigDecimal bd1=new BigDecimal(stroke_frequency);
|
186
|
|
- double stroke_frequency1=bd1.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
187
|
|
- aRow.put("strokeLength",stroke_lengt1);
|
188
|
|
- aRow.put("strokeFrequency",stroke_frequency1);
|
189
|
|
- }
|
190
|
|
- })
|
|
182
|
+ Message in = exchange.getIn();
|
|
183
|
+ HashMap<String, Object> aRow = in.getBody(HashMap.class);
|
|
184
|
+ if (aRow.get("stroke_length") != null && aRow.get("stroke_frequency") != null) {
|
|
185
|
+ double stroke_length = Double.parseDouble(aRow.get("stroke_length").toString());
|
|
186
|
+ double stroke_frequency = Double.parseDouble(aRow.get("stroke_frequency").toString());
|
|
187
|
+ BigDecimal bd = new BigDecimal(stroke_length);
|
|
188
|
+ double stroke_lengt1 = bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
189
|
+ BigDecimal bd1 = new BigDecimal(stroke_frequency);
|
|
190
|
+ double stroke_frequency1 = bd1.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
191
|
+ aRow.put("strokeLength", stroke_lengt1);
|
|
192
|
+ aRow.put("strokeFrequency", stroke_frequency1);
|
|
193
|
+ }
|
|
194
|
+ })
|
191
|
195
|
.setBody(simple("update centralbase.cb_temp_well_mech_daily set stroke_length='${body[strokeLength]}' ,stroke_frequency ='${body[strokeFrequency]}' where well_id = '${body[well_id]}' and prod_date::date='${header.date}' "))
|
192
|
196
|
.doTry()
|
193
|
197
|
.to("jdbc:centralbase")
|
194
|
198
|
.doCatch(Exception.class)
|
195
|
|
- .log("${header.date}"+" routeId:update-avg-mech_daily -> centralbase.cb_temp_well_mech_daily update data failed")
|
|
199
|
+ .log("${header.date}" + " routeId:update-avg-mech_daily -> centralbase.cb_temp_well_mech_daily update data failed")
|
196
|
200
|
.end();
|
197
|
201
|
|
198
|
|
- from("timer:mytimer-insert-mechDaily?period=3600000")
|
|
202
|
+ /* from("timer:mytimer-insert-mechDaily?period=3600000")
|
199
|
203
|
.routeId("insert-mech_daily")
|
200
|
204
|
.process(exchange -> {
|
201
|
205
|
Message in = exchange.getIn();
|
202
|
|
- in.setHeader("date",getDate());
|
|
206
|
+ in.setHeader("date", getDate());
|
203
|
207
|
})
|
204
|
208
|
.setBody(simple("select well_id from centralbase.sys_access_well_control where access_status='1' "))
|
205
|
209
|
.to("jdbc:centralbase")
|
206
|
210
|
.split(body()).process(exchange -> {
|
207
|
211
|
HashMap body = exchange.getIn().getBody(HashMap.class);
|
208
|
|
- exchange.getIn().setHeader("well_id",body.get("well_id"));
|
|
212
|
+ exchange.getIn().setHeader("well_id", body.get("well_id"));
|
209
|
213
|
})
|
210
|
214
|
.setBody(simple("select distinct jh,rq,dym,jy,ly,bj,bs,bx,zs,cc,cs,blx,dl from DBA01 where rq = to_date('${header.date}','yyyy-MM-dd') and jh='${header.well_id}' and qyrq is not null "))
|
211
|
215
|
.to("jdbc:oracle")
|
|
@@ -229,9 +233,10 @@ public class CamelJDBCCofRealTimeConfiguration {
|
229
|
233
|
.doTry()
|
230
|
234
|
.to("jdbc:centralbase")
|
231
|
235
|
.doCatch(Exception.class)
|
232
|
|
- .log("${header.date}"+" routeId:insert-mech_daily -> centralbase.cb_temp_well_mech_daily insert data failed")
|
233
|
|
- .end();
|
234
|
|
- };
|
|
236
|
+ .log("${header.date}" + " routeId:insert-mech_daily -> centralbase.cb_temp_well_mech_daily insert data failed")
|
|
237
|
+ .end();*/
|
|
238
|
+ }
|
|
239
|
+
|
235
|
240
|
};
|
236
|
241
|
}
|
237
|
242
|
}
|