Browse Source

站点优化

shs 1 year ago
parent
commit
d655e1c221

+ 3 - 0
aidex-system/src/main/java/com/aidex/common/app/domain/vo/LocationVO.java

@@ -22,4 +22,7 @@ public class LocationVO extends LocationEntity {
     private Long reseat;
     @ApiModelProperty(value="距离几站",required=true)
     private Long distSiteNum;
+
+    @ApiModelProperty(value="是否到达离我最近的站点",required=true)
+    private Boolean isStopMyLocationSite;
 }

+ 53 - 20
aidex-system/src/main/java/com/aidex/common/app/server/impl/AppService.java

@@ -4,6 +4,7 @@ import com.aidex.common.app.domain.vo.LocationVO;
 import com.aidex.common.app.domain.vo.SysWharfVO;
 import com.aidex.common.app.server.IAppService;
 import com.aidex.common.exception.SysException;
+import com.aidex.common.gps.domain.AlarmDatetailsEntity;
 import com.aidex.common.gps.domain.FenceEntity;
 import com.aidex.common.gps.domain.LocationEntity;
 import com.aidex.common.gps.domain.MyGpsEntity;
@@ -21,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.*;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
@@ -107,6 +109,13 @@ public class AppService implements IAppService {
     public LocationVO findAllLocationByNext(Boolean direction,String lat, String lon){
         if(StringUtils.isEmpty(lat) || StringUtils.isEmpty(lon))
             throw new SysException(4441,"请告诉我你在哪");
+
+        // 离我最近的站点
+        SysWharf wharf = this.findNearestStation(lat,lon);
+
+        if(!wharf.getStatus().equals("0"))
+            throw new SysException(4442, wharf.getWharfNanme()+" 已经停用!请更换其他站点");
+
         // 全部船只信息
         List<MyGpsEntity> allMyGps = iGpsService.findMyGps();
         // 全部在线设备
@@ -120,30 +129,40 @@ public class AppService implements IAppService {
         // 默认到站停留时间
         Integer inStopTime = Integer.valueOf(ConfigUtils.getConfigByKey("pull.in.time").getConfigValue());
 
+        // 停靠速度
+        Integer stopSpeed = Integer.valueOf(ConfigUtils.getConfigByKey("stop.speed").getConfigValue());
+
         for (LocationEntity locationEntity : locationEntities) {
-            if(Double.valueOf(locationEntity.getDir()) <= 0){
+            locationEntity.setIsLongStop(Boolean.FALSE);
+            // 速度等于等 并且方位为零判断为已经停止
+            if(Double.valueOf(locationEntity.getSpeed()) <= Double.valueOf(stopSpeed) && Double.valueOf(locationEntity.getDir()) <= 0){
                 // 获取当天的 LocalDate 对象
-                LocalDate today = LocalDate.now();
-                // 获取当天的开始时间
-                LocalDateTime startOfDay = today.atStartOfDay();
+                LocalDateTime endOfDay = LocalDateTime.now();
                 // 获取当天的结束时间
-                LocalDateTime endOfDay = LocalDateTime.of(today, LocalTime.MAX);
+                LocalDateTime startDay = endOfDay.minusMonths(1);
                 // 转换为时间戳
-                long startTimestamp = startOfDay.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+                long startTimestamp = startDay.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
                 long endTimestamp = endOfDay.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
-                List<FenceEntity> fence = iGpsService.findFenceInByMacId(locationEntity.getMacid(),startTimestamp,endTimestamp);
-                if(fence.size() > 0){
-                    // 取最新数据
-                    FenceEntity fenceEntity = fence.get(0);
-                    locationEntity.setDir(fenceEntity.getDir());
+                List<AlarmDatetailsEntity> alarms = iGpsService.findAlarmDetails(locationEntity.getMacid(),"4",startTimestamp,endTimestamp);
+                if(alarms.size() > 0){
+                    // 取最后一次停靠的方位
+                    AlarmDatetailsEntity alarmDetails = alarms.get(0);
+                    locationEntity.setDir(alarmDetails.getDir());
+                    // 将时间戳转换为LocalDateTime
+                    LocalDateTime longStopTime = LocalDateTime.ofEpochSecond(Long.valueOf(alarmDetails.getAlarmime()) / 1000, 0, java.time.ZoneOffset.UTC);
+                    // 计算两个日期时间之间的分钟数
+                    Long stopTime = ChronoUnit.MINUTES.between(endOfDay, longStopTime);
+
+                    if(stopTime.doubleValue() > Double.valueOf(inStopTime)) {
+                        locationEntity.setIsLongStop(Boolean.TRUE);
+                    }
                 }
             }
         }
 
         // 正反向计算数据
         List<LocationVO> calcList = new ArrayList<>();
-        // 停靠速度
-        Integer stopSpeed = Integer.valueOf(ConfigUtils.getConfigByKey("stop.speed").getConfigValue());
+
 
         // 正反向计算条件
         String[] conditions ;
@@ -179,8 +198,7 @@ public class AppService implements IAppService {
         LocationVO res = null;
         // 有最近的船只则进计算
         if(calcList.size() > 0) {
-            // 离我最近的站点
-            SysWharf wharf = this.findNearestStation(lat,lon);
+
             // 验证船只是否经过该站点
             for (LocationVO locationVO : calcList) {
                 // 验证行驶方向--获取未到达次站点船只--避免已经过站点船只近距离出现
@@ -212,12 +230,19 @@ public class AppService implements IAppService {
             Long endTime = Long.valueOf(res.getServer_time());
             // 减去默认停靠时间在停靠时间内查询进入记录
             Long startTime = endTime - (inStopTime.longValue() * 60 * 1000);
+
+            // 围栏记录数据
+            List<AlarmDatetailsEntity> fenceEntities = iGpsService.findAlarmDetails(res.getMacid(),"4",startTime,endTime);
+
             // 查询是否进入离我最近的站点
-            List<FenceEntity> fenceEntities = iGpsService.findFenceIn(res.getMacid(),wharf.getWharfNanme(),startTime,endTime);
-            // 查询是否进入离船最近的站点
-            List<FenceEntity> fenceShipEntities = iGpsService.findFenceIn(res.getMacid(),wharfShip.getWharfNanme(),startTime,endTime);
+            AlarmDatetailsEntity mySite = fenceEntities.stream().filter(alram -> alram.getDescribe().equals(wharf.getWharfNanme())).findFirst().orElse(null);
+
+            AlarmDatetailsEntity shipSite = fenceEntities.stream().filter(alram -> alram.getDescribe().equals(wharfShip.getWharfNanme())).findFirst().orElse(null);
+
             res.setMyWharf(wharf);
 
+
+            // 距离几站计算
             Long distSiteNum = 0L;
             if(direction){
                 Double position = CalcDist.gps2d(Double.valueOf(wharfShip.getLat()),Double.valueOf(wharfShip.getLng()),Double.valueOf(res.getLat()),Double.valueOf(res.getLon()));
@@ -238,8 +263,16 @@ public class AppService implements IAppService {
             res.setDistSiteNum(distSiteNum);
 
             // 船只已经停靠入站离我最近的站
-            if (isStopOperation && (fenceEntities.size() > 0 || fenceShipEntities.size() > 0)) {
-                res.setStopWharf(wharfShip);
+            if (isStopOperation && (mySite != null || shipSite != null)) {
+                if(res.getIsLongStop())
+                    res.setStopWharf(wharfShip);
+                else {
+                    if(shipSite == null && mySite != null){
+                        res.setStopWharf(wharf);
+                    }else {
+                        res.setStopWharf(wharfShip);
+                    }
+                }
                 res.setIsArrival(Boolean.TRUE);
                 // 如果离我最近与停靠站点不是同一站点则计算时间
                 if(!wharfShip.getWharfNanme().equals(wharf.getWharfNanme())) {

+ 5 - 0
aidex-system/src/main/java/com/aidex/common/gps/common/GpsApi.java

@@ -39,4 +39,9 @@ public interface GpsApi {
      * */
     String findUserDevices = "UserDevices";
 
+
+    /*
+     * 单台设备报警详情
+     * */
+    String alarmDetails = "AlarmDetails";
 }

+ 23 - 0
aidex-system/src/main/java/com/aidex/common/gps/domain/AlarmDatetailsEntity.java

@@ -0,0 +1,23 @@
+package com.aidex.common.gps.domain;
+
+import lombok.Data;
+
+@Data
+public class AlarmDatetailsEntity {
+
+    private String alarmid;
+    private String objectid;
+    private String macid;
+    private String fullName;
+    private String macName;
+    private String alarmime;
+    private String addtime;
+    private String speed;
+    private String lat;
+    private String lon;
+    private String dir;
+    private String describe;
+    private String status;
+    private String alarmType;
+    private String classify;
+}

+ 2 - 0
aidex-system/src/main/java/com/aidex/common/gps/domain/LocationEntity.java

@@ -36,4 +36,6 @@ public class LocationEntity {
     private String device_values;
     @ApiModelProperty(value="今日里程",required=true)
     private String todayMil;
+
+    private Boolean isLongStop;
 }

+ 2 - 0
aidex-system/src/main/java/com/aidex/common/gps/server/IGpsService.java

@@ -25,4 +25,6 @@ public interface IGpsService {
     List<MyGpsEntity> findMyGps();
 
     List<AccEntity> findAccByMacId(String macId, Long startTime, Long endTime);
+
+    List<AlarmDatetailsEntity> findAlarmDetails(String macid,String alarmTypes, Long startTime, Long endTime);
 }

+ 11 - 0
aidex-system/src/main/java/com/aidex/common/gps/server/impl/GpsService.java

@@ -137,4 +137,15 @@ public class GpsService implements IGpsService {
         return myG;
     }
 
+    public List<AlarmDatetailsEntity> findAlarmDetails(String macid,String alarmTypes, Long startTime, Long endTime){
+        Map<String, Object> params = generatorGspApi.GeneratorQueryParams(GpsApi.alarmDetails);
+        params.put("macid",macid);
+        params.put("startTime",startTime);
+        params.put("endTime",endTime);
+        params.put("mapType", GeneratorGspApi.GpsMapType.QQ);
+        params.put("alarmTypes", alarmTypes);
+        List<AlarmDatetailsEntity> alarmDatetailsEntities = gpsRequest.postArray(params).toJavaList(AlarmDatetailsEntity.class);
+        return alarmDatetailsEntities;
+    }
+
 }