|
|
@@ -1,26 +1,21 @@
|
|
1
|
1
|
package com.gct.tools.etlcamelhuge.routeconfig;
|
|
2
|
2
|
|
|
3
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
4
|
|
-import com.gct.tools.etlcamelhuge.entity.MQDiagnoseMsg;
|
|
|
3
|
+import com.gct.tools.etlcamelhuge.MQ.MessageBody;
|
|
|
4
|
+import com.gct.tools.etlcamelhuge.MQ.MessageProducer;
|
|
|
5
|
+import com.gct.tools.etlcamelhuge.entity.DiagnoseMsg;
|
|
5
|
6
|
import org.apache.camel.*;
|
|
6
|
7
|
import org.apache.camel.builder.RouteBuilder;
|
|
7
|
|
-import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
|
8
|
8
|
//import org.apache.rocketmq.common.message.Message;
|
|
9
|
9
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
10
|
|
-import org.slf4j.Logger;
|
|
11
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
12
|
11
|
import org.springframework.context.annotation.Bean;
|
|
13
|
12
|
import org.springframework.context.annotation.Configuration;
|
|
14
|
|
-import org.springframework.http.HttpEntity;
|
|
15
|
|
-import org.springframework.http.HttpHeaders;
|
|
16
|
|
-import org.springframework.http.MediaType;
|
|
17
|
|
-import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
|
|
18
|
13
|
|
|
|
14
|
+import javax.annotation.Resource;
|
|
19
|
15
|
import java.math.BigDecimal;
|
|
20
|
|
-import java.nio.charset.StandardCharsets;
|
|
21
|
16
|
import java.text.SimpleDateFormat;
|
|
|
17
|
+import java.time.LocalDateTime;
|
|
22
|
18
|
import java.util.*;
|
|
23
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
24
|
19
|
|
|
25
|
20
|
/**
|
|
26
|
21
|
* class name: CamelJDBCConfiguration
|
|
|
@@ -271,6 +266,8 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
271
|
266
|
}
|
|
272
|
267
|
return Arrays.stream(doubles).max().getAsDouble();
|
|
273
|
268
|
}
|
|
|
269
|
+ @Resource(name = "diagnoseMessageProducer")
|
|
|
270
|
+ private MessageProducer producer;
|
|
274
|
271
|
@Bean
|
|
275
|
272
|
public RouteBuilder routeBuilderWithOracle1() {
|
|
276
|
273
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
@@ -285,9 +282,9 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
285
|
282
|
//全部执行完成的大概时间在30-40分钟
|
|
286
|
283
|
@Override
|
|
287
|
284
|
public void configure() throws Exception {
|
|
288
|
|
- //0 0 18 * * ? 每天下午6点执行一次
|
|
|
285
|
+ //24小时执行一次
|
|
289
|
286
|
//单个执行时间30s左右,在之前有数据的情况下
|
|
290
|
|
- from("timer:mytimer1?period=99999999999")
|
|
|
287
|
+ from("timer:mytimer1?period=604800000")
|
|
291
|
288
|
.routeId("oracle-1")
|
|
292
|
289
|
.setHeader("date", constant(date1))
|
|
293
|
290
|
.setBody(simple("select distinct jh,cydmc,zyq,zk,qyrq,sccw,qk,bz from zd_zdgs.dba01@A2 where rq = to_date('${header.date}','yyyy-MM-dd') and qyrq is not null "))
|
|
|
@@ -372,7 +369,7 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
372
|
369
|
.log("insert")
|
|
373
|
370
|
.end();
|
|
374
|
371
|
//单独执行时间10s
|
|
375
|
|
- from("timer:mytimer2?period=99999999999")
|
|
|
372
|
+ from("timer:mytimer2?period=3600000")
|
|
376
|
373
|
.routeId("oracle-2")
|
|
377
|
374
|
.setHeader("date", constant(date1))
|
|
378
|
375
|
.setBody(simple("select distinct jh,rq,cyfs,yz,hysx , yysx ,tysx,bs,dym from zd_zdgs.dba01@A2 where rq = to_date('${header.date}','yyyy-MM-dd') and qyrq is not null "))
|
|
|
@@ -396,7 +393,7 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
396
|
393
|
//将查询到的DYM数据更新到cb_pc_pro_wellbore_status_daily中
|
|
397
|
394
|
//0 0 */1 * * ? 每1个小时执行一次
|
|
398
|
395
|
//单独执行时间是4m15s 317条数据
|
|
399
|
|
- from("timer:mytimer5?period=99999999999")
|
|
|
396
|
+ from("timer:mytimer5?period=3600000")
|
|
400
|
397
|
.routeId("oracle-5")
|
|
401
|
398
|
.setHeader("date", constant(date1 + " 00:00:00"))
|
|
402
|
399
|
//三个月之内dym不为空的数据
|
|
|
@@ -409,7 +406,7 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
409
|
406
|
.log("insert !!!")
|
|
410
|
407
|
.end();
|
|
411
|
408
|
//单独执行时间30s
|
|
412
|
|
- from("timer:mytimer3?period=99999999999")
|
|
|
409
|
+ from("timer:mytimer3?period=3600000")
|
|
413
|
410
|
.routeId("oracle-3")
|
|
414
|
411
|
.setHeader("date", constant(date1))
|
|
415
|
412
|
.setBody(simple("select distinct jh,rq,scsj, rcyl1,rcyl,rcql,hs, bz from zd_zdgs.dba01@A2 where rq = to_date('${header.date}','yyyy-MM-dd') and qyrq is not null "))
|
|
|
@@ -432,7 +429,7 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
432
|
429
|
|
|
433
|
430
|
//0 0 */1 * * ? 每1个小时执行一次
|
|
434
|
431
|
//单独执行一次30s
|
|
435
|
|
- from("timer:mytimer4?period=99999999999")
|
|
|
432
|
+ from("timer:mytimer4?period=3600000")
|
|
436
|
433
|
.routeId("oracle-4")
|
|
437
|
434
|
.setHeader("date", constant(date1))
|
|
438
|
435
|
.setBody(simple("select distinct jh,rq,dym,jy,ly,bj,bs,bx,zs,cc,cs,blx,dl from zd_zdgs.dba01@A2 where rq = to_date('${header.date}','yyyy-MM-dd') and qyrq is not null "))
|
|
|
@@ -460,7 +457,7 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
460
|
457
|
//从天安哪里获取的数据
|
|
461
|
458
|
//0 0 */1 * * ? 每1个小时执行一次
|
|
462
|
459
|
//单独执行一小时的数据30s
|
|
463
|
|
- from("timer:mytimer7?period=99999999999")
|
|
|
460
|
+ /* from("timer:mytimer7?period=3600000")
|
|
464
|
461
|
.routeId("jdbc-gtsj-?")
|
|
465
|
462
|
.setBody(simple("select max(prod_date) from centralbase.cb_temp_well_mech_runtime "))
|
|
466
|
463
|
.to("jdbc:centralbase")
|
|
|
@@ -501,9 +498,29 @@ public class CamelJDBCConfiguration /*extends RouteBuilder */ {
|
|
501
|
498
|
.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) " +
|
|
502
|
499
|
"values ('${body[well_name]}','${body[dyna_create_time]}','${body[stroke]}','${body[frequency]}','${body[susp_max_load]}','${body[susp_min_load]}','${body[sgt]}')"))
|
|
503
|
500
|
.to("jdbc:centralbase")
|
|
504
|
|
- .log("insert!!!").end();
|
|
|
501
|
+ .log("insert!!!").end();*/
|
|
|
502
|
+
|
|
|
503
|
+ from("timer:mytimer1?period=3600000")
|
|
|
504
|
+ .routeId("centralbase-1")
|
|
|
505
|
+ .setBody(simple("select so.well_id,so.well_common_name,so.org_id,ti.prod_date,ti.stroke_frequency,ti.stroke_length,ti.sgt from centralbase.cb_temp_well_mech_runtime ti, centralbase.cb_cd_well_source so where ti.well_id = so.well_id and ti.prod_date =(select max(prod_date) from centralbase.cb_temp_well_mech_runtime) "))
|
|
|
506
|
+ .to("jdbc:centralbase")
|
|
|
507
|
+ .split(body()).log("log{body}")
|
|
|
508
|
+ .process(exchange -> {
|
|
|
509
|
+ Message in = exchange.getIn();
|
|
|
510
|
+ HashMap<String, Object> aRow = in.getBody(HashMap.class);
|
|
|
511
|
+ String wellName =aRow.get("well_common_name").toString();
|
|
|
512
|
+ String wellId =aRow.get("well_id").toString();
|
|
|
513
|
+ String orgId = aRow.get("org_id").toString();
|
|
|
514
|
+ String prodDate = aRow.get("prod_date").toString().substring(0,19);
|
|
|
515
|
+ Double strokeLength = Double.valueOf(aRow.get("stroke_length").toString());
|
|
|
516
|
+ Double strokeFrequency = Double.valueOf(aRow.get("stroke_frequency").toString());
|
|
|
517
|
+ System.out.println("strokeFrequency"+strokeFrequency);
|
|
|
518
|
+ String sgt = aRow.get("sgt").toString();
|
|
|
519
|
+ DiagnoseMsg diagnoseMsg = new DiagnoseMsg(wellId, wellName, orgId, prodDate, sgt, LocalDateTime.now().toString(), strokeLength, strokeFrequency);
|
|
|
520
|
+ producer.send((MessageBody) diagnoseMsg);
|
|
|
521
|
+ }).log("send success").end();
|
|
505
|
522
|
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
506
|
|
- /* from("timer:mytimer2?period=999999999")
|
|
|
523
|
+ /* from("timer:mytimer2?period=3600000")
|
|
507
|
524
|
.routeId("oracle-2")
|
|
508
|
525
|
.setBody(simple("select distinct station_id,station_name from centralbase.cb_cd_well_source"))
|
|
509
|
526
|
.to("jdbc:centralbase")
|