1078-优化列表展示效果

This commit is contained in:
648540858
2024-03-14 18:04:28 +08:00
parent d4c531dc12
commit 23a72e94e6
21 changed files with 235 additions and 60 deletions

View File

@@ -14,13 +14,25 @@ public class JTDevice {
* 省域ID
*/
@Schema(description = "省域ID")
private int provinceId;
private String provinceId;
/**
* 省域文字描述
*/
@Schema(description = "省域文字描述")
private String provinceText;
/**
* 市县域ID
*/
@Schema(description = "市县域ID")
private int cityId;
private String cityId;
/**
* 市县域文字描述
*/
@Schema(description = "市县域文字描述")
private String cityText;
/**
* 制造商ID
@@ -38,6 +50,12 @@ public class JTDevice {
* 终端ID
*/
@Schema(description = "终端ID")
private String terminalId;
/**
* 设备ID
*/
@Schema(description = "设备ID")
private String deviceId;
/**
@@ -80,22 +98,46 @@ public class JTDevice {
@Schema(description = "状态")
private boolean status;
public int getProvinceId() {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getProvinceId() {
return provinceId;
}
public void setProvinceId(int provinceId) {
public void setProvinceId(String provinceId) {
this.provinceId = provinceId;
}
public int getCityId() {
public String getProvinceText() {
return provinceText;
}
public void setProvinceText(String provinceText) {
this.provinceText = provinceText;
}
public String getCityId() {
return cityId;
}
public void setCityId(int cityId) {
public void setCityId(String cityId) {
this.cityId = cityId;
}
public String getCityText() {
return cityText;
}
public void setCityText(String cityText) {
this.cityText = cityText;
}
public String getMakerId() {
return makerId;
}
@@ -112,6 +154,14 @@ public class JTDevice {
this.deviceModel = deviceModel;
}
public String getTerminalId() {
return terminalId;
}
public void setTerminalId(String terminalId) {
this.terminalId = terminalId;
}
public String getDeviceId() {
return deviceId;
}
@@ -184,11 +234,21 @@ public class JTDevice {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
@Override
public String toString() {
return "JTDevice{" +
", 省域ID='" + provinceId + '\'' +
", 省域文字描述='" + provinceText + '\'' +
", 市县域ID='" + cityId + '\'' +
", 市县域文字描述='" + cityText + '\'' +
", 制造商ID='" + makerId + '\'' +
", 终端型号='" + deviceModel + '\'' +
", 终端ID='" + terminalId + '\'' +
", 设备ID='" + deviceId + '\'' +
", 车牌颜色=" + plateColor +
", 车牌='" + plateNo + '\'' +
", 鉴权码='" + authenticationCode + '\'' +
", status=" + status +
'}';
}
}

View File

@@ -50,9 +50,9 @@ public class Jt808Decoder extends ByteToMessageDecoder {
if (header.is2019Version()) {
header.setVersion(buf.readUnsignedByte());
String devId = ByteBufUtil.hexDump(buf.readSlice(10));
header.setDevId(devId.replaceFirst("^0*", ""));
header.setTerminalId(devId.replaceFirst("^0*", ""));
} else {
header.setDevId(ByteBufUtil.hexDump(buf.readSlice(6)).replaceFirst("^0*", ""));
header.setTerminalId(ByteBufUtil.hexDump(buf.readSlice(6)).replaceFirst("^0*", ""));
}
header.setSn(buf.readUnsignedShort());

View File

@@ -65,12 +65,12 @@ public class Jt808EncoderCmd extends MessageToByteEncoder<Cmd> {
byteBuf.writeByte(header.getVersion());
// 终端手机号
byteBuf.writeBytes(ByteBufUtil.decodeHexDump(Bin.strHexPaddingLeft(header.getDevId(), 20)));
byteBuf.writeBytes(ByteBufUtil.decodeHexDump(Bin.strHexPaddingLeft(header.getTerminalId(), 20)));
} else {
// 消息体属性
byteBuf.writeShort(encode.readableBytes());
byteBuf.writeBytes(ByteBufUtil.decodeHexDump(Bin.strHexPaddingLeft(header.getDevId(), 12)));
byteBuf.writeBytes(ByteBufUtil.decodeHexDump(Bin.strHexPaddingLeft(header.getTerminalId(), 12)));
}
// 消息体流水号

View File

@@ -10,6 +10,7 @@ import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
/**
* @author QingtaiJiang
@@ -20,6 +21,13 @@ public class Jt808Handler extends ChannelInboundHandlerAdapter {
private final static Logger log = LoggerFactory.getLogger(Jt808Handler.class);
private ApplicationEventPublisher applicationEventPublisher = null;
public Jt808Handler(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Rs) {
@@ -42,6 +50,8 @@ public class Jt808Handler extends ChannelInboundHandlerAdapter {
Session session = ctx.channel().attr(Session.KEY).get();
log.info("< Tcp disconnect {}", session);
ctx.close();
applicationEventPublisher.publishEvent();
}
@Override

View File

@@ -69,7 +69,7 @@ public class TcpServer {
.addLast(new Jt808Decoder(applicationEventPublisher, service))
.addLast(new Jt808Encoder())
.addLast(new Jt808EncoderCmd())
.addLast(new Jt808Handler());
.addLast(new Jt808Handler(applicationEventPublisher));
}
});
ChannelFuture channelFuture = bootstrap.bind(port).sync();

View File

@@ -8,23 +8,26 @@ import java.util.List;
@Mapper
public interface JTDeviceMapper {
@Select("SELECT * FROM wvp_device de where device_id=${devId}")
JTDevice getDevice(@Param("devId") String devId);
@Select("SELECT * FROM wvp_jt_device where terminal_id=#{terminalId}")
JTDevice getDevice(@Param("terminalId") String terminalId);
@Update(value = {" <script>" +
"UPDATE wvp_jt_device " +
"SET update_time=#{updateTime}" +
"<if test=\"deviceId != null\">, device_id=#{deviceId}</if>" +
"<if test=\"provinceId != null\">, province_id=#{provinceId}</if>" +
"<if test=\"provinceText != null\">, province_text=#{provinceText}</if>" +
"<if test=\"cityId != null\">, city_id=#{cityId}</if>" +
"<if test=\"cityText != null\">, city_text=#{cityText}</if>" +
"<if test=\"makerId != null\">, maker_id=#{makerId}</if>" +
"<if test=\"deviceModel != null\">, device_model=#{deviceModel}</if>" +
"<if test=\"plateColor != null\">, plate_color=#{plateColor}</if>" +
"<if test=\"plateNo != null\">, plate_no=#{plateNo}</if>" +
"<if test=\"authenticationCode != null\">, authentication_code=#{localIp}</if>" +
"<if test=\"authenticationCode != null\">, authentication_code=#{authenticationCode}</if>" +
"<if test=\"longitude != null\">, longitude=#{longitude}</if>" +
"<if test=\"latitude != null\">, latitude=#{latitude}</if>" +
"<if test=\"status != null\">, status=#{status}</if>" +
"WHERE device_id=#{deviceId}"+
"WHERE terminal_id=#{terminalId}"+
" </script>"})
void updateDevice(JTDevice device);
@Select(value = {" <script>" +
@@ -34,6 +37,7 @@ public interface JTDeviceMapper {
"WHERE " +
"1=1" +
" <if test='query != null'> AND (" +
"jd.terminal_id LIKE concat('%',#{query},'%') " +
"jd.province_id LIKE concat('%',#{query},'%') " +
"OR jd.city_id LIKE concat('%',#{query},'%') " +
"OR jd.maker_id LIKE concat('%',#{query},'%') " +
@@ -48,8 +52,11 @@ public interface JTDeviceMapper {
List<JTDevice> getDeviceList(@Param("query") String query, @Param("online") Boolean online);
@Insert("INSERT INTO wvp_jt_device (" +
"terminal_id,"+
"province_id,"+
"province_text,"+
"city_id,"+
"city_text,"+
"maker_id,"+
"device_id,"+
"device_model,"+
@@ -61,8 +68,11 @@ public interface JTDeviceMapper {
"create_time,"+
"update_time"+
") VALUES (" +
"#{terminalId}," +
"#{provinceId}," +
"#{provinceText}," +
"#{cityId}," +
"#{cityText}," +
"#{makerId}," +
"#{deviceId}," +
"#{deviceModel}," +
@@ -76,6 +86,6 @@ public interface JTDeviceMapper {
")")
void addDevice(JTDevice device);
@Delete("delete from wvp_jt_device where device_id = #{deviceId}")
void deleteDeviceByDeviceId(@Param("deviceId") String deviceId);
@Delete("delete from wvp_jt_device where terminal_id = #{terminalId}")
void deleteDeviceByTerminalId(@Param("terminalId") String terminalId);
}

View File

@@ -15,11 +15,12 @@ public class Header {
Integer msgPro;
// 标识
String devId;
String terminalId;
// 消息体流水号
Integer sn;
// 协议版本号
Short version = -1;
@@ -40,12 +41,12 @@ public class Header {
this.msgPro = msgPro;
}
public String getDevId() {
return devId;
public String getTerminalId() {
return terminalId;
}
public void setDevId(String devId) {
this.devId = devId;
public void setTerminalId(String terminalId) {
this.terminalId = terminalId;
}
public Integer getSn() {

View File

@@ -34,7 +34,7 @@ public class J0001 extends Re {
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
SessionManager.INSTANCE.response(header.getDevId(), "0001", (long) respNo, JSON.toJSONString(this));
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, JSON.toJSONString(this));
return null;
}

View File

@@ -0,0 +1,58 @@
package com.genersoft.iot.vmp.jt1078.proc.request;
import com.alibaba.fastjson2.JSON;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.Session;
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
/**
* 终端注销
*/
@MsgId(id = "0003")
public class J0003 extends Re {
private final static Logger log = LoggerFactory.getLogger(J0003.class);
int respNo;
String respId;
int result;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
respNo = buf.readUnsignedShort();
respId = ByteBufUtil.hexDump(buf.readSlice(2));
result = buf.readUnsignedByte();
log.info("[JT-注销] 设备: {}", header.getTerminalId());
return null;
}
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
SessionManager.INSTANCE.response(header.getTerminalId(), "0001", (long) respNo, JSON.toJSONString(this));
return null;
}
public int getRespNo() {
return respNo;
}
public String getRespId() {
return respId;
}
public int getResult() {
return result;
}
@Override
public ApplicationEvent getEvent() {
return null;
}
}

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.codec.netty.Jt808Handler;
@@ -9,6 +10,7 @@ import com.genersoft.iot.vmp.jt1078.proc.response.J8100;
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.Session;
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
import io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,9 +36,9 @@ public class J0100 extends Re {
protected Rs decode0(ByteBuf buf, Header header, Session session) {
Short version = header.getVersion();
device = new JTDevice();
device.setProvinceId(buf.readUnsignedShort());
device.setProvinceId(buf.readUnsignedShort() + "");
if (version >= 1) {
device.setCityId(buf.readUnsignedShort());
device.setCityId(buf.readUnsignedShort() + "");
// decode as 2019
byte[] bytes11 = new byte[11];
buf.readBytes(bytes11);
@@ -59,7 +61,7 @@ public class J0100 extends Re {
}
} else {
// decode as 2013
device.setCityId(buf.readUnsignedShort());
device.setCityId(buf.readUnsignedShort() + "");
// decode as 2019
byte[] bytes5 = new byte[5];
buf.readBytes(bytes5);
@@ -90,17 +92,34 @@ public class J0100 extends Re {
J8100 j8100 = new J8100();
j8100.setRespNo(header.getSn());
// 从数据库判断这个设备是否合法
JTDevice deviceInDb = service.getDevice(header.getDevId());
JTDevice deviceInDb = service.getDevice(header.getTerminalId());
if (deviceInDb != null) {
j8100.setResult(J8100.SUCCESS);
String authenticationCode = UUID.randomUUID().toString();
j8100.setCode(authenticationCode);
deviceInDb.setAuthenticationCode(authenticationCode);
deviceInDb.setStatus(true);
deviceInDb.setProvinceId(device.getProvinceId());
CivilCodePo provinceCivilCodePo = CivilCodeUtil.INSTANCE.get(device.getProvinceId());
if (provinceCivilCodePo != null) {
deviceInDb.setProvinceText(provinceCivilCodePo.getName());
}
deviceInDb.setCityId(device.getCityId());
CivilCodePo cityCivilCodePo = CivilCodeUtil.INSTANCE.get(device.getProvinceId() +
String.format("%04d", Integer.parseInt(device.getCityId())));
if (cityCivilCodePo != null) {
deviceInDb.setCityText(cityCivilCodePo.getName());
}
deviceInDb.setDeviceModel(device.getDeviceModel());
deviceInDb.setMakerId(device.getMakerId());
deviceInDb.setDeviceId(device.getDeviceId());
// TODO 支持直接展示车牌颜色的描述
deviceInDb.setPlateColor(device.getPlateColor());
deviceInDb.setPlateNo(device.getPlateNo());
service.updateDevice(deviceInDb);
log.info("[注册成功] 设备: {}", device.getDeviceId());
log.info("[JT-注册成功] 设备: {}", deviceInDb);
}else {
log.info("[注册失败] 未授权设备: {}", device.getDeviceId());
log.info("[JT-注册失败] 未授权设备: {}", header.getTerminalId());
j8100.setResult(J8100.FAIL);
// 断开连接,清理资源
if (session.isRegistered()) {

View File

@@ -51,7 +51,7 @@ public class J1205 extends Re {
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
SessionManager.INSTANCE.response(header.getDevId(), "1205", (long) respNo, JSON.toJSONString(this));
SessionManager.INSTANCE.response(header.getTerminalId(), "1205", (long) respNo, JSON.toJSONString(this));
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());

View File

@@ -24,7 +24,7 @@ public abstract class Re {
public Rs decode(ByteBuf buf, Header header, Session session, Ijt1078Service service) {
if (session != null && !StringUtils.hasLength(session.getDevId())) {
session.register(header.getDevId(), (int) header.getVersion(), header);
session.register(header.getTerminalId(), (int) header.getVersion(), header);
}
Rs rs = decode0(buf, header, session);
Rs rsHand = handler(header, session, service);

View File

@@ -6,7 +6,7 @@ import com.github.pagehelper.PageInfo;
import java.util.List;
public interface Ijt1078Service {
JTDevice getDevice(String devId);
JTDevice getDevice(String terminalId);
void updateDevice(JTDevice deviceInDb);

View File

@@ -19,8 +19,8 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override
public JTDevice getDevice(String devId) {
return jtDeviceMapper.getDevice(devId);
public JTDevice getDevice(String terminalId) {
return jtDeviceMapper.getDevice(terminalId);
}
@Override
@@ -45,6 +45,6 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Override
public void deleteDeviceByDeviceId(String deviceId) {
jtDeviceMapper.deleteDeviceByDeviceId(deviceId);
jtDeviceMapper.deleteDeviceByTerminalId(deviceId);
}
}

View File

@@ -27,6 +27,10 @@ public enum CivilCodeUtil {
}
}
public CivilCodePo get(String code) {
return civilCodeMap.get(code);
}
public CivilCodePo getParentCode(String code) {
if (code.length() > 8) {
return null;
@@ -45,6 +49,5 @@ public enum CivilCodeUtil {
}
return civilCodeMap.get(parentCode);
}
}
}