7.1
15832144755
2021-07-01 ba21fcf8482029f7634b62d60daf171538001769
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
package com.hxzkoa.controller;
 
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.hxzkoa.json.tb_historyinwarning;
import com.hxzkoa.json.tb_realinwarning;
import com.hxzkoa.json.tb_realkaoqing;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.json.tb_warning;
import com.hxzkoa.services.WarningService;
import com.hxzkoa.udp.GetNowTime;
import com.hxzkoa.udp.Udp_Out;
/*import com.hxzkoa.udp.Udp_Receive;*/
import com.hxzkoa.util.Config;
import com.hxzkoa.util.ExcelUtils;
import com.hxzkoa.util.HttpUtil;
import com.hxzkoa.util.ModifyConfig;
import com.hxzkoa.util.PageUtil;
import com.hxzkoa.util.RequestUtils;
 
import net.sf.json.JSONObject;
 
@Controller
public class WarningController {
    @Autowired
    private WarningService warningService;
 
    @RequestMapping(value = "/warningSummary.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String warningSummary(HttpServletRequest request) {
        String toPage = "forward:/hxzk/warning/warningSummary.jsp";
        List<tb_warning> warningSummaryList = warningService.getWarningSummary(1);
        request.setAttribute("warningSummaryList", warningSummaryList);
        int curPage = 1;
        int count = warningService.getWarningSummaryCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        return toPage;
    }
 
    @ResponseBody
    @RequestMapping(value = "/warningSummary_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String warningSummary_search(HttpServletRequest request) throws IOException {
        JSONObject json = new JSONObject();
        String input = request.getParameter("input");
        if (("").equals(input) || input == null) {
            String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
            tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
            input = tag.getTag_id();
            List<tb_warning> warningSummaryList = warningService.searchWarningSummary(input);
            if (warningSummaryList.size()>0){
                json.put("result", warningSummaryList.get(0));
            } else {
                json.put("result", "null");
            }
        } else {
            int curPage = 1;
            List<Integer> pageList = new ArrayList<Integer>();
            List<tb_warning> warningSummaryList = warningService.searchWarningSummary(input);
            pageList.add(1);
            json.put("dataList", warningSummaryList);
            json.put("pageList", pageList);
            json.put("curPage", curPage);
        }
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/warningSummary_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String warningSummary_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = warningService.getWarningSummaryCount();
        int minPage = PageUtil.getMinPage(count);
        int curPage = Integer.parseInt(curPageStr);
        int page = 1;
        if ("pre".equals(pageStr)) {
            if (curPage > 1) {
                page = curPage - 1;
            }
        } else if ("next".equals(pageStr)) {
            if (curPage < minPage) {
                page = curPage + 1;
            }
        } else {
            page = Integer.parseInt(pageStr);
        }
        List<tb_warning> labelManagementList = warningService.getWarningSummary(page);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", labelManagementList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/warningSummary_export.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String warningSummary_export(HttpServletRequest request, HttpServletResponse response) {
        String toPage = "forward:/hxzk/label/labelManagement.jsp";
        List<tb_warning> tb_warningList = warningService.getWarningSummary();
        String[] rowName = { "序号", "警告类型", "设备ID", "处理情况", "更新时间" };
        List<Object[]> dataList = objectToArray_warningSummary(tb_warningList);
        ExcelUtils excel = new ExcelUtils("告警汇总", rowName, dataList);
        OutputStream out;
        try {
            String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
            String headStr = "attachment; filename=\"" + fileName + "\"";
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setHeader("Content-Disposition", headStr);
            out = response.getOutputStream();
            excel.export(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toPage;
    }
 
    // tb_warning 导出表格 对象转数组
    public static List<Object[]> objectToArray_warningSummary(List<tb_warning> tb_warningList) {
        List<Object[]> reList = new ArrayList<>();
        for (int i = 0; i < tb_warningList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_warning warn = (tb_warning) tb_warningList.get(i);
            words.add(warn.getId() + "");
            words.add(warn.getType());
            words.add(warn.getObjectid());
            words.add(warn.getStatus());
            words.add(warn.getTime());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
        }
        return reList;
    }
 
    @RequestMapping(value = "/realTimeWarning.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String realTimeWarning(HttpServletRequest request) {
        String toPage = "forward:/hxzk/warning/realTimeWarning.jsp";
        List<tb_realinwarning> realTimeWarningList = warningService.getRealinWarning(1);
        request.setAttribute("realTimeWarningList", realTimeWarningList);
        int curPage = 1;
        int count = warningService.getRealinWarningCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        return toPage;
    }
 
    @ResponseBody
    @RequestMapping(value = "/realTimeWarning_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void realTimeWarning_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        warningService.realinWarning_delete(checkVal);
    }
 
    @ResponseBody
    @RequestMapping(value = "/realTimeWarning_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void realTimeWarning_deleteAll(HttpServletRequest request) {
        warningService.realinWarning_deleteAll();
    }
 
    @ResponseBody
    @RequestMapping(value = "/realTimeWarning_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String realTimeWarning_search(HttpServletRequest request) throws IOException {
        JSONObject json = new JSONObject();
        String input = request.getParameter("input");
        if (("").equals(input) || input == null) {
            String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
            tb_tag tag = (tb_tag) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_tag.class);
            input = tag.getTag_id();
            List<tb_realinwarning> realTimeWarningList = warningService.searchRealinWarning(input);
            if (realTimeWarningList.size()>0){
                json.put("result", realTimeWarningList.get(0));
            } else {
                json.put("result", "null");
            }
        } else {
            int curPage = 1;
            List<Integer> pageList = new ArrayList<Integer>();
            List<tb_realinwarning> realTimeWarningList = warningService.searchRealinWarning(input);
            pageList.add(1);
            json.put("dataList", realTimeWarningList);
            json.put("pageList", pageList);
            json.put("curPage", curPage);
        }
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/realTimeWarning_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String realTimeWarning_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = warningService.getRealinWarningCount();
        int minPage = PageUtil.getMinPage(count);
        int curPage = Integer.parseInt(curPageStr);
        int page = 1;
        if ("pre".equals(pageStr)) {
            if (curPage > 1) {
                page = curPage - 1;
            }
        } else if ("next".equals(pageStr)) {
            if (curPage < minPage) {
                page = curPage + 1;
            }
        } else {
            page = Integer.parseInt(pageStr);
        }
        List<tb_realinwarning> realTimeWarningList = warningService.getRealinWarning(page);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", realTimeWarningList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/realTimeWarning_export.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String realTimeWarning_export(HttpServletRequest request, HttpServletResponse response) {
        String toPage = "forward:/hxzk/warning/realTimeWarning.jsp";
        List<tb_realinwarning> realinWarningList = warningService.getRealinWarning();
        String[] rowName = { "区域", "名称", "部门", "标签ID", "进入时间" };
        List<Object[]> dataList = objectToArray_realTimeWarning(realinWarningList);
        ExcelUtils excel = new ExcelUtils("实时告警", rowName, dataList);
        OutputStream out;
        try {
            String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
            String headStr = "attachment; filename=\"" + fileName + "\"";
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setHeader("Content-Disposition", headStr);
            out = response.getOutputStream();
            excel.export(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toPage;
    }
 
    // tb_realinwarning 导出表格 对象转数组
    public static List<Object[]> objectToArray_realTimeWarning(List<tb_realinwarning> realinWarningList) {
        List<Object[]> reList = new ArrayList<>();
        for (int i = 0; i < realinWarningList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_realinwarning warn = (tb_realinwarning) realinWarningList.get(i);
            words.add(warn.getArea());
            words.add(warn.getName());
            words.add(warn.getBumen());
            words.add(warn.getTagid());
            words.add(warn.getIntime());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
        }
        return reList;
    }
 
    @RequestMapping(value = "/historicalWarning.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String historicalWarning(HttpServletRequest request) {
        String toPage = "forward:/hxzk/warning/historicalWarning.jsp";
        List<tb_historyinwarning> historicalWarningList = warningService.getHistoricalWarning(1);
        request.setAttribute("historicalWarningList", historicalWarningList);
        int curPage = 1;
        int count = warningService.getHistoricalWarningCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        return toPage;
    }
 
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void historicalWarning_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        warningService.historicalWarning_delete(checkVal);
    }
    
    @ResponseBody
    @RequestMapping(value = "/Warning_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void Warning_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        String tagids = request.getParameter("tagids");
        String types = request.getParameter("types");
        checkValStr = checkValStr.replaceAll("\"", "");
        tagids = tagids.replaceAll("\"", "");
        types = types.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        String[] tagid = tagids.split(",");
        String[] typess = types.split(",");
        warningService.Warning_delete(checkVal);
        for (int i = 0; i < tagid.length; i++) {
            String xieyi = "BSTOCS1,DELETEWARN," +tagid[i]+ "," +typess[i]+ ",END";
            Udp_Out.udp_to_cs(xieyi);
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void historicalWarning_deleteAll(HttpServletRequest request) {
        warningService.historicalWarning_deleteAll();
    }
    
    @ResponseBody
    @RequestMapping(value = "/Warning_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void Warning_deleteAll(HttpServletRequest request) {
        warningService.Warning_deleteAll();
        String xieyi = "BSTOCS1,DELETEWARNALL,END";
        Udp_Out.udp_to_cs(xieyi);
    }
 
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_search.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String historicalWarning_search(HttpServletRequest request) {
        String input = request.getParameter("input");
        int curPage = 1;
        List<Integer> pageList = new ArrayList<Integer>();
        List<tb_historyinwarning> historicalWarningList = warningService.searchHistoricalWarning(input);
        pageList.add(1);
        JSONObject json = new JSONObject();
        json.put("dataList", historicalWarningList);
        json.put("pageList", pageList);
        json.put("curPage", curPage);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String labelManagement_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = warningService.getHistoricalWarningCount();
        int minPage = PageUtil.getMinPage(count);
        int curPage = Integer.parseInt(curPageStr);
        int page = 1;
        if ("pre".equals(pageStr)) {
            if (curPage > 1) {
                page = curPage - 1;
            }
        } else if ("next".equals(pageStr)) {
            if (curPage < minPage) {
                page = curPage + 1;
            }
        } else {
            page = Integer.parseInt(pageStr);
        }
        List<tb_historyinwarning> historyinwarningList = warningService.getHistoricalWarning(page);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", historyinwarningList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
 
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_export.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String historicalWarning_export(HttpServletRequest request, HttpServletResponse response) {
        String toPage = "forward:/hxzk/warning/historicalWarning.jsp";
        List<tb_historyinwarning> historyinwarningList = warningService.getHistoricalWarning();
        String[] rowName = { "序号", "区域", "名称", "部门", "标签ID", "进入时间", "出去时间", "停留时长", "备注" };
        List<Object[]> dataList = objectToArray_historicalWarning(historyinwarningList);
        ExcelUtils excel = new ExcelUtils("历史告警", rowName, dataList);
        OutputStream out;
        try {
            String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
            String headStr = "attachment; filename=\"" + fileName + "\"";
            response.setContentType("APPLICATION/OCTET-STREAM");
            response.setHeader("Content-Disposition", headStr);
            out = response.getOutputStream();
            excel.export(out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return toPage;
    }
 
    // tb_historyinwarning 导出表格 对象转数组
    public static List<Object[]> objectToArray_historicalWarning(List<tb_historyinwarning> historyinwarningList) {
        List<Object[]> reList = new ArrayList<>();
        for (int i = 0; i < historyinwarningList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_historyinwarning warn = (tb_historyinwarning) historyinwarningList.get(i);
            words.add(warn.getId() + "");
            words.add(warn.getArea());
            words.add(warn.getName());
            words.add(warn.getBumen());
            words.add(warn.getTagid());
            words.add(warn.getIntime());
            words.add(warn.getOuttime());
            words.add(warn.getAlltime());
            words.add(warn.getBeizhu());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
        }
        return reList;
    }
    
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_handle.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void historicalWarning_handle(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        String types = request.getParameter("types");
        types = types.replaceAll("\"", "");
        String[] typess = types.split(",");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        warningService.historicalWarning_handle(checkVal);
        for (int i = 0; i < checkVal.length; i++) {
            String xieyi = "BSTOCS1,DELLWARN," +checkVal[i]+ "," +typess[i]+ ",END";
            Udp_Out.udp_to_cs(xieyi);
        }
    }
    
    @ResponseBody
    @RequestMapping(value = "/historicalWarning_handleAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void historicalWarning_handleAll(HttpServletRequest request) {
        warningService.historicalWarning_handleAll();
        warningService.historicalWarning_handleAll_realpositoin();
        String xieyi = "BSTOCS1,DELLWARNALL,END";
        Udp_Out.udp_to_cs(xieyi);
    }
 
    @RequestMapping(value = "/warning_bw_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void warning_bw_add(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_warning warning = (tb_warning) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_warning.class);
        //显示sql
        String sqlString = "INSERT tb_warning (type,objectid,status,time) VALUES ("+warning.getType()+","+warning.getObjectid()+","+warning.getStatus()+","+GetNowTime.timestamp2()+")";
        String messageJson = GetNowTime.timestamp2()+ " 收:"+ sqlString ;
        String BaowenPath = Config.getBaowenConfig();
        String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
        if (baowenStatus.equals("1")){
            /* Udp_Receive.mysqlMessage.add(messageJson); */
        }
        //
        warningService.warning_add(warning);
    }
 
    @RequestMapping(value = "/realinwarning_bw_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void realinwarning_bw_add(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_realinwarning realinwarning = (tb_realinwarning) JSONObject.toBean(JSONObject.fromObject(jsonString),
                tb_realinwarning.class);
        //显示sql
        String sqlString =  "INSERT tb_realinwarning (area,name,bumen,tagid,intime) VALUES ("+realinwarning.getArea()+","+realinwarning.getName()+","+realinwarning.getBumen()+","+realinwarning.getTagid()+","+GetNowTime.timestamp2()+")";
        String messageJson = GetNowTime.timestamp2()+ " 收:"+ sqlString ;
        String BaowenPath = Config.getBaowenConfig();
        String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
        if (baowenStatus.equals("1")){
            /* Udp_Receive.mysqlMessage.add(messageJson); */
        }
        //
        warningService.realinwarning_add(realinwarning);
    }
 
    @RequestMapping(value = "/realinwarning_bw_remove.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void realinwarning_bw_remove(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_realinwarning realinwarning = (tb_realinwarning) JSONObject.toBean(JSONObject.fromObject(jsonString),
                tb_realinwarning.class);
        //显示sql
        String sqlString =  "DELETE FROM tb_realinwarning WHERE id = " + realinwarning.getId();
        String messageJson =  GetNowTime.timestamp2()+ " 收:"+ sqlString ;
        String BaowenPath = Config.getBaowenConfig();
        String baowenStatus = ModifyConfig.readData(BaowenPath, "baowenSwitch");
        if (baowenStatus.equals("1")){
            /* Udp_Receive.mysqlMessage.add(messageJson); */
        }
        //
        String[] checkVal = { realinwarning.getTagid() };
        warningService.realinWarning_delete(checkVal);
    }
}