bug修复
This commit is contained in:
parent
b1b6077840
commit
1e8776c6b3
@ -15,6 +15,8 @@ public class Location {
|
||||
private Short speed;
|
||||
private Short direction;
|
||||
private String time;
|
||||
private Long mileage; //里程
|
||||
private float mainFuelTankHeight; //主油箱高度
|
||||
|
||||
public static Location parseFromLocationMsg(LocationMessage msg) {
|
||||
Location location = new Location();
|
||||
|
||||
@ -3,8 +3,6 @@ package com.zhgd.netty.tcp.location;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -19,8 +17,8 @@ public class LocationMessage extends DataPacket {
|
||||
private short speed; //速度 2字节
|
||||
private short direction; //方向 2字节
|
||||
private String time; //时间 6字节BCD
|
||||
private float mileage; //里程
|
||||
private float mainFuelTankHeight; //主油箱高度
|
||||
private Long mileage; //里程
|
||||
private float mainFuelTankHeight; //主油箱高度 单位0.1mm
|
||||
|
||||
public LocationMessage(ByteBuf byteBuf) {
|
||||
super(byteBuf);
|
||||
@ -38,17 +36,23 @@ public class LocationMessage extends DataPacket {
|
||||
this.setSpeed(bb.readShort());
|
||||
this.setDirection(bb.readShort());
|
||||
this.setTime(BCD.toBcdTimeString(readBytes(6)));
|
||||
//读取其他数据
|
||||
while (bb.isReadable()) {
|
||||
byte type = bb.readByte();
|
||||
short type = bb.readUnsignedByte();
|
||||
if (!bb.isReadable()) {
|
||||
break;
|
||||
}
|
||||
byte len = bb.readByte();
|
||||
if (Objects.equals(type, '1')) {
|
||||
if (Objects.equals(len, '4')) {
|
||||
this.setMileage(bb.readFloat());
|
||||
}
|
||||
} else if (Objects.equals(type, '2')) {
|
||||
if (Objects.equals(len, '2')) {
|
||||
this.setMileage(bb.readShort());
|
||||
if (type == 1) {
|
||||
if (len == 4) {
|
||||
this.setMileage(bb.readUnsignedInt());
|
||||
}
|
||||
} else if (type == 2) {
|
||||
if (len == 2) {
|
||||
this.setMainFuelTankHeight(bb.readShort());
|
||||
}
|
||||
} else {
|
||||
readBytes(len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
package com.zhgd.netty.tcp.location;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.sun.org.slf4j.internal.Logger;
|
||||
import com.sun.org.slf4j.internal.LoggerFactory;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionAlarm;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionData;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionDayRecord;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionDev;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.mapper.VehiclePositionAlarmMapper;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.mapper.VehiclePositionDataMapper;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.mapper.VehiclePositionDayRecordMapper;
|
||||
import com.zhgd.xmgl.modules.vehicleposition.mapper.VehiclePositionDevMapper;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -16,6 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 具体处理类
|
||||
*/
|
||||
@ -28,6 +34,10 @@ public class LocationMessageHandler extends BaseHandler<LocationMessage> {
|
||||
@Autowired
|
||||
VehiclePositionDevMapper vehiclePositionDevMapper;
|
||||
@Autowired
|
||||
VehiclePositionDayRecordMapper vehiclePositionDayRecordMapper;
|
||||
@Autowired
|
||||
VehiclePositionAlarmMapper vehiclePositionAlarmMapper;
|
||||
@Autowired
|
||||
@Qualifier("workerGroup")
|
||||
private NioEventLoopGroup workerGroup;
|
||||
|
||||
@ -44,22 +54,147 @@ public class LocationMessageHandler extends BaseHandler<LocationMessage> {
|
||||
if (dev == null) {
|
||||
return;
|
||||
}
|
||||
VehiclePositionData firstData = vehiclePositionDataMapper.getTodayBeginData(dev.getDevSn());
|
||||
VehiclePositionData entity = new VehiclePositionData();
|
||||
entity.setDevSn(dev.getDevSn());
|
||||
//entity.setBatteryPercentage();
|
||||
//entity.setTotalFuelConsumptionDay();
|
||||
//entity.setTotalSleepTimeDay();
|
||||
//entity.setCumulativeOperatingFuelConsumptionDay();
|
||||
//entity.setTotalWorkTimeDay();
|
||||
double hourBt = DateUtil.between(DateUtil.beginOfDay(new Date()), new Date(), DateUnit.HOUR);
|
||||
entity.setMileage(location.getMileage());
|
||||
double trackDistanceDay = 0D;
|
||||
if (firstData != null) {
|
||||
trackDistanceDay = location.getMileage() - firstData.getMileage();
|
||||
entity.setTotalFuelConsumptionDay(location.getMainFuelTankHeight() - firstData.getTotalFuelConsumptionDay());
|
||||
entity.setCumulativeOperatingFuelConsumptionDay(location.getMainFuelTankHeight() - firstData.getTotalFuelConsumptionDay());
|
||||
entity.setTotalSleepTimeDay(firstData.getTotalSleepTimeDay());
|
||||
entity.setTotalWorkTimeDay(hourBt - firstData.getTotalSleepTimeDay());
|
||||
} else {
|
||||
trackDistanceDay = 0D;
|
||||
entity.setCumulativeOperatingFuelConsumptionDay(0D);
|
||||
entity.setTotalFuelConsumptionDay(0D);
|
||||
entity.setTotalSleepTimeDay(hourBt);
|
||||
entity.setTotalWorkTimeDay(0D);
|
||||
}
|
||||
entity.setLongitude(Double.valueOf(location.getLongitude()));
|
||||
entity.setLatitude(Double.valueOf(location.getLatitude()));
|
||||
entity.setProjectSn(dev.getProjectSn());
|
||||
entity.setSpeed(Double.valueOf(location.getSpeed()));
|
||||
vehiclePositionDataMapper.insert(entity);
|
||||
|
||||
//日行数据
|
||||
VehiclePositionDayRecord dayRecordFirst = vehiclePositionDayRecordMapper.getTodayBeginData(dev.getDevSn());
|
||||
if (dayRecordFirst != null) {
|
||||
dayRecordFirst.setTrackDistanceDay(Double.valueOf(location.getMileage()));
|
||||
vehiclePositionDayRecordMapper.updateById(dayRecordFirst);
|
||||
} else {
|
||||
dayRecordFirst = new VehiclePositionDayRecord();
|
||||
dayRecordFirst.setDevSn(dev.getDevSn());
|
||||
dayRecordFirst.setTrackDistanceDay(0D);
|
||||
dayRecordFirst.setDay(DateUtil.today());
|
||||
dayRecordFirst.setProjectSn(dev.getProjectSn());
|
||||
vehiclePositionDayRecordMapper.insert(dayRecordFirst);
|
||||
}
|
||||
|
||||
//报警数据
|
||||
int al = location.getAlarm();
|
||||
if ((al & (1 << 0)) != 0) {
|
||||
addAlarm("紧急报警,触动报警开关后触发", dev);
|
||||
}
|
||||
if ((al & (1 << 1)) != 0) {
|
||||
addAlarm("超速报警", dev);
|
||||
}
|
||||
if ((al & (1 << 2)) != 0) {
|
||||
addAlarm("疲劳驾驶", dev);
|
||||
}
|
||||
if ((al & (1 << 3)) != 0) {
|
||||
addAlarm("危险预警", dev);
|
||||
}
|
||||
if ((al & (1 << 4)) != 0) {
|
||||
addAlarm("GNSS 模块发生故障", dev);
|
||||
}
|
||||
if ((al & (1 << 5)) != 0) {
|
||||
addAlarm("GNSS 天线未接或被剪断", dev);
|
||||
}
|
||||
if ((al & (1 << 6)) != 0) {
|
||||
addAlarm("GNSS 天线短路", dev);
|
||||
}
|
||||
if ((al & (1 << 7)) != 0) {
|
||||
addAlarm("终端主电源欠压", dev);
|
||||
}
|
||||
if ((al & (1 << 8)) != 0) {
|
||||
addAlarm("终端主电源掉电", dev);
|
||||
}
|
||||
if ((al & (1 << 9)) != 0) {
|
||||
addAlarm("终端 LCD 或显示器故障", dev);
|
||||
}
|
||||
if ((al & (1 << 10)) != 0) {
|
||||
addAlarm("TTS 模块故障", dev);
|
||||
}
|
||||
if ((al & (1 << 11)) != 0) {
|
||||
addAlarm("摄像头故障", dev);
|
||||
}
|
||||
if ((al & (1 << 12)) != 0) {
|
||||
addAlarm("道路运输证 IC 卡模块故障", dev);
|
||||
}
|
||||
if ((al & (1 << 13)) != 0) {
|
||||
addAlarm("超速预警", dev);
|
||||
}
|
||||
if ((al & (1 << 14)) != 0) {
|
||||
addAlarm("疲劳驾驶预警", dev);
|
||||
}
|
||||
if ((al & (1 << 18)) != 0) {
|
||||
addAlarm("当天累计驾驶超时", dev);
|
||||
}
|
||||
if ((al & (1 << 19)) != 0) {
|
||||
addAlarm("超时停车", dev);
|
||||
}
|
||||
if ((al & (1 << 20)) != 0) {
|
||||
addAlarm("进出区域", dev);
|
||||
}
|
||||
if ((al & (1 << 21)) != 0) {
|
||||
addAlarm("进出路线", dev);
|
||||
}
|
||||
if ((al & (1 << 22)) != 0) {
|
||||
addAlarm("路段行驶时间不足/过长", dev);
|
||||
}
|
||||
if ((al & (1 << 23)) != 0) {
|
||||
addAlarm("路线偏离报警", dev);
|
||||
}
|
||||
if ((al & (1 << 24)) != 0) {
|
||||
addAlarm("车辆 VSS 故障", dev);
|
||||
}
|
||||
if ((al & (1 << 25)) != 0) {
|
||||
addAlarm("车辆油量异常", dev);
|
||||
}
|
||||
if ((al & (1 << 26)) != 0) {
|
||||
addAlarm("车辆被盗(通过车辆防盗器)", dev);
|
||||
}
|
||||
if ((al & (1 << 27)) != 0) {
|
||||
addAlarm("车辆非法点火", dev);
|
||||
}
|
||||
if ((al & (1 << 28)) != 0) {
|
||||
addAlarm("车辆非法位移", dev);
|
||||
}
|
||||
if ((al & (1 << 29)) != 0) {
|
||||
addAlarm("碰撞预警", dev);
|
||||
}
|
||||
if ((al & (1 << 30)) != 0) {
|
||||
addAlarm("侧翻预警", dev);
|
||||
}
|
||||
if ((al & (1 << 31)) != 0) {
|
||||
addAlarm("非法开门报警(终端未设置区域时,不判断非法开门)", dev);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("LocationMessageHandler 解析报文信息发生错误", e);
|
||||
} finally {
|
||||
ReferenceCountUtil.release(message.getBody());
|
||||
}
|
||||
}
|
||||
|
||||
private void addAlarm(String alarmInformation, VehiclePositionDev dev) {
|
||||
VehiclePositionAlarm alarm = new VehiclePositionAlarm();
|
||||
alarm.setDevSn(dev.getDevSn());
|
||||
alarm.setAlarmInformation(alarmInformation);
|
||||
alarm.setProjectSn(dev.getProjectSn());
|
||||
vehiclePositionAlarmMapper.insert(alarm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.zhgd.netty.tcp.location;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
@ -31,8 +31,6 @@ public class TcpNettyServerJT808 {
|
||||
@Autowired
|
||||
private LocationMessageHandler locationMessageHandler;
|
||||
@Autowired
|
||||
private MessageDecoder messageDecoder;
|
||||
@Autowired
|
||||
private MessageEncoder messageEncoder;
|
||||
@Autowired
|
||||
@Qualifier("bossGroup")
|
||||
@ -60,7 +58,7 @@ public class TcpNettyServerJT808 {
|
||||
socketChannel.pipeline()
|
||||
.addLast(new DelimiterBasedFrameDecoder(1100, Unpooled.copiedBuffer(new byte[]{JT808Const.PKG_DELIMITER}),
|
||||
Unpooled.copiedBuffer(new byte[]{JT808Const.PKG_DELIMITER, JT808Const.PKG_DELIMITER})))
|
||||
.addLast(messageDecoder)
|
||||
.addLast(new MessageDecoder())
|
||||
.addLast(messageEncoder)
|
||||
.addLast(locationMessageHandler);
|
||||
}
|
||||
|
||||
@ -106,6 +106,10 @@ public class VehiclePositionData implements Serializable {
|
||||
@ApiModelProperty(value = "时速")
|
||||
private Double speed;
|
||||
|
||||
@ApiModelProperty(value = "里程表的值")
|
||||
private Long mileage;
|
||||
|
||||
|
||||
/**
|
||||
* 车牌号
|
||||
*/
|
||||
|
||||
@ -23,4 +23,6 @@ public interface VehiclePositionDataMapper extends BaseMapper<VehiclePositionDat
|
||||
IPage<VehiclePositionData> pageList(Page<VehiclePositionData> page, @Param(Constants.WRAPPER) QueryWrapper<VehiclePositionData> queryWrapper);
|
||||
|
||||
List<VehiclePositionData> pageList(@Param(Constants.WRAPPER) QueryWrapper<VehiclePositionData> queryWrapper);
|
||||
|
||||
VehiclePositionData getTodayBeginData(String devSn);
|
||||
}
|
||||
|
||||
@ -27,4 +27,6 @@ public interface VehiclePositionDayRecordMapper extends BaseMapper<VehiclePositi
|
||||
IPage<VehiclePositionDayRecord> pageList(Page<VehiclePositionDayRecord> page, @Param("p") HashMap<String, Object> paramMap);
|
||||
|
||||
List<VehiclePositionDayRecord> pageList(@Param("p") HashMap<String, Object> paramMap);
|
||||
|
||||
VehiclePositionDayRecord getTodayBeginData(String devSn);
|
||||
}
|
||||
|
||||
@ -7,4 +7,13 @@
|
||||
join vehicle_position_dev vpd on vpa.dev_sn = vpd.dev_sn
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="getTodayBeginData" resultType="com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionData">
|
||||
select *
|
||||
from vehicle_position_data vpd
|
||||
where vpd.dev_sn = #{devSn}
|
||||
and vpd.create_time >= current_date
|
||||
order by vpd.create_time
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@ -13,4 +13,13 @@
|
||||
and day <![CDATA[<=]]> concat(#{p.month},'31')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getTodayBeginData" resultType="com.zhgd.xmgl.modules.vehicleposition.entity.VehiclePositionDayRecord">
|
||||
select *
|
||||
from vehicle_position_day_record
|
||||
where dev_sn = #{devSn}
|
||||
and create_time >= current_date
|
||||
order by create_time
|
||||
limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user