guoshilong
2023-11-16 00165e5d50f47c99d9eb7c2fc784bef4d3f72aca
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
package cn.gistack.nky.service.impl;
 
import cn.gistack.common.utils.CommonUtil;
import cn.gistack.nky.entity.ArimaPredict;
import cn.gistack.nky.mapper.ArimaPredictMapper;
import cn.gistack.nky.requestpojo.ArimaPredictReqPo;
import cn.gistack.nky.requestpojo.QueryReqPo;
import cn.gistack.nky.resultpojo.DataResChildrenPo;
import cn.gistack.nky.service.IArimaPredictService;
import cn.gistack.nky.service.INkyService;
import cn.gistack.nky.service.IZtApiService;
import cn.gistack.nky.vo.ArimaPredictVO;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
@AllArgsConstructor
public class ArimaPredictServiceImpl extends ServiceImpl<ArimaPredictMapper, ArimaPredict> implements IArimaPredictService {
    private final INkyService nkyService;
    private final IZtApiService ztApiService;
 
    @Override
    public void getData(String type) {
        List<DataResChildrenPo> cdList = getCdList(type);
        cdList.forEach(dataResChildrenPo -> {
                //循环请求预测结果
                QueryReqPo queryReqPo = new QueryReqPo(dataResChildrenPo,type);
                //请求预测结果
                ArimaPredict arimaPredict = nkyService.arimaQuery(queryReqPo);
                if (arimaPredict != null){
                    //存储预测结果至数据库
                    save(arimaPredict);
                }
        });
    }
 
    @Override
    public void predictData(String type) {
        List<DataResChildrenPo> cdList = getCdList(type);
 
        if (type.equals("1")){
            //渗压
                cdList.forEach(dataResChildrenPo -> {
                    ArimaPredictReqPo arimaPredictReqPo = new ArimaPredictReqPo(dataResChildrenPo, type);
                    //循环预测请求
                    nkyService.arimaPredict(arimaPredictReqPo);
                });
        }else if (type.equals("2")){
            //渗流
            cdList.forEach(dataResChildrenPo -> {
                ArimaPredictReqPo arimaPredictReqPo = new ArimaPredictReqPo(dataResChildrenPo, type);
                //循环预测请求
                nkyService.arimaPredict(arimaPredictReqPo);
            });
        }else if (type.equals("3") || type.equals("4") || type.equals("5")){
            cdList.forEach(dataResChildrenPo -> {
                //循环预测请求
                ArimaPredictReqPo arimaPredictReqPoX = new ArimaPredictReqPo(dataResChildrenPo, "3");
                nkyService.arimaPredict(arimaPredictReqPoX);
 
                ArimaPredictReqPo arimaPredictReqPoY = new ArimaPredictReqPo(dataResChildrenPo, "4");
                nkyService.arimaPredict(arimaPredictReqPoY);
 
                ArimaPredictReqPo arimaPredictReqPoZ = new ArimaPredictReqPo(dataResChildrenPo, "5");
                nkyService.arimaPredict(arimaPredictReqPoZ);
            });
        }
 
 
    }
 
    @Override
    public List<ArimaPredictVO> getFutureData(String resCd, String type) {
        List<ArimaPredictVO> futureData = new ArrayList<>();
        if (type.equals("3")){
            //位移另一张表
            futureData=baseMapper.getFutureDataWy(resCd,type);
        }else{
             futureData = baseMapper.getFutureData(resCd, type);
        }
 
        futureData.forEach(arimaPredict -> {
            arimaPredict.setPredicts(JSON.parse(arimaPredict.getPredicts().toString()));
        });
        return futureData;
    }
 
    @Override
    public boolean save(ArimaPredict entity) {
 
        if (ObjectUtil.isEmpty(entity.getId())){
            return false;
        }
 
        List<ArimaPredict> 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;
        }
        List<DataResChildrenPo> filterList = filterTimeList(cdList, 24);
        return filterList;
    }
 
    /**
     * 筛选时间内的集合
     * @param sourceList
     * @param timeGap
     * @return
     */
    public List<DataResChildrenPo> filterTimeList(List<DataResChildrenPo> sourceList,Integer timeGap){
        //当前时间的时间戳
        Long todayTimeStamp = DateUtil.now().getTime();
 
        //过去时间的时间戳
        Long beforeTimeStamp = todayTimeStamp - 1000*60*60*timeGap;
 
        //过去时间的日期
        Date beforeDate = new Date(beforeTimeStamp);
 
        List<DataResChildrenPo> collect = sourceList.stream().filter(item -> CommonUtil.strToDate(item.getTm()).after(beforeDate)).collect(Collectors.toList());
 
        return collect;
    }
}