1078-优化列表展示效果
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user