15832144755
2022-03-17 bc131131c5c96f8cb3bed679d4a359820c22e335
src/main/java/com/hxzkoa/controller/ZhwController.java
@@ -1,6 +1,11 @@
package com.hxzkoa.controller;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
@@ -9,6 +14,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -22,7 +28,9 @@
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;
@@ -32,6 +40,8 @@
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;
@@ -41,6 +51,8 @@
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.services.ZhwService;
import com.hxzkoa.services.AnchorService;
import com.hxzkoa.services.AttendanceService;
import com.hxzkoa.services.FenceService;
import com.hxzkoa.udp.Dell_Ip;
import com.hxzkoa.udp.GetNowTime;
import com.hxzkoa.udp.ReadPeizhiMessage;
@@ -48,10 +60,16 @@
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 com.hxzkoa.util.RtspToMP4;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import net.sf.json.JSONObject;
@@ -67,13 +85,61 @@
   private SysSettingService sysSettingService; 
   @Autowired
   private AnchorService AnchorService; 
   @Autowired
   private FenceService fenceService;
   @Autowired
   private AttendanceService attendanceService;
   
   httpsos sos = new httpsos();
   
   Process process ;
   private Map<Integer,Process> map=new HashMap<>();
    @ResponseBody
    @RequestMapping("/Shipinstart")
    public void Start(Integer id, String FileName) {
        String ffmpegPath="F:\\ffmpeg\\ffmpeg-4.4-essentials_build\\bin\\ffmpeg.exe";
        String streamUrl="rtsp://admin:hxzk20151102@192.168.1.64:554/Streaming/Channels/101";
        String FilePath="E:\\data\\MP4\\"+FileName;
        RtspToMP4 tomp4 = new RtspToMP4();
        Process process = tomp4.StartRecord(ffmpegPath, streamUrl, FilePath);
        if(null!=process){
            map.put(id,process);
        }
    }
    @RequestMapping("/Shipinstop")
    public void stop(Integer id) {
        if(map.containsKey(id)){
            Process process = map.get(id);
            if(null!=process){
                RtspToMP4 tomp4 = new RtspToMP4();
                tomp4.stopRecord(process);
            }
        }
    }
   @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();
      List<tb_fence> fenceList = fenceService.getFenceList();
      List<String> fencenames = new ArrayList<>();
      for (int i =0;i < fenceList.size(); i++) {
         fencenames.add(fenceList.get(i).getName());
      }
      Map realAttendanceTypeMap = attendanceService.getRealAttendanceType();
      List<String> realAttendance_k = new ArrayList<String>();
//    List<Integer> realAttendance_v = new ArrayList<Integer>();
      Iterator<String> realAttendanceTypeIter = realAttendanceTypeMap.keySet().iterator();
      while (realAttendanceTypeIter.hasNext()) {
         String key = realAttendanceTypeIter.next();
         realAttendance_k.add(key);
//       realAttendance_v.add((int) realAttendanceTypeMap.get(key));
      }
      request.setAttribute("guanlianList", realAttendance_k);
      request.setAttribute("fenceList", fencenames);
      request.setAttribute("floorList", floorList);
      return toPage;
   }
@@ -137,7 +203,12 @@
   @ResponseBody
   public int drawFence_add(HttpServletRequest request) {
      tb_fence fence = new tb_fence();
      fence.setFloor(request.getParameter("layer"));
      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"));
@@ -153,7 +224,7 @@
      fence.setStop(end);
      
      fence.setColor(request.getParameter("yanse"));
      ZhwService.drawFence_add(fence);
      int aaa = 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);
      
@@ -178,17 +249,86 @@
         ZhwService.fenceInout_add(name,zb_inout,shape,floor);
      }
      
      return 0;
      return aaa;
   }
   @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("百度地图") && !layer.equals("手动输入") && !layer.equals("自动输入")) {
         Integer layerjj = Integer.parseInt(layer);
         layer = layerjj.toString();
      }else {
         layer = "百度地图";
      }
      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");
      String zuobiaodufen = (String) request.getParameter("zuobiaodufen");
      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"));
      int aaa = ZhwService.sanweiFence_add(fence);
      String xieyi = "BSTOCS1,ADDFENCE,"+fence.getFloor()+","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+zuobiao+","+fence.getShape()+","+fence.getStart()+","+fence.getStop()+","+GetNowTime.now()+","+fence.getColor()+","+fence.getBaoliu1()+",END";
      Udp_Out.udp_to_cs(xieyi);
      sysSettingService.guiling();
      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 aaa;
   }
   
   @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();
      List<tb_fence> fenceList = fenceService.getFenceList2();
      request.setAttribute("fenceList", fenceList);
      request.setAttribute("floorList", floorList);
      return toPage;
   }
   
   @RequestMapping(value="/trackTagid2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_track> queryTagid2(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="/trackTagid.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_track> queryTagid(HttpServletRequest request) throws ParseException {  
@@ -196,53 +336,81 @@
       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;
       String fence = request.getParameter("fence");
       if (fence.equals("空")) {
         final List<tb_track> tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         return tagList;
       } else {
         final List<tb_track> tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         final List<tb_track> tagList2 = new ArrayList<>();
         for (int i=0;i<tagList.size();i++) {
            Point2D.Double dian = new Point2D.Double(Double.parseDouble(tagList.get(i).getX()),Double.parseDouble(tagList.get(i).getY()));
            String[] fences = fence.split(";");
            List<Point2D.Double> fencedian = new ArrayList<>();
            for (int j=0;j<fences.length;j++) {
               String[] aaa = fences[j].split(",");
               Point2D.Double diana = new Point2D.Double(Double.parseDouble(aaa[0]),Double.parseDouble(aaa[1]));
               fencedian.add(diana);
            }
            if (isInPolygon(dian,fencedian)) {
               tagList2.add(tagList.get(i));
            }
         }
         return tagList2;
       }
   }
   @RequestMapping(value="/trackTagida.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public JSONObject queryTagida(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");
       String fence = request.getParameter("fence");
       JSONObject json = new JSONObject();
       if (fence.equals("空")) {
         final List<tb_track> tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         json.put("dataList", tagList);
         return json;
       } else {
         final List<tb_track> tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         final List<tb_track> tagList2 = new ArrayList<>();
         for (int i=0;i<tagList.size();i++) {
            Point2D.Double dian = new Point2D.Double(Double.parseDouble(tagList.get(i).getX()),Double.parseDouble(tagList.get(i).getY()));
            String[] fences = fence.split(";");
            List<Point2D.Double> fencedian = new ArrayList<>();
            for (int j=0;j<fences.length;j++) {
               String[] aaa = fences[j].split(",");
               Point2D.Double diana = new Point2D.Double(Double.parseDouble(aaa[0]),Double.parseDouble(aaa[1]));
               fencedian.add(diana);
            }
            if (isInPolygon(dian,fencedian)) {
               tagList2.add(tagList.get(i));
            }
         }
         json.put("dataList", tagList2);
         return json;
       }
   }
   
   @RequestMapping(value="/getRealPosition.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_realpositoin> getRealPosition(HttpServletRequest request) { 
      //从tb_person中取最新更新的[p_tagid,p_x,p_y,p_floor,p_addtime]
      String floor = request.getParameter("floor");
//    long timeNow =  System.currentTimeMillis();
//    long timeStart = timeNow - 10000; //取10s内最新的一条数据作为当前的实时位置,后期可更改,此处为ms单位
      long timeStart = 0;
      
      //根据时间筛选出数据
      List<tb_person> realLocationList = ZhwService.getpersonLocation(floor);
      List<tb_person> personLocationList = new ArrayList<tb_person>();
      for ( tb_person node : realLocationList) {
         String timeRecent = node.getP_addtiem();
         Timestamp ts = Timestamp.valueOf(timeRecent);
         long times = ts.getTime();
         System.out.println("times"+times);
         if (times >= timeStart) {
            personLocationList.add(node);
         }
      }
      
      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 : personLocationList) {
         List<tb_tag> taglist = new ArrayList<tb_tag>();
         List<tb_person> personlist = new ArrayList<tb_person>();
      for (tb_person node : realLocationList) {
         String tagid = node.getP_tagid();
         taglist = ZhwService.getRealTagState(tagid);
         personlist = ZhwService.getRealpersonState(tagid);
         tb_realpositoin position = new tb_realpositoin();
         position.setTagid(tagid);
         if (personlist.isEmpty()) {
            position.setPower("");
            position.setLife("");
         } else {
            position.setPower(personlist.get(0).getP_power());
            position.setLife(personlist.get(0).getP_online());
         }
         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());
@@ -260,43 +428,19 @@
   @RequestMapping(value="/getRealPosition_all.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_realpositoin> getRealPosition_all(HttpServletRequest request) { 
      //从tb_person中取最新更新的[p_tagid,p_x,p_y,p_floor,p_addtime]
//    long timeNow =  System.currentTimeMillis();
      //long timeStart = timeNow - 10000; //取10s内最新的一条数据作为当前的实时位置,后期可更改,此处为ms单位
      long timeStart = 0;
      
      //根据时间筛选出数据
      List<tb_person> realLocationList = ZhwService.getpersonLocation_all();
      List<tb_person> personLocationList = new ArrayList<tb_person>();
      for ( tb_person node : realLocationList) {
         String timeRecent = node.getP_addtiem();
         Timestamp ts = Timestamp.valueOf(timeRecent);
         long times = ts.getTime();
         System.out.println("times"+times);
         if (times >= timeStart) {
            personLocationList.add(node);
         }
      }
      
      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 : personLocationList) {
         List<tb_tag> taglist = new ArrayList<tb_tag>();
      for (tb_person node : realLocationList) {
         String tagid = node.getP_tagid();
         taglist = ZhwService.getRealTagState(tagid);
         tb_realpositoin position = new tb_realpositoin();
         position.setTagid(tagid);
         if (taglist.isEmpty()) {
            position.setPower("");
            position.setLife("");
         } else {
            position.setPower(taglist.get(0).getPower());
            position.setLife(taglist.get(0).getStatus());
         }
         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());
@@ -304,13 +448,36 @@
         position.setSos(node.getP_sos());
         position.setTime(node.getP_addtiem());
         position.setFence(node.getP_fence());
         position.setChaichu(node.getBaoliu6());
         finalPositionList.add(position);
      }
      
      return finalPositionList;
   }
   
   @ResponseBody
   @RequestMapping(value="/getpersonid.do",method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject getpersonid(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      List<tb_person> realTrackList = ZhwService.getpersonid(tagid);
      JSONObject json = new JSONObject();
      json.put("X", realTrackList.get(0).getP_x());
      json.put("Y", realTrackList.get(0).getP_y());
      return json;
   }
   @ResponseBody
   @RequestMapping(value="/getgpsid.do",method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject getgpsid(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      List<tb_gps> realTrackList = ZhwService.getgpsid(tagid);
      JSONObject json = new JSONObject();
      json.put("jingdu", realTrackList.get(0).getGsp_jingdu());
      json.put("weidu", realTrackList.get(0).getGps_weidu());
      json.put("haibagao", realTrackList.get(0).getGps_haiba_gao());
      return json;
   }
   @RequestMapping(value="/getRealTrack.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<ArrayList<tb_track>> getRealTrack(HttpServletRequest request) {
@@ -399,7 +566,7 @@
   @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();
      List<tb_system> settingList = sysSettingService.getSetting();
      return settingList;
   }
   
@@ -422,23 +589,40 @@
   @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) {
            finalGPSList.add(node);
//       }
         if (node.getGsp_jingdu() != null && !node.getGsp_jingdu().equals("00000.000000") && node.getGps_weidu() != null && !node.getGps_weidu().equals("00000.000000")) {
            String[] jingdu = node.getGsp_jingdu().split("\\.");
            String[] weidu = node.getGps_weidu().split("\\.");
            if (jingdu[0].length() == 3 && weidu[0].length() == 2) {
               finalGPSList.add(node);
            }
         }
      };
      return finalGPSList;
   }
   
   @RequestMapping(value="/getGPSa.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public JSONObject getGPSa(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      final List<tb_gps> gpsList = ZhwService.getGPS();
      List<tb_gps> finalGPSList = new ArrayList<tb_gps>();
      for ( tb_gps node : gpsList) {
         if (node.getGsp_jingdu() != null && !node.getGsp_jingdu().equals("00000.000000") && node.getGps_weidu() != null && !node.getGps_weidu().equals("00000.000000")) {
            String[] jingdu = node.getGsp_jingdu().split("\\.");
            String[] weidu = node.getGps_weidu().split("\\.");
            if (jingdu[0].length() == 3 && weidu[0].length() == 2) {
               finalGPSList.add(node);
            }
         }
      };
      json.put("dataList", finalGPSList);
      return json;
   }
   @RequestMapping(value="/getGPSTrack.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_gps> getGPSTrack(HttpServletRequest request) throws ParseException {  
@@ -449,6 +633,18 @@
      return finalGPSList;
   }
   
   @RequestMapping(value="/getGPSTracka.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public JSONObject getGPSTracka(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);
      JSONObject json = new JSONObject();
      json.put("dataList", finalGPSList);
      return json;
   }
   @RequestMapping(value="/qiehuanditu_option.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_map> qiehuanditu_option(HttpServletRequest request) {  
@@ -462,7 +658,7 @@
      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"));
      //System.out.print(ModifyConfig.readData(filePath, "map_now"));
      return "1";
   }
   
@@ -473,8 +669,8 @@
//    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);
//    //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();
@@ -735,12 +931,50 @@
   public void sosgaojing(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      ZhwService.sosgao(tagid);
      String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",SOS,END";
      Udp_Out.udp_to_cs(xieyi);
   }
   
   @RequestMapping(value = "/fencegaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void fencegaojing(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      String type=request.getParameter("type");
      ZhwService.fencegao(tagid);
      String xieyi = "BSTOCS1,DELLWARN," +tagid+ ","+type+",END";
      Udp_Out.udp_to_cs(xieyi);
   }
   @RequestMapping(value = "/chaichugaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void chaichugaojing(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      ZhwService.chaichugao(tagid);
      String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",被拆除,END";
      Udp_Out.udp_to_cs(xieyi);
   }
   @RequestMapping(value = "/gaojingzongchuli.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void gaojingzongchuli(HttpServletRequest request) throws IOException {
      List<tb_person> soslist = ZhwService.getsosgaojing();
      for (int i=0; i<soslist.size(); i++) {
         String tagid = soslist.get(i).getP_tagid();
         ZhwService.sosgao(tagid);
         String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",SOS,END";
         Udp_Out.udp_to_cs(xieyi);
      }
      List<tb_person> fencelist = ZhwService.getfencegaojing();
      for (int i=0; i<fencelist.size(); i++) {
         String tagid = fencelist.get(i).getP_tagid();
         ZhwService.fencegao(tagid);
         String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",危险区域,END";
         Udp_Out.udp_to_cs(xieyi);
      }
      List<tb_person> chufencelist = ZhwService.getchufencegaojing();
      for (int i=0; i<fencelist.size(); i++) {
         String tagid = chufencelist.get(i).getP_tagid();
         ZhwService.fencegao(tagid);
         String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",出区域告警,END";
         Udp_Out.udp_to_cs(xieyi);
      }
   }
   
   @ResponseBody
@@ -749,9 +983,9 @@
      String tagid=request.getParameter("tagid");
      ZhwService.shipin(tagid);
      List<tb_person> fencename = ZhwService.getfencename(tagid);
//    System.out.print(fencename.get(0).getP_fencename());
//    //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());
//    //System.out.print(id.get(0).getShebeiid());
      List<tb_shipin> bb =null;
      return id;
   }
@@ -769,4 +1003,476 @@
      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="/getRealPositionsana.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public JSONObject getRealPositionsana(HttpServletRequest request) {
      long timeStart = 0;
      JSONObject json = new JSONObject();
      //根据时间筛选出数据
      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());
         position.setFangkeid(node.getP_fangkeid());
         position.setJingdu(node.getP_jingdu());
         position.setWeidu(node.getP_weidu());
         position.setGaocheng(node.getP_gaocheng());
         finalPositionList.add(position);
      }
      json.put("dataList", finalPositionList);
      return json;
   }
   @RequestMapping(value="/getkaoqinsan.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_realkaoqing> getkaoqinsan(HttpServletRequest request) {
      List<tb_realkaoqing> realkaoqingList = ZhwService.getkaoqinsan();
      System.out.print("------------------------");
      System.out.print("------------------------"+realkaoqingList.get(0).getName());
      return realkaoqingList;
   }
   @RequestMapping(value = "/xiafazhendong.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void xiafazhendong(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      String xieyi = "55BB,TAG_SHAKE,10,"+tagid+",END";
      Udp_Out.udp_to_cs(xieyi);
   }
   @RequestMapping("bofang.do")
    public void shangchuan2() {
        int flag = -1;
        // 输出ffmpeg推流日志
        String ffmpegPath = "F:\\ffmpeg\\ffmpeg-4.4-essentials_build\\bin\\";
        try {
            String command = ffmpegPath;
            command += "ffmpeg -rtsp_transport tcp"; // ffmpeg开头,-re代表按照帧率发送,在推流时必须有
            command += " -i \"rtsp://admin:hxzk20151102@192.168.3.64:554/Streaming/Channels/102\""; // 指定要推送的视频
            command += " -q 0 -f mpegts -codec:v mpeg1video -s 1280x720 http://127.0.0.1:8081/123456"; // 指定推送服务器,-f:指定格式   1280  720
            System.out.println("ffmpeg推流命令:" + command);
            process = Runtime.getRuntime().exec(command);
            // 输出ffmpeg推流日志
            BufferedReader br= new BufferedReader(new InputStreamReader(process.getErrorStream()));
            String line = "";
            while ((line = br.readLine()) != null) {
                System.out.println("视频推流信息[" + line + "]");
            }
            flag = process.waitFor();
            //这里是为了区分不同的流,需求会打开多个摄像头,根据token
            //后面可以对不需要的流关闭
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
   @RequestMapping("tingzhibofang.do")
   public void tingzhibofang() {
      process.destroy();
   }
   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;
       }
       public static boolean isInPolygon(Point2D.Double point, List<Point2D.Double> pts){
              int N = pts.size();
              boolean boundOrVertex = true;
              int intersectCount = 0;//交叉点数量
              double precision = 2e-10; //浮点类型计算时候与0比较时候的容差
              Point2D.Double p1, p2;//临近顶点
              Point2D.Double p = point; //当前点
              p1 = pts.get(0);
              for(int i = 1; i <= N; ++i){
                  if(p.equals(p1)){
                      return boundOrVertex;
                  }
                  p2 = pts.get(i % N);
                  if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){
                      p1 = p2;
                      continue;
                  }
                  //射线穿过算法
                  if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){
                      if(p.y <= Math.max(p1.y, p2.y)){
                          if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){
                              return boundOrVertex;
                          }
                          if(p1.y == p2.y){
                              if(p1.y == p.y){
                                  return boundOrVertex;
                              }else{
                                  ++intersectCount;
                              }
                          }else{
                              double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
                              if(Math.abs(p.y - xinters) < precision){
                                  return boundOrVertex;
                              }
                              if(p.y < xinters){
                                  ++intersectCount;
                              }
                          }
                      }
                  }else{
                      if(p.x == p2.x && p.y <= p2.y){
                          Point2D.Double p3 = pts.get((i+1) % N);
                          if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){
                              ++intersectCount;
                          }else{
                              intersectCount += 2;
                          }
                      }
                  }
                  p1 = p2;
              }
              if(intersectCount % 2 == 0){//偶数在多边形外
                  return false;
              } else { //奇数在多边形内
                  return true;
              }
          }
}