1078-查询区域或线路数据
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
package com.genersoft.iot.vmp.jt1078.bean;
|
||||
|
||||
public interface JTAreaOrRoute {
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.Date;
|
||||
|
||||
@Schema(description = "圆形区域")
|
||||
public class JTCircleArea {
|
||||
public class JTCircleArea implements JTAreaOrRoute{
|
||||
|
||||
@Schema(description = "区域 ID")
|
||||
private long id;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "多边形区域")
|
||||
public class JTPolygonArea {
|
||||
public class JTPolygonArea implements JTAreaOrRoute{
|
||||
|
||||
@Schema(description = "区域 ID")
|
||||
private long id;
|
||||
|
||||
@@ -9,7 +9,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@Schema(description = "矩形区域")
|
||||
public class JTRectangleArea {
|
||||
public class JTRectangleArea implements JTAreaOrRoute{
|
||||
|
||||
@Schema(description = "区域 ID")
|
||||
private long id;
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "路线")
|
||||
public class JTRoute {
|
||||
public class JTRoute implements JTAreaOrRoute{
|
||||
|
||||
@Schema(description = "路线 ID")
|
||||
private long id;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTAreaOrRoute;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTPositionBaseInfo;
|
||||
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;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询区域或线路数据应答
|
||||
*
|
||||
*/
|
||||
@MsgId(id = "0608")
|
||||
public class J0608 extends Re {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(J0100.class);
|
||||
private JTPositionBaseInfo positionInfo;
|
||||
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
int type = buf.readByte();
|
||||
long dataLength = buf.readUnsignedInt();
|
||||
log.info("[JT-查询区域或线路数据应答]: 类型: {}, 数量: {}", type, dataLength);
|
||||
List<JTAreaOrRoute> areaOrRoutes = new ArrayList<>();
|
||||
if (dataLength == 0) {
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0608", null, areaOrRoutes);
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < dataLength; i++) {
|
||||
switch (type) {
|
||||
case 1:
|
||||
// 查询圆形区域数据
|
||||
break;
|
||||
case 2:
|
||||
// 查询矩形区域数据
|
||||
break;
|
||||
case 3:
|
||||
// 查询多 边形区域数据
|
||||
break;
|
||||
case 4:
|
||||
// 查询线路数据
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int respNo = buf.readUnsignedShort();
|
||||
positionInfo = J0200.getPositionInfo(buf);
|
||||
log.info("[JT-车辆控制应答]: {}", positionInfo.toString());
|
||||
SessionManager.INSTANCE.response(header.getTerminalId(), "0500", (long) respNo, positionInfo);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
JTDevice deviceInDb = service.getDevice(header.getTerminalId());
|
||||
J8001 j8001 = new J8001();
|
||||
j8001.setRespNo(header.getSn());
|
||||
j8001.setRespId(header.getMsgId());
|
||||
if (deviceInDb == null) {
|
||||
j8001.setResult(J8001.FAIL);
|
||||
}else {
|
||||
// TODO 优化为发送异步事件,定时读取队列写入数据库
|
||||
deviceInDb.setLongitude(positionInfo.getLongitude());
|
||||
deviceInDb.setLatitude(positionInfo.getLatitude());
|
||||
service.updateDevice(deviceInDb);
|
||||
j8001.setResult(J8001.SUCCESS);
|
||||
}
|
||||
return j8001;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationEvent getEvent() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.genersoft.iot.vmp.jt1078.proc.response;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询区域或线路数据
|
||||
*/
|
||||
@MsgId(id = "8608")
|
||||
public class J8608 extends Rs {
|
||||
|
||||
|
||||
/**
|
||||
* 查询类型, 1 = 查询圆形区域数据 ,2 = 查询矩形区域数据 ,3 = 查询多 边形区域数据 ,4 = 查询线路数据
|
||||
*/
|
||||
private int type;
|
||||
|
||||
|
||||
/**
|
||||
* 要查询的区域或线路的 ID
|
||||
*/
|
||||
private List<Long> idList;
|
||||
|
||||
|
||||
@Override
|
||||
public ByteBuf encode() {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
buffer.writeByte(type);
|
||||
if (idList == null || idList.isEmpty()) {
|
||||
buffer.writeByte(0);
|
||||
return buffer;
|
||||
}else {
|
||||
buffer.writeByte(idList.size());
|
||||
}
|
||||
for (Long id : idList) {
|
||||
buffer.writeInt((int) (id & 0xffffffffL));
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Long> getIdList() {
|
||||
return idList;
|
||||
}
|
||||
|
||||
public void setIdList(List<Long> idList) {
|
||||
this.idList = idList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user