guoshilong
2024-03-05 2f8eaa7c850445fde0cdca0e8ecddcb7e2a936a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package cn.gistack.nky.service.impl;
 
import cn.gistack.nky.entity.ArimaPredict;
import cn.gistack.nky.entity.HstPredict;
import cn.gistack.nky.mapper.HstPredictMapper;
import cn.gistack.nky.requestpojo.HstPredictReqPo;
import cn.gistack.nky.requestpojo.PredictWatersPo;
import cn.gistack.nky.requestpojo.QueryReqPo;
import cn.gistack.nky.resultpojo.DataResChildrenPo;
import cn.gistack.nky.resultpojo.NewSwFuturePo;
import cn.gistack.nky.service.IHstPredictService;
import cn.gistack.nky.service.IHsybService;
import cn.gistack.nky.service.INkyService;
import cn.gistack.nky.service.IZtApiService;
import cn.gistack.nky.vo.HstPredictVO;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class HstPredictServiceImpl extends ServiceImpl<HstPredictMapper, HstPredict> implements IHstPredictService {
    @Autowired
    private INkyService nkyService;
    @Autowired
    private IZtApiService ztApiService;
    @Autowired
    private IHsybService hsybService;
 
 
    @Override
    public void getData(String type) {
        List<DataResChildrenPo> cdList = getCdList(type);
        List<DataResChildrenPo> collect = cdList.stream().filter(
//            item -> item.getRes_cd().equals("42011640018") || item.getRes_cd().equals("42128140006")
            item -> item.getRes_cd().equals("42011640018") || item.getRes_cd().equals("42130350046")|| item.getRes_cd().equals("42092250024")|| item.getRes_cd().equals("42022250039")|| item.getRes_cd().equals("42132150292")
 
        ).collect(Collectors.toList());
        collect.forEach(dataResChildrenPo -> {
            //循环请求预测结果
            QueryReqPo queryReqPo = new QueryReqPo(dataResChildrenPo, type);
            //请求预测结果
            HstPredict hstPredict = nkyService.hstQuery(queryReqPo);
            if (hstPredict != null) {
                //存储预测结果至数据库
                save(hstPredict);
            }
        });
    }
 
//    private String resCd = "";
 
    @Override
    public void predictData(String type) {
        List<DataResChildrenPo> cdList = getCdList(type);
        //暂时筛选出数据
//        List<DataResChildrenPo> collect = cdList.stream().filter(
//            item -> item.getRes_cd().equals("42011640018") || item.getRes_cd().equals("42130350046")|| item.getRes_cd().equals("42092250024")|| item.getRes_cd().equals("42022250039")|| item.getRes_cd().equals("42132150292")
//        ).collect(Collectors.toList());
 
//        predict(collect,type);
 
        newPredict(cdList,type);
 
 
    }
 
    private void newPredict(List<DataResChildrenPo> collect, String type) {
 
        String resCd = "";
        //无数据直接返回
        if (collect.size() == 0){
            return;
        }
        List<NewSwFuturePo> future = new ArrayList<>();
        if (type.equals("1") || type.equals("2")){
 
            for (int i = 0; i < collect.size(); i++) {
                DataResChildrenPo dataResChildrenPo = collect.get(i);
                String currentResCd = dataResChildrenPo.getRes_cd();
 
                //第一个水库
                if (future.size() == 0 && resCd.equals("")){
                    future = hsybService.getNewFuture(currentResCd);
                    //当前水库
                    resCd = currentResCd;
                } else if (!resCd.equals(currentResCd)) {
                    //其他水库,获取新的预测数据
                    future = hsybService.getNewFuture(currentResCd);
                    //更换为新水库
                    resCd = currentResCd;
                }
 
                //预测数据构造请求数据
                if (future != null && future.size() > 0) {
                    List<PredictWatersPo> po = new ArrayList<>();
                    future.forEach(item -> {
                        PredictWatersPo predictWatersPo = new PredictWatersPo();
                        //设置时间
                        predictWatersPo.setTime(item.getTime());
                        //设置预测水位
                        predictWatersPo.setValue(Double.parseDouble(item.getSw()));
                        po.add(predictWatersPo);
                    });
                    HstPredictReqPo arimaPredictReqPo = new HstPredictReqPo(dataResChildrenPo, type, po);
                    //循环预测请求
                    nkyService.hstPredict(arimaPredictReqPo);
                }
 
 
            }
        }else if (type.equals("3") || type.equals("4") || type.equals("5")){
 
            for (int i = 0; i < collect.size(); i++) {
                DataResChildrenPo dataResChildrenPo = collect.get(i);
                String currentResCd = dataResChildrenPo.getRes_cd();
 
                //第一个水库
                if (future.size() == 0 && resCd.equals("")){
                    future = hsybService.getNewFuture(currentResCd);
                    //当前水库
                    resCd = currentResCd;
                } else if (!resCd.equals(currentResCd)) {
                    //其他水库,获取新的预测数据
                    future = hsybService.getNewFuture(currentResCd);
                    //更换为新水库
                    resCd = currentResCd;
                }
 
                //预测数据构造请求数据
                if (future != null && future.size() > 0) {
                    List<PredictWatersPo> po = new ArrayList<>();
                    future.forEach(item -> {
                        PredictWatersPo predictWatersPo = new PredictWatersPo();
                        //设置时间
                        predictWatersPo.setTime(item.getTime());
                        //设置预测水位
                        predictWatersPo.setValue(Double.parseDouble(item.getSw()));
                        po.add(predictWatersPo);
                    });
                    //循环预测请求(位移一起请求减少请求次数)
                    HstPredictReqPo arimaPredictReqPoX = new HstPredictReqPo(dataResChildrenPo, "3", po);
                    nkyService.hstPredict(arimaPredictReqPoX);
 
                    HstPredictReqPo arimaPredictReqPoY = new HstPredictReqPo(dataResChildrenPo, "4", po);
                    nkyService.hstPredict(arimaPredictReqPoY);
 
                    HstPredictReqPo arimaPredictReqPoZ = new HstPredictReqPo(dataResChildrenPo, "5", po);
                    nkyService.hstPredict(arimaPredictReqPoZ);
                }
            }
        }
 
    }
 
    private void predict(List<DataResChildrenPo> collect, String type) {
        String resCd = "";
        //无数据直接返回
        if (collect.size() == 0){
            return;
        }
        List<List<String>> future = new ArrayList<>();
        if (type.equals("1") || type.equals("2")){
 
            for (int i = 0; i < collect.size(); i++) {
                DataResChildrenPo dataResChildrenPo = collect.get(i);
                String currentResCd = dataResChildrenPo.getRes_cd();
 
                //第一个水库
                if (future.size() == 0 && resCd.equals("")){
                    future = hsybService.getFuture(currentResCd);
                    //当前水库
                    resCd = currentResCd;
                } else if (!resCd.equals(currentResCd)) {
                    //其他水库,获取新的预测数据
                    future = hsybService.getFuture(currentResCd);
                    //更换为新水库
                    resCd = currentResCd;
                }
 
                //预测数据构造请求数据
                if (future != null && future.size() > 0) {
                    List<PredictWatersPo> po = new ArrayList<>();
                    future.forEach(item -> {
                        PredictWatersPo predictWatersPo = new PredictWatersPo();
                        //设置时间
                        predictWatersPo.setTime(item.get(0));
                        //设置预测水位
                        predictWatersPo.setValue(Double.parseDouble(item.get(2)));
                        po.add(predictWatersPo);
                    });
                    HstPredictReqPo arimaPredictReqPo = new HstPredictReqPo(dataResChildrenPo, type, po);
                    //循环预测请求
                    nkyService.hstPredict(arimaPredictReqPo);
                }
 
 
            }
        }else if (type.equals("3") || type.equals("4") || type.equals("5")){
 
            for (int i = 0; i < collect.size(); i++) {
                DataResChildrenPo dataResChildrenPo = collect.get(i);
                String currentResCd = dataResChildrenPo.getRes_cd();
 
                //第一个水库
                if (future.size() == 0 && resCd.equals("")){
                    future = hsybService.getFuture(currentResCd);
                    //当前水库
                    resCd = currentResCd;
                } else if (!resCd.equals(currentResCd)) {
                    //其他水库,获取新的预测数据
                    future = hsybService.getFuture(currentResCd);
                    //更换为新水库
                    resCd = currentResCd;
                }
 
                //预测数据构造请求数据
                if (future != null && future.size() > 0) {
                    List<PredictWatersPo> po = new ArrayList<>();
                    future.forEach(item -> {
                        PredictWatersPo predictWatersPo = new PredictWatersPo();
                        //设置时间
                        predictWatersPo.setTime(item.get(0));
                        //设置预测水位
                        predictWatersPo.setValue(Double.parseDouble(item.get(2)));
                        po.add(predictWatersPo);
                    });
                    //循环预测请求(位移一起请求减少请求次数)
                    HstPredictReqPo arimaPredictReqPoX = new HstPredictReqPo(dataResChildrenPo, "3", po);
                    nkyService.hstPredict(arimaPredictReqPoX);
 
                    HstPredictReqPo arimaPredictReqPoY = new HstPredictReqPo(dataResChildrenPo, "4", po);
                    nkyService.hstPredict(arimaPredictReqPoY);
 
                    HstPredictReqPo arimaPredictReqPoZ = new HstPredictReqPo(dataResChildrenPo, "5", po);
                    nkyService.hstPredict(arimaPredictReqPoZ);
                }
            }
        }
    }
 
    @Override
    public List<HstPredictVO> getFutureData(String resCd, String type) {
        List<HstPredictVO> list = new ArrayList<>();
        if (type.equals("3")) {
            list = baseMapper.getFutureDataWy(resCd, type);
        } else {
            list = baseMapper.getFutureData(resCd, type);
        }
 
 
        list.forEach(hstPredict -> {
            if (hstPredict.getPredictList() != null) {
                hstPredict.setPredictList(JSON.parse(hstPredict.getPredictList().toString()));
            } else {
                hstPredict.setPredictList("[]");
            }
            hstPredict.setPreWaterList(JSON.parse(hstPredict.getPreWaterList().toString()));
        });
 
        return list;
    }
 
    @Override
    public boolean save(HstPredict entity) {
 
        if (ObjectUtil.isEmpty(entity.getCreateTime())) {
            return false;
        }
 
        List<HstPredict> list = baseMapper.selectTodayData(entity);
 
        if (list.size() > 0) {
            //删除该数据,添加最新数据
//            baseMapper.deleteById(list.get(0));
//            return super.save(entity);
            return false;
        } else {
            return super.save(entity);
        }
    }
 
    public List<DataResChildrenPo> getCdList(String type) {
        List<DataResChildrenPo> cdList = new ArrayList<>();
        if (type.equals("1")) {
            //获取渗压测点
            cdList = ztApiService.getSy();
        } else if (type.equals("2")) {
            //获取渗流测点
            cdList = ztApiService.getSl();
        } else if (type.equals("3") || type.equals("4") || type.equals("5")) {
            //获取位移测点
            cdList = ztApiService.getWy();
        } else {
            return null;
        }
        return cdList;
    }
 
}