1078-设备注册支持从数据库校验是否合法
This commit is contained in:
@@ -1,45 +1,75 @@
|
||||
package com.genersoft.iot.vmp.jt1078.bean;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* JT 设备
|
||||
*/
|
||||
@Schema(description = "jt808设备")
|
||||
public class JTDevice {
|
||||
|
||||
/**
|
||||
* 省域ID
|
||||
*/
|
||||
@Schema(description = "省域ID")
|
||||
private int provinceId;
|
||||
|
||||
/**
|
||||
* 市县域ID
|
||||
*/
|
||||
@Schema(description = "市县域ID")
|
||||
private int cityId;
|
||||
|
||||
/**
|
||||
* 制造商ID
|
||||
*/
|
||||
@Schema(description = "制造商ID")
|
||||
private String makerId;
|
||||
|
||||
/**
|
||||
* 终端型号
|
||||
*/
|
||||
@Schema(description = "终端型号")
|
||||
private String deviceModel;
|
||||
|
||||
/**
|
||||
* 终端ID
|
||||
*/
|
||||
@Schema(description = "终端ID")
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 车牌颜色
|
||||
*/
|
||||
@Schema(description = "车牌颜色")
|
||||
private int plateColor;
|
||||
|
||||
/**
|
||||
* 车牌
|
||||
*/
|
||||
@Schema(description = "车牌")
|
||||
private String plateNo;
|
||||
|
||||
/**
|
||||
* 鉴权码
|
||||
*/
|
||||
@Schema(description = "鉴权码")
|
||||
private String authenticationCode;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
@Schema(description = "经度")
|
||||
private Double longitude;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
@Schema(description = "纬度")
|
||||
private Double latitude;
|
||||
|
||||
|
||||
|
||||
public int getProvinceId() {
|
||||
return provinceId;
|
||||
}
|
||||
@@ -95,4 +125,28 @@ public class JTDevice {
|
||||
public void setPlateNo(String plateNo) {
|
||||
this.plateNo = plateNo;
|
||||
}
|
||||
|
||||
public String getAuthenticationCode() {
|
||||
return authenticationCode;
|
||||
}
|
||||
|
||||
public void setAuthenticationCode(String authenticationCode) {
|
||||
this.authenticationCode = authenticationCode;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.genersoft.iot.vmp.jt1078.dao;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
@Mapper
|
||||
public interface JTDeviceMapper {
|
||||
|
||||
@Select("SELECT * FROM wvp_device de where device_id=${devId}")
|
||||
JTDevice getDevice(@Param("devId") String devId);
|
||||
|
||||
@Update(value = {" <script>" +
|
||||
"UPDATE wvp_jt_device " +
|
||||
"SET update_time=#{updateTime}" +
|
||||
"<if test=\"provinceId != null\">, province_id=#{provinceId}</if>" +
|
||||
"<if test=\"cityId != null\">, city_id=#{cityId}</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\">, authenticationCode=#{localIp}</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}"+
|
||||
" </script>"})
|
||||
void updateDevice(JTDevice device);
|
||||
}
|
||||
@@ -10,6 +10,6 @@ public class RegisterEventListener implements ApplicationListener<RegisterEvent>
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(RegisterEvent event) {
|
||||
System.out.println("收到设备注册: "+ event.getDeviceId());
|
||||
System.out.println("收到设备注册: "+ event.getDevice().getDeviceId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 终端注册
|
||||
@@ -82,11 +83,20 @@ public class J0100 extends Re {
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
// TODO 从数据库判断这个设备是否合法
|
||||
J8100 j8100 = new J8100();
|
||||
j8100.setRespNo(header.getSn());
|
||||
j8100.setResult(J8100.SUCCESS);
|
||||
j8100.setCode("WVP_YYDS");
|
||||
// 从数据库判断这个设备是否合法
|
||||
JTDevice deviceInDb = service.getDevice(header.getDevId());
|
||||
if (deviceInDb != null) {
|
||||
j8100.setResult(J8100.SUCCESS);
|
||||
String authenticationCode = UUID.randomUUID().toString();
|
||||
j8100.setCode(authenticationCode);
|
||||
deviceInDb.setAuthenticationCode(authenticationCode);
|
||||
service.updateDevice(deviceInDb);
|
||||
}else {
|
||||
j8100.setResult(J8100.FAIL);
|
||||
// TODO 断开连接,清理资源
|
||||
}
|
||||
return j8100;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,11 @@ public class J8100 extends Rs {
|
||||
* 0 成功
|
||||
* 1 车辆已被注册
|
||||
* 2 数据库中无该车辆
|
||||
* 2 终端已被注册
|
||||
* 2 数据库中无该终端
|
||||
* 3 终端已被注册
|
||||
* 4 数据库中无该终端
|
||||
*/
|
||||
public static final Integer SUCCESS = 0;
|
||||
public static final Integer FAIL = 4;
|
||||
|
||||
Integer respNo;
|
||||
Integer result;
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
package com.genersoft.iot.vmp.jt1078.service;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
|
||||
public interface Ijt1078Service {
|
||||
JTDevice getDevice(String devId);
|
||||
|
||||
void updateDevice(JTDevice deviceInDb);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
package com.genersoft.iot.vmp.jt1078.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.dao.JTDeviceMapper;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
|
||||
@Autowired
|
||||
private JTDeviceMapper jtDeviceMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public JTDevice getDevice(String devId) {
|
||||
return jtDeviceMapper.getDevice(devId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(JTDevice device) {
|
||||
jtDeviceMapper.updateDevice(device);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user