Browse Source

完善功能

master
zhangyeguang 3 months ago
parent
commit
be5fb14cea
  1. 21
      common/src/main/java/com/jiagutech/ams/utils/StringToIntegerDeserializer.java
  2. 1
      social/src/main/java/com/jiagutech/ams/controller/DeviceController.java
  3. 4
      social/src/main/java/com/jiagutech/ams/model/TrackDataJG.java
  4. 3
      social/src/main/java/com/jiagutech/ams/model/request/JobCreateRequest.java
  5. 15
      social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java

21
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<Integer> {
@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);
}
}
}

1
social/src/main/java/com/jiagutech/ams/controller/DeviceController.java

@ -34,7 +34,6 @@ public class DeviceController {
@Operation(summary = "获取在线设备列表") @Operation(summary = "获取在线设备列表")
@GetMapping("/onlineAndRound") @GetMapping("/onlineAndRound")
@SaCheckRole(value = {"machinist", "admin"}, mode = SaMode.OR)
public R<List<DeviceInfo>> onlineAndRound(@RequestParam(required = false, defaultValue = "0") double maxLng, public R<List<DeviceInfo>> onlineAndRound(@RequestParam(required = false, defaultValue = "0") double maxLng,
@RequestParam(required = false, defaultValue = "0") double maxLat, @RequestParam(required = false, defaultValue = "0") double maxLat,
@RequestParam(required = false, defaultValue = "0") double minLng, @RequestParam(required = false, defaultValue = "0") double minLng,

4
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;
/** /**
* 海拔高度,单位: * 海拔高度,单位:

3
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.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.deser.std.NumberDeserializers; import com.fasterxml.jackson.databind.deser.std.NumberDeserializers;
import com.jiagutech.ams.utils.StringToIntegerDeserializer;
import com.jiagutech.ams.utils.StringToLongDeserializer; import com.jiagutech.ams.utils.StringToLongDeserializer;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -37,7 +38,7 @@ public class JobCreateRequest {
/** /**
* 设备ID * 设备ID
*/ */
@JsonDeserialize(using = StringToLongDeserializer.class)
@JsonDeserialize(using = StringToIntegerDeserializer.class)
private int deviceId; private int deviceId;
/** /**
* 作业类型 * 作业类型

15
social/src/main/java/com/jiagutech/ams/service/DeviceServiceImpl.java

@ -43,6 +43,7 @@ public class DeviceServiceImpl implements DeviceService {
@Override @Override
public List<DeviceInfo> onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) { public List<DeviceInfo> onlineAndRound(double maxLng, double maxLat, double minLng, double minLat) {
log.info("maxlat={},minlat={},maxlng={},minlng={}", maxLat, minLat, maxLng, minLng);
Set<String> keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY); Set<String> keys = stringRedisTemplate.keys(TRACK_PREFIX_REDIS_KEY);
List<DeviceInfo> deviceInfos = new ArrayList<>(); List<DeviceInfo> deviceInfos = new ArrayList<>();
if (CollectionUtils.isNotEmpty(keys)) { if (CollectionUtils.isNotEmpty(keys)) {
@ -50,14 +51,20 @@ public class DeviceServiceImpl implements DeviceService {
if (CollectionUtils.isEmpty(values)) { if (CollectionUtils.isEmpty(values)) {
return deviceInfos; return deviceInfos;
} }
log.info("所有的在线农机={}", keys);
List<TrackDataJG> trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).toList(); List<TrackDataJG> trackDataJGS = values.stream().map(s -> JSON.parseObject(s, TrackDataJG.class)).toList();
Predicate<TrackDataJG> predicate = t -> t.getLat() <= maxLat && t.getLat() >= minLat
&& ((t.getLng() >= -180 && t.getLng() <= maxLng) || (t.getLng() >= minLng && t.getLng() <= 180));
Predicate<TrackDataJG> 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) { if (maxLat == 0 && minLat == 0 && maxLng == 0 && minLng == 0) {
predicate = t -> true; predicate = t -> true;
} }
Consumer<TrackDataJG> consumer = t -> deviceInfos.add(new DeviceInfo().setBoxNum(t.getDroneId()).setLng(t.getLng()).setLat(t.getLat())); Consumer<TrackDataJG> consumer = t -> deviceInfos.add(new DeviceInfo().setBoxNum(t.getDroneId()).setLng(t.getLng()).setLat(t.getLat()));
trackDataJGS.stream().filter(predicate).forEach(consumer); trackDataJGS.stream().filter(predicate).forEach(consumer);
log.info("根据范围过滤后的农机列表:{}", deviceInfos);
LoginUser loginUser = LoginUtil.getLoginUser(); LoginUser loginUser = LoginUtil.getLoginUser();
if (loginUser != null && loginUser.getDept() != null) { if (loginUser != null && loginUser.getDept() != null) {
long deptId = loginUser.getDept().getId(); long deptId = loginUser.getDept().getId();
@ -72,7 +79,9 @@ public class DeviceServiceImpl implements DeviceService {
iterator.remove(); iterator.remove();
continue; 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());
} }
} }
} }

Loading…
Cancel
Save