localizer
ljw 2025-10-25 13:37:26 +08:00
commit 356aff0f5b
7 changed files with 67 additions and 17 deletions

View File

@ -9,21 +9,31 @@ import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class Localizer {
/**
* Id
*/
@Getter
@Setter
protected String terminalId;
/**
*
*/
@Getter
@Setter
protected LocalizerType localizerType;
private int speedThreshold;
/**
*
*/
@Setter
private Integer speedThreshold;
public int getSpeedThreshold() {
return speedThreshold == null ? 60 : speedThreshold;
}
public boolean isOnline() {
return JT808.isOnline(terminalId);

View File

@ -4,6 +4,7 @@ import com.njzscloud.common.localizer.DeviceStore;
import com.njzscloud.common.localizer.Localizer;
import com.njzscloud.common.localizer.jt808.JT808;
import com.njzscloud.common.localizer.jt808.message.JT808Message;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
@ -28,7 +29,7 @@ public class JT808MessageHandler extends ChannelInboundHandlerAdapter {
String terminalPhone = message.getTerminalPhone();
Localizer localizer = DeviceStore.determineLocalizer(terminalPhone);
if (localizer == null) {
// log.warn("设备不存在:{}", terminalPhone);
log.warn("设备不存在:{}", terminalPhone);
ctx.channel().close();
return;
}
@ -45,14 +46,15 @@ public class JT808MessageHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// log.warn("客户端断开连接: {}", ctx.channel().remoteAddress());
log.warn("客户端断开连接: {}", ctx.channel().remoteAddress());
// clients.remove(ctx.channel());
JT808.unregister(ctx.channel());
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
log.error("发生异常: {}", cause.getMessage(), cause);
Channel channel = ctx.channel();
log.error("发生异常: {}{}", channel == null ? "无IP" : channel.remoteAddress(), cause.getMessage(), cause);
ctx.close();
}
}

View File

@ -15,7 +15,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.function.Consumer;
@Slf4j
@ -94,7 +93,7 @@ public abstract class JT808MessageListener {
*/
public void onLocationReport(TerminalMessageBody message) {
String terminalId = message.getTerminalId();
JT808.sendGeneralReply(terminalId, message.getMessageId(), message.getFlowId());
// JT808.sendGeneralReply(terminalId, message.getMessageId(), message.getFlowId());
byte[] body = message.getBody();
ByteBuf byteBuf = Unpooled.wrappedBuffer(body);
try {
@ -104,9 +103,11 @@ public abstract class JT808MessageListener {
return;
}
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf);
double speed = locationReportMsg.getSpeed();
int speedThreshold = localizer.getSpeedThreshold();
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
.setTerminalId(terminalId)
.setOverspeed(locationReportMsg.getSpeed() > localizer.getSpeedThreshold());
.setOverspeed(speed > speedThreshold);
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);
} finally {
@ -118,10 +119,9 @@ public abstract class JT808MessageListener {
*
*/
public void onLocationBatchUpload(TerminalMessageBody message) {
JT808.sendGeneralReply(message.getTerminalId(), message.getMessageId(), message.getFlowId());
// JT808.sendGeneralReply(message.getTerminalId(), message.getMessageId(), message.getFlowId());
String terminalId = message.getTerminalId();
byte[] body = message.getBody();
log.info("批量上报:{}", Arrays.toString(body));
ByteBuf byteBuf = Unpooled.wrappedBuffer(body);
try {
int count = byteBuf.readUnsignedShort();
@ -136,9 +136,10 @@ public abstract class JT808MessageListener {
int length = byteBuf.readUnsignedShort();
LocationReportMessage locationReportMsg = new LocationReportMessage(byteBuf.slice(byteBuf.readerIndex(), length));
byteBuf.skipBytes(length);
double speed = locationReportMsg.getSpeed();
RealtimeLocationResult realtimeLocationResult = BeanUtil.copyProperties(locationReportMsg, RealtimeLocationResult.class)
.setTerminalId(terminalId)
.setOverspeed(locationReportMsg.getSpeed() > speedThreshold)
.setOverspeed(speed > speedThreshold)
.setType(type);
Mqtt.publish(terminalId + "/track_location", realtimeLocationResult);
Mqtt.publish(terminalId + "/track_location_real", realtimeLocationResult);

View File

@ -1,5 +1,6 @@
package com.njzscloud.common.localizer.mqtt;
import cn.hutool.core.collection.CollUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.njzscloud.common.localizer.DeviceStore;
import com.njzscloud.common.localizer.Localizer;
@ -175,8 +176,15 @@ public class MqttMsgHandlers {
@MqttListener(topic = "location/load")
public void load(MqttMsg msg) {
List<DeviceLoadParam> deviceLoadParams = msg.getMsg(typeReference.getType());
if (CollUtil.isEmpty(deviceLoadParams)) {
log.warn("未收到定位器加载参数");
return;
}
LinkedList<Localizer> list = deviceLoadParams.stream()
.map(it -> new Localizer().setTerminalId(it.getTerminalId()).setLocalizerType(it.getLocalizerType()))
.map(it -> new Localizer()
.setTerminalId(it.getTerminalId())
.setSpeedThreshold(it.getSpeedThreshold())
.setLocalizerType(it.getLocalizerType()))
.collect(Collectors.toCollection(LinkedList::new));
DeviceStore.setLocalizers(list);
}

View File

@ -15,8 +15,15 @@ public class DeviceLoadParam {
* ID
*/
private String terminalId;
/**
*
*/
private LocalizerType localizerType;
/**
*
*/
private Integer speedThreshold;
}

View File

@ -65,9 +65,9 @@ wechat:
private-key-path: classpath:cert/apiclient_cert.p12
# private-key-path: D:/project/再昇云/代码/njzscloud/njzscloud-svr/src/main/resources/cert/apiclient_cert.p12
# 支付回调地址
notify-url: http://115.29.236.92:8082/payment/wechat/notify
notify-url: http://139.224.32.69:80/api/payment/wechat/notify
# 退款回调地址
refund-notify-url: http://115.29.236.92:8082/payment/wechat/refundNotify
refund-notify-url: http://139.224.32.69:80/api/payment/wechat/refundNotify
mqtt:
enabled: true
@ -78,3 +78,11 @@ mqtt:
localizer:
enabled: false
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341101', '341100', '340000', '341100', '341101', '', '市辖区', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341122', '341100', '340000', '341100', '341122', '', '来安县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341124', '341100', '340000', '341100', '341124', '', '全椒县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341125', '341100', '340000', '341100', '341125', '', '定远县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341126', '341100', '340000', '341100', '341126', '', '凤阳县', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341181', '341100', '340000', '341100', '341181', '', '天长市', 3, 0);
# INSERT INTO greenfrog.sys_district (id, pid, province, city, area, town, district_name, tier, sort) VALUES ('341182', '341100', '340000', '341100', '341182', '', '明光市', 3, 0);

View File

@ -209,7 +209,7 @@
INNER JOIN order_car_in_out d ON d.id = a.car_in_out_id
WHERE a.order_status = 'YiWanCheng'
AND a.deleted = 0
ORDER BY c.category_name
GROUP BY c.category_name
</select>
<select id="garbageInfo" resultType="java.util.Map">
SELECT area_name areaName, weight
@ -255,7 +255,21 @@
d.goods_name goodsName,
e.category_name categoryName,
f.station_name stationName,
g.company_name transCompanyName
g.company_name transCompanyName,
a.order_status orderStatus,
CASE a.order_status
WHEN 'YiYuYue' THEN '已预约'
WHEN 'DaiPaiDan' THEN '待派单'
WHEN 'DaiJieDan' THEN '待接单'
WHEN 'YiJieDan' THEN '已接单'
WHEN 'QingYunZhong' THEN '清运中'
WHEN 'YiJinChang' THEN '已进场'
WHEN 'YiChuChang' THEN '已出场'
WHEN 'YiWanCheng' THEN '已完成'
WHEN 'YiQuXiao' THEN '已取消'
ELSE ''
END orderStatusTxt,
a.create_time createTime
FROM order_info a
INNER JOIN order_car_in_out b ON b.id = a.car_in_out_id
INNER JOIN order_cargo_place c ON c.id = a.cargo_place_id