3.7
fxl
2023-03-07 52cffc4ab8e9787a6f233295502c7c9788dddae1
src/main/java/com/hxzkoa/controller/ZhwController.java
@@ -1,20 +1,38 @@
package com.hxzkoa.controller;
import java.awt.geom.Point2D;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Date;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLEncoder;
//import java.sql.Date;
import java.util.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,24 +40,40 @@
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_department;
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_history_power;
import com.hxzkoa.json.tb_jingwei;
import com.hxzkoa.json.tb_jobhistory;
import com.hxzkoa.json.tb_map;
import com.hxzkoa.json.tb_message;
import com.hxzkoa.json.tb_nav;
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.services.AttendanceService;
import com.hxzkoa.services.BasicInfoService;
import com.hxzkoa.services.FenceService;
import com.hxzkoa.services.LabelService;
import com.hxzkoa.services.MapService;
import com.hxzkoa.udp.Dell_Ip;
import com.hxzkoa.udp.GetNowTime;
import com.hxzkoa.udp.ReadPeizhiMessage;
@@ -47,10 +81,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;
@@ -66,13 +106,86 @@
   private SysSettingService sysSettingService; 
   @Autowired
   private AnchorService AnchorService; 
   @Autowired
   private FenceService fenceService;
   @Autowired
   private AttendanceService attendanceService;
   @Autowired
   private BasicInfoService basicInfoService;
   @Autowired
   private LabelService labelService;
   @Autowired
   private MapService mapService;
   
   httpsos sos = new httpsos();
   
   Process process ;
   private Map<Integer,Process> map=new HashMap<>();
   private Map<String,String[]> persons=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());
      }
      List<String> realAttendance_k = new ArrayList<String>();
      List<tb_department> departments = basicInfoService.getDepartmentManagement2();
      for (int i =0;i < departments.size(); i++) {
         realAttendance_k.add(departments.get(i).getDepartmentName());
      }
      request.setAttribute("guanlianList", realAttendance_k);
      request.setAttribute("fenceList", fencenames);
      request.setAttribute("floorList", floorList);
      return toPage;
   }
   @RequestMapping(value = "/xiangdaototwo.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String xiangdaototwo(HttpServletRequest request) {
      String toPage = "forward:/hxzk/fence/drawFencexiangdao.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());
      }
      List<String> realAttendance_k = new ArrayList<String>();
      List<tb_department> departments = basicInfoService.getDepartmentManagement2();
      for (int i =0;i < departments.size(); i++) {
         realAttendance_k.add(departments.get(i).getDepartmentName());
      }
      List<tb_tag> labelManagementListaa = labelService.getLabelManagementa();
      request.setAttribute("labelManagementListaa", labelManagementListaa);
      request.setAttribute("guanlianList", realAttendance_k);
      request.setAttribute("fenceList", fencenames);
      request.setAttribute("floorList", floorList);
      return toPage;
   }
@@ -102,6 +215,14 @@
      return mapList;
   }
   
   @RequestMapping(value="/floornumTomap_all2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_map> floornumTomap_all2(HttpServletRequest request) {
      String floor = request.getParameter("floor");
      final List<tb_map> mapList = ZhwService.getMap_all2(floor);
      return mapList;
   }
   @RequestMapping(value="/getFloorByMapname.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_map> getFloorByMapname(HttpServletRequest request) {  
@@ -115,7 +236,13 @@
   public List<tb_fence> getFloorFence(HttpServletRequest request) {  
       String floor_number = request.getParameter("value");
      final List<tb_fence> fenceList = ZhwService.getFence(floor_number);
      return fenceList;
      final List<tb_fence> fenceList2 = new ArrayList<tb_fence>();
      for (int i = 0; i < fenceList.size(); i++) {
         if (!fenceList.get(i).getType().equals("变电站")) {
            fenceList2.add(fenceList.get(i));
         }
      }
      return fenceList2;
   }
   
   @RequestMapping(value="/getFloorFence_all.do", method = { RequestMethod.POST, RequestMethod.GET })
@@ -136,61 +263,315 @@
   @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"));
      
      String zuobiao =(String) request.getParameter("zuobiao");
      int aaa = 1;
      List<tb_fence> fencesss = ZhwService.getFenceaaa(fence.getName());
      if (fencesss.size() == 0) {
         aaa = 0;
         String xingzhuang = request.getParameter("xingzhuang");
         fence.setShape(xingzhuang);
         String zuobiao =(String) request.getParameter("zuobiao");
         String baowen = "";
         if (xingzhuang.equals("多边形")) {
            String[] zuobiaos = zuobiao.split(",");
            String str = "";
            for (int i=0; i<zuobiaos.length; i++) {
               if (i == zuobiaos.length-1) {
                  str += zuobiaos[i];
                  break;
               }
               if (i%2 == 0) {
                  str += zuobiaos[i]+":";
               } else {
                  str += zuobiaos[i]+";";
               }
            }
            baowen = str;
         } else {
            baowen = zuobiao.replace(",", ":");
         }
         fence.setZuobiao(zuobiao);
         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()+","+baowen+","+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 aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/begindrawa.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String begindraw(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String xieyi = "BSTOCS1,drawfence,outwarning,"+tagid+",start,end";
      Udp_Out.udp_to_cs(xieyi);
      return "1";
   }
   @ResponseBody
   @RequestMapping(value = "/enddrawa.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String enddrawa(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
      String xieyi = "BSTOCS1,drawfence,outwarning,"+tagid+",stop,end";
      Udp_Out.udp_to_cs(xieyi);
      return "1";
   }
   @RequestMapping(value = "/xiangdaoone.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String xiangdaoone(HttpServletRequest request) {
      String toPage = "forward:/hxzk/label/labelManagementxiangdaoone.jsp";
      List<tb_tag> labelManagementList = labelService.getLabelManagement(1);
      List<tb_tag> labelManagementListaa = labelService.getLabelManagementa();
      request.setAttribute("labelManagementList", labelManagementList);
      request.setAttribute("labelManagementListaa", labelManagementListaa);
      int curPage = 1;
      int count = labelService.getLabelManagementCount();
      int minPage = PageUtil.getMinPage(count);
      // System.out.print(minPage);
      request.setAttribute("pageList", PageUtil.getPage(minPage));
      request.setAttribute("curPage", curPage);
      return toPage;
   }
   @RequestMapping(value = "/saveFence2.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String drawFence_add2(HttpServletRequest request) {
      String toPage = "forward:/hxzk/label/labelManagementxiangdaothree.jsp";
      tb_fence fence = new tb_fence();
      fence.setFloor(request.getParameter("layer"));
      fence.setType(request.getParameter("weilanleixing"));
      fence.setBaoliu2(request.getParameter("tagid"));
      fence.setName(request.getParameter("quyumingcheng"));
//    String zuobiao =(String) request.getParameter("zuobiao");
      String zuobiao = ZhwService.getfencezuobiao();
      fence.setZuobiao(zuobiao);
      fence.setShape(request.getParameter("xingzhuang"));
      fence.setShape("多边形");
      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);
      List<String> realAttendance_k = new ArrayList<String>();
      List<tb_department> departments = basicInfoService.getDepartmentManagement2();
      for (int i =0;i < departments.size(); i++) {
         realAttendance_k.add(departments.get(i).getDepartmentName());
      }
      request.setAttribute("guanlianList", realAttendance_k);
      request.setAttribute("fence", fence);
      return toPage;
   }
   @RequestMapping(value = "/saveFence3.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public void drawFence_add3(HttpServletRequest request) {
      tb_fence fence = new tb_fence();
      fence.setFloor(request.getParameter("floor"));
      fence.setType(request.getParameter("type"));
      fence.setBaoliu2(request.getParameter("baoliu2"));
      fence.setName(request.getParameter("name"));
//    String zuobiao =(String) request.getParameter("zuobiao");
      String zuobiao = ZhwService.getfencezuobiao();
      fence.setZuobiao(zuobiao);
      
      return 0;
      String haibagao = ZhwService.getfencehaibagao();
      fence.setBaoliu6(haibagao);
      fence.setShape(request.getParameter("shape"));
      fence.setStart(request.getParameter("start"));
      fence.setStop(request.getParameter("stop"));
      fence.setColor(request.getParameter("color"));
      fence.setBaoliu3(request.getParameter("baoliu3"));
      fence.setBaoliu1(request.getParameter("baoliu1"));
      fence.setBumen(request.getParameter("bumen"));
      fence.setBaoliu4(request.getParameter("baoliu4"));
      int aaa = ZhwService.drawFence_add2(fence);
      String xieyi = "BSTOCS1,ADDFENCE,"+fence.getFloor()+","+fence.getType()+","+fence.getBumen()+","+fence.getName()+","+fence.getZuobiao().replace(",", ":")+","+fence.getShape()+","+fence.getStart()+","+fence.getStop()+","+GetNowTime.now()+","+fence.getColor()+","+fence.getBaoliu1()+","+fence.getBaoliu6()+","+fence.getBaoliu2()+","+fence.getBaoliu3()+","+fence.getBaoliu4()+",END";
      Udp_Out.udp_to_cs(xieyi);
      String type = request.getParameter("type");
      String name = request.getParameter("name");
      String floor = request.getParameter("floor");
      String shape = request.getParameter("shape");
         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);
         }
   }
   @RequestMapping(value = "/addfence0.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public String addfence0(HttpServletRequest request) {
      tb_fence fence = new tb_fence();
      fence.setFloor(request.getParameter("floor"));
      fence.setType("变电站");
//    fence.setBaoliu2(request.getParameter("baoliu2"));
      fence.setName(request.getParameter("name")+1);
      fence.setBaoliu7(request.getParameter("baoliu7"));
//    String zuobiao =(String) request.getParameter("zuobiao");
      String zuobiao = ZhwService.getfencezuobiao();
      fence.setZuobiao(zuobiao);
      String haibagao = ZhwService.getfencehaibagao();
      fence.setBaoliu6(haibagao);
      fence.setShape("多边形");
      fence.setStart("00:00:00");
      fence.setStop("23:59:59");
      fence.setColor(request.getParameter("color"));
      fence.setBaoliu3(request.getParameter("baoliu3"));
      fence.setBaoliu1(request.getParameter("baoliu1"));
      fence.setBumen(request.getParameter("bumen"));
      fence.setBaoliu4(request.getParameter("baoliu4"));
      int aaa = ZhwService.drawFence_add2(fence);
      String xieyi = "BSTOCS1,ADDFENCE,"+fence.getFloor()+","+fence.getType()+","+fence.getBumen()+","+request.getParameter("name")+","+fence.getZuobiao().replace(",", ":")+","+fence.getShape()+","+fence.getStart()+","+fence.getStop()+","+GetNowTime.now()+","+fence.getColor()+","+fence.getBaoliu1()+","+fence.getBaoliu7()+",,"+fence.getBaoliu3()+","+fence.getBaoliu4()+",END";
      Udp_Out.udp_to_cs(xieyi);
      String type = request.getParameter("type");
      String name = request.getParameter("name");
      String floor = request.getParameter("floor");
      String shape = request.getParameter("shape");
//       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 = "/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"));
      int aaa = 1;
      List<tb_fence> fencesss = ZhwService.getFenceaaa(fence.getName());
      if (fencesss.size() == 0) {
         aaa = 0;
         fence.setBaoliu1(request.getParameter("fencegao"));
         String zuobiao =(String) request.getParameter("zuobiao");
         String zuobiaodufen = (String) request.getParameter("zuobiaodufen");
         zuobiao = zuobiao.replace(",", ":");
         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()+","+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="/trackTagid.do", method = { RequestMethod.POST, RequestMethod.GET })
   @RequestMapping(value="/trackTagid2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_track> queryTagid(HttpServletRequest request) throws ParseException {
   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");
@@ -199,49 +580,109 @@
      return tagList;
   }
   
   @RequestMapping(value="/trackTagid.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_track> queryTagid(HttpServletRequest request) throws ParseException {
      String panduan = request.getParameter("panduan");
       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");
       if (fence.equals("空")) {
         List<tb_track> tagList = new ArrayList<>();
         if (panduan.equals("true")) {
            tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         } else {
            tagList = ZhwService.getTagtrack2(tag_id, begin_time, end_time, floor);
         }
         return tagList;
       } else {
         List<tb_track> tagList = new ArrayList<>();
         if (panduan.equals("true")) {
            tagList = ZhwService.getTagtrack(tag_id, begin_time, end_time, floor);
         } else {
            tagList = ZhwService.getTagtrack2(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="/trackTagid3.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_track> queryTagid3(HttpServletRequest request) throws ParseException {
       String tag_id = request.getParameter("tagid");
       String begin_time = request.getParameter("begin");
       String end_time = request.getParameter("end");
       List<tb_track> tagList = ZhwService.getTagtrack3(tag_id, begin_time, end_time);
      return tagList;
   }
   @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());
@@ -249,52 +690,76 @@
         position.setTime(node.getP_addtiem());
         position.setFence(node.getP_fence());
         position.setSousuo(node.getP_sousuo());
         position.setShipin(node.getP_shipin());
         position.setBumen(node.getP_department());
         position.setBaoliu22(node.getBaoliu22());
//       position.setPhone(node.getP_phone());
//       position.setIdcardnum(node.getP_idcardnum());
//       position.setJingdu(node.getP_jingdu());
//       position.setWeidu(node.getP_weidu());
//       position.setGaocheng(node.getBaoliu10());
         
         finalPositionList.add(position);
      }
      return finalPositionList;
   }
   
   @RequestMapping(value="/getRealPosition_all.do", method = { RequestMethod.POST, RequestMethod.GET })
   @RequestMapping(value="/getRealPositiona.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;
   public JSONObject getRealPositiona(HttpServletRequest request) {
      String floor = request.getParameter("floor");
      JSONObject json = new JSONObject();
      //根据时间筛选出数据
      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_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 : personLocationList) {
         List<tb_tag> taglist = new ArrayList<tb_tag>();
      for (tb_person node : realLocationList) {
         if (node.getP_online().equals("1")) {
         String tagid = node.getP_tagid();
         taglist = ZhwService.getRealTagState(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(""+((double)Math.round(Double.parseDouble(node.getP_x()))/100));
         position.setPosy(""+((double)Math.round(Double.parseDouble(node.getP_y()))/100));
         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.setBumen(node.getP_department());
         position.setPhone(node.getP_phone());
         position.setIdcardnum(node.getP_idcardnum());
         position.setJingdu(node.getP_jingdu());
         position.setWeidu(node.getP_weidu());
         position.setGaocheng(node.getBaoliu10());
         
         if (taglist.isEmpty()) {
            position.setPower("");
            position.setLife("");
         } else {
            position.setPower(taglist.get(0).getPower());
            position.setLife(taglist.get(0).getStatus());
         finalPositionList.add(position);
         }
      }
      json.put("dataList", finalPositionList);
      return json;
   }
   @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());
@@ -302,13 +767,41 @@
         position.setSos(node.getP_sos());
         position.setTime(node.getP_addtiem());
         position.setFence(node.getP_fence());
         position.setShipin(node.getP_shipin());
         position.setShipingname(node.getP_shipingname());
         position.setChaichu(node.getBaoliu6());
         position.setBaoliu20(node.getBaoliu20());
         position.setBaoliu21(node.getBaoliu21());
         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());
      json.put("time", realTrackList.get(0).getP_addtiem());
      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) {
@@ -397,10 +890,52 @@
   @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;
   }
   
   @RequestMapping(value="/getSysSetting_list2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public String getSysSetting_list2(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      List<tb_system> settingList = sysSettingService.getSetting();
      List<tb_nav> navList = ZhwService.getnav();
      List<tb_person> persons = ZhwService.getbumen();
      List<String> realAttendance_k = new ArrayList<String>();
      List<tb_department> departments = basicInfoService.getDepartmentManagement2();
      for (int i =0;i < departments.size(); i++) {
         realAttendance_k.add(departments.get(i).getDepartmentName());
      }
      json.put("dataList", settingList);
      json.put("dataList2", navList);
      json.put("dataList3", persons);
      json.put("dataList4", realAttendance_k);
      return json.toString();
   }
   @RequestMapping(value="/getSysSetting_list3.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public String getSysSetting_list3(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      List<tb_system> settingList = sysSettingService.getSetting();
      List<tb_nav> navList = ZhwService.getnav();
      List<tb_person> persons = ZhwService.getbumen();
      List<String> realAttendance_k = new ArrayList<String>();
      List<tb_department> departments = basicInfoService.getDepartmentManagement2();
      for (int i =0;i < departments.size(); i++) {
         realAttendance_k.add(departments.get(i).getDepartmentName());
      }
      HttpSession session = request.getSession();
      ServletContext application = session.getServletContext();
      String username = application.getAttribute("username").toString();
      json.put("xianuser", username);
      json.put("dataList", settingList);
      json.put("dataList2", navList);
      json.put("dataList3", persons);
      json.put("dataList4", realAttendance_k);
      return json.toString();
   }
   @RequestMapping(value="/getAnchorInfo.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_achor> getAnchorInfo(HttpServletRequest request) { 
@@ -420,23 +955,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 {  
@@ -447,6 +999,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) {  
@@ -454,25 +1018,27 @@
      return mapList;
   }
   
   @RequestMapping(value="/qiehuanditu_option2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_map> qiehuanditu_option2(HttpServletRequest request) {
      String floor = request.getParameter("floor");
      List<tb_map> mapList = ZhwService.getFloor2(floor);
      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"));
      //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();
@@ -480,6 +1046,16 @@
      return maplist;
   }
   
   @RequestMapping(value="/qiehuanditu1.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<String> qiehuanditu1(HttpServletRequest request) {
      List<tb_map> maps = mapService.getMapManagement();
      List<String> maplist = new ArrayList<String>();
      String map = maps.get(0).getMapname();
      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);
@@ -733,12 +1309,95 @@
   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 = "/jinmengaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void jinmengaojing(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      ZhwService.jinmengao(tagid);
      String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",未授权进入告警,END";
      Udp_Out.udp_to_cs(xieyi);
   }
   @RequestMapping(value = "/chumengaojing.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void chumengaojing(HttpServletRequest request) throws IOException {
      String tagid=request.getParameter("tagid");
      ZhwService.chumengao(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();
      String xieyi = "BSTOCS1,DELLWARNALL,END";
      Udp_Out.udp_to_cs(xieyi);
      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);
      }
      List<tb_person> jinchumenlist = ZhwService.getjinchumengaojing();
      for (int i=0; i<fencelist.size(); i++) {
         String tagid = chufencelist.get(i).getP_tagid();
         ZhwService.jinmengao(tagid);
         ZhwService.chumengao(tagid);
//       String xieyi = "BSTOCS1,DELLWARN," +tagid+ ",出区域告警,END";
//       Udp_Out.udp_to_cs(xieyi);
      }
   }
   @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 = "/shipinzhuangtai2.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void shipinzhuangtai2(HttpServletRequest request){
      String tagid=request.getParameter("tagid");
      ZhwService.shipin(tagid);
   }
   
   @RequestMapping(value = "/sousuo.do", method = { RequestMethod.POST, RequestMethod.GET })
@@ -754,4 +1413,1158 @@
      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)/100;//-54732
         Double yo = -(y)/100;//+10268
         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="/getRealPositionsan2.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_realpositoin> getRealPositionsan2(HttpServletRequest request) {
      long timeStart = 0;
      //根据时间筛选出数据
      List<tb_person> realLocationList = ZhwService.getpersonLocationsan();
      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) {
         double jiao = 0.00;
         if (persons.containsKey(node.getP_tagid())) {
            double x1 = Double.valueOf(node.getP_x());
            double y1 = Double.valueOf(node.getP_y());
            double x2 = Double.valueOf(persons.get(node.getP_tagid())[0]);
            double y2 = Double.valueOf(persons.get(node.getP_tagid())[1]);
            double c = x1-x2;
            double a = y1-y2;
            if (node.getBaoliu22() != null && node.getBaoliu22() != "") {
               if (node.getBaoliu22().equals("0")) {
                  jiao = Math.toDegrees(Math.atan2(c, a));
               } else {
                  String[] xy = node.getBaoliu23().split(",");
                  jiao = Math.toDegrees(Math.atan2(Double.valueOf(xy[0]), Double.valueOf(xy[1])));
               }
               if (String.valueOf(jiao).equals("0.0")) {
                  jiao = Double.valueOf(persons.get(node.getP_tagid())[2]).doubleValue();
               }
            }
         }
         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.setSex(node.getP_sex());
         position.setMinzu(node.getP_minzu());
         position.setPhone(node.getP_phone());
         position.setBumen(node.getP_department());
         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.setJiao(String.valueOf(jiao));
         position.setBaoliu22(node.getBaoliu22());
         position.setBaoliu23(node.getBaoliu23());
         position.setBaoliu24(node.getBaoliu24());
         String[] bb = new String[]{node.getP_x(),node.getP_y(),String.valueOf(jiao)};
         persons.put(node.getP_tagid(), bb);
         finalPositionList.add(position);
      }
      return finalPositionList;
   }
   @RequestMapping(value="/getRealPositionsan3.do", method = { RequestMethod.POST, RequestMethod.GET })
   @ResponseBody
   public List<tb_realpositoin> getRealPositionsan3(HttpServletRequest request) {
      long timeStart = 0;
      String floor = request.getParameter("floor");
      //根据时间筛选出数据
      List<tb_person> realLocationList = ZhwService.getpersonLocationsan3(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) {
         double jiao = 0.00;
         if (persons.containsKey(node.getP_tagid())) {
            double x1 = Double.valueOf(node.getP_x());
            double y1 = Double.valueOf(node.getP_y());
            double x2 = Double.valueOf(persons.get(node.getP_tagid())[0]);
            double y2 = Double.valueOf(persons.get(node.getP_tagid())[1]);
            double c = x1-x2;
            double a = y1-y2;
            if (node.getBaoliu22().equals("0")) {
               jiao = Math.toDegrees(Math.atan2(c, a));
            } else {
               String[] xy = node.getBaoliu23().split(",");
               jiao = Math.toDegrees(Math.atan2(Double.valueOf(xy[0]), Double.valueOf(xy[1])));
            }
            if (String.valueOf(jiao).equals("0.0")) {
               jiao = Double.valueOf(persons.get(node.getP_tagid())[2]).doubleValue();
            }
         }
         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.setSex(node.getP_sex());
         position.setMinzu(node.getP_minzu());
         position.setPhone(node.getP_phone());
         position.setBumen(node.getP_department());
         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.setJiao(String.valueOf(jiao));
         position.setBaoliu22(node.getBaoliu22());
         position.setBaoliu23(node.getBaoliu23());
         position.setBaoliu24(node.getBaoliu24());
         String[] bb = new String[]{node.getP_x(),node.getP_y(),String.valueOf(jiao)};
         persons.put(node.getP_tagid(), bb);
         finalPositionList.add(position);
      }
      return finalPositionList;
   }
   public double qiujiao(int a,int b,int c) {
      double angle = 0.00;
      if (a+b-c!=0) {
         angle=Math.toDegrees(Math.acos((a*a+b*b-c*c)/(2*a*b)));//C的角度
      }
        return angle;
    }
   @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.getpersonLocationsan2();
//    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) {
//       if (node.getP_online().equals("1")) {
            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.setIdcardnum(node.getP_idcardnum());
            position.setPosx(node.getP_x());
            position.setPosy(node.getP_y());
            position.setFloor(node.getP_floor());
            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());
            position.setPhone(node.getP_phone());
            position.setType(node.getP_type());
            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();
      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(HttpServletRequest request) {
      String name = request.getParameter("name");
      List<tb_shipin> shipins = fenceService.searchshipinManagement(name);
      String yonghuming = shipins.get(0).getYonghuming();
      String mima = shipins.get(0).getMima();
      String ipdizhi = shipins.get(0).getBaoliu1();
        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://"+yonghuming+":"+mima+"@"+ipdizhi+":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();
   }
   @RequestMapping(value = "jingweijuli.do", method = { RequestMethod.POST, RequestMethod.GET })
    public String tojisuan(HttpServletRequest request,  HttpServletResponse response){
      String toPage = "forward:/hxzk/basicInfo/jisuan.jsp";
      List<tb_jingwei> findjingwei = ZhwService.getjingwei();
        request.setAttribute("dataList", findjingwei);
        return toPage;
    }
   @ResponseBody
    @RequestMapping(value = "jisuanjingwei.do",  method = { RequestMethod.POST, RequestMethod.GET })
    public JSONObject jisuanjingwei (String str) {
        JSONObject json = new JSONObject();
        String disab = disab(str);
        String[] split = str.split(";");
        String qishi = split[1]+"/"+split[0];
        String zhongzhi = split[3]+"/"+split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        ZhwService.addjingwei(jingwei);
        List<tb_jingwei> findjingwei = ZhwService.getjingwei();
        json.put("jieguo",disab);
        json.put("dataList",findjingwei);
        return json;
    }
   @ResponseBody
    @RequestMapping(value = "jisuanjingwei2.do",  method = { RequestMethod.POST, RequestMethod.GET })
    public JSONObject jisuanjingwei2 (String str) {
        JSONObject json = new JSONObject();
        String[] split = str.split(";");
        double[] sy = gpstodu(split[1], split[0]);
        String str2 = sy[1]+";"+sy[0];
        json.put("jieguo",str2);
        return json;
    }
   @ResponseBody
    @RequestMapping(value = "jisuanjingwei3.do",  method = { RequestMethod.POST, RequestMethod.GET })
    public JSONObject jisuanjingwei3 (HttpServletRequest request) {
        JSONObject json = new JSONObject();
        String qidian = request.getParameter("qidian");
        String zhongdian = request.getParameter("zhongdian");
        String[] qidians = qidian.split(",");
        String[] zhongdians = zhongdian.split(",");
        String str = qidians[2]+";"+qidians[4]+";"+zhongdians[2]+";"+zhongdians[4];
        String disab = disab(str);
        String[] split = str.split(";");
        String qishi = split[1]+"/"+split[0];
        String zhongzhi = split[3]+"/"+split[2];
        tb_jingwei jingwei = new tb_jingwei();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(new Date());
        jingwei.setQishi(qishi);
        jingwei.setZhongzhi(zhongzhi);
        jingwei.setJieguo(disab);
        jingwei.setAddtime(format);
        ZhwService.addjingwei(jingwei);
        List<tb_jingwei> findjingwei = ZhwService.getjingwei();
        json.put("jieguo",disab);
        json.put("dataList",findjingwei);
        return json;
    }
   @ResponseBody
   @RequestMapping(value = "/startjob.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String startjob(HttpServletRequest request) {
      List<tb_fence> fences = fenceService.getFenceLista();
      for (int i = 0;i<fences.size();i++) {
         tb_jobhistory job = new tb_jobhistory();
         job.setFencename(fences.get(i).getName());
         job.setDepartment(fences.get(i).getBumen());
         job.setTagid(fences.get(i).getBaoliu2());
         job.setHigh(fences.get(i).getBaoliu1());
         job.setFenceaddtime(fences.get(i).getAddtime());
         job.setType("开始作业");
         job.setBeizhu("");
         fenceService.zuoyeadd(job);
      }
      String xieyi = "BSTOCS1,WORK,START,END";
      Udp_Out.udp_to_cs(xieyi);
      return "1";
   }
   @ResponseBody
   @RequestMapping(value = "/endjob.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String endjob(HttpServletRequest request) {
      List<tb_fence> fences = fenceService.getFenceLista();
      for (int i = 0;i<fences.size();i++) {
         tb_jobhistory job = new tb_jobhistory();
         job.setFencename(fences.get(i).getName());
         job.setDepartment(fences.get(i).getBumen());
         job.setTagid(fences.get(i).getBaoliu2());
         job.setHigh(fences.get(i).getBaoliu1());
         job.setFenceaddtime(fences.get(i).getAddtime());
         job.setType("结束作业");
         job.setBeizhu("");
         fenceService.zuoyeadd(job);
      }
      String xieyi = "BSTOCS1,WORK,STOP,END";
      Udp_Out.udp_to_cs(xieyi);
      return "1";
   }
   @ResponseBody
   @RequestMapping(value = "/suspendjob.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String suspendjob(HttpServletRequest request) {
      List<tb_fence> fences = fenceService.getFenceLista();
      for (int i = 0;i<fences.size();i++) {
         tb_jobhistory job = new tb_jobhistory();
         job.setFencename(fences.get(i).getName());
         job.setDepartment(fences.get(i).getBumen());
         job.setTagid(fences.get(i).getBaoliu2());
         job.setHigh(fences.get(i).getBaoliu1());
         job.setFenceaddtime(fences.get(i).getAddtime());
         job.setType("暂停作业");
         job.setBeizhu("");
         fenceService.zuoyeadd(job);
      }
      String xieyi = "BSTOCS1,WORK,PAUSE,END";
      Udp_Out.udp_to_cs(xieyi);
      return "1";
   }
   @ResponseBody
   @RequestMapping(value = "/getzuoye.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject getzuoye(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      List<tb_jobhistory> tb_jobhistorys = fenceService.getzuoye();
      json.put("dataList", tb_jobhistorys);
      return json;
   }
   @ResponseBody
   @RequestMapping(value = "/jobexport.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String jobexport(HttpServletRequest request, HttpServletResponse response) {
      List<tb_jobhistory> tb_jobhistorys = fenceService.getzuoye();
      String[] rowName = { "序号", "操作步骤", "围栏名称", "关联部门", "关联标签", "围栏高度", "围栏绘制时间", "记录时间", "备注" };
      List<Object[]> dataList = objectToArray_job(tb_jobhistorys);
      ExcelUtils excel = new ExcelUtils("作业历史", rowName, dataList);
      OutputStream out;
      String fileName = "";
      try {
         fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
         String filePath2 = request.getServletContext().getRealPath("/") + "hxzk/image/excels/"+fileName;
         out = new FileOutputStream(filePath2);
         excel.export(out);
         out.flush();
         out.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return fileName;
   }
   @RequestMapping(value = "/tiaozhuanfa.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String tiaozhuanfa(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
      String floor = request.getParameter("floor");
      String toPage = "forward:/hxzk/mapshow/mapShowfa.jsp";
      request.setAttribute("floor", floor);
      return toPage;
   }
   @ResponseBody
   @RequestMapping(value = "/getmessagea.do", method = { RequestMethod.POST, RequestMethod.GET})
   public String getmessagea(HttpServletRequest request) {
      JSONObject json = new JSONObject();
      List<tb_message> messages = ZhwService.getmessage();
      Date date = new Date();
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      cal.add(Calendar.DATE, -3);
      String date2 = simpleDateFormat.format(cal.getTime());
      ZhwService.deletemessage(date2);
      json.put("dataList", messages);
      return json.toString();
   }
   @RequestMapping(value = "/sendmessage.do", method = {RequestMethod.POST, RequestMethod.GET})
   public void sendmessage(HttpServletRequest request) {
      HttpSession session = request.getSession();
      ServletContext application = session.getServletContext();
      String username = application.getAttribute("username").toString();
      String arr = request.getParameter("arr");
      String message = request.getParameter("message");
      if (arr.equals("all")) {
         List<tb_person> persons = ZhwService.getbumen();
         for (int i=0; i<persons.size(); i++) {
            String xieyi = "BSTOCS1,TOMESSAGE,"+persons.get(i).getP_tagid()+","+message+","+username+",END";
            Udp_Out.udp_to_cs(xieyi);
         }
      } else {
         String[] tagids = arr.split(",");
         for (int i=0; i<tagids.length; i++) {
            String xieyi = "BSTOCS1,TOMESSAGE,"+tagids[i]+","+message+","+username+",END";
            Udp_Out.udp_to_cs(xieyi);
         }
      }
   }
   @ResponseBody
   @RequestMapping(value="getlixiana.do",method= {RequestMethod.POST,RequestMethod.GET})
   public String getlixiana() {
      String pan = ZhwService.getlixian();
      SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String date = sf.format(new Date());
      int aaa = get_time_cha_s(date,pan);
      String bbb = "";
      if (aaa < 20) {
         bbb = "true";
      } else {
         bbb = "false";
      }
      return bbb;
   }
   @RequestMapping(value = "updateexe.do",method= {RequestMethod.POST,RequestMethod.GET})
    public void tiaoguo(HttpServletResponse response, HttpServletRequest request) {
        String url = "file:///D:\\eclipseworkspace\\定位引擎软件\\定位引擎软件.rar";
        try {
            response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode("定位平台软件.rar","UTF-8") + "\"");
            response.setContentType("APPLICATION/OCTET-STREAM");
            BufferedInputStream in = new BufferedInputStream(new URL(url).openStream());
            BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
            byte dataBuffer[] = new byte[1024];
            int bytesRead;
            while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
                out.write(dataBuffer, 0, bytesRead);
            }
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   @RequestMapping(value = "todownload.do", method = {RequestMethod.POST,RequestMethod.GET})
   public String todownload(HttpServletRequest request) {
      String toPage = "forward:/hxzk/gujian/download.html";
      return toPage;
   }
   @RequestMapping(value = "download.do", method = {RequestMethod.POST,RequestMethod.GET})
   public String download(HttpServletRequest request,HttpServletResponse response) {
      String toPage = "forward:/hxzk/gujian/download.html";
      String filename = request.getParameter("name");
      String filepath = "D:\\gujian\\";
      File file = new File(filepath+filename);
      try {
         response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode(filename,"UTF-8") + "\"");
         response.setContentType("APPLICATION/OCTET-STREAM");
         FileInputStream ina = new FileInputStream(file);
         BufferedInputStream in = new BufferedInputStream(ina);
         BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
         int len = 0;
         while ((len = in.read()) != -1) {
            out.write(len);
         }
         out.flush();
         out.close();
         in.close();
      } catch (Exception e) {
         // TODO 自动生成的 catch 块
         e.printStackTrace();
      }
      return toPage;
   }
   @RequestMapping(value = "/mapdisplay.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String mapdisplay(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
      String toPage = "forward:/hxzk/mapdisplay/mapdisplay.jsp";
      return toPage;
   }
   @RequestMapping(value = "/tomap.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String tomap(HttpServletRequest request,  HttpServletResponse response) throws ServletException, IOException {
      String toPage = "forward:/hxzk/mapshow/mapShowfeng3.jsp";
      return toPage;
   }
   public static int get_time_cha_s(String a,String b) {
      final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
      Date date1=parseDateByPattern(a, yyyyMMddHHmmss);
      Date date2=parseDateByPattern(b, yyyyMMddHHmmss);
      return getTimeDelta(date1, date2);
   }
   public static Date parseDateByPattern(String dateStr,String dateFormat){
      SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
      try {
         return sdf.parse(dateStr);
      } catch (ParseException e) {
         e.printStackTrace();
      }
      return null;
   }
   public static int getTimeDelta(Date date1,Date date2){
      long timeDelta=(date1.getTime()-date2.getTime())/1000;//单位是秒
      int secondsDelta=timeDelta>0?(int)timeDelta:(int)Math.abs(timeDelta);
      return secondsDelta;
   }
   /**计算2个时分秒的差*/
   public static int get_time_cha_HMS(String a,String b) {
      final String HHmmss = "HH:mm:ss";
      Date date1=parseDateByPattern(a, HHmmss);
      Date date2=parseDateByPattern(b, HHmmss);
      return getTimeDelta(date1, date2);
   }
   /**计算时间差返回boolean*/
   public static boolean shijiancha(String time,int p) {
      boolean a=false;
      int b= get_time_cha_s(GetNowTime.now(),time);
      //当前时间和之前时间差大于某个数值p
      if(b>p) {
         a=true;
      }
      return a;
   }
   // 作业信息 导出表格 对象转数组
      public static List<Object[]> objectToArray_job(List<tb_jobhistory> history_powerList) {
         List<Object[]> reList = new ArrayList<>();
         for (int i = 0; i < history_powerList.size(); i++) {
            List<String> words = new ArrayList<String>();
            tb_jobhistory history_power = (tb_jobhistory) history_powerList.get(i);
            words.add(history_power.getId() + "");
            words.add(history_power.getType());
            words.add(history_power.getFencename());
            words.add(history_power.getDepartment());
            words.add(history_power.getTagid());
            words.add(history_power.getHigh());
            words.add(history_power.getFenceaddtime());
            words.add(history_power.getAddtime());
            words.add(history_power.getBeizhu());
            String[] array = words.toArray(new String[0]);
            reList.add(array);
         }
         return reList;
      }
   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;
              }
          }
       public static String todu(String strs) {
              int i = strs.indexOf('.');
              String strDu = 1 < 0 ? strs : strs.substring(0, i);
              String strFen = "";
              String strMiao = "";
              if (i > 0) {
                  Float fen = Float.parseFloat(strs.substring(i));
                  strFen = Float.toString(fen * 60);
                  i = strFen.indexOf('.');
                  if (i > 0) {
                      Float miao = Float.parseFloat(strFen.substring(i));
                      strFen = strFen.substring(0, i);
                      strMiao = Float.toString(miao * 60);
                      i = strMiao.indexOf('.');
                      strMiao = strMiao.substring(0, i + 4);
                      strMiao = String.format("%.2f", Float.parseFloat(strMiao));
                  }
              }
              String Du = strDu + strFen + strMiao;
              return Du;
          }
         static double a=6378.137;
          static double e=0.0818192;
          static double k0=0.9996;
          static double e2=e*e;
          static double e4=e2*e2;
          static double e6=e4*e2;
          static double E0=500;
          static double N0=0;
          static String floor="0";
          static double lat_a =0;
          static double lon_a =0;
          static double lon_b=0;
          static double lat_b=0;
          static double xa=0;
          static double ya=0;
          static double xb=0;
          static double yb=0;
          static int k=0;
          static int sizes=2;
          static double[] xycs=null;
          static double utme0;
          static double utmn0;
          static double c;
          static double s;
          static double t;
          static double f;
          /**计算2个经纬度的距离*/
          public static String disab(String jwd) {
              DecimalFormat df = new DecimalFormat("0.00");
              String[] bb=jwd.split(";");
              double jd0=Double.parseDouble(bb[1]);
              double wd0=Double.parseDouble(bb[0]);
              double jd1=Double.parseDouble(bb[3]);
              double wd1=Double.parseDouble(bb[2]);
              double[] a=run_gps2xyurt(wd0,jd0,wd1,jd1);
              double disa=a[0]*a[0]+a[1]*a[1];
              double dis=Math.sqrt(Math.abs(disa))*100;
              String temp = df.format(dis);
              System.out.println(jwd+"的距离是:"+temp);
              return temp;
          }
          public static double[] run_gps2xyurt(
                  double lat0,
                  double lon0,
                  double lat,
                  double lon) {
              int[] realxy=new int[2];
              double[] xycs=initiize_ublox_zeropoint(lat0, lon0,0);
              double x0=xycs[0];
              double y0=xycs[1];
              double c=xycs[2];
              double s=xycs[3];
              double[] xy=new double[2];
              double x= ubloxraw2xy(lat,lon)[0]-x0;
              double y=ubloxraw2xy(lat,lon)[1]-y0;
              xy[0] =c*x - s*y;
              xy[1] =s*x + c*y;
//            double x1=xy[1]*100;
//            double y1=xy[0]*100;
//
//            realxy[0]=(int)x1;
//            realxy[1]=(int)y1;
              return xy;
          }
          public static double[] initiize_ublox_zeropoint(double lat, double lon, double th){
              double[] xycs=new double[4];
              xycs[0]=ubloxraw2xy(lat,lon)[0];
              xycs[1]=ubloxraw2xy(lat,lon)[1];
              double th1=th*Math.PI/180;//x轴与正北方向夹角th(单位是度)
              xycs[2]=Math.cos(th1);
              xycs[3]=Math.sin(th1);
              return xycs;
          }
          public static double[] ubloxraw2xy(double lat, double lon) {
              double[] xy=new double[3];
              double lond = ublox_dm2d(lon);
              double latd = ublox_dm2d(lat);
              double[] dxy = utm(latd, lond);
              xy[0]= dxy[0]* 1000;
              xy[1]= dxy[1]* 1000;
              xy[2]= dxy[2];
              return xy;
          }
          public static double ublox_dm2d(double ddmm_dot_m) {
              double d0=Math.floor(ddmm_dot_m/100);
              double d=d0+(ddmm_dot_m-d0*100)/60;
              return d;
          }
          public static double[] utm(double lat,double lon) {
              double[] dxy=new double[3];
              double zonenum1=lon/6;
              //floor是地板的意思,表示向下取整
              if(zonenum1>0) {
                  zonenum1=Math.floor(zonenum1);
              }else {//向上取整
                  zonenum1=Math.ceil(zonenum1);//向上取整
              }
              double Zonenum=zonenum1+31;
              double lambda0=((Zonenum-1)*6-180+3)*(Math.PI)/180;
              double phi=lat*(Math.PI)/180;
              double lambda=lon*(Math.PI)/180;
              double v=1/Math.sqrt((1-e2*Math.pow(Math.sin(phi),2)));
              double A=(lambda-lambda0)* Math.cos(phi);
              double A2=A*A;
              double A3=A2*A;
              double A4=A3*A;
              double A5=A4*A;
              double A6=A5*A;
              double T=Math.tan(phi)* Math.tan(phi);
              double T2=T*T;
              double C=e2* Math.cos(phi)* Math.cos(phi)/(1-e2);
              double C2=C*C;
              double s=(1-e2/4-3*e4/64-5*e6/256)* phi-
                      (3*e2/8+3*e4/32+45*e6/1024)* Math.sin(2*phi)+
                      (15*e4/256+45*e6/1024)* Math.sin(4* phi)-35*e6/3072* Math.sin(6*phi);
              dxy[0]=E0+k0*a*v*(A+(1-T+C)*A3/6+(5-18*T+T2)*A5/120);
              dxy[1]=N0+k0*a*(s+v* Math.tan(phi)*(A2/2+(5-T+9*C+4*C2)*A4/24+(61-58*T+T2)*A6/720));
              dxy[2]=Zonenum;
              return dxy;
          }
          //度分转度
          public static String todufen(String Du, String Fen, String Miao) {
              Float strDu = Float.valueOf(Du);
              Float strFen = Float.valueOf(Fen) / 60;
              Float strMiao = Float.valueOf(Miao) / 60;
              Float dufenmiao = strDu + strFen + strMiao;
              String format = String.format("%.6f", dufenmiao);
              return format;
          }
          public static double[] gpstodu(String gps_weidu, String gps_jingdu) {
              double[] a = {0, 0};
              String weidu = todufen(gps_weidu.substring(0, 2), gps_weidu.substring(2, 4), gps_weidu.substring(4));
              String jingdu = todufen(gps_jingdu.substring(0, 3), gps_jingdu.substring(3, 5), gps_jingdu.substring(5));
              a[0] = Double.parseDouble(weidu);
              a[1] = Double.parseDouble(jingdu);
              return a;
          }
}