瀏覽代碼

0827-稳定版-完善(发送消息时可以不用wellList)

gxt 3 年之前
父節點
當前提交
803ae1a557

+ 31 - 28
src/main/java/com/gct/tools/etlcamelhuge/controller/GtController.java

@@ -49,44 +49,47 @@ public class GtController {
49 49
         List<String> wellList = gtBody.getWellList().stream().map(x->x.toString()).collect(Collectors.toList());
50 50
         JSONObject jsonObject = new JSONObject();
51 51
         jdbcTemplate = new JdbcTemplate(dataSource);
52
-        int curPage = 0;
53
-        int pageSize = 5000;
54 52
         int sumData = 0;
55 53
         try {
56
-                for (int i = 0; i < wellList.size(); i++) {
54
+                if (wellList.isEmpty() || wellList.size()==0 ){
57 55
                     String sql = String.format("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 " +
58
-                            " where ti.well_id = so.well_id and ti.well_id = '%s' and ti.prod_date between '%s' and '%s' ",wellList.get(i) ,startDate,endDate);
59
-                    String countSql = String.format("select count(1) from (%s)",sql);
60
-                    //Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
61
-                    List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
62
-                    for (Map<String, Object> map : list) {
63
-                        String wellName =map.get("well_common_name").toString();
64
-                        String wellId =map.get("well_id").toString();
65
-                        String orgId = map.get("org_id").toString();
66
-                        String prodDate = map.get("prod_date").toString().substring(0,19);
67
-                        Double strokeLength = Double.valueOf(map.get("stroke_length").toString());
68
-                        Double strokeFrequency = Double.valueOf(map.get("stroke_frequency").toString());
69
-                        String sgt = map.get("sgt").toString();
70
-                        if (sgt == null || sgt.length() ==0){
71
-                            sgt = "0,0,0,0,0,0,0,0,0,0";
72
-                        }
73
-                        DiagnoseMsg diagnoseMsg = new DiagnoseMsg(wellId, wellName, orgId, prodDate, sgt, LocalDateTime.now().toString(), strokeLength, strokeFrequency);
74
-                        producer.send((MessageBody) diagnoseMsg);
56
+                            " where ti.well_id = so.well_id  and ti.prod_date between '%s' and '%s' " ,startDate,endDate);
57
+                    sumData = sendDataToMQ(sql);
58
+                }else {
59
+                    for (int i = 0; i < wellList.size(); i++) {
60
+                        String sql = String.format("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 " +
61
+                                " where ti.well_id = so.well_id and ti.well_id = '%s' and ti.prod_date between '%s' and '%s' ", wellList.get(i), startDate, endDate);
62
+                        sumData = sendDataToMQ(sql);
75 63
                     }
76
-                   /* sumData += list.size();
77
-                    if (list.size()< pageSize){
78
-                        break;
79
-                    }
80
-                    curPage ++ ;*/
81 64
                 }
82
-
83 65
         }catch (Exception e){
84 66
             e.printStackTrace();
85 67
             jsonObject.put("error",e.getMessage());
86 68
         }finally {
87
-            jsonObject.put("sumData",sumData);
69
+            jsonObject.put("发送数据为sumData",sumData);
88 70
         }
89
-        return    jsonObject;
71
+        return  jsonObject;
72
+    }
73
+
74
+    public int sendDataToMQ(String sql){
75
+        int sumData = 0;
76
+        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
77
+        for (Map<String, Object> map : list) {
78
+            String wellName = map.get("well_common_name").toString();
79
+            String wellId = map.get("well_id").toString();
80
+            String orgId = map.get("org_id").toString();
81
+            String prodDate = map.get("prod_date").toString().substring(0, 19);
82
+            Double strokeLength = Double.valueOf(map.get("stroke_length").toString());
83
+            Double strokeFrequency = Double.valueOf(map.get("stroke_frequency").toString());
84
+            String sgt = map.get("sgt").toString();
85
+            if (sgt == null || sgt.length() == 0) {
86
+                sgt = "0,0,0,0,0,0,0,0,0,0";
87
+            }
88
+            DiagnoseMsg diagnoseMsg = new DiagnoseMsg(wellId, wellName, orgId, prodDate, sgt, LocalDateTime.now().toString(), strokeLength, strokeFrequency);
89
+            //producer.send((MessageBody) diagnoseMsg);
90
+            sumData++;
91
+        }
92
+        return sumData;
90 93
     }
91 94
 
92 95
    /* @GetMapping("/getGTSJ")

+ 3 - 3
src/main/resources/application.yml

@@ -116,7 +116,7 @@ server:
116 116
 
117 117
 rocketmq:
118 118
   #rocketmq的路由调度器的地址
119
-  name-server: 101.200.219.190:9876
119
+  name-server: 10.72.143.2:9876
120 120
   producer:
121 121
     # 消息分组
122 122
     group: aoid
@@ -134,7 +134,7 @@ gct:
134 134
         group: diagnose
135 135
         access-key: diagnose-msg-v1
136 136
         secret-key: diagnose-msg-v1
137
-      name-server: 101.200.219.190:9876
137
+      name-server: 10.72.143.2:9876
138 138
       consumer:
139 139
         group: diagnose
140 140
         access-key: diagnose-msg-v1
@@ -147,7 +147,7 @@ gct:
147 147
         group: warn
148 148
         access-key: warn-msg-v1
149 149
         secret-key: warn-msg-v1
150
-      name-server: 101.200.219.190:9876
150
+      name-server: 10.72.143.2:9876
151 151
       consumer:
152 152
         group: warn
153 153
         access-key: warn-msg-v1