gxt 3 vuotta sitten
vanhempi
commit
513ab98bf2

+ 13 - 14
src/main/java/com/gct/tools/etlcamelhuge/routeconfig/CamelJDBCCofRealTimeConfiguration.java

@@ -8,15 +8,14 @@ import org.apache.camel.Message;
8 8
 import org.apache.camel.builder.RouteBuilder;
9 9
 import org.springframework.context.annotation.Bean;
10 10
 import org.springframework.context.annotation.Configuration;
11
+import org.springframework.util.StringUtils;
11 12
 
12 13
 import javax.annotation.Resource;
13 14
 import java.math.BigDecimal;
15
+import java.math.RoundingMode;
14 16
 import java.time.LocalDateTime;
15 17
 import java.time.format.DateTimeFormatter;
16
-import java.util.ArrayList;
17
-import java.util.Arrays;
18
-import java.util.HashMap;
19
-import java.util.List;
18
+import java.util.*;
20 19
 
21 20
 /**
22 21
  * class name: CamelJDBCCofRealTimeConfiguration.java
@@ -93,7 +92,7 @@ public class CamelJDBCCofRealTimeConfiguration  {
93 92
                     String prod_date = aRow.get("dyna_create_time").toString().split("\\+")[0];
94 93
                     aRow.put("dyna_create_time", prod_date);
95 94
                     aRow.put("sgt", "");
96
-                    if (aRow.get("displacement") != null && !aRow.get("displacement").equals("") && aRow.get("disp_load") != null && !aRow.get("disp_load").equals("")) {
95
+                    if (!StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))) {
97 96
                         String[] displacements = aRow.get("displacement").toString().split(";");//10 四舍五入
98 97
                         String[] disp_loads = aRow.get("disp_load").toString().split(";");
99 98
                         Double susp_max_load = max(disp_loads);
@@ -113,7 +112,7 @@ public class CamelJDBCCofRealTimeConfiguration  {
113 112
                         aRow.put("susp_min_load",susp_min_load);
114 113
                     }
115 114
                     //对于位移没有数据,所有数据都在载荷中的特殊数据做特别处理
116
-                    else if ((aRow.get("displacement") == null || aRow.get("displacement").equals("")) && (aRow.get("disp_load") != null && !aRow.get("disp_load").equals(""))){
115
+                    else if (StringUtils.isEmpty(aRow.get("displacement")) && !StringUtils.isEmpty(aRow.get("disp_load"))){
117 116
                         String disp_load = aRow.get("disp_load").toString().replaceAll(";", ",");
118 117
                         Double[][] doubles = SGTUtil.encodeToDoubleArray(disp_load);
119 118
                         aRow.put("sgt", SGTUtil.encodeToString(doubles));
@@ -131,19 +130,19 @@ public class CamelJDBCCofRealTimeConfiguration  {
131 130
                         aRow.put("susp_max_load",susp_max_load);
132 131
                         aRow.put("susp_min_load",susp_min_load);
133 132
                     }
134
-                    if (aRow.get("stroke") == null) aRow.put("stroke", "0.0");
135
-                    if (aRow.get("frequency") == null) aRow.put("frequency", "0.0");
136
-                    if (aRow.get("susp_max_load") == null) aRow.put("susp_max_load", "0.0");
137
-                    if (aRow.get("susp_min_load") == null) aRow.put("susp_min_load", "0.0");
138
-                    if (aRow.get("frequency") != null){
133
+                    aRow.putIfAbsent("stroke", "0.0");
134
+                    aRow.putIfAbsent("frequency", "0.0");
135
+                    aRow.putIfAbsent("susp_max_load", "0.0");
136
+                    aRow.putIfAbsent("susp_min_load", "0.0");
137
+                    if (!StringUtils.isEmpty(aRow.get("frequency"))){
139 138
                         BigDecimal bd=new BigDecimal(aRow.get("frequency").toString());
140
-                        double frequency=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
139
+                        double frequency=bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
141 140
                         aRow.put("frequency",frequency);
142 141
                     }
143
-                    if (aRow.get("stroke") != null){
142
+                    if (!StringUtils.isEmpty(aRow.get("stroke"))){
144 143
                         double stroke1 = Double.parseDouble(aRow.get("stroke").toString());
145 144
                         BigDecimal bd=new BigDecimal(stroke1);
146
-                        double stroke=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
145
+                        double stroke=bd.setScale(1, RoundingMode.HALF_UP).doubleValue();
147 146
                         aRow.put("stroke",stroke);
148 147
                     }
149 148
                             String wellName =aRow.get("well_name").toString();

+ 4 - 2
src/main/java/com/gct/tools/etlcamelhuge/routeconfig/CamelJDBCConfiguration.java

@@ -51,7 +51,7 @@ public class CamelJDBCConfiguration {
51 51
 
52 52
                 RouteDefinition OrgAndWellSource= (RouteDefinition) from("timer:insert-OrgAndWellSource?period=86400000")
53 53
                         .routeId("insert-OrgAndWellSource")
54
-                        .setHeader("date", constant(getDate()))
54
+                        .setHeader("date", constant(getDate()+" 00:00:00"))
55 55
                         .process(exchange -> {
56 56
                             org = 0;
57 57
                             orgIdPreList = new HashMap<>();
@@ -71,7 +71,7 @@ public class CamelJDBCConfiguration {
71 71
                             orgIdPreList.put(body.get("org_id_pre"),body.get("org_id"));
72 72
                         }).end();
73 73
                         setMyBody(OrgAndWellSource)
74
-                       .setBody(simple("select  distinct jh,cydmc,zyq,zk,qyrq,sccw,qk,bz from DBA01 where jh ='${header.well_id}' "))
74
+                       .setBody(simple("select  distinct jh,cydmc,zyq,zk,qyrq,sccw,qk,bz from DBA01 where rq=to_date('${header.date}','yyyy-mm-dd hh24:mi:ss') and jh ='${header.well_id}'"))
75 75
                        .to("jdbc:oracle")
76 76
                        .transform()
77 77
                        .body((result) -> {
@@ -106,6 +106,8 @@ public class CamelJDBCConfiguration {
106 106
                       if(orgIDs.get(org_level3) !=null){
107 107
                           aRow.put("org_id",orgIDs.get(org_level3));
108 108
                       }
109
+                      String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
110
+                      aRow.putIfAbsent("QYRQ",format);
109 111
                   })
110 112
                   .setBody(simple("insert into centralbase.cb_cd_well_source (well_id,well_common_name,spud_date,org_id,station_id,station_name,completion_name,PRODUCING_AREA_name,remarks) " +
111 113
                                   "select '${body[JH]}','${body[JM]}','${body[QYRQ]}'::timestamp,'${body[org_id]}','${body[station_id]}','${body[ZK]}','${body[SCCW]}','${body[QK]}','${body[BZ]}' " +