|
@@ -1,22 +1,34 @@
|
1
|
1
|
package com.gct.tool.service;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSON;
|
3
|
4
|
import com.alibaba.fastjson.JSONArray;
|
4
|
5
|
import com.alibaba.fastjson.JSONObject;
|
|
6
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
7
|
+import com.gct.tool.entity.centralbase.CbCdWellSource;
|
|
8
|
+import com.gct.tool.entity.centralbase.CbPcProWellboreVolDaily;
|
5
|
9
|
import com.gct.tool.entity.sql.QueryBody;
|
6
|
10
|
import com.gct.tool.feign.DataBankClient;
|
7
|
11
|
import com.gct.tool.feign.DataBankTokenClient;
|
|
12
|
+import com.gct.tool.feign.WorkDiagramClient;
|
|
13
|
+import com.gct.tool.mapper.centralbase.CbCdWellSourceMapper;
|
|
14
|
+import com.gct.tool.mapper.centralbase.CbPcProWellboreVolDailyMapper;
|
8
|
15
|
import lombok.extern.slf4j.Slf4j;
|
|
16
|
+import org.mockito.internal.util.StringUtil;
|
9
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
18
|
import org.springframework.stereotype.Service;
|
|
19
|
+import org.springframework.util.StringUtils;
|
11
|
20
|
|
12
|
|
-import java.sql.SQLOutput;
|
|
21
|
+import java.time.LocalDateTime;
|
|
22
|
+import java.time.format.DateTimeFormatter;
|
13
|
23
|
import java.util.*;
|
|
24
|
+import java.util.stream.Collectors;
|
14
|
25
|
|
15
|
26
|
@Service
|
16
|
27
|
@Slf4j
|
17
|
28
|
public class LoadBaseDataService {
|
18
|
29
|
|
19
|
|
- final String identity = "CDF03A45C9BF4D9B85155364FAAEE08C14D85F6D51774A59GMXF6MBQG4ZDOKZXL4YF6KZSGEZGEKZWMBQTMKZVL43WCYJVG4XWCMLDGUXT22DKO43TAZ3CMYXXEL3AMFWWWN3ROFXGEZZSONYDAMBTGEYTKLRVGEZTONZXFYXTAMBSF4YDAMQ";
|
|
30
|
+ final String governDataServiceIdentity = "CDF03A45C9BF4D9B85155364FAAEE08C14D85F6D51774A59GMXF6MBQG4ZDOKZXL4YF6KZSGEZGEKZWMBQTMKZVL43WCYJVG4XWCMLDGUXT22DKO43TAZ3CMYXXEL3AMFWWWN3ROFXGEZZSONYDAMBTGEYTKLRVGEZTONZXFYXTAMBSF4YDAMQ";
|
|
31
|
+ final String sharedDataServiceIdentity = "77ACF8C095A94D3CA3474B9561FEA62D352F67FAE44AF04CMA2TGLZPMJPTGKZUF4XTIKZSGRRDGK27MIZGAKZOF5RDGNZTGBQS4YRWF4XT2NDFGZ2DCNLIFYYXEY3XMBVG4NRSNR4DGZTEMRWTAMBTGEZC4MBQGUXTONZXFYXTAMBSF4YDAMQ";
|
20
|
32
|
|
21
|
33
|
@Autowired
|
22
|
34
|
BaseResourceService baseResourceService;
|
|
@@ -26,12 +38,22 @@ public class LoadBaseDataService {
|
26
|
38
|
@Autowired
|
27
|
39
|
DataBankTokenClient tokenClient;
|
28
|
40
|
|
29
|
|
- private void printMap(Object o,boolean isPrintNull,Set<String>filterSet){
|
30
|
|
- ((Map)o).forEach((k,v)->{
|
31
|
|
- if ((isPrintNull || Objects.nonNull(v))&&(Objects.isNull(filterSet)|| filterSet.contains(k)))
|
32
|
|
- System.out.printf("%s:%s\n",k,v);
|
|
41
|
+ @Autowired
|
|
42
|
+ WorkDiagramClient workDiagramClient;
|
|
43
|
+
|
|
44
|
+ @Autowired
|
|
45
|
+ CbCdWellSourceMapper cbCdWellSourceMapper;
|
|
46
|
+
|
|
47
|
+ @Autowired
|
|
48
|
+ CbPcProWellboreVolDailyMapper cbPcProWellboreVolDailyMapper;
|
|
49
|
+
|
|
50
|
+ private void printMap(Object o, boolean isPrintNull, Set<String> filterSet) {
|
|
51
|
+ ((Map) o).forEach((k, v) -> {
|
|
52
|
+ if ((isPrintNull || Objects.nonNull(v)) && (Objects.isNull(filterSet) || filterSet.contains(k)))
|
|
53
|
+ System.out.printf("%s:%s\n", k, v);
|
33
|
54
|
});
|
34
|
55
|
}
|
|
56
|
+
|
35
|
57
|
/**
|
36
|
58
|
* @return
|
37
|
59
|
*/
|
|
@@ -43,24 +65,106 @@ public class LoadBaseDataService {
|
43
|
65
|
wellIds.forEach(wellId -> {
|
44
|
66
|
QueryBody queryBody = new QueryBody();
|
45
|
67
|
queryBody.select("TL").eq("WELL_LEGAL_NAME", wellId);
|
46
|
|
- JSONObject object = dataBankClient.getCdWellData(queryBody.toJsonMap(), 0, 10, identity);
|
|
68
|
+ JSONObject object = dataBankClient.getCdWellData(queryBody.toJsonMap(), 0, 10, governDataServiceIdentity);
|
47
|
69
|
System.out.println(object);
|
48
|
70
|
JSONArray array = object.getJSONObject("resultData").getJSONArray("content");
|
49
|
71
|
// ((Map) array.get(0)).forEach((k,v)-> System.out.printf(k+","));
|
50
|
72
|
System.out.println("");
|
51
|
73
|
array.forEach(o -> {
|
52
|
|
- printMap(o,false,null);
|
|
74
|
+ printMap(o, false, null);
|
53
|
75
|
// System.out.printf("%s,%s\n",((Map) o).get("WELL_LEGAL_NAME"),((Map) o).get("WELL_ID"));
|
54
|
76
|
});
|
55
|
77
|
});
|
56
|
78
|
}
|
57
|
79
|
|
58
|
|
- public void loadVolDailyData(){
|
|
80
|
+ public void loadVolDailyData() {
|
|
81
|
+ List<CbCdWellSource> cbCdWellSources = cbCdWellSourceMapper.selectList(new QueryWrapper<>());
|
|
82
|
+ cbCdWellSources.forEach(cbCdWellSource -> {
|
|
83
|
+ QueryBody queryBody = new QueryBody();
|
|
84
|
+ String dateStr = LocalDateTime.now().minusDays(3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
85
|
+ queryBody.select("TL").eq("WELL_ID", cbCdWellSource.getWellId()).gt("PROD_DATE", dateStr);
|
|
86
|
+ JSONObject object = dataBankClient.getVolDailyData(queryBody.toJsonMap(), 0, 5, governDataServiceIdentity);
|
|
87
|
+ JSONArray array = object.getJSONObject("resultData").getJSONArray("content");
|
|
88
|
+ for (int i = 0; i < array.size(); i++) {
|
|
89
|
+ JSONObject volDailyJson = array.getJSONObject(i);
|
|
90
|
+ CbPcProWellboreVolDaily volDaily = volDailyJson.toJavaObject(CbPcProWellboreVolDaily.class);
|
|
91
|
+ volDaily.setWaterCut(volDailyJson.getDouble("WATER_CUT_RATIO"));
|
|
92
|
+ QueryWrapper<CbPcProWellboreVolDaily> wrapper = new QueryWrapper<CbPcProWellboreVolDaily>()
|
|
93
|
+ .eq("well_id", volDaily.getWellId())
|
|
94
|
+ .eq("prod_date", volDaily.getProdDate());
|
|
95
|
+ if (Objects.isNull(cbPcProWellboreVolDailyMapper.selectOne(wrapper))) {
|
|
96
|
+ cbPcProWellboreVolDailyMapper.insert(volDaily);
|
|
97
|
+ } else {
|
|
98
|
+ cbPcProWellboreVolDailyMapper.update(volDaily, wrapper);
|
|
99
|
+ }
|
|
100
|
+ }
|
59
|
101
|
|
|
102
|
+ });
|
60
|
103
|
}
|
61
|
104
|
|
62
|
|
- public void loadStatusDailyData(){
|
|
105
|
+ public void loadStatusDailyData() {
|
|
106
|
+ List<CbCdWellSource> cbCdWellSources = cbCdWellSourceMapper.selectList(new QueryWrapper<>());
|
|
107
|
+ cbCdWellSources = cbCdWellSources.subList(0, 1);
|
|
108
|
+ cbCdWellSources.forEach(cbCdWellSource -> {
|
|
109
|
+ QueryBody queryBody = new QueryBody();
|
|
110
|
+ String dateStr = LocalDateTime.now().minusDays(365).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
111
|
+ queryBody.select("TL").eq("WELL_ID", cbCdWellSource.getWellId());
|
|
112
|
+// queryBody.select("TL");
|
|
113
|
+ JSONObject object = dataBankClient.getStatusDailyData(queryBody.toJsonMap(), 0, 500, sharedDataServiceIdentity);
|
|
114
|
+ JSONArray array = object.getJSONObject("resultData").getJSONArray("content");
|
|
115
|
+ HashSet<String> filterSet = new HashSet<>();
|
|
116
|
+ filterSet.add("OIL_NOZZLE");
|
|
117
|
+ filterSet.add("START_PUMP_DEPTH");
|
|
118
|
+ filterSet.add("START_PUMP_LIQ_LEVEL");
|
|
119
|
+ filterSet.add("END_PUMP_DEPTH");
|
|
120
|
+ filterSet.add("END_PUMP_LIQ_LEVEL");
|
|
121
|
+ array.forEach(o -> printMap(o, true, null));
|
|
122
|
+// for (int i = 0; i < array.size(); i++) {
|
|
123
|
+// JSONObject volDailyJson = array.getJSONObject(i);
|
|
124
|
+// CbPcProWellboreVolDaily volDaily = volDailyJson.toJavaObject(CbPcProWellboreVolDaily.class);
|
|
125
|
+// volDaily.setWaterCut(volDailyJson.getDouble("WATER_CUT_RATIO"));
|
|
126
|
+// QueryWrapper<CbPcProWellboreVolDaily> wrapper = new QueryWrapper<CbPcProWellboreVolDaily>()
|
|
127
|
+// .eq("well_id", volDaily.getWellId())
|
|
128
|
+// .eq("prod_date", volDaily.getProdDate());
|
|
129
|
+// if (Objects.isNull( cbPcProWellboreVolDailyMapper.selectOne(wrapper))){
|
|
130
|
+// cbPcProWellboreVolDailyMapper.insert(volDaily);
|
|
131
|
+// } else {
|
|
132
|
+// cbPcProWellboreVolDailyMapper.update(volDaily,wrapper);
|
|
133
|
+// }
|
|
134
|
+// }
|
|
135
|
+ });
|
|
136
|
+ }
|
63
|
137
|
|
|
138
|
+ private JSONArray executeRemoteSql(String sqlString){
|
|
139
|
+ System.out.println(sqlString);
|
|
140
|
+ String res = workDiagramClient.getWorkDiagramData(sqlString);
|
|
141
|
+ res=res.replace("\\","");
|
|
142
|
+ res=res.substring(1,res.length()-1);
|
|
143
|
+ JSONObject selectMaxTimeJson = JSONObject.parseObject(res);
|
|
144
|
+ return selectMaxTimeJson.getJSONArray("dataList");
|
64
|
145
|
}
|
65
|
146
|
|
|
147
|
+ public void loadWorkDiagramData(){
|
|
148
|
+ List<CbCdWellSource> cbCdWellSources = cbCdWellSourceMapper.selectList(new QueryWrapper<>());
|
|
149
|
+ cbCdWellSources = cbCdWellSources.subList(0, 1);
|
|
150
|
+ cbCdWellSources.forEach(cbCdWellSource -> {
|
|
151
|
+ String selectNearlyWorkDiagramSqlStr = String.format(
|
|
152
|
+ "select * from PC_FD_PUMPJACK_DYNA_DIA_T@A11gxk where DYNA_CREATE_TIME = " +
|
|
153
|
+ "(select max(DYNA_CREATE_TIME) from PC_FD_PUMPJACK_DYNA_DIA_T@A11gxk where WELL_COMMON_NAME = '%s')" +
|
|
154
|
+ "and WELL_COMMON_NAME = '%s'",
|
|
155
|
+ cbCdWellSource.getWellLegalName(),cbCdWellSource.getWellLegalName());
|
|
156
|
+ JSONObject nearlyWorkDiagram = executeRemoteSql(selectNearlyWorkDiagramSqlStr).getJSONObject(0);
|
|
157
|
+ String displacement = nearlyWorkDiagram.getString("DISPLACEMENT");
|
|
158
|
+ String load = nearlyWorkDiagram.getString("DISP_LOAD");
|
|
159
|
+ List<Double[]> sgt = new ArrayList<>();
|
|
160
|
+ List<Double> dispacementList = Arrays.stream(displacement.split(";")).map(Double::parseDouble).collect(Collectors.toList());
|
|
161
|
+ List<Double> loadList = Arrays.stream(load.split(";")).map(Double::parseDouble).collect(Collectors.toList());
|
|
162
|
+ for (int i=0;i<Math.min(dispacementList.size(),loadList.size());i++){
|
|
163
|
+ sgt.add(new Double[]{dispacementList.get(i),loadList.get(i)});
|
|
164
|
+ }
|
|
165
|
+ Double stroke = Double.parseDouble(nearlyWorkDiagram.getString("STROKE"));
|
|
166
|
+ Double frequency = Double.parseDouble(nearlyWorkDiagram.getString("FREQUENCY"));
|
|
167
|
+
|
|
168
|
+ });
|
|
169
|
+ }
|
66
|
170
|
}
|