guoshilong
2024-04-28 90cc59400715f3ece6384eddf01cefd8eff449ea
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
package cn.gistack.nky.feign;
 
import cn.gistack.nky.entity.AlarmGet;
import cn.gistack.nky.fegin.INkyClient;
import cn.gistack.nky.resultpojo.BaseCd;
import cn.gistack.nky.resultpojo.NkyBindDetailResult;
import cn.gistack.nky.resultpojo.ResDamMonitorResult;
import cn.gistack.nky.service.*;
import cn.gistack.nky.vo.AlarmGetVO;
import cn.gistack.nky.vo.PageVO;
import cn.gistack.sm.patrol.feign.PatrolTaskClient;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
 
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
@NonDS
@ApiIgnore
@RestController
@AllArgsConstructor
@Slf4j
public class NkyClientImpl implements INkyClient {
 
    private final INkyService nkyService;
    private final IArimaPredictService arimaPredictService;
    private final IHstPredictService hstPredictService;
    private final IAlarmGetService alarmGetService;
    private final PatrolTaskClient patrolTaskClient;
    private final IZtApiService ztApiService;
 
 
    @Override
    @GetMapping(GET_ARIMA_DATA)
    public void arimaQueryData(String type) {
        arimaPredictService.getData(type);
    }
 
    @Override
    @GetMapping(PREDICT_ARIMA_DATA)
    public void arimaPredictData(String type) {
        arimaPredictService.predictData(type);
    }
 
    @Override
    @GetMapping(GET_HST_DATA)
    public void hstQueryData(String type) {
        hstPredictService.getData(type);
    }
 
    @Override
    @GetMapping(PREDICT_HST_DATA)
    public void hstPredictData(String type) {
        hstPredictService.predictData(type);
    }
 
    @Override
    @GetMapping(GET_BATCH_DATA)
    public void batchData(String type) {
        alarmGetService.batchData(type);
    }
 
    @Override
    @GetMapping(ALARM_GET_DATA)
    public void alarmGetData(String type) {
        alarmGetService.alarmGetData(type);
    }
 
    @Override
    @PostMapping(GET_ALARM_DETAIL)
    public List<AlarmGetVO> getAlarmDetail(AlarmGetVO alarmGet) {
        return alarmGetService.getAlarmDetail(alarmGet);
    }
 
    @Override
    @PostMapping(GET_ALARM_DETAIL_PAGE)
    public PageVO<AlarmGetVO> getAlarmDetailPage(Integer current, Integer size, AlarmGetVO alarmGet,
                                                 String ascs,
                                                 String descs) {
        Query query = new Query();
        query.setCurrent(current);
        query.setSize(size);
        query.setAscs(ascs);
        query.setDescs(descs);
        IPage<AlarmGetVO> alarmDetailPage = alarmGetService.getAlarmDetailPage(Condition.getPage(query), alarmGet);
 
        PageVO<AlarmGetVO> pageVO = new PageVO();
 
        pageVO.setData(alarmDetailPage.getRecords());
        pageVO.setTotal(alarmDetailPage.getTotal());
        pageVO.setCurrent(alarmDetailPage.getCurrent());
        pageVO.setSize(alarmDetailPage.getSize());
 
        return pageVO;
    }
 
    @Override
    @PostMapping(UPDATE_ALARM_GET)
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateAlarmGet(AlarmGetVO alarmGet) {
        //修改处置状态
        AlarmGetVO byId = alarmGetService.getAlarmVO(alarmGet);
 
        String processDefinitionId = "c2d5326e-e27b-11ed-a04e-00ff0b362ee4";
 
        //日常巡查
        String taskType = "1641037874390999041";
 
        //杨树堰水库大坝预警巡查
        String title = StringUtil.format("{}大坝预警巡查", byId.getReservoirName());
 
        //杨树堰水库在2023-11-29 17:41:19时监测到位移GN1测点,测点值为2.37,预警等级为三级
 
        String resNm = byId.getReservoirName();
        String tm = DateUtil.format(byId.getTime(), "MM月dd日HH时mm分");
        String typeName = byId.getTypeName();
        String cdNm = byId.getCdName();
        String value = byId.getValue();
        String level = String.valueOf(byId.getLevel());
 
        String content = StringUtil.format("{}在{}时监测到{}{}测点值为{},预警等级为{}级",
            resNm, tm, typeName, cdNm, value, level);
        String resCd = byId.getDamId();
 
        //创建巡查任务
        String taskId = patrolTaskClient.createTask(processDefinitionId, taskType, title, content, resCd);
        alarmGet.setTaskId(taskId);
        return alarmGetService.updateById(alarmGet);
    }
 
    @Override
    @PostMapping(UPDATE_ALARM_GET_STATUS)
    public Boolean updateStatus(AlarmGet alarmGet) {
        return alarmGetService.updateById(alarmGet);
    }
 
    @Override
    @GetMapping(FINISH_TASK)
    public Boolean finishTask(String taskId) {
 
        AlarmGet alarmGet = alarmGetService.getOne(new QueryWrapper<AlarmGet>().eq("TASK_ID", taskId));
 
        if (alarmGet != null) {
            //设置预警为已处理
            alarmGet.setStatus("1");
            Boolean aBoolean = updateStatus(alarmGet);
            return aBoolean;
        }
        return false;
    }
 
    @Override
    @PostMapping(INIT_ALGORITHM)
    public void initAlgorithm(List<String> resList) {
        List<ResDamMonitorResult> resDamMonitorResultList = ztApiService.getResDamMonitor();
        //获取水库之后,根据标识是否有监测站请求测点
        resDamMonitorResultList.forEach(resDamMonitorResult -> {
            String resGuid = resDamMonitorResult.getCode();
            if (resDamMonitorResult.getIs_sy().equals("1")){
                activeAlgorithm(resGuid,"sy","1");
            }
            if (resDamMonitorResult.getIs_sl().equals("1")){
                activeAlgorithm(resGuid,"sl","2");
            }
            if (resDamMonitorResult.getIs_wy().equals("1")){
                activeAlgorithm(resGuid,"wy","3,4,5");
            }
        });
    }
 
    private void activeAlgorithm(String resGuid,String type,String nkyType){
        String taskCategory = "2107";
        List<BaseCd> cdList = ztApiService.getBaseCd(resGuid,type);
        List<String> nkyTypeList = Arrays.asList(nkyType.split(","));
 
 
        cdList.forEach(baseCd -> {
            String pointId = baseCd.getCd();
 
            nkyTypeList.forEach(nkyTypeFlag->{
 
                //请求测点之后,循环测点,判断算法绑定情况
                List<NkyBindDetailResult> nkyBindDetailResultList = nkyService.getBindDetail(baseCd.getRes_cd(),baseCd.getCd(),nkyTypeFlag);
                //过滤出   多元线性回归预测模型异常判定  algorithmCategory: 2107
                List<NkyBindDetailResult> filterCollect = nkyBindDetailResultList.stream().filter(nkyBindDetailResult -> nkyBindDetailResult.getAlgorithmCategory().equals(taskCategory)).collect(Collectors.toList());
 
                if (filterCollect.size() == 0){
                    //如果是空的,说明没有启用该算法;先启用该算法
//                    JSONObject bindEnableParams = new JSONObject();
//
//                    bindEnableParams.put("status",1);
//                    bindEnableParams.put("taskCategory",taskCategory);
//                    bindEnableParams.put("damId",resGuid);
//                    bindEnableParams.put("pointId",pointId);
//                    bindEnableParams.put("type",nkyTypeFlag);
//                    boolean bindEnableRes = nkyService.bindEnable(bindEnableParams);
//                    //成功启用,设置值
//                    if (bindEnableRes){
//
//                        JSONObject bindParamParams = new JSONObject();
//
//                        bindParamParams.put("damId",resGuid);
//                        bindParamParams.put("pointId",pointId);
//                        bindParamParams.put("type",nkyTypeFlag);
//                        bindParamParams.put("algorithmCategory",taskCategory);
//                        bindParamParams.put("reserve1","4,3.3,2.7,2");
//
//                        boolean bindParamRes = nkyService.bindParam(bindParamParams);
//                    }
 
                }
            });
        });
    }
 
}