|
@@ -98,9 +98,7 @@ public class GtController {
|
98
|
98
|
@GetMapping("/getGTSJ")
|
99
|
99
|
@ApiOperation(value = "从实时的机采数据生产的表中获取数据放入到 Runtime 表中")
|
100
|
100
|
public JSONObject getGTSJ(@RequestBody GTBody gtBody){
|
101
|
|
-
|
102
|
101
|
String startDate = gtBody.getStartDate();
|
103
|
|
- String endDate = gtBody.getEndDate();
|
104
|
102
|
JSONArray wellList = gtBody.getWellList();
|
105
|
103
|
JSONObject jsonObject = new JSONObject();
|
106
|
104
|
jdbcTemplate = new JdbcTemplate(dataSourceOfGTSJ);
|
|
@@ -108,54 +106,29 @@ public class GtController {
|
108
|
106
|
int pageSize = 5000;
|
109
|
107
|
int sumData = 0;
|
110
|
108
|
try {
|
111
|
|
- for (int i = 0; i < wellList.size(); i++) {
|
112
|
|
- String sql = String.format("select distinct well_name,dyna_create_time,check_date,displacement,disp_load,stroke,frequency,susp_max_load,susp_min_load from public.pc_fd_pumpjack_dyna_dia_t where dyna_create_time > '%s' and well_name = '%s' offset %d limit %d ", startDate, wellList.get(i));
|
113
|
|
- List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
114
|
|
- for (Map<String, Object> map : list) {
|
115
|
|
- String prod_date = map.get("dyna_create_time").toString().split("\\+")[0];
|
116
|
|
- map.put("dyna_create_time", prod_date);
|
117
|
|
- if (map.get("displacement") != null && !map.get("displacement").equals("") && map.get("disp_load") != null && !map.get("disp_load").equals("")) {
|
118
|
|
- String[] displacements = map.get("displacement").toString().split(";");//10 四舍五入
|
119
|
|
- String[] disp_loads = map.get("disp_load").toString().split(";");
|
120
|
|
- Double susp_max_load = max(disp_loads);
|
121
|
|
- Double susp_min_load = min(disp_loads);
|
122
|
|
- String sgt = "";
|
123
|
|
- for (int y = 0; y < displacements.length; y++) {
|
124
|
|
- sgt = sgt + displacements[y] + "," + disp_loads[y] + ",";
|
125
|
|
- }
|
126
|
|
- String[] s = sgt.split(",");
|
127
|
|
- String w = "";
|
128
|
|
- for (int x = 0; x < s.length; x++) {
|
129
|
|
- w += new BigDecimal(Math.round(Double.parseDouble(s[x]) * 100)).stripTrailingZeros().toPlainString() + ",";
|
130
|
|
- }
|
131
|
|
- Double[][] doubles = SGTUtil.encodeToDoubleArray(w);
|
132
|
|
- map.put("sgt", SGTUtil.encodeToString(doubles));
|
133
|
|
- map.put("susp_max_load",susp_max_load);
|
134
|
|
- map.put("susp_min_load",susp_min_load);
|
135
|
|
- }
|
136
|
|
- if (map.get("stroke") == null) map.put("stroke", "0.0");
|
137
|
|
- if (map.get("frequency") == null) map.put("frequency", "0.0");
|
138
|
|
- if (map.get("susp_max_load") == null) map.put("susp_max_load", "0.0");
|
139
|
|
- if (map.get("susp_min_load") == null) map.put("susp_min_load", "0.0");
|
140
|
|
- if (map.get("frequency") != null){
|
141
|
|
- BigDecimal bd=new BigDecimal(map.get("frequency").toString());
|
142
|
|
- double frequency=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
143
|
|
- map.put("frequency",frequency);
|
144
|
|
- }
|
145
|
|
- if (map.get("stroke") != null){
|
146
|
|
- double stroke1 = Double.parseDouble(map.get("stroke").toString());
|
147
|
|
- BigDecimal bd=new BigDecimal(stroke1);
|
148
|
|
- double stroke=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
149
|
|
- map.put("stroke",stroke);
|
150
|
|
- }
|
151
|
|
- jdbcTemplate.update("insert into centralbase.cb_temp_well_mech_runtime(well_id,prod_date,stroke_length,stroke_frequency,susp_max_load,susp_min_load,sgt) " +
|
152
|
|
- "values (?,?,?,?,?,?,?)",map.get("well_name").toString(),map.get("dyna_create_time"),map.get("stroke"),map.get("frequency"),map.get("susp_max_load"),map.get("susp_min_load"),map.get("sgt"));
|
153
|
|
- }
|
154
|
|
- sumData += list.size();
|
155
|
|
- if (list.size()< pageSize){
|
156
|
|
- break;
|
|
109
|
+ if (wellList.isEmpty() || wellList.size() ==0 ){
|
|
110
|
+ while (true){
|
|
111
|
+ String sql = String.format("select distinct well_name,dyna_create_time,check_date,displacement,disp_load,stroke,frequency,susp_max_load,susp_min_load from public.pc_fd_pumpjack_dyna_dia_t where dyna_create_time > '%s' limit %d offset %d ", startDate,curPage,pageSize);
|
|
112
|
+ List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
113
|
+ sql = String.format("select count(1) from public.pc_fd_pumpjack_dyna_dia_t where dyna_create_time > '%s' ", startDate );
|
|
114
|
+ Integer count = jdbcTemplate.queryForObject(sql, Integer.class);
|
|
115
|
+ int pageNum = (count % pageSize ==0 ) ?(count / pageSize) : (count/pageSize)+1;
|
|
116
|
+ insertDataToRunTime(list);
|
|
117
|
+ sumData += list.size();
|
|
118
|
+ curPage ++;
|
|
119
|
+ if (curPage>pageNum) break;
|
157
|
120
|
}
|
158
|
|
- curPage ++ ;
|
|
121
|
+ }else {
|
|
122
|
+ for (int i = 0; i < wellList.size(); i++) {
|
|
123
|
+ String sql = String.format("select distinct well_name,dyna_create_time,check_date,displacement,disp_load,stroke,frequency,susp_max_load,susp_min_load from public.pc_fd_pumpjack_dyna_dia_t where dyna_create_time > '%s' and well_name = '%s' limit %d offset %d ", startDate, wellList.get(i),curPage,pageSize);
|
|
124
|
+ List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
|
|
125
|
+ insertDataToRunTime(list);
|
|
126
|
+ sumData += list.size();
|
|
127
|
+ if (list.size()< pageSize){
|
|
128
|
+ break;
|
|
129
|
+ }
|
|
130
|
+ curPage ++ ;
|
|
131
|
+ }
|
159
|
132
|
}
|
160
|
133
|
}catch (Exception e){
|
161
|
134
|
jsonObject.put("error",e.getMessage());
|
|
@@ -163,8 +136,50 @@ public class GtController {
|
163
|
136
|
jsonObject.put("sumData",sumData);
|
164
|
137
|
}
|
165
|
138
|
return jsonObject;
|
166
|
|
- }
|
167
|
|
-
|
|
139
|
+}
|
|
140
|
+ public void insertDataToRunTime(List<Map<String, Object>> list){
|
|
141
|
+ for (Map<String, Object> map : list) {
|
|
142
|
+ String prod_date = map.get("dyna_create_time").toString().split("\\+")[0];
|
|
143
|
+ map.put("dyna_create_time", prod_date);
|
|
144
|
+ if (map.get("displacement") != null && !map.get("displacement").equals("") && map.get("disp_load") != null && !map.get("disp_load").equals("")) {
|
|
145
|
+ String[] displacements = map.get("displacement").toString().split(";");//10 四舍五入
|
|
146
|
+ String[] disp_loads = map.get("disp_load").toString().split(";");
|
|
147
|
+ Double susp_max_load = max(disp_loads);
|
|
148
|
+ Double susp_min_load = min(disp_loads);
|
|
149
|
+ String sgt = "";
|
|
150
|
+ for (int y = 0; y < displacements.length; y++) {
|
|
151
|
+ sgt = sgt + displacements[y] + "," + disp_loads[y] + ",";
|
|
152
|
+ }
|
|
153
|
+ String[] s = sgt.split(",");
|
|
154
|
+ String w = "";
|
|
155
|
+ for (int x = 0; x < s.length; x++) {
|
|
156
|
+ w += new BigDecimal(Math.round(Double.parseDouble(s[x]) * 100)).stripTrailingZeros().toPlainString() + ",";
|
|
157
|
+ }
|
|
158
|
+ Double[][] doubles = SGTUtil.encodeToDoubleArray(w);
|
|
159
|
+ map.put("sgt", SGTUtil.encodeToString(doubles));
|
|
160
|
+ map.put("susp_max_load",susp_max_load);
|
|
161
|
+ map.put("susp_min_load",susp_min_load);
|
|
162
|
+ }
|
|
163
|
+ if (map.get("stroke") == null) map.put("stroke", "0.0");
|
|
164
|
+ if (map.get("frequency") == null) map.put("frequency", "0.0");
|
|
165
|
+ if (map.get("susp_max_load") == null) map.put("susp_max_load", "0.0");
|
|
166
|
+ if (map.get("susp_min_load") == null) map.put("susp_min_load", "0.0");
|
|
167
|
+ if (map.get("frequency") != null){
|
|
168
|
+ BigDecimal bd=new BigDecimal(map.get("frequency").toString());
|
|
169
|
+ double frequency=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
170
|
+ map.put("frequency",frequency);
|
|
171
|
+ }
|
|
172
|
+ if (map.get("stroke") != null){
|
|
173
|
+ double stroke1 = Double.parseDouble(map.get("stroke").toString());
|
|
174
|
+ BigDecimal bd=new BigDecimal(stroke1);
|
|
175
|
+ double stroke=bd.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
176
|
+ map.put("stroke",stroke);
|
|
177
|
+ }
|
|
178
|
+ jdbcTemplate = new JdbcTemplate(dataSource);
|
|
179
|
+ jdbcTemplate.update("insert into centralbase.cb_temp_well_mech_runtime(well_id,prod_date,stroke_length,stroke_frequency,susp_max_load,susp_min_load,sgt) " +
|
|
180
|
+ "values (?,?,?,?,?,?,?)",map.get("well_name").toString(),map.get("dyna_create_time"),map.get("stroke"),map.get("frequency"),map.get("susp_max_load"),map.get("susp_min_load"),map.get("sgt"));
|
|
181
|
+ }
|
|
182
|
+ }
|
168
|
183
|
|
169
|
184
|
public Double min(String[] strings){
|
170
|
185
|
double[] doubles = new double[strings.length];
|