guoshilong
2023-08-03 dadbaf3ce1e06a9ad84c66b0a7fe5fc3dfa39313
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
package cn.gistack.nky.service.impl;
 
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.cj.util.StringUtils;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
@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);
        cdList.forEach(dataResChildrenPo -> {
            ArimaPredictReqPo arimaPredictReqPo = new ArimaPredictReqPo(dataResChildrenPo, type);
            //循环预测请求
            nkyService.arimaPredict(arimaPredictReqPo);
        });
    }
 
    @Override
    public boolean save(ArimaPredict entity) {
 
        if (ObjectUtil.isEmpty(entity.getId())){
            return false;
        }
 
        //遍历表中当前水库,当前测点,当前类型的数据,检查是否有重复数据
        ArimaPredict params = new ArimaPredict();
        params.setDamId(entity.getDamId());
        params.setPointId(entity.getPointId());
        params.setType(entity.getType());
        params.setCreateTime(entity.getCreateTime());
 
        List<ArimaPredict> list = list(Condition.getQueryWrapper(params));
 
        if (list.size()>0){
            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")){
            //获取渗流测点
            return null;
        }else if (type.equals("3") || type.equals("4") || type.equals("5")){
            //获取位移测点
            cdList = ztApiService.getWy();
        }else {
            return null;
        }
        return cdList;
    }
}