|
@@ -1,7 +1,6 @@
|
1
|
1
|
package com.gct.tools.etlcamelhuge.routeconfig;
|
2
|
2
|
|
3
|
3
|
|
4
|
|
-import com.alibaba.fastjson.JSONArray;
|
5
|
4
|
import com.alibaba.fastjson.JSONObject;
|
6
|
5
|
import com.gct.common.util.SGTUtil;
|
7
|
6
|
import com.gct.tools.etlcamelhuge.entity.ZDJG_WELL;
|
|
@@ -10,8 +9,6 @@ import com.gct.tools.etlcamelhuge.util.TransUtil;
|
10
|
9
|
import org.apache.camel.Message;
|
11
|
10
|
import org.apache.camel.builder.RouteBuilder;
|
12
|
11
|
import org.apache.camel.model.dataformat.JsonLibrary;
|
13
|
|
-import org.apache.commons.lang3.ArrayUtils;
|
14
|
|
-import org.eclipse.jetty.util.ArrayUtil;
|
15
|
12
|
import org.springframework.context.annotation.Configuration;
|
16
|
13
|
|
17
|
14
|
import java.io.*;
|
|
@@ -20,13 +17,10 @@ import java.net.HttpURLConnection;
|
20
|
17
|
import java.net.URL;
|
21
|
18
|
import java.net.URLEncoder;
|
22
|
19
|
import java.text.SimpleDateFormat;
|
23
|
|
-import java.time.LocalDateTime;
|
24
|
|
-import java.time.format.DateTimeFormatter;
|
25
|
20
|
import java.util.ArrayList;
|
26
|
21
|
import java.util.Date;
|
27
|
22
|
import java.util.HashMap;
|
28
|
23
|
import java.util.List;
|
29
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
30
|
24
|
|
31
|
25
|
|
32
|
26
|
@Configuration
|
|
@@ -72,6 +66,60 @@ public class CamelRestConfiguration extends RouteBuilder {
|
72
|
66
|
return date;
|
73
|
67
|
}
|
74
|
68
|
|
|
69
|
+ public String loadPhdDate( String well_id) throws Exception {
|
|
70
|
+ URL restURL = new URL("http://11.72.128.71/api-service/tsdb/getLast?appKey=SR5vY4bED7");
|
|
71
|
+
|
|
72
|
+ //此处的urlConnection对象实际上是根据URL的请求协议(此处是http) 生成的URLConnection类 的子类HttpURLConnection
|
|
73
|
+ HttpURLConnection conn = (HttpURLConnection) restURL.openConnection();
|
|
74
|
+
|
|
75
|
+ //请求方式
|
|
76
|
+ conn.setRequestMethod("POST");
|
|
77
|
+
|
|
78
|
+ //设置是否从httpUrlConnection读入,默认情况下是true; httpUrlConnection.setDoInput(true);
|
|
79
|
+ conn.setDoOutput(true);
|
|
80
|
+
|
|
81
|
+ //allowUserInteraction 如果为 true,则在允许用户交互(例如弹出一个验证对话框)的上下文中对此 URL 进行检查。
|
|
82
|
+ conn.setAllowUserInteraction(false);
|
|
83
|
+ DataOutputStream out = new DataOutputStream(conn
|
|
84
|
+ .getOutputStream());
|
|
85
|
+ String content = "id="+URLEncoder.encode(well_id+"/upData/电流平衡率", "UTF-8");
|
|
86
|
+ out.writeBytes(content);
|
|
87
|
+ out.flush();
|
|
88
|
+ out.close();
|
|
89
|
+ PrintStream ps = new PrintStream(conn.getOutputStream());
|
|
90
|
+
|
|
91
|
+ ps.close();
|
|
92
|
+
|
|
93
|
+ InputStream is = null;
|
|
94
|
+ if (conn.getResponseCode() == 200) {
|
|
95
|
+ is = conn.getInputStream();
|
|
96
|
+ } else {
|
|
97
|
+ is = conn.getErrorStream();
|
|
98
|
+ }
|
|
99
|
+ BufferedReader bReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
|
100
|
+ List<String> list = new ArrayList<>();
|
|
101
|
+
|
|
102
|
+ String line, resultStr = "";
|
|
103
|
+ while (null != (line = bReader.readLine())) {
|
|
104
|
+ resultStr += line;
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ String value = "";
|
|
108
|
+ JSONObject json = null;
|
|
109
|
+ try {
|
|
110
|
+ json = JSONObject.parseObject(resultStr);
|
|
111
|
+
|
|
112
|
+ if (json.size() > 0) {
|
|
113
|
+ value = json.get("value").toString();
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ } catch (Exception e) {
|
|
117
|
+ System.out.println(resultStr);
|
|
118
|
+ }
|
|
119
|
+// System.out.println(value);
|
|
120
|
+ return value;
|
|
121
|
+ }
|
|
122
|
+
|
75
|
123
|
|
76
|
124
|
public ZDJG_WELL loadGtData(String param, String well_id, String sysDate) throws Exception {
|
77
|
125
|
// String date = getDate();
|
|
@@ -175,7 +223,7 @@ public class CamelRestConfiguration extends RouteBuilder {
|
175
|
223
|
@Override
|
176
|
224
|
public synchronized void configure() throws Exception {
|
177
|
225
|
|
178
|
|
- /*JSONObject body = new JSONObject();
|
|
226
|
+ JSONObject body = new JSONObject();
|
179
|
227
|
|
180
|
228
|
restConfiguration()
|
181
|
229
|
.component("servlet")
|
|
@@ -203,6 +251,7 @@ public class CamelRestConfiguration extends RouteBuilder {
|
203
|
251
|
// in.setHeader("id",aRow.get("id")+"/analyse/功图数据");
|
204
|
252
|
// in.setHeader("wellid",aRow.get("code"));
|
205
|
253
|
if (aRow.get("typeName").toString().indexOf("油井")> 0){
|
|
254
|
+ Double phd = "".equals(loadPhdDate(aRow.get("id").toString())) ? 0 : Double.valueOf(loadPhdDate(aRow.get("id").toString()) );
|
206
|
255
|
ZDJG_WELL zdjg_well = loadGtData(aRow.get("id")+"/analyse/功图数据", aRow.get("code").toString(), "2021-08-17");
|
207
|
256
|
aRow.put("sgt",gtTransUtil(zdjg_well.getZd_init_sgt()) );//null
|
208
|
257
|
aRow.put("susp_max_load",zdjg_well.getSxzh());//最大载荷
|
|
@@ -211,18 +260,19 @@ public class CamelRestConfiguration extends RouteBuilder {
|
211
|
260
|
aRow.put("frequency",zdjg_well.getFrequence());
|
212
|
261
|
aRow.put("dyna_create_time",zdjg_well.getProd_date());
|
213
|
262
|
aRow.put("well_name",aRow.get("code"));
|
|
263
|
+ aRow.put("phd",phd== null ? 0: phd);
|
214
|
264
|
}
|
215
|
265
|
|
216
|
266
|
|
217
|
267
|
})
|
218
|
|
- .log("${in.header.date}")
|
|
268
|
+// .log("${body[phd]}"+ "sql" + "${body[well_name]}")
|
219
|
269
|
.doTry()
|
220
|
|
- .setBody(simple("insert into centralbase.cb_temp_well_mech_runtime(well_id,prod_date,stroke_length,stroke_frequency,susp_max_load,susp_min_load,sgt) " +
|
221
|
|
- "values( '${body[well_name]}','${in.header.date}','${body[stroke]}','${body[frequency]}','${body[susp_max_load]}','${body[susp_min_load]}','${body[sgt]}') " ))
|
|
270
|
+ .setBody(simple("insert into centralbase.cb_temp_well_mech_runtime(well_id,prod_date,stroke_length,stroke_frequency,susp_max_load,susp_min_load,sgt,elec_pump_current_b) " +
|
|
271
|
+ "values( '${body[well_name]}','${in.header.date}','${body[stroke]}','${body[frequency]}','${body[susp_max_load]}','${body[susp_min_load]}','${body[sgt]}','${body[phd]}') " ))
|
222
|
272
|
// "where NOT EXISTS (SELECT * FROM centralbase.cb_temp_well_mech_runtime WHERE well_id = '${body[well_name]}' and prod_date = '${in.header.date}' )"))
|
223
|
273
|
.to("jdbc:centralbase")
|
224
|
274
|
.doCatch(Exception.class)
|
225
|
|
- .end();*/
|
|
275
|
+ .end();
|
226
|
276
|
|
227
|
277
|
/* JSONArray jsonArray = new JSONArray();
|
228
|
278
|
JSONObject search = new JSONObject();
|