[1078] 增加状态变化通知和位置事件

This commit is contained in:
lin
2025-08-05 18:05:18 +08:00
parent d7f5e7d771
commit c90836261a
11 changed files with 146 additions and 86 deletions

View File

@@ -6,13 +6,13 @@ import lombok.Setter;
import org.springframework.context.ApplicationEvent;
/**
* 注册事件
* 设备更新事件
*/
public class RegisterEvent extends ApplicationEvent {
public class DeviceUpdateEvent extends ApplicationEvent {
private static final long serialVersionUID = 1L;
public RegisterEvent(Object source) {
public DeviceUpdateEvent(Object source) {
super(source);
}

View File

@@ -0,0 +1,27 @@
package com.genersoft.iot.vmp.jt1078.event;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.bean.JTPositionBaseInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.context.ApplicationEvent;
/**
* 设备更新事件
*/
public class JTPositionEvent extends ApplicationEvent {
private static final long serialVersionUID = 1L;
public JTPositionEvent(Object source) {
super(source);
}
@Getter
@Setter
private String phoneNumber;
@Getter
@Setter
private JTPositionBaseInfo positionInfo;
}

View File

@@ -2,8 +2,6 @@ package com.genersoft.iot.vmp.jt1078.event.eventListener;
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
import com.genersoft.iot.vmp.jt1078.event.ConnectChangeEvent;
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
import com.genersoft.iot.vmp.jt1078.proc.request.J0003;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
import org.slf4j.Logger;

View File

@@ -3,7 +3,7 @@ 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.event.RegisterEvent;
import com.genersoft.iot.vmp.jt1078.event.DeviceUpdateEvent;
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;
@@ -13,8 +13,6 @@ import com.genersoft.iot.vmp.utils.CivilCodeUtil;
import com.genersoft.iot.vmp.utils.DateUtil;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import java.io.UnsupportedEncodingException;
@@ -33,6 +31,7 @@ import java.util.UUID;
public class J0100 extends Re {
private JTDevice device;
private JTDevice deviceForUpdate;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
@@ -87,33 +86,32 @@ public class J0100 extends Re {
J8100 j8100 = new J8100();
j8100.setRespNo(header.getSn());
// 从数据库判断这个设备是否合法
JTDevice deviceInDb = service.getDevice(header.getPhoneNumber());
if (deviceInDb != null) {
deviceForUpdate = service.getDevice(header.getPhoneNumber());
if (deviceForUpdate != null) {
j8100.setResult(J8100.SUCCESS);
String authenticationCode = UUID.randomUUID().toString();
j8100.setCode(authenticationCode);
deviceInDb.setAuthenticationCode(authenticationCode);
deviceInDb.setStatus(true);
deviceInDb.setProvinceId(device.getProvinceId());
deviceInDb.setRegisterTime(DateUtil.getNow());
deviceForUpdate.setAuthenticationCode(authenticationCode);
deviceForUpdate.setStatus(true);
deviceForUpdate.setProvinceId(device.getProvinceId());
deviceForUpdate.setRegisterTime(DateUtil.getNow());
CivilCodePo provinceCivilCodePo = CivilCodeUtil.INSTANCE.get(device.getProvinceId());
if (provinceCivilCodePo != null) {
deviceInDb.setProvinceText(provinceCivilCodePo.getName());
deviceForUpdate.setProvinceText(provinceCivilCodePo.getName());
}
deviceInDb.setCityId(device.getCityId());
deviceForUpdate.setCityId(device.getCityId());
CivilCodePo cityCivilCodePo = CivilCodeUtil.INSTANCE.get(device.getProvinceId() +
String.format("%04d", Integer.parseInt(device.getCityId())));
if (cityCivilCodePo != null) {
deviceInDb.setCityText(cityCivilCodePo.getName());
deviceForUpdate.setCityText(cityCivilCodePo.getName());
}
deviceInDb.setModel(device.getModel());
deviceInDb.setMakerId(device.getMakerId());
deviceInDb.setTerminalId(device.getTerminalId());
deviceForUpdate.setModel(device.getModel());
deviceForUpdate.setMakerId(device.getMakerId());
deviceForUpdate.setTerminalId(device.getTerminalId());
// TODO 支持直接展示车牌颜色的描述
deviceInDb.setPlateColor(device.getPlateColor());
deviceInDb.setPlateNo(device.getPlateNo());
service.updateDevice(deviceInDb);
log.info("[JT-注册成功] 设备: {}", deviceInDb);
deviceForUpdate.setPlateColor(device.getPlateColor());
deviceForUpdate.setPlateNo(device.getPlateNo());
log.info("[JT-注册成功] 设备: {}", deviceForUpdate);
}else {
log.info("[JT-注册失败] 未授权设备: {}", header.getPhoneNumber());
j8100.setResult(J8100.FAIL);
@@ -127,8 +125,8 @@ public class J0100 extends Re {
@Override
public ApplicationEvent getEvent() {
RegisterEvent registerEvent = new RegisterEvent(this);
registerEvent.setDevice(device);
DeviceUpdateEvent registerEvent = new DeviceUpdateEvent(this);
registerEvent.setDevice(deviceForUpdate);
return registerEvent;
}
}

View File

@@ -2,6 +2,7 @@ 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.DeviceUpdateEvent;
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;
@@ -25,6 +26,7 @@ import java.nio.charset.Charset;
public class J0102 extends Re {
private String authenticationCode;
private JTDevice deviceForUpdate;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
@@ -49,7 +51,8 @@ public class J0102 extends Re {
}else {
j8001.setResult(J8001.SUCCESS);
if (!device.isStatus()) {
device.setStatus(true);
deviceForUpdate = device;
deviceForUpdate.setStatus(true);
service.updateDevice(device);
}
}
@@ -58,7 +61,9 @@ public class J0102 extends Re {
@Override
public ApplicationEvent getEvent() {
return null;
DeviceUpdateEvent registerEvent = new DeviceUpdateEvent(this);
registerEvent.setDevice(deviceForUpdate);
return registerEvent;
}
}

View File

@@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.*;
import com.genersoft.iot.vmp.jt1078.event.DeviceUpdateEvent;
import com.genersoft.iot.vmp.jt1078.event.JTPositionEvent;
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;
@@ -25,12 +27,12 @@ public class J0201 extends Re {
private final static Logger log = LoggerFactory.getLogger(J0100.class);
private JTPositionBaseInfo positionInfo;
private String phoneNumber;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
phoneNumber = header.getPhoneNumber();
int respNo = buf.readUnsignedShort();
positionInfo = JTPositionBaseInfo.decode(buf);
log.info("[JT-位置信息查询应答]: {}", positionInfo);
SessionManager.INSTANCE.response(header.getPhoneNumber(), "0201", (long) respNo, positionInfo);
@@ -39,24 +41,21 @@ public class J0201 extends Re {
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
JTDevice deviceInDb = service.getDevice(header.getPhoneNumber());
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);
}
j8001.setResult(J8001.SUCCESS);
return j8001;
}
@Override
public ApplicationEvent getEvent() {
return null;
if (positionInfo == null || phoneNumber == null ) {
return null;
}
JTPositionEvent registerEvent = new JTPositionEvent(this);
registerEvent.setPhoneNumber(phoneNumber);
registerEvent.setPositionInfo(positionInfo);
return registerEvent;
}
}

View File

@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
import com.genersoft.iot.vmp.jt1078.bean.*;
import com.genersoft.iot.vmp.jt1078.event.JTPositionEvent;
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;
@@ -23,9 +24,11 @@ import org.springframework.context.ApplicationEvent;
public class J0500 extends Re {
private JTPositionBaseInfo positionInfo;
private String phoneNumber;
@Override
protected Rs decode0(ByteBuf buf, Header header, Session session) {
phoneNumber = header.getPhoneNumber();
int respNo = buf.readUnsignedShort();
positionInfo = JTPositionBaseInfo.decode(buf);
log.info("[车辆控制应答] {}", header.getPhoneNumber());
@@ -35,24 +38,21 @@ public class J0500 extends Re {
@Override
protected Rs handler(Header header, Session session, Ijt1078Service service) {
JTDevice deviceInDb = service.getDevice(header.getPhoneNumber());
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);
}
j8001.setResult(J8001.SUCCESS);
return j8001;
}
@Override
public ApplicationEvent getEvent() {
return null;
if (positionInfo == null || phoneNumber == null ) {
return null;
}
JTPositionEvent registerEvent = new JTPositionEvent(this);
registerEvent.setPhoneNumber(phoneNumber);
registerEvent.setPositionInfo(positionInfo);
return registerEvent;
}
}

View File

@@ -42,7 +42,7 @@ public class J0901 extends Re {
J8001 j8001 = new J8001();
j8001.setRespNo(header.getSn());
j8001.setRespId(header.getMsgId());
return null;
return j8001;
}
@Override

View File

@@ -9,16 +9,15 @@ import com.genersoft.iot.vmp.conf.ftpServer.FtpSetting;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.ftpServer.UserManager;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelService;
import com.genersoft.iot.vmp.jt1078.bean.*;
import com.genersoft.iot.vmp.jt1078.bean.common.ConfigAttribute;
import com.genersoft.iot.vmp.jt1078.bean.config.JTAloneChanel;
import com.genersoft.iot.vmp.jt1078.bean.config.JTChannelListParam;
import com.genersoft.iot.vmp.jt1078.bean.config.JTChannelParam;
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
import com.genersoft.iot.vmp.jt1078.dao.JTChannelMapper;
import com.genersoft.iot.vmp.jt1078.dao.JTTerminalMapper;
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
import com.genersoft.iot.vmp.jt1078.event.DeviceUpdateEvent;
import com.genersoft.iot.vmp.jt1078.event.JTPositionEvent;
import com.genersoft.iot.vmp.jt1078.proc.response.*;
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
import com.genersoft.iot.vmp.jt1078.session.FtpDownloadManager;
@@ -43,13 +42,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.PostConstruct;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.util.*;
import java.util.concurrent.SynchronousQueue;
@Service
@Slf4j
@@ -88,6 +87,33 @@ public class jt1078ServiceImpl implements Ijt1078Service {
@Autowired
private FtpDownloadManager downloadManager;
// 服务启动后五分钟内没有尽量连接的设备设置为离线
@PostConstruct
public void init(){
// 检查session与在线终端是是否对应 不对应则设置终端离线
List<JTDevice> deviceList = jtDeviceMapper.getDeviceList(null, true);
if (deviceList.isEmpty()) {
return;
}
for (JTDevice device : deviceList) {
Session session = SessionManager.INSTANCE.get(device.getPhoneNumber());
if (session == null) {
device.setStatus(false);
// 通道发送状态变化通知
List<JTChannel> jtChannels = jtChannelMapper.selectAll(device.getId(), null);
List<CommonGBChannel> channelList = new ArrayList<>();
for (JTChannel jtChannel : jtChannels) {
if (jtChannel.getGbId() > 0) {
jtChannel.setGbStatus("OFF");
channelList.add(jtChannel);
}
}
channelService.updateStatus(channelList);
updateDevice(device);
}
}
}
/**
* 流到来的处理
*/
@@ -107,26 +133,37 @@ public class jt1078ServiceImpl implements Ijt1078Service {
}
/**
* 设备注册的通知
* 设备更新的通知
*/
@Async("taskExecutor")
@EventListener
public void onApplicationEvent(RegisterEvent event) {
// 首次注册设备根据终端参数获取
// JTDevice device = event.getDevice();
// List<JTChannel> channelList = jtChannelMapper.selectAllByDevicePhoneNumber(device.getPhoneNumber());
// if (!channelList.isEmpty()) {
// return;
// }
// JTDeviceConfig jtDeviceConfig = queryConfig(device.getPhoneNumber(), null);
// JTChannelParam channelParam = jtDeviceConfig.getChannelParam();
// if (channelParam != null && channelParam.getJtAloneChanelList() != null && !channelParam.getJtAloneChanelList().isEmpty()) {
// // 写入通道
// List<JTAloneChanel> jtAloneChanelList = channelParam.getJtAloneChanelList();
// for (JTAloneChanel jtAloneChanel : jtAloneChanelList) {
//
// }
// }
public void onApplicationEvent(DeviceUpdateEvent event) {
JTDevice device = event.getDevice();
if (device == null || device.getPhoneNumber() == null) {
return;
}
JTDevice deviceInDb = getDevice(event.getDevice().getPhoneNumber());
if (deviceInDb.isStatus() != device.isStatus()) {
// 通道发送状态变化通知
List<JTChannel> jtChannels = jtChannelMapper.selectAll(deviceInDb.getId(), null);
List<CommonGBChannel> channelList = new ArrayList<>();
for (JTChannel jtChannel : jtChannels) {
if (jtChannel.getGbId() > 0) {
jtChannel.setGbStatus("OFF");
channelList.add(jtChannel);
}
}
channelService.updateStatus(channelList);
}
updateDevice(event.getDevice());
}
/**
* 位置更新的通知
*/
@Async("taskExecutor")
@EventListener
public void onApplicationEvent(JTPositionEvent event) {
}

View File

@@ -333,6 +333,13 @@ export function queryMediaData(data) {
data: data
})
}
export function setPhoneBook(data) {
return request({
method: 'post',
url: '/api/jt1078/set-phone-book',
data: data
})
}
export function shooting(data) {
return request({
method: 'post',

View File

@@ -42,7 +42,6 @@ import {
stopCruise,
stopScan,
wiper,
getAllForMap,
stopPlayChannel,
queryRecord,
playback,
@@ -493,16 +492,6 @@ const actions = {
})
})
},
getAllForMap({ commit }, params) {
return new Promise((resolve, reject) => {
getAllForMap(params).then(response => {
const { data } = response
resolve(data)
}).catch(error => {
reject(error)
})
})
},
queryRecord({ commit }, params) {
return new Promise((resolve, reject) => {
queryRecord(params).then(response => {