From be5fb14cea481af16b59f3d24cbe4c473e4d5407 Mon Sep 17 00:00:00 2001 From: zhangyeguang Date: Wed, 25 Sep 2024 16:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/StringToIntegerDeserializer.java | 21 +++++++++++++++++++ .../ams/controller/DeviceController.java | 1 - .../com/jiagutech/ams/model/TrackDataJG.java | 4 ++-- .../ams/model/request/JobCreateRequest.java | 3 ++- .../ams/service/DeviceServiceImpl.java | 15 ++++++++++--- 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 common/src/main/java/com/jiagutech/ams/utils/StringToIntegerDeserializer.java diff --git a/common/src/main/java/com/jiagutech/ams/utils/StringToIntegerDeserializer.java b/common/src/main/java/com/jiagutech/ams/utils/StringToIntegerDeserializer.java new file mode 100644 index 0000000..5926e3e --- /dev/null +++ b/common/src/main/java/com/jiagutech/ams/utils/StringToIntegerDeserializer.java @@ -0,0 +1,21 @@ +package com.jiagutech.ams.utils; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; + +public class StringToIntegerDeserializer extends JsonDeserializer { + + @Override + public Integer deserialize(JsonParser jsonParser, DeserializationContext context) + throws IOException { + String value = jsonParser.getText(); + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw new IOException("Unable to parse value as Long: " + value, e); + } + } +} \ No newline at end of file diff --git a/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java b/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java index 87aca55..a7b856b 100644 --- a/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java +++ b/social/src/main/java/com/jiagutech/ams/controller/DeviceController.java @@ -34,7 +34,6 @@ public class DeviceController { @Operation(summary = "获取在线设备列表") @GetMapping("/onlineAndRound") - @SaCheckRole(value = {"machinist", "admin"}, mode = SaMode.OR) public R> onlineAndRound(@RequestParam(required = false, defaultValue = "0") double maxLng, @RequestParam(required = false, defaultValue = "0") double maxLat, @RequestParam(required = false, defaultValue = "0") double minLng, diff --git a/social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java b/social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java index 4c78740..f890486 100644 --- a/social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java +++ b/social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java @@ -26,12 +26,12 @@ public class TrackDataJG implements Serializable { /** * 纬度 */ - private Double lat; + private double lat; /** * 经度 */ - private Double lng; + private double lng; /** * 海拔高度,单位:米 diff --git a/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java b/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java index b0cc159..8cecad7 100644 --- a/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java +++ b/social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java @@ -3,6 +3,7 @@ package com.jiagutech.ams.model.request; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.deser.std.NumberDeserializers; +import com.jiagutech.ams.utils.StringToIntegerDeserializer; import com.jiagutech.ams.utils.StringToLongDeserializer; import lombok.Data; import lombok.experimental.Accessors; @@ -37,7 +38,7 @@ public class JobCreateRequest { /** * 设备ID */ - @JsonDeserialize(using = StringToLongDeserializer.class) + @JsonDeserialize(using = StringToIntegerDeserializer.class) private int deviceId; /** * 作业类型 diff --git a/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java b/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java index b3f1852..ef3440c 100644 --- a/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java +++ b/social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java @@ -43,6 +43,7 @@ public class DeviceServiceImpl implements DeviceService { @Override public List onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) { + log.info("maxlat={},minlat={},maxlng={},minlng={}", maxLat, minLat, maxLng, minLng); Set keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY); List deviceInfos = new ArrayList<>(); if (CollectionUtils.isNotEmpty(keys)) { @@ -50,14 +51,20 @@ public class DeviceServiceImpl implements DeviceService { if (CollectionUtils.isEmpty(values)) { return deviceInfos; } + log.info("所有的在线农机={}", keys); List trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).toList(); - Predicate predicate = t -> t.getLat() <= maxLat && t.getLat() >= minLat - && ((t.getLng() >= -180 && t.getLng() <= maxLng) || (t.getLng() >= minLng && t.getLng() <= 180)); + Predicate predicate = t -> { + log.info("农机{},经纬度:{}", t.getDroneId(), t.getLng() + "," + t.getLat()); + + return t.getLat() <= maxLat && t.getLat() >= minLat + && t.getLng() <= maxLng && t.getLng() >= minLng; + }; if (maxLat == 0 && minLat == 0 && maxLng == 0 && minLng == 0) { predicate = t -> true; } Consumer consumer = t -> deviceInfos.add(new DeviceInfo().setBoxNum(t.getDroneId()).setLng(t.getLng()).setLat(t.getLat())); trackDataJGS.stream().filter(predicate).forEach(consumer); + log.info("根据范围过滤后的农机列表:{}", deviceInfos); LoginUser loginUser = LoginUtil.getLoginUser(); if (loginUser != null && loginUser.getDept() != null) { long deptId = loginUser.getDept().getId(); @@ -72,7 +79,9 @@ public class DeviceServiceImpl implements DeviceService { iterator.remove(); continue; } - deviceInfo.setDeviceId(exists.get().getDeviceId()).setStatus(exists.get().getStatus()); + deviceInfo.setDeviceId(exists.get().getDeviceId()).setStatus(exists.get().getStatus()) + .setName(exists.get().getName()) + .setLicensePlate(exists.get().getLicensePlate()); } } }