|
|
@@ -216,8 +216,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
//判断传入的version是0或者为空
|
|
|
if (version == 0 || StrUtil.isBlank(String.valueOf(version))) {
|
|
|
processVersionZero(paramJson, json);
|
|
|
- }
|
|
|
- else if (version == 1) {
|
|
|
+ } else if (version == 1) {
|
|
|
//网络类型
|
|
|
Integer networkCode = paramJson.getIntValue("networkType");
|
|
|
NetworkType network = NetworkType.NetworkTypeName(networkCode);
|
|
|
@@ -225,7 +224,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String userId = paramJson.getString("userId");//1000
|
|
|
//查询userId是否存在
|
|
|
User userIdCode = userMapper.selectByCode(userId);
|
|
|
- if ( userIdCode == null || StrUtil.isBlank(userIdCode.getCode())) {
|
|
|
+ if (userIdCode == null || StrUtil.isBlank(userIdCode.getCode())) {
|
|
|
return buildErrorResponse(NExcCode.ERROR_USERID, json);
|
|
|
}
|
|
|
//产品编号
|
|
|
@@ -240,6 +239,9 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
String deviceName = paramJson.getString("deviceId");
|
|
|
//SIM卡号
|
|
|
String sim = paramJson.getString("sim");
|
|
|
+ //通信模块mac(这是传给你的字段,然后插入到数据库中)
|
|
|
+ String netMac = paramJson.getString("netMac");
|
|
|
+
|
|
|
//通过查询获取到参数
|
|
|
String id = userIdCode.getId();
|
|
|
//查找用户id
|
|
|
@@ -273,11 +275,12 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
return buildErrorResponse(NExcCode.ERROR_PLATFORM_NULL, json);
|
|
|
}
|
|
|
//添加修改设备
|
|
|
- handleDevice(deviceName, sim, productId, id);
|
|
|
+ handleDevice(platform, deviceName, netMac, sim, productId, id);
|
|
|
+
|
|
|
//通过平台进行设备注册
|
|
|
switch (platform) {
|
|
|
case 1:
|
|
|
- handleAliYunRegistration(json, version, network, userId, productId, protocol, deviceName, platform, productKey);
|
|
|
+ handleAliYunRegistration(json, version, network, userId, productId, protocol, deviceName, platform, productKey);//走的阿里云
|
|
|
break;
|
|
|
case 2:
|
|
|
return buildErrorResponse(NExcCode.ERROR_PLATFORM_TYPE, json);
|
|
|
@@ -291,6 +294,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
return json.toString();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//处理版本1的local设备注册
|
|
|
private void handleLocalRegistration(JSONObject json, JSONObject paramJson, NetworkType network, String userId, String productId, NetworkProtocol protocol, String deviceName, String wifi, String deviceSecret, String remoteAddress, int remotePort) {
|
|
|
//WiFi注册
|
|
|
@@ -334,6 +338,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
json.put("productKey", productKey);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//处理版本0的设备注册
|
|
|
private void processVersionZero(JSONObject paramJson, JSONObject json) {
|
|
|
String deviceName = paramJson.getString("deviceId"); //device表中的mac
|
|
|
@@ -350,32 +355,32 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
json.put("deviceSecret", registData.getString("DeviceSecret"));
|
|
|
json.put("productKey", registData.getString("ProductKey"));
|
|
|
}
|
|
|
-
|
|
|
- Device device = deviceMapper.selectByMac(deviceName);
|
|
|
- if(device != null) {
|
|
|
- device.setSim(sim);
|
|
|
- if(StringUtils.isEmpty(userCode)) {
|
|
|
- User user = userMapper.selectByCode(userCode);
|
|
|
- if(user != null) {
|
|
|
- device.setTenantId(user.getId());
|
|
|
- }
|
|
|
- deviceMapper.updateByPrimaryKeySelective2(device);
|
|
|
+
|
|
|
+ Device device = deviceMapper.selectByMac(deviceName);
|
|
|
+ if (device != null) {
|
|
|
+ device.setSim(sim);
|
|
|
+ if (StringUtils.isEmpty(userCode)) {
|
|
|
+ User user = userMapper.selectByCode(userCode);
|
|
|
+ if (user != null) {
|
|
|
+ device.setTenantId(user.getId());
|
|
|
+ }
|
|
|
+ deviceMapper.updateByPrimaryKeySelective2(device);
|
|
|
}
|
|
|
- }else {
|
|
|
- device = new Device();
|
|
|
- device.setId(UUIDUtil.get32UUID());
|
|
|
- device.setMac(deviceName);
|
|
|
- device.setSim(sim);
|
|
|
- device.setCreatetime(new Date());
|
|
|
- if(StringUtils.isEmpty(userCode)) {
|
|
|
- User user = userMapper.selectByCode(userCode);
|
|
|
- if(user != null) {
|
|
|
- device.setTenantId(user.getId());
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ device = new Device();
|
|
|
+ device.setId(UUIDUtil.get32UUID());
|
|
|
+ device.setMac(deviceName);
|
|
|
+ device.setSim(sim);
|
|
|
+ device.setCreatetime(new Date());
|
|
|
+ if (StringUtils.isEmpty(userCode)) {
|
|
|
+ User user = userMapper.selectByCode(userCode);
|
|
|
+ if (user != null) {
|
|
|
+ device.setTenantId(user.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- deviceMapper.insertSelective(device);
|
|
|
+ deviceMapper.insertSelective(device);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//截取deviceId
|
|
|
@@ -389,21 +394,29 @@ class MyServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Wifi泵新增修改设备信息
|
|
|
+ private void handleWifiDevice(String deviceName, String netMac, String sim, String productId, String id) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//新增修改设备信息
|
|
|
- private void handleDevice(String deviceName, String sim, String productId, String id) {
|
|
|
+ private void handleDevice(Integer platform, String deviceName, String netMac, String sim, String productId, String id) {
|
|
|
//查询数据库是否存在该设备
|
|
|
Device deviceMac = deviceMapper.selectByMac(deviceName);
|
|
|
if (deviceMac == null) {
|
|
|
- //不存在,则新增设备
|
|
|
- //添加操作
|
|
|
- Device NewDevice = new Device();
|
|
|
- NewDevice.setId(UUIDUtil.get32UUID());
|
|
|
- NewDevice.setMac(deviceName);
|
|
|
- NewDevice.setSim(sim);
|
|
|
- NewDevice.setProductId(productId);
|
|
|
- NewDevice.setCreatetime(new Date());
|
|
|
- NewDevice.setTenantId(id);
|
|
|
- deviceMapper.insertSelective(NewDevice);
|
|
|
+ Device newDevice = new Device();
|
|
|
+ newDevice.setId(UUIDUtil.get32UUID());
|
|
|
+ newDevice.setMac(deviceName);
|
|
|
+ newDevice.setSim(sim);
|
|
|
+ newDevice.setProductId(productId);
|
|
|
+ newDevice.setCreatetime(new Date());
|
|
|
+ newDevice.setTenantId(id);
|
|
|
+
|
|
|
+ if (platform != 1) {
|
|
|
+ newDevice.setNetMac(netMac);
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceMapper.insertSelective(newDevice);
|
|
|
} else {
|
|
|
//如果存在,检查productId是否一致
|
|
|
boolean needUpdate = false;
|