|
|
@@ -5,6 +5,7 @@ import com.github.microservice.http.APIResponseModel;
|
|
|
import com.github.microservice.models.common.CommonResult;
|
|
|
import com.github.microservice.models.project.ProjectConfigQueryParam;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.types.deviceUse.DeviceCategory;
|
|
|
import com.github.microservice.types.deviceUse.DeviceState;
|
|
|
import com.github.microservice.types.deviceUse.OnLineState;
|
|
|
import com.github.microservice.types.deviceUse.RegistType;
|
|
|
@@ -231,6 +232,7 @@ public class GateWayInfoService extends SuperService {
|
|
|
commonResult.setFailed("数据不存在");
|
|
|
return ResultContent.buildSuccess(commonResult);
|
|
|
}
|
|
|
+ // 找到连接账号的信息
|
|
|
ResultContent<GateWayUserInfo> resultContent = gateWayUserInfoService.verifyMqttUser(operationMessage.getTopic());
|
|
|
if (resultContent.isFailed()) {
|
|
|
commonResult.setFailed(resultContent.getMsg());
|
|
|
@@ -272,9 +274,11 @@ public class GateWayInfoService extends SuperService {
|
|
|
if (StringUtils.isEmpty(param.getProductCode())) {
|
|
|
return ResultContent.buildFail("productCode不能为空");
|
|
|
}
|
|
|
+ // 设备deviceId
|
|
|
if (StringUtils.isEmpty(param.getDeviceId())) {
|
|
|
return ResultContent.buildFail("deviceId不能为空");
|
|
|
}
|
|
|
+ // 设备名称
|
|
|
if (StringUtils.isEmpty(param.getDeviceName())) {
|
|
|
return ResultContent.buildFail("deviceName不能为空");
|
|
|
}
|
|
|
@@ -324,8 +328,11 @@ public class GateWayInfoService extends SuperService {
|
|
|
List<DeviceInfoAddParam> devices = new ArrayList<>();
|
|
|
DeviceInfoAddParam deviceInfoAddParam = new DeviceInfoAddParam();
|
|
|
BeanUtils.copyProperties(param, deviceInfoAddParam);
|
|
|
+
|
|
|
deviceInfoAddParam.setRegistType(registType);
|
|
|
deviceInfoAddParam.setDeviceCategory(iotTemplate.getDeviceCategory());
|
|
|
+ deviceInfoAddParam.setDeviceType(iotTemplate.getDeviceType());
|
|
|
+ deviceInfoAddParam.setSpecType(iotTemplate.getSpecType());
|
|
|
devices.add(deviceInfoAddParam);
|
|
|
|
|
|
// 设备列表
|
|
|
@@ -336,30 +343,8 @@ public class GateWayInfoService extends SuperService {
|
|
|
// 保存设备信息
|
|
|
ResultContent<DeviceInfo> resultContent = deviceInfoService.addDeviceInfo(device);
|
|
|
DeviceInfo deviceInfo = resultContent.getContent();
|
|
|
-
|
|
|
- if (registType == RegistType.DirectConnection) {
|
|
|
- // 直连
|
|
|
- List<GateWay2Device> _list = gateWay2DeviceDao.findByDeviceInfo(deviceInfo);
|
|
|
- gateWay2DeviceDao.deleteAll(_list);
|
|
|
- } else if (registType == RegistType.Gateway) {
|
|
|
- // 网关注册
|
|
|
- // 设备可以绑定到多个网关,一个网关只能绑定设备一次
|
|
|
- GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
|
|
|
- if (ObjectUtils.isEmpty(gateWay2Device)) {
|
|
|
- gateWay2Device = new GateWay2Device();
|
|
|
- gateWay2Device.setState(OnLineState.OnLine);
|
|
|
- } else {
|
|
|
- }
|
|
|
- gateWay2Device.setGateWayInfo(gateWayInfo);
|
|
|
- gateWay2Device.setGateWayId(gateWayInfo.getGateWayId());
|
|
|
- gateWay2Device.setDeviceInfo(deviceInfo);
|
|
|
- gateWay2Device.setDeviceId(deviceInfo.getDeviceId());
|
|
|
-
|
|
|
- gateWay2Device.setBindTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
- gateWay2DeviceDao.save(gateWay2Device);
|
|
|
- }
|
|
|
+ deviceBindGateWay(deviceInfo, gateWayInfo);
|
|
|
deviceInfos.add(deviceInfo);
|
|
|
-
|
|
|
// 更新设备的topic
|
|
|
iotService.updateAllDeviceIotMainGateWayInfo(deviceInfo);
|
|
|
}
|
|
|
@@ -374,6 +359,49 @@ public class GateWayInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备绑定 网关
|
|
|
+ *
|
|
|
+ * @param deviceInfo
|
|
|
+ * @param gateWayInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent deviceBindGateWay(DeviceInfo deviceInfo, GateWayInfo gateWayInfo) {
|
|
|
+ if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
+ return ResultContent.buildFail("设备信息为空");
|
|
|
+ }
|
|
|
+ // 如果设备时网关
|
|
|
+ if (deviceInfo.getDeviceCategory() == DeviceCategory.GW) {
|
|
|
+ List<GateWay2Device> _list = gateWay2DeviceDao.findByDeviceInfo(deviceInfo);
|
|
|
+ gateWay2DeviceDao.deleteAll(_list);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ RegistType _registType = deviceInfo.getRegistType();
|
|
|
+ if (_registType == RegistType.DirectConnection) {
|
|
|
+ // 直连
|
|
|
+ List<GateWay2Device> _list = gateWay2DeviceDao.findByDeviceInfo(deviceInfo);
|
|
|
+ gateWay2DeviceDao.deleteAll(_list);
|
|
|
+ } else if (_registType == RegistType.Gateway) {
|
|
|
+ // 网关注册
|
|
|
+ // 设备可以绑定到多个网关,一个网关只能绑定设备一次
|
|
|
+ GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
|
|
|
+ if (ObjectUtils.isEmpty(gateWay2Device)) {
|
|
|
+ gateWay2Device = new GateWay2Device();
|
|
|
+ gateWay2Device.setState(OnLineState.OnLine);
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ gateWay2Device.setGateWayInfo(gateWayInfo);
|
|
|
+ gateWay2Device.setGateWayId(gateWayInfo.getGateWayId());
|
|
|
+ gateWay2Device.setDeviceInfo(deviceInfo);
|
|
|
+ gateWay2Device.setDeviceId(deviceInfo.getDeviceId());
|
|
|
+
|
|
|
+ gateWay2Device.setBindTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
+ gateWay2DeviceDao.save(gateWay2Device);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 注册网关
|
|
|
*
|