15832144755
2022-03-17 bc131131c5c96f8cb3bed679d4a359820c22e335
src/main/java/com/hxzkoa/controller/GpsController.java
@@ -1,12 +1,14 @@
package com.hxzkoa.controller;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
@@ -21,11 +23,12 @@
import org.springframework.web.servlet.ModelAndView;
import com.hxzkoa.json.tb_gps;
import com.hxzkoa.json.tb_person;
import com.hxzkoa.json.tb_realocation;
import com.hxzkoa.json.tb_system;
import com.hxzkoa.json.tb_track;
import com.hxzkoa.json.tb_tag;
import com.hxzkoa.services.GpsService;
import com.hxzkoa.services.LabelService;
import com.hxzkoa.services.LocationService;
import com.hxzkoa.services.SysSettingService;
import com.hxzkoa.udp.Dell_GNGGA;
import com.hxzkoa.udp.Udp_Out;
@@ -34,7 +37,6 @@
import com.hxzkoa.util.ExcelUtils;
import com.hxzkoa.util.ModifyConfig;
import com.hxzkoa.util.PageUtil;
import com.hxzkoa.util.RequestUtils;
import net.sf.json.JSONObject;
@@ -43,7 +45,11 @@
   @Autowired
   private GpsService gpsService;
   @Autowired
   private LabelService labelService;
   @Autowired
   private SysSettingService sysSettingService;
   @Autowired
   private LocationService locationService;
   
   @ResponseBody
   @RequestMapping(value = "/updateperson.do",method = { RequestMethod.POST, RequestMethod.GET })
@@ -56,13 +62,13 @@
   @RequestMapping(value = "/xinhuifang.do",method = { RequestMethod.POST, RequestMethod.GET })
   public ArrayList<String> xinhuifang(HttpServletRequest request) {
      ArrayList<String> baowen = AddTxt.txt2String();
      System.out.print(baowen.get(0));
      //System.out.print(baowen.get(0));
      return baowen;
   }
   
   @RequestMapping(value = "/huifang.do",method = { RequestMethod.POST, RequestMethod.GET })
   public String huifang(HttpServletRequest request) {
      String toPage = "forward:/hxzk/GPS/gpsHuifang.jsp";
      String toPage = "forward:/hxzk/baidu.jsp";
      return toPage;
   }
   
@@ -145,6 +151,20 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/gpsManagement_deletea.do", method = { RequestMethod.POST, RequestMethod.GET })
   public int gpsManagement_deletea(HttpServletRequest request) throws ParseException {
      String checkValStr = request.getParameter("checkVal");
      checkValStr = checkValStr.replaceAll("\"", "");
      String[] checkVal = checkValStr.split(",");
      int aaa = gpsService.gpsManagement_deletea(checkVal);
      for(int i = 0; i < checkVal.length; i++) {
         String xieyi = "BSTOCS1,DELETEGPS,"+checkVal[i]+",END";
         Udp_Out.udp_to_cs(xieyi);
      }
      return aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/gpsManagement_export.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String gpsManagement_export(HttpServletRequest request, HttpServletResponse response) {
      String toPage = "forward:/hxzk/GPS/gpsManagement.jsp";
@@ -209,6 +229,22 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocationa.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject historicalgpsLocationa(HttpServletRequest request) throws SQLException {
      JSONObject json = new JSONObject();
      String date = request.getParameter("date");
      int aaa = locationService.searchtablenameLocation("tb_gps_track_"+date);
      if (aaa != 0) {
         List<tb_gps> trackList = gpsService.getTracka(date);
         json.put("dateList", trackList);
      } else {
         List<tb_gps> trackList = new ArrayList<>();
         json.put("dateList", trackList);
      }
      return json;
   }
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_page.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String historicalgpsLocation_page(HttpServletRequest request) {
      String pageStr = request.getParameter("page");
@@ -256,6 +292,21 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_deletea.do", method = { RequestMethod.POST, RequestMethod.GET })
   public int historicalgpsLocation_deletea(HttpServletRequest request) {
      String checkValStr = request.getParameter("checkVal");
      String datea = request.getParameter("datea");
      checkValStr = checkValStr.replaceAll("\"", "");
      String[] checkVal = checkValStr.split(",");
      int bbb = locationService.searchtablenameLocation("tb_gps_track_"+datea);
      int aaa = 0;
      if (bbb != 0) {
         aaa = gpsService.realTimegpsLocation_deletea(checkVal,datea);
      }
      return aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_deleteAll.do", method = { RequestMethod.POST, RequestMethod.GET })
   public void historicalLocation_deleteAll(HttpServletRequest request) {
      String date = request.getParameter("aaaa");
@@ -263,6 +314,18 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_deleteAlla.do", method = { RequestMethod.POST, RequestMethod.GET })
   public int historicalLocation_deleteAlla(HttpServletRequest request) {
      String date = request.getParameter("date");
      int bbb = locationService.searchtablenameLocation("tb_gps_track_"+date);
      int aaa = 0;
      if (bbb != 0) {
         aaa = gpsService.realTimegpsLocation_deleteAlla(date);
      }
      return aaa;
   }
   @ResponseBody
   @RequestMapping(value = "/getstatus.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String getstatus(HttpServletRequest request) {
      String tagid = request.getParameter("tagid");
@@ -271,6 +334,15 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/getstatusss.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String getstatusss(HttpServletRequest request) {
      String tagid = "8888";
      //System.out.print("执行了");
      String zhuangtai = gpsService.getpersontagid(tagid);
      return zhuangtai;
   }
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_search.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String historicalgpsLocation_search(HttpServletRequest request) {
      String input = request.getParameter("input");
@@ -287,6 +359,23 @@
   }
   
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_searcha.do", method = { RequestMethod.POST, RequestMethod.GET })
   public JSONObject historicalgpsLocation_searcha(HttpServletRequest request) {
      String input = request.getParameter("tagid");
      String date = request.getParameter("date");
      JSONObject json = new JSONObject();
      int aaa = locationService.searchtablenameLocation("tb_gps_track_"+date);
      if (aaa != 0) {
         List<tb_gps> historicalLocationList = gpsService.searchRealTimegpsLocation(input,date);
         json.put("dataList", historicalLocationList);
      } else {
         List<tb_gps> abc = new ArrayList<>();
         json.put("dataList", abc);
      }
      return json;
   }
   @ResponseBody
   @RequestMapping(value = "/historicalgpsLocation_export.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String gpshistoricalPower_export(HttpServletRequest request, HttpServletResponse response) {
      String toPage = "forward:/hxzk/label/historicalgpsLocation.jsp";
@@ -294,21 +383,10 @@
      String begin = request.getParameter("begintime");
      String end = request.getParameter("endtime");
      String date = request.getParameter("date");
//    Enumeration<String> paraNames=request.getParameterNames();
//    String thisName = null;
//    String thisValue = null;
//    String[] value = null;
//    int i = 0;
//    for(Enumeration<String> e=paraNames;e.hasMoreElements();){
//         thisName=e.nextElement()+"";  //name名
//         thisValue=request.getParameter(thisName);   //name名对应的值
//         value[i] = thisValue;
//         i++;
//     }
      List<tb_gps> historicalLocationList = gpsService.getRealTimegpsLocation(tagid,begin,end,date);
      String[] rowName = {"序号", "设备编号","纬度","经度","GPS状态","卫星数","海拔高","差分站ID","电量","更新时间"};
      List<Object[]> dataList = objectToArray(historicalLocationList);
      System.out.print(dataList.get(0));
      //System.out.print(dataList.get(0));
      ExcelUtils excel = new ExcelUtils("GPS数据", rowName, dataList);
      OutputStream out;
      try {
@@ -326,6 +404,27 @@
      return toPage;
   }
   
   @ResponseBody
   @RequestMapping(value = "/totxt.do", method = { RequestMethod.POST, RequestMethod.GET })
   public String totxt(HttpServletRequest request,HttpServletResponse response) throws IOException {
      String toPage = "forward:/hxzk/label/historicalgpsLocation.jsp";
      String date = request.getParameter("date");
      InputStream is;
      OutputStream os;
      String filename = date + ".txt";
      response.setHeader("Content-Disposition", "attachement;filename=" + filename);
      is = new FileInputStream("C:\\" +date+ ".txt");
      os = response.getOutputStream();
      int len = 0;
        byte[] buffer = new byte[1024];
        while ((len = is.read(buffer)) != -1) {
            os.write(buffer, 0, len);
        }
        os.close();
        is.close();
      return toPage;
   }
   // 对象转数组
      public static List<Object[]> objectToArray(List<tb_gps> sensorManagementList) {
         List<Object[]> reList = new ArrayList<>();