浏览代码

new gt load

xsr 11 月之前
父节点
当前提交
54b64ffc97
共有 1 个文件被更改,包括 111 次插入17 次删除
  1. 111 17
      src/main/java/com/gct/tools/etlcamelhuge/routeconfig/CamelRestConfiguration.java

+ 111 - 17
src/main/java/com/gct/tools/etlcamelhuge/routeconfig/CamelRestConfiguration.java

@@ -1,6 +1,7 @@
1 1
 package com.gct.tools.etlcamelhuge.routeconfig;
2 2
 
3 3
 
4
+import com.alibaba.fastjson.JSONArray;
4 5
 import com.alibaba.fastjson.JSONObject;
5 6
 import com.gct.common.util.SGTUtil;
6 7
 import com.gct.tools.etlcamelhuge.entity.ZDJG_WELL;
@@ -121,6 +122,99 @@ public class CamelRestConfiguration extends RouteBuilder {
121 122
     }
122 123
 
123 124
 
125
+    public ZDJG_WELL loadGtDataNew(String param, String well_id, String sysDate) throws Exception {
126
+//        String date = getDate();
127
+
128
+        URL restURL = new URL("http://11.72.128.71/script/gt?userId=x8ZXIR9SGT&names="+well_id);
129
+
130
+        //此处的urlConnection对象实际上是根据URL的请求协议(此处是http) 生成的URLConnection类 的子类HttpURLConnection
131
+        HttpURLConnection conn = (HttpURLConnection) restURL.openConnection();
132
+
133
+        //请求方式
134
+        conn.setRequestMethod("GET");
135
+
136
+        //设置是否从httpUrlConnection读入,默认情况下是true; httpUrlConnection.setDoInput(true);
137
+        conn.setDoOutput(false);
138
+        conn.setDoInput(true);
139
+
140
+        //allowUserInteraction 如果为 true,则在允许用户交互(例如弹出一个验证对话框)的上下文中对此 URL 进行检查。
141
+        conn.setAllowUserInteraction(false);
142
+
143
+        InputStream is = null;
144
+        if (conn.getResponseCode() == 200){
145
+            is = conn.getInputStream();
146
+        }else {
147
+            is= conn.getErrorStream();
148
+        }
149
+        BufferedReader bReader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
150
+        String line, resultStr = "";
151
+        while (null != (line = bReader.readLine())) {
152
+            resultStr += line;
153
+        }
154
+
155
+        ZDJG_WELL z = new ZDJG_WELL();
156
+        JSONObject json = null;
157
+        try {
158
+            json = JSONArray.parseArray(resultStr).getJSONObject(0);
159
+
160
+            if(json.size()>0){
161
+                String value = json.get("data").toString();
162
+                String time = json.get("time").toString();
163
+                time= time.replace("Z", " UTC"); //2019-06-27T16:00:00.000 UTC
164
+                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");//转换时区格式
165
+                Date cjDate = format1 .parse(time) ;
166
+                SimpleDateFormat fomat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
167
+                SimpleDateFormat fomat3 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
168
+                String mydate = fomat2.format(cjDate);
169
+                JSONObject json2= JSONObject.parseObject(value);
170
+                String bool = json2.getString("state").toString();
171
+                z.setIs_device_close(bool.equals("true")? "在线": "不在线");
172
+                z.setIs_well_close("关井");
173
+                if (!bool.equals("false")){
174
+                    String data = json2.get("data").toString();
175
+                    JSONObject jsonObject = JSONObject.parseObject(data);
176
+//                    String offset = jsonObject.getString("offset");
177
+                    String jh = well_id.replace(" ", "");
178
+                    z.setWell_common_name(jh);
179
+                    String gtsj = TransUtil.tranSGT(jsonObject.getString("offset"),jsonObject.getString("load"));
180
+                    Date timeRtu = null;
181
+                    String  rtutime = jsonObject.getString("time");
182
+                    timeRtu = fomat3.parse("0000-00-00 00:".equals(rtutime)? "2021-04-10 10:10": rtutime);
183
+                    Date yunpingtai = fomat2.parse(mydate);
184
+                    long time1 = timeRtu.getTime();
185
+                    long time2 = yunpingtai.getTime();
186
+                    Date date = new Date();
187
+                    long time3 = date.getTime();
188
+                    int hours1 = (int) ((time3 - time2) / (1000 * 60 * 60));
189
+                    int hours = (int) ((time2 - time1) / (1000 * 60 * 60));
190
+                    //云平台和采集时间相差要小于4小时
191
+                    if (hours <4 && !"".equals(gtsj) && hours1< 4 ){
192
+                        z.setZd_init_sgt(gtsj);//位移载荷点
193
+//                        z.setProd_date(mydate);
194
+//                        z.setSys_date(sysDate);
195
+//                        z.setIs_well_close(Double.valueOf(jsonObject.getString("minCurrent")) > 0 ? "开井": "关井");
196
+//                        z.setPressure(0);
197
+                        if (jsonObject.getString("strokeFrequency") != null){
198
+                            z.setStroke(CALUtil.round((Double.valueOf(jsonObject.getString("strokeFrequency"))) * 100) / 100);//冲程,但GTSB_2的冲程是CC字段
199
+                        }
200
+                        if (jsonObject.getString("stroke") != null){
201
+                            z.setFrequence(CALUtil.round((Double.valueOf(jsonObject.getString("stroke"))) * 100) / 100);//冲次,但GTSB_2的冲次是PJXC字段
202
+                        }
203
+                        z.setSxzh(Double.parseDouble(jsonObject.getString("maxLoad")));//最大载荷
204
+                        z.setXxzh(Double.parseDouble(jsonObject.getString("minLoad")));//最小载荷
205
+                        z.setWell_common_name(well_id);
206
+                    }
207
+                }
208
+            }
209
+        }catch (Exception e){
210
+            e.printStackTrace();
211
+        }
212
+        bReader.close();
213
+        is.close();
214
+        return z;
215
+    }
216
+
217
+    @Deprecated
124 218
     public ZDJG_WELL loadGtData(String param, String well_id, String sysDate) throws Exception {
125 219
 //        String date = getDate();
126 220
 
@@ -223,31 +317,31 @@ public class CamelRestConfiguration extends RouteBuilder {
223 317
     @Override
224 318
     public synchronized void configure() throws Exception {
225 319
 
226
-        JSONObject body = new JSONObject();
227
-
228 320
           restConfiguration()
229 321
                 .component("servlet")
230 322
                 .host("11.72.128.71");
231 323
         from("timer:mytimer?period=3600000")
232
-                .setBody(simple(body.toJSONString()))
233
-                .to("rest:post:/api-service/device/query?appKey=MOsEWVl8S0&type=simple&pageSize=8000&page=1")
234
-                .unmarshal().json(JsonLibrary.Jackson)
235
-                .split(body()).process(
236
-                exchange -> {
237
-                    Message in = exchange.getIn();
238
-                    HashMap<String, Object> aRow = in.getBody(HashMap.class);
239
-                    in.setHeader("id",aRow.get("data"));
240
-                    in.setHeader("date", getDate());
241
-                })
242
-
243
-                .setBody(simple("${in.header.id}"))
324
+                .setBody(simple("select  *  from centralbase.cb_cd_well_source"))
325
+                .to("jdbc:centralbase")
326
+//                .to("rest:post:/api-service/device/query?appKey=MOsEWVl8S0&type=simple&pageSize=8000&page=1")
327
+//                .unmarshal().json(JsonLibrary.Jackson)
328
+//                .split(body()).process(
329
+//                exchange -> {
330
+//                    Message in = exchange.getIn();
331
+//                    HashMap<String, Object> aRow = in.getBody(HashMap.class);
332
+//                    in.setHeader("id",aRow.get("data"));
333
+//                    in.setHeader("date", getDate());
334
+//                })
335
+//
336
+//                .setBody(simple("${in.header.id}"))
244 337
                 .split(body()).process(
245 338
                 exchange -> {
246 339
                     Message in = exchange.getIn();
247 340
                     HashMap<String, Object> aRow = in.getBody(HashMap.class);
248 341
                     if (aRow.get("typeName").toString().indexOf("油井")> 0){
249
-                        Double phd = "".equals(loadPhdDate(aRow.get("id").toString())) ?  0 : Double.valueOf(loadPhdDate(aRow.get("id").toString()) );
250
-                        ZDJG_WELL zdjg_well = loadGtData(aRow.get("id")+"/analyse/功图数据", aRow.get("code").toString(), "2021-08-17");
342
+//                        Double phd = "".equals(loadPhdDate(aRow.get("id").toString())) ?  0 : Double.valueOf(loadPhdDate(aRow.get("id").toString()) );
343
+//                        ZDJG_WELL zdjg_well = loadGtDataNew(aRow.get("id")+"/analyse/功图数据", aRow.get("code").toString(), "2021-08-17");
344
+                        ZDJG_WELL zdjg_well = loadGtDataNew("", aRow.get("well_id").toString(), "");
251 345
                         aRow.put("sgt",zdjg_well.getZd_init_sgt() );//null
252 346
                         aRow.put("susp_max_load",zdjg_well.getSxzh());//最大载荷
253 347
                         aRow.put("susp_min_load",zdjg_well.getXxzh());//最小载荷
@@ -255,7 +349,7 @@ public class CamelRestConfiguration extends RouteBuilder {
255 349
                         aRow.put("frequency",zdjg_well.getFrequence());
256 350
                         aRow.put("dyna_create_time",zdjg_well.getProd_date());
257 351
                         aRow.put("well_name",aRow.get("code"));
258
-                        aRow.put("phd",phd== null ? 0: phd);
352
+                        aRow.put("phd","");
259 353
                     }
260 354
                 })
261 355
 //                .log("${body[phd]}"+ "sql" + "${body[well_name]}")