智慧保安后台管理-外网
Administrator
2021-12-16 cdcd2d540de3e6ba4c2e9e7c6a879416da78c17b
src/main/java/org/springblade/modules/equipage/controller/fixed.java
@@ -107,7 +107,7 @@
            status = liveLocationService.save(liveLocation);
            //数据推送
            String s1 =
               "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time,location) " +
               "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time) " +
                  "values(" + "'" + liveLocation.getId() + "'" + "," +
                  "'" + liveLocation.getType() + "'" + "," +
                  "'" + liveLocation.getWorkerId() + "'" + "," +
@@ -138,6 +138,7 @@
    */
   @Scheduled(cron = "0 0 * * * ?")
   public void Peog() throws Exception {
      System.out.println("押运人员");
      String url = "http://47.104.104.46/api/client/getgistrack.php";
      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);
@@ -163,36 +164,41 @@
         JSONArray jsonArray = JSONArray.fromObject(a);
         String s1 = "";
         String track = jsonArray.getJSONObject(0).get("track").toString();
         JSONArray jsonArray1 = JSONArray.fromObject(track);
         for (int j = 0; j < jsonArray1.size(); j++) {
            String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
            String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
            String date = jsonArray1.getJSONObject(j).get("date").toString();
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
               //使用SimpleDateFormat的parse()方法生成Date
               Date dates = sf.parse(date);
               locus.setRecordTime(dates);
               //打印Date
            } catch (ParseException e) {
               e.printStackTrace();
            }
            locus.setLongitude(gis_jd);
            locus.setLatitude(gis_wd);
            locusService.save(locus);
            //数据推送
            s1 += "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values" +
               " (" + "'" + locus.getId() + "'" + "," +
               "'" + locus.getType() + "'" + "," +
               "'" + locus.getWorkerId() + "'" + "," +
               "'" + locus.getLongitude() + "'" + "," +
               "'" + locus.getLatitude() + "'" + "," +
               "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
            if (j != jsonArray1.size() - 1) {
               s1 += ";";
            }
         if (track.equals("[]")){
            System.out.println("数据为空");
         }
         FtpUtil.sqlFileUpload(s1);
         else {
            JSONArray jsonArray1 = JSONArray.fromObject(track);
            for (int j = 0; j < jsonArray1.size(); j++) {
               String gis_jd = jsonArray1.getJSONObject(j).get("gis_jd").toString();
               String gis_wd = jsonArray1.getJSONObject(j).get("gis_wd").toString();
               String date = jsonArray1.getJSONObject(j).get("date").toString();
               SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
               try {
                  //使用SimpleDateFormat的parse()方法生成Date
                  Date dates = sf.parse(date);
                  locus.setRecordTime(dates);
                  //打印Date
               } catch (ParseException e) {
                  e.printStackTrace();
               }
               locus.setLongitude(gis_jd);
               locus.setLatitude(gis_wd);
               locusService.save(locus);
               //数据推送
               s1 += "insert into sys_locus(id,type,worker_id,longitude,latitude,record_time) values" +
                  " (" + "'" + locus.getId() + "'" + "," +
                  "'" + locus.getType() + "'" + "," +
                  "'" + locus.getWorkerId() + "'" + "," +
                  "'" + locus.getLongitude() + "'" + "," +
                  "'" + locus.getLatitude() + "'" + "," +
                  "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(locus.getRecordTime()) + "'" + ")";
               if (j != jsonArray1.size() - 1) {
                  s1 += ";";
               }
            }
            FtpUtil.sqlFileUpload(s1);
         }
      }
   }
@@ -222,50 +228,53 @@
            res = HttpReqUtil.getInstance().doPost(url, params, null);
            String a = "[" + res + "]";
            JSONArray jsonArray = JSONArray.fromObject(a);
            String data = jsonArray.getJSONObject(0).get("data").toString();
            String b = "[" + data + "]";
            JSONArray jsonArrayb = JSONArray.fromObject(b);
            String x = jsonArrayb.getJSONObject(0).get("x").toString();
            String y = jsonArrayb.getJSONObject(0).get("y").toString();
            String timestamp = jsonArrayb.getJSONObject(0).get("timestamp").toString();
            //实时位置实体类
            LiveLocation liveLocation = new LiveLocation();
            liveLocation.setType(2);
            String carnumber = maps.get(i).get("carnumber").toString();
            liveLocation.setWorkerId(carnumber);
            //经度
            liveLocation.setLongitude(x);
            //纬度
            liveLocation.setLatitude(y);
            Date date = timeStamp2Date(timestamp);
            liveLocation.setRecordTime(date);
            //先查询是否已有实时位置信息,如果有,则更新,没有则插入
            LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation);
            boolean status = false;
            if (null == liveLocationInfo) {
               //新增
               status = liveLocationService.save(liveLocation);
               //数据推送
               String s1 =
                  "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time,location) " +
                     "values(" + "'" + liveLocation.getId() + "'" + "," +
                     "'" + liveLocation.getType() + "'" + "," +
                     "'" + liveLocation.getWorkerId() + "'" + "," +
                     "'" + liveLocation.getLongitude() + "'" + "," +
                     "'" + liveLocation.getLatitude() + "'" + "," +
                     "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'"  + ")";
               FtpUtil.sqlFileUpload(s1);
            } else {
               status = liveLocationService.updateById(liveLocationInfo);
               //内网同步
               String s1 =
                  "update sys_live_location set type = " + "'" + liveLocationInfo.getType() + "'" +
                     ",worker_id = " + "'" + liveLocationInfo.getWorkerId() + "'" +
                     ",longitude = " + "'" + liveLocationInfo.getLongitude() + "'" +
                     ",latitude = " + "'" + liveLocationInfo.getLatitude() + "'" +
                     ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocationInfo.getRecordTime()) + "'" +
                     " " + "where id = " + "'" + liveLocationInfo.getId() + "'";
               FtpUtil.sqlFileUpload(s1);
            String code = jsonArray.getJSONObject(0).get("code").toString();
            if (Integer.parseInt(code)==200) {
               String data = jsonArray.getJSONObject(0).get("data").toString();
               String b = "[" + data + "]";
               JSONArray jsonArrayb = JSONArray.fromObject(b);
               String x = jsonArrayb.getJSONObject(0).get("x").toString();
               String y = jsonArrayb.getJSONObject(0).get("y").toString();
               String timestamp = jsonArrayb.getJSONObject(0).get("timestamp").toString();
               //实时位置实体类
               LiveLocation liveLocation = new LiveLocation();
               liveLocation.setType(2);
               String carnumber = maps.get(i).get("carnumber").toString();
               liveLocation.setWorkerId(carnumber);
               //经度
               liveLocation.setLongitude(x);
               //纬度
               liveLocation.setLatitude(y);
               Date date = timeStamp2Date(timestamp);
               liveLocation.setRecordTime(date);
               //先查询是否已有实时位置信息,如果有,则更新,没有则插入
               LiveLocation liveLocationInfo = liveLocationService.getLiveLocationInfo(liveLocation);
               boolean status = false;
               if (null == liveLocationInfo) {
                  //新增
                  status = liveLocationService.save(liveLocation);
                  //数据推送
                  String s1 =
                     "insert into sys_live_location(id,type,worker_id,longitude,latitude,record_time) " +
                        "values(" + "'" + liveLocation.getId() + "'" + "," +
                        "'" + liveLocation.getType() + "'" + "," +
                        "'" + liveLocation.getWorkerId() + "'" + "," +
                        "'" + liveLocation.getLongitude() + "'" + "," +
                        "'" + liveLocation.getLatitude() + "'" + "," +
                        "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocation.getRecordTime()) + "'" + ")";
                  FtpUtil.sqlFileUpload(s1);
               } else {
                  status = liveLocationService.updateById(liveLocationInfo);
                  //内网同步
                  String s1 =
                     "update sys_live_location set type = " + "'" + liveLocationInfo.getType() + "'" +
                        ",worker_id = " + "'" + liveLocationInfo.getWorkerId() + "'" +
                        ",longitude = " + "'" + liveLocationInfo.getLongitude() + "'" +
                        ",latitude = " + "'" + liveLocationInfo.getLatitude() + "'" +
                        ",record_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(liveLocationInfo.getRecordTime()) + "'" +
                        " " + "where id = " + "'" + liveLocationInfo.getId() + "'";
                  FtpUtil.sqlFileUpload(s1);
               }
            }
         } catch (Exception e) {
            e.printStackTrace();
@@ -292,7 +301,6 @@
    */
   @Scheduled(cron = "0 0 * * * ?")
   public void locationhistoryTrack() {
      System.out.println("车辆轨迹");
      Calendar calendar = Calendar.getInstance();
      /* HOUR_OF_DAY 指示一天中的小时 */
      calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1);