Compare commits
No commits in common. "dc4b0143e0b8d74137aa12bf77f720b88127af92" and "4b0c7627fe5a37ba6f0687b847a521b293c1ce8c" have entirely different histories.
dc4b0143e0
...
4b0c7627fe
|
|
@ -6,7 +6,6 @@ import com.njzscloud.common.mqtt.util.Mqtt;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
@ -22,7 +21,7 @@ public class DeviceStore {
|
||||||
Mqtt.publish("localizer/loader");
|
Mqtt.publish("localizer/loader");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLocalizers(List<Localizer> list) {
|
public static void setLocalizers(LinkedList<Localizer> list) {
|
||||||
localizersWriteLock.lock();
|
localizersWriteLock.lock();
|
||||||
try {
|
try {
|
||||||
log.info("重新加载设备:{}", list.size());
|
log.info("重新加载设备:{}", list.size());
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,7 @@ public class Localizer {
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
protected String terminalId;
|
protected String terminalId;
|
||||||
/**
|
|
||||||
* 车牌
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private String licensePlate;
|
|
||||||
/**
|
/**
|
||||||
* 设备类型
|
* 设备类型
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public final class Htzj {
|
public final class Htzj {
|
||||||
private static HtzjListeners htzjListeners;
|
private static HtzjListeners htzjListeners = new HtzjListeners();
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
htzjListeners = new HtzjListeners();
|
htzjListeners = new HtzjListeners();
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.njzscloud.common.localizer.jt808.support;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import com.njzscloud.common.localizer.DeviceStore;
|
import com.njzscloud.common.localizer.DeviceStore;
|
||||||
import com.njzscloud.common.localizer.Localizer;
|
import com.njzscloud.common.localizer.Localizer;
|
||||||
import com.njzscloud.common.localizer.contant.LocalizerType;
|
import com.njzscloud.common.localizer.contant.LocalizerType;
|
||||||
|
|
@ -11,13 +10,11 @@ import com.njzscloud.common.localizer.contant.MessageType;
|
||||||
import com.njzscloud.common.localizer.jt808.JT808;
|
import com.njzscloud.common.localizer.jt808.JT808;
|
||||||
import com.njzscloud.common.localizer.jt808.message.*;
|
import com.njzscloud.common.localizer.jt808.message.*;
|
||||||
import com.njzscloud.common.localizer.mqtt.result.RealtimeLocationResult;
|
import com.njzscloud.common.localizer.mqtt.result.RealtimeLocationResult;
|
||||||
import com.njzscloud.common.localizer.service.LocalizerService;
|
|
||||||
import com.njzscloud.common.mqtt.util.Mqtt;
|
import com.njzscloud.common.mqtt.util.Mqtt;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -108,12 +105,9 @@ public abstract class JT808MessageListener {
|
||||||
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf);
|
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf);
|
||||||
double speed = locationReportMsg.getSpeed();
|
double speed = locationReportMsg.getSpeed();
|
||||||
int speedThreshold = localizer.getSpeedThreshold();
|
int speedThreshold = localizer.getSpeedThreshold();
|
||||||
String licensePlate = localizer.getLicensePlate();
|
|
||||||
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
|
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
|
||||||
.setLicensePlate(licensePlate)
|
|
||||||
.setTerminalId(terminalId)
|
.setTerminalId(terminalId)
|
||||||
.setOverspeed(speed > speedThreshold);
|
.setOverspeed(speed > speedThreshold);
|
||||||
saveData(realtimeLocationResult);
|
|
||||||
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
|
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
|
||||||
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);
|
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -143,13 +137,10 @@ public abstract class JT808MessageListener {
|
||||||
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf.slice(byteBuf.readerIndex(), length));
|
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf.slice(byteBuf.readerIndex(), length));
|
||||||
byteBuf.skipBytes(length);
|
byteBuf.skipBytes(length);
|
||||||
double speed = locationReportMsg.getSpeed();
|
double speed = locationReportMsg.getSpeed();
|
||||||
String licensePlate = localizer.getLicensePlate();
|
|
||||||
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
|
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
|
||||||
.setLicensePlate(licensePlate)
|
|
||||||
.setTerminalId(terminalId)
|
.setTerminalId(terminalId)
|
||||||
.setOverspeed(speed > speedThreshold)
|
.setOverspeed(speed > speedThreshold)
|
||||||
.setType(type);
|
.setType(type);
|
||||||
saveData(realtimeLocationResult);
|
|
||||||
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
|
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
|
||||||
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);
|
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);
|
||||||
}
|
}
|
||||||
|
|
@ -158,17 +149,6 @@ public abstract class JT808MessageListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void saveData(RealtimeLocationResult realtimeLocationResult) {
|
|
||||||
try {
|
|
||||||
LocalizerService localizerService = SpringUtil.getBean(LocalizerService.class);
|
|
||||||
if (localizerService != null) {
|
|
||||||
localizerService.save(Collections.singletonList(realtimeLocationResult));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("数据保存失败", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询位置响应消息
|
* 查询位置响应消息
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,6 @@ import lombok.experimental.Accessors;
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class RealtimeLocationResult {
|
public class RealtimeLocationResult {
|
||||||
private String terminalId;
|
private String terminalId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 车牌
|
|
||||||
*/
|
|
||||||
private String licensePlate;
|
|
||||||
private int type;
|
private int type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.njzscloud.common.localizer.service;
|
|
||||||
|
|
||||||
|
|
||||||
import com.njzscloud.common.localizer.mqtt.result.RealtimeLocationResult;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface LocalizerService {
|
|
||||||
void save(List<RealtimeLocationResult> data);
|
|
||||||
}
|
|
||||||
|
|
@ -21,19 +21,6 @@
|
||||||
<artifactId>njzscloud-common-core</artifactId>
|
<artifactId>njzscloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njzscloud</groupId>
|
|
||||||
<artifactId>njzscloud-common-mvc</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njzscloud</groupId>
|
|
||||||
<artifactId>njzscloud-common-ws</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.njzscloud</groupId>
|
|
||||||
<artifactId>njzscloud-common-mp</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.njzscloud</groupId>
|
<groupId>com.njzscloud</groupId>
|
||||||
<artifactId>njzscloud-common-localizer</artifactId>
|
<artifactId>njzscloud-common-localizer</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
package com.njzscloud.localizer.device.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.njzscloud.localizer.device.pojo.entity.DeviceEntity;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface DeviceMapper extends BaseMapper<DeviceEntity> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
package com.njzscloud.localizer.device.pojo.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import com.njzscloud.common.localizer.contant.LocalizerType;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("localizer_device")
|
|
||||||
public class DeviceEntity {
|
|
||||||
/**
|
|
||||||
* 设备 Id
|
|
||||||
*/
|
|
||||||
protected String terminalId;
|
|
||||||
/**
|
|
||||||
* 设备类型
|
|
||||||
*/
|
|
||||||
protected LocalizerType localizerType;
|
|
||||||
/**
|
|
||||||
* 车牌
|
|
||||||
*/
|
|
||||||
private String licensePlate;
|
|
||||||
/**
|
|
||||||
* 速度阈值
|
|
||||||
*/
|
|
||||||
private Integer speedThreshold;
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package com.njzscloud.localizer.device.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.njzscloud.localizer.device.mapper.DeviceMapper;
|
|
||||||
import com.njzscloud.localizer.device.pojo.entity.DeviceEntity;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class DeviceService extends ServiceImpl<DeviceMapper, DeviceEntity> implements IService<DeviceEntity> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
package com.njzscloud.localizer.track.controller;
|
|
||||||
|
|
||||||
import com.njzscloud.localizer.track.service.TruckLocationTrackService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆定位数据
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@CrossOrigin
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/truck_location_track")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class TruckLocationTrackController {
|
|
||||||
|
|
||||||
private final TruckLocationTrackService truckLocationTrackService;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
package com.njzscloud.localizer.track.mapper;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import com.njzscloud.localizer.track.pojo.entity.TruckLocationTrackEntity;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆定位数据
|
|
||||||
*/
|
|
||||||
@Mapper
|
|
||||||
public interface TruckLocationTrackMapper extends BaseMapper<TruckLocationTrackEntity> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
package com.njzscloud.localizer.track.pojo.entity;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆定位数据
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@TableName("truck_location_track")
|
|
||||||
public class TruckLocationTrackEntity {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id
|
|
||||||
*/
|
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车牌
|
|
||||||
*/
|
|
||||||
private String licensePlate;
|
|
||||||
/**
|
|
||||||
* 设备号
|
|
||||||
*/
|
|
||||||
private String terminalId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 经度; 单位:度
|
|
||||||
*/
|
|
||||||
private Double longitude;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 纬度; 单位:度
|
|
||||||
*/
|
|
||||||
private Double latitude;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 海拔; 米
|
|
||||||
*/
|
|
||||||
private Integer altitude;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 速度; 千米/小时
|
|
||||||
*/
|
|
||||||
private Double speed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 定位时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime locationTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 方向; 正北为 0 度
|
|
||||||
*/
|
|
||||||
private Integer direction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否超速; 0-->否、1-->是
|
|
||||||
*/
|
|
||||||
private Boolean overspeed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为补偿数据; 0-->否、1-->是
|
|
||||||
*/
|
|
||||||
private Boolean compensate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
|
||||||
private LocalDateTime createTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
package com.njzscloud.localizer.track.pojo.param;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
@Accessors(chain = true)
|
|
||||||
public class LocationTrackSearchParam {
|
|
||||||
private String terminalId;
|
|
||||||
/**
|
|
||||||
* 车牌
|
|
||||||
*/
|
|
||||||
private String licensePlate;
|
|
||||||
private LocalDateTime startTime;
|
|
||||||
private LocalDateTime endTime;
|
|
||||||
private Integer speed;
|
|
||||||
|
|
||||||
public Integer getSpeed() {
|
|
||||||
return speed == null || speed <= 0 ? 1000 : speed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,279 +0,0 @@
|
||||||
package com.njzscloud.localizer.track.service;
|
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.njzscloud.common.core.ex.ExceptionMsg;
|
|
||||||
import com.njzscloud.common.core.thread.ThreadPool;
|
|
||||||
import com.njzscloud.common.core.tuple.Tuple2;
|
|
||||||
import com.njzscloud.common.core.utils.CoordinateConverter;
|
|
||||||
import com.njzscloud.common.core.utils.R;
|
|
||||||
import com.njzscloud.common.localizer.DeviceStore;
|
|
||||||
import com.njzscloud.common.localizer.Localizer;
|
|
||||||
import com.njzscloud.common.localizer.mqtt.result.RealtimeLocationResult;
|
|
||||||
import com.njzscloud.common.localizer.service.LocalizerService;
|
|
||||||
import com.njzscloud.common.ws.support.Websocket;
|
|
||||||
import com.njzscloud.common.ws.support.WsMsg;
|
|
||||||
import com.njzscloud.localizer.device.pojo.entity.DeviceEntity;
|
|
||||||
import com.njzscloud.localizer.device.service.DeviceService;
|
|
||||||
import com.njzscloud.localizer.track.mapper.TruckLocationTrackMapper;
|
|
||||||
import com.njzscloud.localizer.track.pojo.entity.TruckLocationTrackEntity;
|
|
||||||
import com.njzscloud.localizer.track.pojo.param.LocationTrackSearchParam;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
||||||
import org.springframework.context.event.EventListener;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 车辆定位数据
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class TruckLocationTrackService extends ServiceImpl<TruckLocationTrackMapper, TruckLocationTrackEntity> implements LocalizerService, IService<TruckLocationTrackEntity> {
|
|
||||||
private final DeviceService deviceService;
|
|
||||||
ThreadPoolExecutor threadPoolExecutor = ThreadPool.createThreadPool(
|
|
||||||
"GPS 数据",
|
|
||||||
10,
|
|
||||||
200,
|
|
||||||
60,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy()
|
|
||||||
);
|
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
|
||||||
public void onApplicationReady() {
|
|
||||||
List<DeviceEntity> list = deviceService.list();
|
|
||||||
List<Localizer> localizers = list.stream().map(it -> BeanUtil.copyProperties(it, Localizer.class)).collect(Collectors.toList());
|
|
||||||
DeviceStore.setLocalizers(localizers);
|
|
||||||
Websocket.subscribe("up/truck_location_track/history", msg -> {
|
|
||||||
WsMsg.User from = msg.getFrom();
|
|
||||||
String cid = from.getCid();
|
|
||||||
LocationTrackSearchParam param = msg.extractData(LocationTrackSearchParam.class);
|
|
||||||
// String terminalId = param.getTerminalId();
|
|
||||||
String licensePlate = param.getLicensePlate();
|
|
||||||
LocalDateTime startTime = param.getStartTime();
|
|
||||||
LocalDateTime endTime = param.getEndTime();
|
|
||||||
Integer speed = param.getSpeed();
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
int currentPage = 1;
|
|
||||||
// 分页查询,每次500条
|
|
||||||
while (true) {
|
|
||||||
// 检查是否被取消
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Page<TruckLocationTrackEntity> page = new Page<>(currentPage, 500);
|
|
||||||
page.addOrder(OrderItem.asc("location_time"));
|
|
||||||
|
|
||||||
// 分页查询当前页数据
|
|
||||||
IPage<TruckLocationTrackEntity> resultPage = this.page(page, Wrappers.lambdaQuery(TruckLocationTrackEntity.class)
|
|
||||||
.eq(TruckLocationTrackEntity::getLicensePlate, licensePlate)
|
|
||||||
.ge(startTime != null, TruckLocationTrackEntity::getLocationTime, startTime)
|
|
||||||
.le(endTime != null, TruckLocationTrackEntity::getLocationTime, endTime));
|
|
||||||
|
|
||||||
List<TruckLocationTrackEntity> records = resultPage.getRecords();
|
|
||||||
if (records.isEmpty()) {
|
|
||||||
Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/history")
|
|
||||||
.setData(R.failed(ExceptionMsg.SYS_ERR_MSG, "数据发送完成"))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理当前页数据,按时间间隔推送
|
|
||||||
for (TruckLocationTrackEntity record : records) {
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (speed > 100) {
|
|
||||||
if (!ThreadUtil.sleep(speed)) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/history")
|
|
||||||
.setData(R.failed(ExceptionMsg.SYS_ERR_MSG, "数据发送完成"))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Tuple2<Double, Double> doubles = CoordinateConverter.wgs84ToGcj02(record.getLatitude(), record.getLongitude());
|
|
||||||
record.setLatitude(doubles.get_0())
|
|
||||||
.setLongitude(doubles.get_1());
|
|
||||||
boolean publish = Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/history")
|
|
||||||
.setData(R.success(record))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
if (!publish) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断是否为最后一页
|
|
||||||
if (currentPage >= resultPage.getPages()) {
|
|
||||||
Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/history")
|
|
||||||
.setData(R.failed(ExceptionMsg.SYS_ERR_MSG, "数据发送完成"))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 继续查询下一页
|
|
||||||
currentPage++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 其他异常
|
|
||||||
log.error("查询历史轨迹异常", e);
|
|
||||||
}
|
|
||||||
}, threadPoolExecutor);
|
|
||||||
});
|
|
||||||
|
|
||||||
Websocket.subscribe("up/truck_location_track/realtime", msg -> {
|
|
||||||
WsMsg.User from = msg.getFrom();
|
|
||||||
String cid = from.getCid();
|
|
||||||
LocationTrackSearchParam param = msg.extractData(LocationTrackSearchParam.class);
|
|
||||||
// String terminalId = param.getTerminalId();
|
|
||||||
String licensePlate = param.getLicensePlate();
|
|
||||||
Integer speed = param.getSpeed();
|
|
||||||
CompletableFuture.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
LocalDateTime startTime = LocalDateTime.now().minusSeconds(1);
|
|
||||||
int errCount = 0;
|
|
||||||
while (true) {
|
|
||||||
// 检查是否被取消
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Page<TruckLocationTrackEntity> page = new Page<>(1, 10);
|
|
||||||
page.addOrder(OrderItem.asc("location_time"));
|
|
||||||
|
|
||||||
// 分页查询当前页数据
|
|
||||||
IPage<TruckLocationTrackEntity> resultPage = this.page(page, Wrappers.lambdaQuery(TruckLocationTrackEntity.class)
|
|
||||||
.eq(TruckLocationTrackEntity::getLicensePlate, licensePlate)
|
|
||||||
.gt(TruckLocationTrackEntity::getLocationTime, startTime));
|
|
||||||
|
|
||||||
List<TruckLocationTrackEntity> records = resultPage.getRecords();
|
|
||||||
if (records.isEmpty()) {
|
|
||||||
if (errCount >= 200) {
|
|
||||||
log.error("暂无实时数据, 车牌号: {}, 时间: {}", licensePlate, startTime);
|
|
||||||
Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/realtime")
|
|
||||||
.setData(R.failed(ExceptionMsg.SYS_ERR_MSG, "暂无实时数据"))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errCount++;
|
|
||||||
if (!ThreadUtil.sleep(300)) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
startTime = LocalDateTime.now();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
errCount = 0;
|
|
||||||
|
|
||||||
// 处理当前页数据,按时间间隔推送
|
|
||||||
for (TruckLocationTrackEntity record : records) {
|
|
||||||
if (Thread.currentThread().isInterrupted()) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (speed > 100) {
|
|
||||||
if (!ThreadUtil.sleep(speed)) {
|
|
||||||
log.info("任务被取消");
|
|
||||||
Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/realtime")
|
|
||||||
.setData(R.failed(ExceptionMsg.SYS_ERR_MSG, "数据发送完成"))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
startTime = record.getLocationTime();
|
|
||||||
Tuple2<Double, Double> doubles = CoordinateConverter.wgs84ToGcj02(record.getLatitude(), record.getLongitude());
|
|
||||||
record.setLatitude(doubles.get_0())
|
|
||||||
.setLongitude(doubles.get_1());
|
|
||||||
boolean publish = Websocket.publish(new WsMsg()
|
|
||||||
.setEvent("down/truck_location_track/realtime")
|
|
||||||
.setData(R.success(record))
|
|
||||||
.setTo(Collections.singletonList(new WsMsg.User().setCid(cid)))
|
|
||||||
);
|
|
||||||
if (!publish) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 其他异常
|
|
||||||
log.error("查询历史轨迹异常", e);
|
|
||||||
}
|
|
||||||
}, threadPoolExecutor);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* 川SXJ070 12082962846
|
|
||||||
|
|
||||||
川SB070Z 12083145045
|
|
||||||
|
|
||||||
川SYV011 12082915117
|
|
||||||
|
|
||||||
川SYE909 12082855453 */
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void save(List<RealtimeLocationResult> dataList) {
|
|
||||||
for (RealtimeLocationResult realtimeLocationResult : dataList) {
|
|
||||||
if (realtimeLocationResult == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String time = realtimeLocationResult.getTime();
|
|
||||||
double latitude = realtimeLocationResult.getLatitude();
|
|
||||||
double longitude = realtimeLocationResult.getLongitude();
|
|
||||||
|
|
||||||
if (latitude <= 0 && longitude <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TruckLocationTrackEntity entity = new TruckLocationTrackEntity()
|
|
||||||
.setLicensePlate(realtimeLocationResult.getLicensePlate())
|
|
||||||
.setTerminalId(realtimeLocationResult.getTerminalId())
|
|
||||||
.setLatitude(latitude)
|
|
||||||
.setLongitude(longitude)
|
|
||||||
.setAltitude(realtimeLocationResult.getAltitude())
|
|
||||||
.setSpeed(realtimeLocationResult.getSpeed())
|
|
||||||
.setLocationTime(DateUtil.parseLocalDateTime(time))
|
|
||||||
.setDirection(realtimeLocationResult.getDirection())
|
|
||||||
.setOverspeed(realtimeLocationResult.isOverspeed())
|
|
||||||
.setCompensate(realtimeLocationResult.getType() == 1);
|
|
||||||
this.save(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue