15832144755
2021-11-18 37336922a1df99ac1636e398e12e64dedfba10e5
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
package com.hxzkoa.controller;
 
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
 
import com.hxzkoa.json.httpsos;
import com.hxzkoa.json.tb_achor;
import com.hxzkoa.json.tb_fence;
import com.hxzkoa.json.tb_fence_inout;
import com.hxzkoa.json.tb_gas;
import com.hxzkoa.json.tb_gps;
import com.hxzkoa.json.tb_map;
import com.hxzkoa.json.tb_person;
import com.hxzkoa.json.tb_qihou;
import com.hxzkoa.json.tb_realkaoqing;
import com.hxzkoa.json.tb_realocation;
import com.hxzkoa.json.tb_realpositoin;
import com.hxzkoa.json.tb_shipin;
import com.hxzkoa.json.tb_system;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.json.tb_track;
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.services.ZhwService;
import com.hxzkoa.services.AnchorService;
import com.hxzkoa.udp.Dell_Ip;
import com.hxzkoa.udp.GetNowTime;
import com.hxzkoa.udp.ReadPeizhiMessage;
import com.hxzkoa.udp.Read_Write_Anchor_Message;
import com.hxzkoa.udp.Udp_Out;
import com.hxzkoa.util.BytesToHex;
import com.hxzkoa.util.Config;
import com.hxzkoa.util.ExcelUtils;
import com.hxzkoa.util.ModifyConfig;
import com.hxzkoa.util.PageUtil;
import com.hxzkoa.util.RequestUtils;
import com.hxzkoa.util.ResourceUtils;
 
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import net.sf.json.JSONObject;
 
 
@Controller
public class ZhwController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public static String MSG_LOGIN_FAIL = ResourceUtils
            .getString("msg.login.fail");
 
    @Autowired
    private ZhwService ZhwService;
    @Autowired
    private SysSettingService sysSettingService; 
    @Autowired
    private AnchorService AnchorService; 
    
    httpsos sos = new httpsos();
    
    @RequestMapping(value = "/drawFence_init.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String drawFence_init(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String toPage = "forward:/hxzk/fence/drawFence.jsp";
        List<tb_map> floorList = ZhwService.getFloor();
        request.setAttribute("floorList", floorList);
        return toPage;
    }
    
    @RequestMapping(value = "/drawFence.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String drawFence(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String floor_number = request.getParameter("value");
        String toPage = "forward:/hxzk/fence/drawFence.jsp";
        List<tb_map> mapList = ZhwService.getMap(floor_number);
        request.setAttribute("value", mapList);
        request.getRequestDispatcher(toPage).forward(request, response);
        return toPage;
    }
    
    @RequestMapping(value="/floornumTomap.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_map> floorNumtoMap(HttpServletRequest request) {  
        String floor_number = request.getParameter("value");
        final List<tb_map> mapList = ZhwService.getMap(floor_number);
        return mapList;
    }
    
    @RequestMapping(value="/floornumTomap_all.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_map> floornumTomap_all(HttpServletRequest request) {  
        final List<tb_map> mapList = ZhwService.getMap_all();
        return mapList;
    }
    
    @RequestMapping(value="/getFloorByMapname.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_map> getFloorByMapname(HttpServletRequest request) {  
        String mapname = request.getParameter("map");
        final List<tb_map> mapList = ZhwService.getFloorByMapname(mapname);
        return mapList;
    }
    
    @RequestMapping(value="/getFloorFence.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_fence> getFloorFence(HttpServletRequest request) {  
        String floor_number = request.getParameter("value");
        final List<tb_fence> fenceList = ZhwService.getFence(floor_number);
        return fenceList;
    }
    
    @RequestMapping(value="/getFloorFence_all.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_fence> getFloorFence_all(HttpServletRequest request) {  
        final List<tb_fence> fenceList = ZhwService.getFence_all();
        return fenceList;
    }
    
    @RequestMapping(value="/getGas_list.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_gas> getGas_list(HttpServletRequest request) {  
        final List<tb_gas> fenceList = ZhwService.getGas();
        return fenceList;
    }
    
    @RequestMapping(value = "/saveFence.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public int drawFence_add(HttpServletRequest request) {
        tb_fence fence = new tb_fence();
        String layer = request.getParameter("layer");
        if(!layer.equals("百度地图")) {
            Integer layerjj = Integer.parseInt(layer);  
            layer = layerjj.toString();
        }
        fence.setFloor(layer);
        fence.setType(request.getParameter("weilanleixing"));
        fence.setBumen(request.getParameter("guanlianduixiang"));
        fence.setName(request.getParameter("quyumingcheng"));
        
        String zuobiao =(String) request.getParameter("zuobiao");
        fence.setZuobiao(zuobiao);
        
        fence.setShape(request.getParameter("xingzhuang"));
        
        String start = "00:00:00";
        String end = "23:59:59";
        fence.setStart(start);
        fence.setStop(end);
        
        fence.setColor(request.getParameter("yanse"));
        ZhwService.drawFence_add(fence);
        String xieyi = "BSTOCS1,ADDFENCE,"+fence.getFloor()+","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao()+","+fence.getShape()+","+fence.getStart()+","+fence.getStop()+","+GetNowTime.now()+","+fence.getColor()+",END";
        Udp_Out.udp_to_cs(xieyi);
        
        String type = request.getParameter("weilanleixing");
        String name = request.getParameter("quyumingcheng");
        String floor = request.getParameter("layer");
        String shape = request.getParameter("xingzhuang");
        
        if(type.equals("巡检区域")) {
            ZhwService.xunjianSet_add(name);
        } else if (type.equals("定位区域")) {
            String[] zb_list = zuobiao.split(",");
            String zb_inout = "";
            for (int i=0;i<zb_list.length;i++) {
                zb_inout += zb_list[i];
                if (i%2==0) {
                    zb_inout += ",";
                } else if (i%2==1 && i!=zb_list.length-1) {
                    zb_inout += ";";
                }
            }
            ZhwService.fenceInout_add(name,zb_inout,shape,floor);
        }
        
        return 0;
    }
    
    @RequestMapping(value = "/sanweiFence.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public int sanweiFence_add(HttpServletRequest request) {
        tb_fence fence = new tb_fence();
        String layer = request.getParameter("layer");
        if(!layer.equals("百度地图")) {
            Integer layerjj = Integer.parseInt(layer);  
            layer = layerjj.toString();
        }
        fence.setFloor(layer);
        fence.setType(request.getParameter("weilanleixing"));
        fence.setBumen(request.getParameter("guanlianduixiang"));
        fence.setName(request.getParameter("quyumingcheng"));
        fence.setBaoliu1(request.getParameter("fencegao"));
        String zuobiao =(String) request.getParameter("zuobiao");
        fence.setZuobiao(zuobiao);
        
        fence.setShape(request.getParameter("xingzhuang"));
        
        String start = "00:00:00";
        String end = "23:59:59";
        fence.setStart(start);
        fence.setStop(end);
        
        fence.setColor(request.getParameter("yanse"));
        ZhwService.sanweiFence_add(fence);
        String xieyi = "BSTOCS1,ADDFENCE,"+fence.getFloor()+","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao()+","+fence.getShape()+","+fence.getStart()+","+fence.getStop()+","+GetNowTime.now()+","+fence.getColor()+",END";
        Udp_Out.udp_to_cs(xieyi);
        
        String type = request.getParameter("weilanleixing");
        String name = request.getParameter("quyumingcheng");
        String floor = request.getParameter("layer");
        String shape = request.getParameter("xingzhuang");
        
        if(type.equals("巡检区域")) {
            ZhwService.xunjianSet_add(name);
        } else if (type.equals("定位区域")) {
            String[] zb_list = zuobiao.split(",");
            String zb_inout = "";
            for (int i=0;i<zb_list.length;i++) {
                zb_inout += zb_list[i];
                if (i%2==0) {
                    zb_inout += ",";
                } else if (i%2==1 && i!=zb_list.length-1) {
                    zb_inout += ";";
                }
            }
            ZhwService.fenceInout_add(name,zb_inout,shape,floor);
        }
        
        return 0;
    }
    
    @RequestMapping(value = "/queryLocation.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String queryLocation(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String toPage = "forward:/hxzk/location/queryLocation.jsp";
        List<tb_map> floorList = ZhwService.getFloor();
        request.setAttribute("floorList", floorList);
        return toPage;
    }
    
    @RequestMapping(value="/trackTagid.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_track> queryTagid(HttpServletRequest request) throws ParseException {  
        String tag_id = request.getParameter("tag_value");
        String begin_time = request.getParameter("begin_value");
        String end_time = request.getParameter("end_value");
        String floor = request.getParameter("floor_value");
        final List<tb_track> tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
        return tagList;
    }
    
    @RequestMapping(value="/getRealPosition.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_realpositoin> getRealPosition(HttpServletRequest request) { 
        String floor = request.getParameter("floor");
        
        //根据时间筛选出数据
        List<tb_person> realLocationList = ZhwService.getpersonLocation(floor);
        
        List<tb_realpositoin> finalPositionList = new ArrayList<tb_realpositoin>();
        
        //根据每个tagid取tb_tag:[tag_id,state(静止1or运动0),power,status(在线1or离线0),addtime],放入tb_position中
        for (tb_person node : realLocationList) {
            String tagid = node.getP_tagid();
            tb_realpositoin position = new tb_realpositoin();
            position.setTagid(tagid);
            position.setPower(node.getP_power());
            position.setLife(node.getP_online());
            position.setName(node.getP_name());
            position.setPosx(node.getP_x());
            position.setPosy(node.getP_y());
            position.setSos(node.getP_sos());
            position.setTime(node.getP_addtiem());
            position.setFence(node.getP_fence());
            position.setSousuo(node.getP_sousuo());
            position.setShipin(node.getP_shipin());
            
            finalPositionList.add(position);
        }
        return finalPositionList;
    }
    
    @RequestMapping(value="/getRealPosition_all.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_realpositoin> getRealPosition_all(HttpServletRequest request) { 
        
        //根据时间筛选出数据
        List<tb_person> realLocationList = ZhwService.getpersonLocation_all();
        
        List<tb_realpositoin> finalPositionList = new ArrayList<tb_realpositoin>();
        
        //根据每个tagid取tb_tag:[tag_id,state(静止1or运动0),power,status(在线1or离线0),addtime],放入tb_position中
        for (tb_person node : realLocationList) {
            String tagid = node.getP_tagid();
            tb_realpositoin position = new tb_realpositoin();
            position.setTagid(tagid);
            position.setPower(node.getP_power());
            position.setLife(node.getP_online());
            position.setFloor(node.getP_floor());
            position.setName(node.getP_name());
            position.setPosx(node.getP_x());
            position.setPosy(node.getP_y());
            position.setSos(node.getP_sos());
            position.setTime(node.getP_addtiem());
            position.setFence(node.getP_fence());
            
            finalPositionList.add(position);
        }
        
        return finalPositionList;
    }
    
    @RequestMapping(value="/getRealTrack.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<ArrayList<tb_track>> getRealTrack(HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        String[] taglist = tagid.split(",");
        String floor = request.getParameter("floor");
        Long time_range = Long.parseLong(request.getParameter("time")) * 1000;// ms*1000=s
        long timeNow =  System.currentTimeMillis(); 
        long timeStart = timeNow - time_range;
//      long timeStart = 0;
        Timestamp ts=new Timestamp(timeStart);
        String start_str=ts.toString(); // start time string
        //start_str="2021-03-01 10:26:00";
    
        List<tb_track> realTrackList = ZhwService.getRealPosTrack(taglist, start_str, floor);
 
        //get all tag in a list
        List<String> tagList = new ArrayList<String>();
        for (tb_track node : realTrackList) {
            if (tagList.contains(node.getTagid())) {
                continue;
            } else {
                tagList.add(node.getTagid());
            }
        }
        
        // sort all track data by tagid
        List<ArrayList<tb_track>> tmpRealTrackList = new ArrayList<ArrayList<tb_track>>();
        List<ArrayList<tb_track>> finalRealTrackList = new ArrayList<ArrayList<tb_track>>();
 
        for (String tag : tagList) {
            tmpRealTrackList.add(new ArrayList<tb_track>());
        }
        for (tb_track node : realTrackList) {
            int index = tagList.indexOf(node.getTagid());
            tmpRealTrackList.get(index).add(node);
        }
        return tmpRealTrackList;
    }
    
    @RequestMapping(value="/getRealTrack_all.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_track> getRealTrack_all(HttpServletRequest request) {
        String tagid = request.getParameter("tagid");
        String[] taglist = tagid.split(",");
        Long time_range = Long.parseLong(request.getParameter("time")) * 1000;// ms*1000=s
        long timeNow =  System.currentTimeMillis(); 
        long timeStart = timeNow - time_range;
//      long timeStart = 0;
        Timestamp ts=new Timestamp(timeStart);
        String start_str=ts.toString(); // start time string
//      String start_str="2021-03-01 10:26:00";
    
        List<tb_track> realTrackList = ZhwService.getRealPosTrack_all(taglist, start_str);
        
//      List<tb_track> finalRealTrackList = new ArrayList<tb_track>();
        return realTrackList;
//      if (realTrackList.size()<=100) {
//          return realTrackList;
//      } else {
//          int lenth = realTrackList.size();
//          int interval = (int) Math.floor(lenth/100);
//          for (int i=0;i<lenth;i+=interval) {
//              finalRealTrackList.add(realTrackList.get(i));
//          }
//          return finalRealTrackList;
//      }
    }
    
    @RequestMapping(value = "/anchorConfiguration.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String anchorConfiguration(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String toPage = "forward:/hxzk/anchor/anchorConfiguration.jsp";
        List<tb_achor> anchorList = ZhwService.getAnchor();
        request.setAttribute("anchorList", anchorList);
        return toPage;
    }
    
    @RequestMapping(value="/getAnchorip.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_achor> getAnchorip(HttpServletRequest request) {  
        String anchorid = request.getParameter("anchorid");
        final List<tb_achor> anchoripList = ZhwService.getAnchorip(anchorid);
        return anchoripList;
    }
    
    @RequestMapping(value="/getSysSetting_list.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_system> getSysSetting_list(HttpServletRequest request) {
        List<tb_system> settingList = sysSettingService.getSetting();       
        return settingList;
    }
    
    @RequestMapping(value="/getAnchorInfo.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_achor> getAnchorInfo(HttpServletRequest request) { 
        String floor = request.getParameter("floor");
        final List<tb_achor> anchoripList = ZhwService.getAnchorInfo(floor);
        return anchoripList;
    }
    
    @RequestMapping(value="/getAnchorInfo_all.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_achor> getAnchorInfo_all(HttpServletRequest request) { 
        final List<tb_achor> anchoripList = ZhwService.getAnchorInfo_all();
        return anchoripList;
    }
    
    @RequestMapping(value="/getGPS.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_gps> getGPS(HttpServletRequest request) {  
        final List<tb_gps> gpsList = ZhwService.getGPS();
        long timeNow =  System.currentTimeMillis(); 
        long timeStart = timeNow - 1000; //取1s内最新的一条数据作为当前的实时位置,后期可更改,此处为ms单位
//      long timeStart = 0;
        
        List<tb_gps> finalGPSList = new ArrayList<tb_gps>();
        for ( tb_gps node : gpsList) {
            //仅取最新更新时间在当前时间十秒内的数据
//          String timeRecent = node.getAddtime();
//          Timestamp ts = Timestamp.valueOf(timeRecent);
//          long times = ts.getTime();
//          if (times >= timeStart) {
//          int jingdu = node.getGsp_jingdu().length();
//          //System.out.print("执行了"+jingdu);
            if (node.getGsp_jingdu() != null && !node.getGsp_jingdu().equals("00000.000000") && node.getGps_weidu() != null && !node.getGps_weidu().equals("00000.000000")) {
//              String weidu = node.getGps_weidu().substring(0,node.getGps_weidu().length()-1);
//              node.setGps_weidu(weidu);
//              String jingdu2 = node.getGsp_jingdu().substring(0, node.getGsp_jingdu().length()-1);
//              node.setGsp_jingdu(jingdu2);
                finalGPSList.add(node);
            }
//          String weidu = node.getGps_weidu().substring(0,node.getGps_weidu().length()-1);
//          node.setGps_weidu(weidu);
//          String jingdu = node.getGsp_jingdu().substring(0, node.getGsp_jingdu().length()-1);
//          node.setGsp_jingdu(jingdu);
//              finalGPSList.add(node);
//          }
        };
        return finalGPSList;
    }
    
    @RequestMapping(value="/getGPSTrack.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_gps> getGPSTrack(HttpServletRequest request) throws ParseException {  
        String tag_id = request.getParameter("tag_value");
        String begin_time = request.getParameter("begin_value");
        String end_time = request.getParameter("end_value");
        final List<tb_gps> finalGPSList = ZhwService.getGPStrack(tag_id, begin_time, end_time);
        return finalGPSList;
    }
    
    @RequestMapping(value="/qiehuanditu_option.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_map> qiehuanditu_option(HttpServletRequest request) {  
        List<tb_map> mapList = ZhwService.getFloor();
        return mapList;
    }
    
    @RequestMapping(value = "/qiehuanditu_save.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String qiehuanditu_save(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        //String toPage = "forward:/show.do";
        String map_now = request.getParameter("map_now");
        String filePath = Config.getMapConfig();
        ModifyConfig.writeData(filePath,"map_now",map_now);
        //System.out.print(ModifyConfig.readData(filePath, "map_now"));
        return "1";
    }
    
    @RequestMapping(value="/qiehuanditu_get.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> qiehuanditu_get(HttpServletRequest request) {  
//      String filePath = Config.getMapConfig();
//      String map = ModifyConfig.readData(filePath, "map_now");
//      List<String> maplist = new ArrayList<String>();
//      maplist.add(map);
//      //System.out.print("read data");
//      //System.out.print(map);
        List<tb_system> systemlist = sysSettingService.getSetting();
        List<String> maplist = new ArrayList<String>();
        String map = systemlist.get(0).getYulan_map();
        maplist.add(map);
        return maplist;
    }
    
    @RequestMapping(value = "/getAnchor_read_config.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void getAnchor_read_config(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        byte[] byt=Read_Write_Anchor_Message.ReadData((byte)0x2,(byte)0x50);
        System.out.println("读取配置信息:"+BytesToHex.bytesToHex(byt));
        String ip = request.getParameter("ip");
        List<tb_system> settingList = sysSettingService.getSetting();
        Udp_Out.out(byt, byt.length, ip, settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString()); //( , , ,udp_port, wifi_mode)
    }
    
    @RequestMapping(value = "/modify_anchor_version.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void modify_anchor_version(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        tb_achor anchor = (tb_achor) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_achor.class);
        AnchorService.anchorManagement_modify_ip_ver(anchor);
    }
    
    
    @RequestMapping(value="/read_anchor_config_done.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> read_anchor_config_done(HttpServletRequest request) {  
        String filePath = Config.getAnchorConfig();
        List<String> peizhilist = new ArrayList<String>();
        String peizhi = ModifyConfig.readData(filePath, "readpeizhi");
        peizhilist.add(peizhi);
        String shebeimoshi = ModifyConfig.readData(filePath, "shebeimoshi");
        peizhilist.add(shebeimoshi);
        String zhudongceju = ModifyConfig.readData(filePath, "zhudongceju");
        peizhilist.add(zhudongceju);
        String kaiqixintiao = ModifyConfig.readData(filePath, "kaiqixintiao");
        peizhilist.add(kaiqixintiao);
        String jizhanid = ModifyConfig.readData(filePath, "jizhanid");
        peizhilist.add(jizhanid);
        String fashegonglv = ModifyConfig.readData(filePath, "fashegonglv");
        peizhilist.add(fashegonglv);
        String wuchajiaozhun = ModifyConfig.readData(filePath, "wuchajiaozhun");
        peizhilist.add(wuchajiaozhun);
        String lvbocanshu = ModifyConfig.readData(filePath, "lvbocanshu");
        peizhilist.add(lvbocanshu);
        String tongxunxiaozu = ModifyConfig.readData(filePath, "tongxunxiaozu");
        peizhilist.add(tongxunxiaozu);
        String tongxunpinlv = ModifyConfig.readData(filePath, "tongxunpinlv");
        peizhilist.add(tongxunpinlv);
        String tongxunshangxian = ModifyConfig.readData(filePath, "tongxunshangxian");
        peizhilist.add(tongxunshangxian);
        String gujianbanben = ModifyConfig.readData(filePath, "gujianbanben");
        peizhilist.add(gujianbanben);
        String tongbujizhan = ModifyConfig.readData(filePath, "tongbujizhan");
        peizhilist.add(tongbujizhan);
        String tongbuleixing = ModifyConfig.readData(filePath, "tongbuleixing");
        peizhilist.add(tongbuleixing);
        String linjinjizhanshuliang = ModifyConfig.readData(filePath, "linjinjizhanshuliang");
        peizhilist.add(linjinjizhanshuliang);
        String linjinjizhan1 = ModifyConfig.readData(filePath, "linjinjizhan1");
        peizhilist.add(linjinjizhan1);
        String linjinjizhan2 = ModifyConfig.readData(filePath, "linjinjizhan2");
        peizhilist.add(linjinjizhan2);
        String linjinjizhan3 = ModifyConfig.readData(filePath, "linjinjizhan3");
        peizhilist.add(linjinjizhan3);
        String linjinjizhan4 = ModifyConfig.readData(filePath, "linjinjizhan4");
        peizhilist.add(linjinjizhan4);
        String linjinjizhan5 = ModifyConfig.readData(filePath, "linjinjizhan5");
        peizhilist.add(linjinjizhan5);
        String linjinjizhan6 = ModifyConfig.readData(filePath, "linjinjizhan6");
        peizhilist.add(linjinjizhan6);
        String linjinjizhan7 = ModifyConfig.readData(filePath, "linjinjizhan7");
        peizhilist.add(linjinjizhan7);
        String linjinjizhan8 = ModifyConfig.readData(filePath, "linjinjizhan8");
        peizhilist.add(linjinjizhan8);
        String qiehuanjuli = ModifyConfig.readData(filePath, "qiehuanjuli");
        peizhilist.add(qiehuanjuli);
        return peizhilist;
    }
    
    @RequestMapping(value="/modify_anchor_config_done.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> modify_anchor_config_done(HttpServletRequest request) {  
        String ip=request.getParameter("ip");
        String filePath = Config.getAnchorConfig();
        List<String> peizhilist = new ArrayList<String>();
        String peizhi = ModifyConfig.readData(filePath, "readpeizhi");
        if (peizhi.equals("done")) {
            ModifyConfig.writeData(filePath, "shebeimoshi", request.getParameter("shebeimoshi"));
            ModifyConfig.writeData(filePath, "zhudongceju", request.getParameter("zhudongceju"));
            ModifyConfig.writeData(filePath, "kaiqixintiao", request.getParameter("kaiqixintiao"));
            ModifyConfig.writeData(filePath, "jizhanid", request.getParameter("jizhanid"));
            ModifyConfig.writeData(filePath, "fashegonglv", request.getParameter("fashegonglv"));
            ModifyConfig.writeData(filePath, "wuchajiaozhun", request.getParameter("wuchajiaozhun"));
            ModifyConfig.writeData(filePath, "lvbocanshu", request.getParameter("lvbocanshu"));
            ModifyConfig.writeData(filePath, "tongxunxiaozu", request.getParameter("tongxunxiaozu"));
            ModifyConfig.writeData(filePath, "tongxunpinlv", request.getParameter("tongxunpinlv"));
            ModifyConfig.writeData(filePath, "tongxunshangxian", request.getParameter("tongxunshangxian"));
            ModifyConfig.writeData(filePath, "gujianbanben", request.getParameter("gujianbanben"));
            ModifyConfig.writeData(filePath, "tongbujizhan", request.getParameter("tongbujizhan"));
            ModifyConfig.writeData(filePath, "tongbuleixing", request.getParameter("tongbuleixing"));
            ModifyConfig.writeData(filePath, "linjinjizhanshuliang", request.getParameter("linjinjizhanshuliang"));
            ModifyConfig.writeData(filePath, "linjinjizhan1", request.getParameter("linjinjizhan1"));
            ModifyConfig.writeData(filePath, "linjinjizhan2", request.getParameter("linjinjizhan2"));
            ModifyConfig.writeData(filePath, "linjinjizhan3", request.getParameter("linjinjizhan3"));
            ModifyConfig.writeData(filePath, "linjinjizhan4", request.getParameter("linjinjizhan4"));
            ModifyConfig.writeData(filePath, "linjinjizhan5", request.getParameter("linjinjizhan5"));
            ModifyConfig.writeData(filePath, "linjinjizhan6", request.getParameter("linjinjizhan6"));
            ModifyConfig.writeData(filePath, "linjinjizhan7", request.getParameter("linjinjizhan7"));
            ModifyConfig.writeData(filePath, "linjinjizhan8", request.getParameter("linjinjizhan8"));
            ModifyConfig.writeData(filePath, "qiehuanjuli", request.getParameter("qiehuanjuli"));
            
            byte[] byt = ReadPeizhiMessage.save(request.getParameter("jizhanid"), request.getParameter("fashegonglv"), request.getParameter("wuchajiaozhun"), request.getParameter("lvbocanshu"), request.getParameter("tongxunxiaozu"), request.getParameter("tongxunpinlv"), request.getParameter("tongxunshangxian"), request.getParameter("shebeimoshi"), request.getParameter("linjinjizhanshuliang"), request.getParameter("linjinjizhan1"), request.getParameter("linjinjizhan2"),  request.getParameter("linjinjizhan3"), request.getParameter("linjinjizhan4"), request.getParameter("linjinjizhan5"), request.getParameter("linjinjizhan6"), request.getParameter("linjinjizhan7"), request.getParameter("linjinjizhan8"), "", request.getParameter("qiehuanjuli"), request.getParameter("zhudongceju"), request.getParameter("kaiqixintiao"), request.getParameter("tongbujizhan"), request.getParameter("tongbuleixing"));
            
            List<tb_system> settingList = sysSettingService.getSetting();
            System.out.println("保存配置信息是:"+BytesToHex.bytesToHex(byt));
            Udp_Out.out(byt,byt.length,ip, settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString() );
            
        }
        List<String> modi = new ArrayList<String>();
        modi.add("1");
        return modi;
    }
    
    @RequestMapping(value="/modify_all_anchor_config.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> modify_all_anchor_config(HttpServletRequest request) {  
        String filePath = Config.getAnchorConfig();
        ModifyConfig.writeData(filePath, "fashegonglv", request.getParameter("fashegonglv"));
        ModifyConfig.writeData(filePath, "wuchajiaozhun", request.getParameter("wuchajiaozhun"));
        ModifyConfig.writeData(filePath, "lvbocanshu", request.getParameter("lvbocanshu"));
        ModifyConfig.writeData(filePath, "tongxunxiaozu", request.getParameter("tongxunxiaozu"));
        ModifyConfig.writeData(filePath, "tongxunpinlv", request.getParameter("tongxunpinlv"));
        ModifyConfig.writeData(filePath, "tongxunshangxian", request.getParameter("tongxunshangxian"));
        ModifyConfig.writeData(filePath, "tongbujizhan", request.getParameter("tongbujizhan"));
        ModifyConfig.writeData(filePath, "tongbuleixing", request.getParameter("tongbuleixing"));
        
        byte[] byt = ReadPeizhiMessage.alert_all_anchor(request.getParameter("fashegonglv"), request.getParameter("wuchajiaozhun"),
                request.getParameter("lvbocanshu"), request.getParameter("tongxunxiaozu"), request.getParameter("tongxunpinlv"), 
                request.getParameter("tongxunshangxian"), request.getParameter("tongbujizhan"), request.getParameter("tongbuleixing"));
        
        List<tb_system> settingList = sysSettingService.getSetting();
        String port = settingList.get(0).getUdpPort().toString();
        String wifi_mode = settingList.get(0).getWifi_mdel().toString();
        
        System.out.println("修改所有基站信息是:"+BytesToHex.bytesToHex(byt));
        
        List<tb_achor> anchorIpList = ZhwService.getALlAnchor();
        if (anchorIpList.size()!=0) {
            for(int i=0; i<anchorIpList.size();i++) {
                String ip = anchorIpList.get(i).getAnchorip();
                Udp_Out.out(byt, byt.length, ip, port, wifi_mode);
            }
        }
 
        List<String> modi = new ArrayList<String>();
        modi.add("1");
        return modi;
    }
    
    @RequestMapping(value="/restart_anchor.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> restart_anchor(HttpServletRequest request) {  
        byte[] byt=Read_Write_Anchor_Message.WriteData((byte)0x60,(byte)0x2,1);                         
        System.out.println("重启基站信息是:"+BytesToHex.bytesToHex(byt));
        String ip=request.getParameter("ip");
        List<tb_system> settingList = sysSettingService.getSetting();
        Udp_Out.out(byt,byt.length,ip,settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString());
        List<String> rslt = new ArrayList<String>();
        rslt.add("1");
        return rslt;
    }
    
    @RequestMapping(value="/reset_anchor.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> reset_anchor(HttpServletRequest request) {  
        byte[] byt=Read_Write_Anchor_Message.WriteData((byte)0x62,(byte)0x2,1); 
        System.out.println("恢复出厂设置信息是:"+BytesToHex.bytesToHex(byt));
        String ip=request.getParameter("ip");
        List<tb_system> settingList = sysSettingService.getSetting();
        Udp_Out.out(byt,byt.length,ip,settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString());
        List<String> rslt = new ArrayList<String>();
        rslt.add("1");
        return rslt;
    }
    
    @RequestMapping(value="/anchorCeju.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> anchorCeju(HttpServletRequest request) {  
        String begin=request.getParameter("begin");
        System.out.println("begin"+begin);
        List<tb_system> settingList = sysSettingService.getSetting();
        if (begin.equals("true")) {
            //点击了开始测距
            String ip_a = request.getParameter("beice");
            String beice_anchor = request.getParameter("beice_anchor");
            String filePath = Config.getAnchorConfig();
            ModifyConfig.writeData(filePath, "beice_anchor", beice_anchor);
            byte[] byt=Read_Write_Anchor_Message.WriteData((byte)0x10,(byte)0x2,1);
            System.out.println("基站开始测距:"+BytesToHex.bytesToHex(byt));
            Udp_Out.out(byt,byt.length,ip_a, settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString());
        } else if (begin.equals("false")) {
            //点击了取消测距
            String ip_a = request.getParameter("beice");
            String ip_b = request.getParameter("ceju");
            byte[] byt=Read_Write_Anchor_Message.WriteData((byte)0x10,(byte)0x2,0);                                     
            System.out.println("基站取消测距:"+BytesToHex.bytesToHex(byt));
            Udp_Out.out(byt,byt.length,ip_a,settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString());
            byte[] byt2=Read_Write_Anchor_Message.WriteData((byte)0x10,(byte)0x2,0);
            System.out.println("基站取消测距:"+BytesToHex.bytesToHex(byt2));
            Udp_Out.out(byt2,byt2.length,ip_b, settingList.get(0).getUdpPort().toString(), settingList.get(0).getWifi_mdel().toString());
        }
        List<String> rslt = new ArrayList<String>();
        rslt.add("1");
        return rslt;
    }
    
    @RequestMapping(value="/getAnchorhuce.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<String> getAnchorhuce(HttpServletRequest request) {  
        String filePath = Config.getAnchorConfig();
        String huceju = ModifyConfig.readData(filePath, "huceju");
        System.out.println("huceju"+huceju);
        List<String> rslt = new ArrayList<String>();
        rslt.add(huceju);
        return rslt;
    }
 
    @RequestMapping(value = "/gpsRecord_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void gpsRecord_add(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        logger.info("传入数据IData:" + jsonString);
        tb_gps gps = (tb_gps) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_gps.class);
        List<tb_gps> searchGpsList = ZhwService.searchGps(gps.getTagid());
        if (searchGpsList.size()>0){
            ZhwService.gpsRecord_modify(gps);
        } else {
            ZhwService.gpsRecord_add(gps);
        }   
    }
    
    @RequestMapping(value = "/gpsTrack_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void gpsTrack_add(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        logger.info("传入数据IData:" + jsonString);
        tb_gps gps = (tb_gps) JSONObject.toBean(JSONObject.fromObject(jsonString), tb_gps.class);
        ZhwService.gpsTrack_add(gps);
    }
    
    @RequestMapping(value = "/httpsos.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void http(HttpServletRequest request) throws IOException {
        String jsonString = RequestUtils.getRequestJsonString(request, Config.getCharset());
        JSONObject str = JSONObject.fromObject(jsonString);
        sos = (httpsos)JSONObject.toBean(str, httpsos.class);
    }
    
    @RequestMapping(value = "/sosgaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void sosgaojing(HttpServletRequest request) throws IOException {
        String tagid=request.getParameter("tagid");
        ZhwService.sosgao(tagid);
    }
    
    @RequestMapping(value = "/fencegaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void fencegaojing(HttpServletRequest request) throws IOException {
        String tagid=request.getParameter("tagid");
        ZhwService.fencegao(tagid);
    }
    
    @ResponseBody
    @RequestMapping(value = "/shipinzhuangtai.do", method = { RequestMethod.POST, RequestMethod.GET })
    public List<tb_shipin> shipinzhuangtai(HttpServletRequest request){
        String tagid=request.getParameter("tagid");
        ZhwService.shipin(tagid);
        List<tb_person> fencename = ZhwService.getfencename(tagid);
//      //System.out.print(fencename.get(0).getP_fencename());
        List<tb_shipin> id = ZhwService.getshebeiid(fencename.get(0).getP_fencename());
//      //System.out.print(id.get(0).getShebeiid());
        List<tb_shipin> bb =null;
        return id;
    }
    
    @RequestMapping(value = "/sousuo.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void sousuo(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String tagid = request.getParameter("tagid");
        String[] tagids = tagid.split(",");
        String xieyi = "BSTOCS1,sousuo,"+tagids[0]+",END";
        Udp_Out.udp_to_cs(xieyi);
    }
    
    @RequestMapping(value = "/sousuoquxiao.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void sousuoquxiao(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
        String xieyi = "BSTOCS1,give_up_sousuo,END";
        Udp_Out.udp_to_cs(xieyi);
    }
    
    @RequestMapping(value = "/qihouManagement.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String qihouManagement(HttpServletRequest request) {
        String toPage = "forward:/hxzk/qihou.jsp";
        List<tb_qihou> qihouManagementList = ZhwService.qihoucha(1);
        request.setAttribute("qihouManagementList", qihouManagementList);
        int curPage = 1;
        int count = ZhwService.getqihouManagementCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        return toPage;
    }
 
    @RequestMapping(value = "/qihouManagement_add.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void qihouManagement_add(HttpServletRequest request) throws IOException {
        tb_qihou qihou = new tb_qihou();
        qihou.setPlace(request.getParameter("place"));
        qihou.setWeather(request.getParameter("weather"));
        qihou.setWd(request.getParameter("wd"));
        qihou.setSd(request.getParameter("sd"));
        ZhwService.qihouzeng(qihou);
    }
 
    @RequestMapping(value = "/qihouManagement_modify.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void qihouManagement_modify(HttpServletRequest request) {
        tb_qihou qihou = new tb_qihou();
        String id = request.getParameter("id");
        qihou.setId(Integer.parseInt(id));
        qihou.setPlace(request.getParameter("place"));
        qihou.setWeather(request.getParameter("weather"));
        qihou.setWd(request.getParameter("wd"));
        qihou.setSd(request.getParameter("sd"));
        ZhwService.qihougai(qihou);
    }
 
//  @RequestMapping(value = "/labelManagement_modifyAll.do", method = { RequestMethod.POST, RequestMethod.GET })
//  public void labelManagement_modifyAll(HttpServletRequest request) {
//      tb_tag tag = new tb_tag();
//      tag.setGaodu(request.getParameter("gaodu"));
//      tag.setSudu(request.getParameter("sudu"));
//      tag.setPinglv(request.getParameter("pinglv"));
//      labelService.labelManagement_modifyAll(tag);
//      String xieyi = "BSTOCS1,ALTERALLTAG,"+tag.getGaodu()+","+tag.getSudu()+","+tag.getPinglv()+",END";
//      Udp_Out.udp_to_cs(xieyi);
//      // 需要遍历修改
//      List<tb_tag> labelList = labelService.getLabelManagement();
//      for (int i = 0; i < labelList.size(); i++) {
//          String tag_id = labelList.get(i).getTag_id();
//          // 修改标签同时需要修改tb_person 需要先查再改否则覆盖空
//          List<tb_person> searchPersonManagement = basicInfoService.searchPersonManagement(tag_id);
//          if(searchPersonManagement!=null){
//              tb_person person = searchPersonManagement.get(0);
//              person.setP_tagid(tag.getTag_id());
//              person.setP_name(tag.getState());
//              person.setP_power(tag.getPower());
//              basicInfoService.personManagement_modify(person);
//          }
//      }
//  }
 
    @ResponseBody
    @RequestMapping(value = "/qihouManagement_delete.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void qihouManagement_delete(HttpServletRequest request) {
        String checkValStr = request.getParameter("checkVal");
        checkValStr = checkValStr.replaceAll("\"", "");
        String[] checkVal = checkValStr.split(",");
        ZhwService.qihoudelete(checkVal);
    }
 
    @ResponseBody
    @RequestMapping(value = "/qihouManagement_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
    public void qihouManagement_deleteAll(HttpServletRequest request) {
        ZhwService.qihoudeleteAll();
    }
    
    @ResponseBody
    @RequestMapping(value = "/qihouManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String qihouManagement_export(HttpServletRequest request, HttpServletResponse response) {
        String toPage = "forward:/hxzk/qihou.jsp";
        List<tb_qihou> tb_qihouList = ZhwService.qihoucha();
        String[] rowName = { "ID", "时间", "地点", "天气", "温度", "湿度" };
        List<Object[]> dataList = objectToArray_qihouManagement(tb_qihouList);
        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;
    }
    
    @ResponseBody
    @RequestMapping(value = "/qihouManagement_exportTemplate.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String qihouManagement_exportTemplate(HttpServletRequest request, HttpServletResponse response) {
        String toPage = "forward:/hxzk/qihou.jsp";
        List<tb_qihou> qihouTemplateList = ZhwService.qihoucha(1);
        String[] rowName = { "时间", "地点", "天气", "温度", "湿度"};
        List<Object[]> dataList = objectToArray_qihouManagement2(qihouTemplateList);
        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;
    }
    
    @ResponseBody
    @RequestMapping(value = "/qihouManagement_page.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String qihouManagement_page(HttpServletRequest request) {
        String pageStr = request.getParameter("page");
        String curPageStr = request.getParameter("curPage");
        int count = ZhwService.getqihouManagementCount();
        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_qihou> qihouManagementList = ZhwService.qihoucha(page);
        List<Integer> pageList = PageUtil.getPage(PageUtil.getLocPage(page, curPage), page, minPage);
        JSONObject json = new JSONObject();
        json.put("dataList", qihouManagementList);
        json.put("pageList", pageList);
        json.put("curPage", page);
        return json.toString();
    }
    
    @RequestMapping(value = "/uploadqihou.do")
    public String uploadqihou(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
        String toPage = "forward:/hxzk/qihou.jsp";
        String filePath = request.getServletContext().getRealPath("/") + "hxzk\\upload\\";
        String filename = files[0].getOriginalFilename();
        try {
            File existFile = new File(filePath);
            if (!existFile.exists()) {
                existFile.mkdir();
            }
            for (MultipartFile file : files) {
                file.transferTo(new File(filePath + file.getOriginalFilename()));
                //System.out.print(file.getOriginalFilename());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        int result = 0;
        String path = filePath + filename;
        // 选取Excel文件得到工作薄
        Workbook workbook;
        try {
            File file = new File(path);
            workbook = Workbook.getWorkbook(file);
            // 选择工作表,通过Workbook的getSheet方法选择第一个工作表(从0开始)
            Sheet sheet = workbook.getSheet(0);
            int rows = sheet.getRows();
            // 选择Cell,读取单元格 通过Sheet的getCell方法选择位置为C2的单元格(两个参数都从0开始)
            for (int i = 3; i < rows; i++) {
                // 读取信息,通过Cell的getContents方法读取单元格的值把单元格中的信息以字符的形式读取出来
                // String status = sheet.getCell(0, i).getContents();
                String time = sheet.getCell(0, i).getContents();
                String place = sheet.getCell(1, i).getContents();
                String weather = sheet.getCell(2, i).getContents();
                String wd = sheet.getCell(3, i).getContents();
                String sd = sheet.getCell(4, i).getContents();
                    tb_qihou qihou = new tb_qihou();
                    // tag.setStatus(status);
                    qihou.setTime(time);
                    qihou.setPlace(place);
                    qihou.setWeather(weather);
                    qihou.setWd(wd);
                    qihou.setSd(sd);
                    result = ZhwService.qihouzeng(qihou);
            }
            // 释放资源
            workbook.close();
        } catch (BiffException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        request.setAttribute("resultList", result);
        List<tb_qihou> qihouManagementList = ZhwService.qihoucha(1);
        request.setAttribute("qihouManagementList", qihouManagementList);
        int curPage = 1;
        int count = ZhwService.getqihouManagementCount();
        int minPage = PageUtil.getMinPage(count);
        request.setAttribute("pageList", PageUtil.getPage(minPage));
        request.setAttribute("curPage", curPage);
        File file = new File(path);
        file.delete();
        return toPage;
    }
    
    @RequestMapping(value="/getRealPositionsan.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_realpositoin> getRealPositionsan(HttpServletRequest request) { 
        long timeStart = 0;
        
        //根据时间筛选出数据
        List<tb_person> realLocationList = ZhwService.getpersonLocationsan();
        for ( tb_person node : realLocationList) {
            Double x = Double.valueOf(node.getP_x());
            Double y = Double.valueOf(node.getP_y());
            Double xo = (x-54732)/100;
            Double yo = -(y+10268)/100;
            List<Double> xy = ZhwController.cal2(xo, yo);
            node.setP_x((xy.get(0)).toString());
            node.setP_y((xy.get(1)).toString());
        }
        
        List<tb_realpositoin> finalPositionList = new ArrayList<tb_realpositoin>();
        
        //根据每个tagid取tb_tag:[tag_id,state(静止1or运动0),power,status(在线1or离线0),addtime],放入tb_position中
        for (tb_person node : realLocationList) {
            String tagid = node.getP_tagid();
            tb_realpositoin position = new tb_realpositoin();
            position.setTagid(tagid);
            position.setPower(node.getP_power());
            position.setLife(node.getP_online());
            position.setName(node.getP_name());
            position.setPosx(node.getP_x());
            position.setPosy(node.getP_y());
            position.setSos(node.getP_sos());
            position.setTime(node.getP_addtiem());
            position.setFence(node.getP_fence());
            position.setSousuo(node.getP_sousuo());
            position.setShipin(node.getP_shipin());
            position.setInkaoqing(node.getP_kaoqing());
            
            finalPositionList.add(position);
        }
        return finalPositionList;
    }
    
    @RequestMapping(value="/getkaoqinsan.do", method = { RequestMethod.POST, RequestMethod.GET })
    @ResponseBody
    public List<tb_realkaoqing> getkaoqinsan(HttpServletRequest request) { 
        List<tb_realkaoqing> realkaoqingList = ZhwService.getkaoqinsan();
        return realkaoqingList;
    }
    
    public static List<Object[]> objectToArray_qihouManagement2(List<tb_qihou> tb_qihouList) {
        List<Object[]> reList = new ArrayList<>();
        for (int i = 0; i < tb_qihouList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_qihou qihou = (tb_qihou) tb_qihouList.get(i);
            words.add(qihou.getTime());
            words.add(qihou.getPlace());
            words.add(qihou.getWeather());
            words.add(qihou.getWd());
            words.add(qihou.getSd());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
        }
        return reList;
    }
    
    // tb_qihou 导出表格 对象转数组
        public static List<Object[]> objectToArray_qihouManagement(List<tb_qihou> tb_qihouList) {
            List<Object[]> reList = new ArrayList<>();
            for (int i = 0; i < tb_qihouList.size(); i++) {
                List<String> words = new ArrayList<String>();
                tb_qihou qihou = (tb_qihou) tb_qihouList.get(i);
                words.add(String.valueOf(qihou.getId()));
                words.add(qihou.getTime());
                words.add(qihou.getPlace());
                words.add(qihou.getWeather());
                words.add(qihou.getWd());
                words.add(qihou.getSd());
                String[] array = words.toArray(new String[0]);
                reList.add(array);
            }
            return reList;
        }
        
        /**
          * 以K0 + 877为原点
          * @param px X坐标
          * @param py y坐标
          */
         private static List<Double> cal2(double px, double py) {
          double mx1 = 12738394.2203293;
          double my1 = 4586352.97186441;
          double rx = 1.0439323780911336;
          double ry = 1.0443204318588795;
          
          double mx = mx1 + px * rx;
          double my = my1 + py * ry;
          
          List<Double> xy = new ArrayList<Double>();
          xy.add(mx);
          xy.add(my);
          return xy;
         }
}