diff --git a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/Localizer.java b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/Localizer.java index 0ae5154..b4a07c2 100644 --- a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/Localizer.java +++ b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/Localizer.java @@ -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); diff --git a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageHandler.java b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageHandler.java index 12dd327..28c6a25 100644 --- a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageHandler.java +++ b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageHandler.java @@ -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(); } } diff --git a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageListener.java b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageListener.java index 9ccd3df..caa1dd1 100644 --- a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageListener.java +++ b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/jt808/support/JT808MessageListener.java @@ -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); diff --git a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/MqttMsgHandlers.java b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/MqttMsgHandlers.java index a7c801b..03dac83 100644 --- a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/MqttMsgHandlers.java +++ b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/MqttMsgHandlers.java @@ -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 deviceLoadParams = msg.getMsg(typeReference.getType()); + if (CollUtil.isEmpty(deviceLoadParams)) { + log.warn("未收到定位器加载参数"); + return; + } LinkedList 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); } diff --git a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/param/DeviceLoadParam.java b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/param/DeviceLoadParam.java index 3650298..18df868 100644 --- a/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/param/DeviceLoadParam.java +++ b/njzscloud-common/njzscloud-common-localizer/src/main/java/com/njzscloud/common/localizer/mqtt/param/DeviceLoadParam.java @@ -15,8 +15,15 @@ public class DeviceLoadParam { * 终端ID */ private String terminalId; + /** * 定位器类别 */ private LocalizerType localizerType; + + /** + * 速度阈值 + */ + private Integer speedThreshold; + } diff --git a/njzscloud-svr/src/main/resources/application-prod.yml b/njzscloud-svr/src/main/resources/application-prod.yml index db98383..ac2dbb9 100644 --- a/njzscloud-svr/src/main/resources/application-prod.yml +++ b/njzscloud-svr/src/main/resources/application-prod.yml @@ -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); diff --git a/njzscloud-svr/src/main/resources/mapper/bs/StatisticsMapper.xml b/njzscloud-svr/src/main/resources/mapper/bs/StatisticsMapper.xml index cb4fcb0..8be5ce2 100644 --- a/njzscloud-svr/src/main/resources/mapper/bs/StatisticsMapper.xml +++ b/njzscloud-svr/src/main/resources/mapper/bs/StatisticsMapper.xml @@ -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