Browse Source

设备定位处理

LuoDLeo 2 months ago
parent
commit
24d934b07c

+ 2 - 1
src/main/java/org/springblade/common/enums/FacilityStatusEnum.java

@@ -7,7 +7,8 @@ public enum FacilityStatusEnum {
 
     ON_LINE("在线", 1),
     OFF_LINE("离线", 2),
-    FAULT("故障", 3);
+    FAULT("故障", 3),
+    OFFSET("位移", 4);
 
     private String name;
     private Integer value;

+ 9 - 4
src/main/java/org/springblade/modules/api/controller/ApiVendingController.java

@@ -15,6 +15,7 @@ import org.springblade.common.enums.FacilityStatusEnum;
 import org.springblade.common.enums.OrderStateEnum;
 import org.springblade.common.enums.VargoWayStatusEnum;
 import org.springblade.common.enums.VendingLogEnum;
+import org.springblade.common.utils.DistanceUtils;
 import org.springblade.modules.api.request.VendingHeartReq;
 import org.springblade.modules.api.request.VendingOrderReq;
 import org.springblade.modules.api.request.VendingShipReq;
@@ -188,7 +189,10 @@ public class ApiVendingController {
         Date now = new Date();
         facility.setHeartbeatTime(now);
         if ("0".equals(req.getErrorNum()) || "OK".equals(req.getStatus())) {
-            facility.setFacilityStatus(FacilityStatusEnum.ON_LINE.getValue());
+            if (FacilityStatusEnum.FAULT.getValue().equals(facility.getFacilityStatus())
+                    || FacilityStatusEnum.OFF_LINE.getValue().equals(facility.getFacilityStatus())) {
+                facility.setFacilityStatus(FacilityStatusEnum.ON_LINE.getValue());
+            }
 
             //将异常货道恢复
             facilityCargoWayService.updateCargoWayStatus(String.valueOf(facility.getId()), null, VargoWayStatusEnum.NORMAL);
@@ -197,15 +201,16 @@ public class ApiVendingController {
             //"location": "N,22.97637,E,113.37804"
             String[] split = req.getLocation().split(",");
 
-            //TODO 2024/9/26 LuoDLeo 位置过大,发短信提醒
-            //double distance = DistanceUtils.getDistance(Double.parseDouble(facility.getLongitude()), Double.parseDouble(facility.getLatitude()), Double.parseDouble(split[3]), Double.parseDouble(split[1]));
+            double distance = DistanceUtils.getDistance(Double.parseDouble(facility.getLongitude()), Double.parseDouble(facility.getLatitude()), Double.parseDouble(split[3]), Double.parseDouble(split[1]));
+            if (distance >= 0.5) {
+                facility.setFacilityStatus(FacilityStatusEnum.OFFSET.getValue());
+            }
 
             //更新位置
             facility.setLatitude(split[1]);//纬度N
             facility.setLongitude(split[3]);//经度E
 
             facilityService.updateById(facility);
-
             return;
         } else {
             //设备故障