支持从数据库查询注册的设备是否合法

This commit is contained in:
648540858
2024-03-13 00:04:52 +08:00
parent 613452b3fc
commit dc38df6288
15 changed files with 163 additions and 115 deletions

View File

@@ -4,6 +4,7 @@ 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;
@@ -32,7 +33,7 @@ public class J0001 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
SessionManager.INSTANCE.response(header.getDevId(), "0001", (long) respNo, JSON.toJSONString(this));
return null;
}

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
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 io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
@@ -23,7 +24,7 @@ public class J0002 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
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 io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
@@ -22,7 +23,7 @@ public class J0004 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
return null;
}

View File

@@ -1,10 +1,12 @@
package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
import com.genersoft.iot.vmp.jt1078.proc.Header;
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 io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
@@ -21,67 +23,56 @@ import java.io.UnsupportedEncodingException;
@MsgId(id = "0100")
public class J0100 extends Re {
private int provinceId;
private int cityId;
private String makerId;
private String deviceModel;
private String deviceId;
private int plateColor;
private String plateNo;
private JTDevice device;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
Short version = header.getVersion();
provinceId = buf.readUnsignedShort();
device = new JTDevice();
device.setProvinceId(buf.readUnsignedShort());
if (version >= 1) {
cityId = buf.readUnsignedShort();
device.setCityId(buf.readUnsignedShort());
// decode as 2019
byte[] bytes11 = new byte[11];
buf.readBytes(bytes11);
makerId = new String(bytes11).trim();
device.setMakerId(new String(bytes11).trim());
byte[] bytes30 = new byte[30];
buf.readBytes(bytes30);
deviceModel = new String(bytes30).trim();
device.setDeviceModel(new String(bytes30).trim());
buf.readBytes(bytes30);
deviceId = new String(bytes30).trim();
device.setDeviceId(new String(bytes30).trim());
plateColor = buf.readByte();
device.setPlateColor(buf.readByte());
byte[] plateColorBytes = new byte[buf.readableBytes()];
buf.readBytes(plateColorBytes);
try {
plateNo = new String(plateColorBytes, "GBK").trim();
device.setPlateNo(new String(plateColorBytes, "GBK").trim());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else {
// decode as 2013
cityId = buf.readUnsignedShort();
device.setCityId(buf.readUnsignedShort());
// decode as 2019
byte[] bytes5 = new byte[5];
buf.readBytes(bytes5);
makerId = new String(bytes5).trim();
device.setMakerId(new String(bytes5).trim());
byte[] bytes20 = new byte[20];
buf.readBytes(bytes20);
deviceModel = new String(bytes20).trim();
device.setDeviceModel(new String(bytes20).trim());
byte[] bytes7 = new byte[7];
buf.readBytes(bytes7);
deviceId = new String(bytes7).trim();
device.setDeviceId(new String(bytes7).trim());
plateColor = buf.readByte();
device.setPlateColor(buf.readByte());
byte[] plateColorBytes = new byte[buf.readableBytes()];
buf.readBytes(plateColorBytes);
try {
plateNo = new String(plateColorBytes, "GBK").trim();
device.setPlateNo(new String(plateColorBytes, "GBK").trim());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
@@ -90,7 +81,8 @@ public class J0100 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
// TODO 从数据库判断这个设备是否合法
J8100 j8100 = new J8100();
j8100.setRespNo(header.getSn());
j8100.setResult(J8100.SUCCESS);
@@ -101,13 +93,7 @@ public class J0100 extends Re {
@Override
public ApplicationEvent getEvent() {
RegisterEvent registerEvent = new RegisterEvent(this);
registerEvent.setProvinceId(provinceId);
registerEvent.setCityId(cityId);
registerEvent.setDeviceId(deviceId);
registerEvent.setDeviceModel(deviceModel);
registerEvent.setMakerId(makerId);
registerEvent.setPlateColor(plateColor);
registerEvent.setPlateNo(plateNo);
registerEvent.setDevice(device);
return registerEvent;
}
}

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
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 io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
@@ -26,7 +27,7 @@ public class J0102 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
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 io.netty.buffer.ByteBuf;
import org.springframework.context.ApplicationEvent;
@@ -23,7 +24,7 @@ public class J0200 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());

View File

@@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.proc.Header;
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
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;
@@ -49,7 +50,7 @@ public class J1205 extends Re {
}
@Override
protected Rs handler(Header header, Session session) {
protected Rs handler(Header header, Session session, Ijt1078Service service) {
SessionManager.INSTANCE.response(header.getDevId(), "1205", (long) respNo, JSON.toJSONString(this));
J8001 j8001 = new J8001();

View File

@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
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 io.netty.buffer.ByteBuf;
import org.slf4j.Logger;
@@ -19,14 +20,14 @@ public abstract class Re {
protected abstract Rs decode0(ByteBuf buf, Header header, Session session);
protected abstract Rs handler(Header header, Session session);
protected abstract Rs handler(Header header, Session session, Ijt1078Service service);
public Rs decode(ByteBuf buf, Header header, Session session) {
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);
}
Rs rs = decode0(buf, header, session);
Rs rsHand = handler(header, session);
Rs rsHand = handler(header, session, service);
if (rs == null && rsHand != null) {
rs = rsHand;
} else if (rs != null && rsHand != null) {

View File

@@ -12,6 +12,13 @@ import io.netty.util.CharsetUtil;
*/
@MsgId(id = "8100")
public class J8100 extends Rs {
/**
* 0 成功
* 1 车辆已被注册
* 2 数据库中无该车辆
* 2 终端已被注册
* 2 数据库中无该终端
*/
public static final Integer SUCCESS = 0;
Integer respNo;