|
|
@@ -1,22 +1,19 @@
|
|
|
package com.zhongshu.iot.server.core.service.device;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-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;
|
|
|
-import com.zhongshu.iot.client.model.mqtt.*;
|
|
|
+import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
|
|
|
+import com.zhongshu.iot.client.model.mqtt.DeviceInfoRegistParam;
|
|
|
import com.zhongshu.iot.client.type.IotDataType;
|
|
|
import com.zhongshu.iot.server.core.dao.iot.IotTemplateDao;
|
|
|
import com.zhongshu.iot.server.core.dao.mqtt.*;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.IotTemplate;
|
|
|
import com.zhongshu.iot.server.core.domain.iot.mqtt.*;
|
|
|
import com.zhongshu.iot.server.core.httpRequest.ApiRequestService;
|
|
|
-import com.zhongshu.iot.server.core.httpRequest.conf.FullCardAPIConfig;
|
|
|
import com.zhongshu.iot.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
|
|
|
import com.zhongshu.iot.server.core.service.iot.IotThingService;
|
|
|
@@ -25,7 +22,6 @@ import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
import com.zhongshu.iot.server.core.util.JMXUtil;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
|
import com.zhongshu.iot.server.core.util.mqtt.MqttTopicUtils;
|
|
|
-import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
|
|
|
import lombok.Cleanup;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
|
|
|
@@ -33,8 +29,6 @@ import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.management.MBeanServerConnection;
|
|
|
@@ -53,14 +47,9 @@ import java.util.concurrent.CompletableFuture;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
+@Deprecated
|
|
|
public class GateWayInfoService extends SuperService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private GateWayInfoDao gateWayInfoDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private GateWay2UserDao gateWay2UserDao;
|
|
|
-
|
|
|
@Autowired
|
|
|
private DeviceInfoService deviceInfoService;
|
|
|
|
|
|
@@ -102,119 +91,123 @@ public class GateWayInfoService extends SuperService {
|
|
|
|
|
|
@Autowired
|
|
|
private IotTemplateDao iotTemplateDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IotThingService iotThingService;
|
|
|
|
|
|
- /**
|
|
|
- * 注册 网关
|
|
|
- *
|
|
|
- * @param dataStr
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent<Object> gateWayRegister(String dataId, String dataStr) {
|
|
|
- log.info("gateWayRegister: {}", dataId);
|
|
|
- CommonResult commonResult = new CommonResult();
|
|
|
- OperationMessage operationMessage = operationMessageDao.findTopByDataId(dataId);
|
|
|
- commonResult.setMessageId(dataId);
|
|
|
- if (ObjectUtils.isEmpty(operationMessage)) {
|
|
|
- commonResult.setFailed("数据不存在");
|
|
|
- return ResultContent.buildSuccess(commonResult);
|
|
|
- }
|
|
|
- ResultContent<GateWayUserInfo> resultContent = gateWayUserInfoService.verifyMqttUser(operationMessage.getTopic());
|
|
|
- if (resultContent.isFailed()) {
|
|
|
- commonResult.setFailed(resultContent.getMsg());
|
|
|
- return ResultContent.buildSuccess(commonResult);
|
|
|
- }
|
|
|
-
|
|
|
- GateWayInfoAddParam param = null;
|
|
|
- try {
|
|
|
- param = JSONUtil.toBean(dataStr, GateWayInfoAddParam.class);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage());
|
|
|
- commonResult.setFailed(resultContent.getMsg());
|
|
|
- return ResultContent.buildSuccess(commonResult);
|
|
|
- }
|
|
|
- GateWayUserInfo gateWayUserInfo = resultContent.getContent();
|
|
|
- param.setMqttUserName(gateWayUserInfo.getUserName());
|
|
|
-
|
|
|
- // 网关基本信息维护
|
|
|
- ResultContent<GateWayInfo> content = addGateWayInfo(param);
|
|
|
- if (content.isSuccess()) {
|
|
|
- } else {
|
|
|
- commonResult.setFailed(content.getMsg());
|
|
|
- return ResultContent.buildSuccess(commonResult);
|
|
|
- }
|
|
|
- commonResult.setSuccess("注册成功");
|
|
|
- return ResultContent.buildSuccess(commonResult);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加网关
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent<GateWayInfo> addGateWayInfo(GateWayInfoAddParam param) {
|
|
|
- if (StringUtils.isEmpty(param.getGateWayId())) {
|
|
|
- return ResultContent.buildFail("gateWayId不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(param.getGateWayName())) {
|
|
|
- return ResultContent.buildFail("gateWayName不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
|
- return ResultContent.buildFail("projectInfoCode不能为空");
|
|
|
- }
|
|
|
- if (param.getHbInterval() != null && param.getHbInterval() <= 0) {
|
|
|
- return ResultContent.buildFail("hbInterval不符合规范");
|
|
|
- }
|
|
|
- ResultContent checkIdContent = JMXUtil.checkDeviceIdLength(param.getGateWayId(), "gateWayId");
|
|
|
- if (checkIdContent.isFailed()) {
|
|
|
- return ResultContent.buildFail(checkIdContent.getMsg());
|
|
|
- }
|
|
|
- ResultContent checkNameContent = JMXUtil.checkDeviceNameLength(param.getGateWayName(), "gateWayName");
|
|
|
- if (checkNameContent.isFailed()) {
|
|
|
- return ResultContent.buildFail(checkNameContent.getMsg());
|
|
|
- }
|
|
|
-
|
|
|
- ProjectInfo projectInfo = null;
|
|
|
- if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
|
|
|
- projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
|
- }
|
|
|
- if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
- return ResultContent.buildFail("projectInfoCode不存在");
|
|
|
- }
|
|
|
- GateWayUserInfo gateWayUserInfo = gateWayUserInfoDao.findTopByUserName(param.getMqttUserName());
|
|
|
- if (StringUtils.isNotEmpty(gateWayUserInfo.getProjectCode()) && !gateWayUserInfo.getProjectCode().equals(param.getProjectInfoCode())) {
|
|
|
- return ResultContent.buildFail("projectInfoCode不匹配");
|
|
|
- }
|
|
|
-
|
|
|
- GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
|
|
|
- if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
- gateWayInfo = new GateWayInfo();
|
|
|
- gateWayInfo.setActivityTime(System.currentTimeMillis());
|
|
|
- gateWayInfo.setState(DeviceState.Enable);
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtils.copyProperties(param, gateWayInfo, "id");
|
|
|
- gateWayInfo.setOnLineState(OnLineState.OnLine);
|
|
|
- gateWayInfo.setLastOnlineTime(System.currentTimeMillis());
|
|
|
- if (ObjectUtils.isNotEmpty(projectInfo)) {
|
|
|
- gateWayInfo.setProjectInfo(projectInfo);
|
|
|
- }
|
|
|
-
|
|
|
- gateWayInfoDao.save(gateWayInfo);
|
|
|
-
|
|
|
- log.info("网关注册成功");
|
|
|
- // 通知同步 (网关信息)
|
|
|
- deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
|
|
|
-
|
|
|
- // 更新连接账号关联的设备数量
|
|
|
- gateWayUserInfoService.updateBindNumber(gateWayInfo.getMqttUserName());
|
|
|
-
|
|
|
- // 同步权限
|
|
|
- jmxSyncService.syncSecurityToMQTTService(gateWayInfo);
|
|
|
- return ResultContent.buildSuccess(gateWayInfo);
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoDao deviceInfoDao;
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 注册 网关
|
|
|
+// *
|
|
|
+// * @param dataStr
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent<Object> gateWayRegister(String dataId, String dataStr) {
|
|
|
+// log.info("gateWayRegister: {}", dataId);
|
|
|
+// CommonResult commonResult = new CommonResult();
|
|
|
+// OperationMessage operationMessage = operationMessageDao.findTopByDataId(dataId);
|
|
|
+// commonResult.setMessageId(dataId);
|
|
|
+// if (ObjectUtils.isEmpty(operationMessage)) {
|
|
|
+// commonResult.setFailed("数据不存在");
|
|
|
+// return ResultContent.buildSuccess(commonResult);
|
|
|
+// }
|
|
|
+// ResultContent<GateWayUserInfo> resultContent = gateWayUserInfoService.verifyMqttUser(operationMessage.getTopic());
|
|
|
+// if (resultContent.isFailed()) {
|
|
|
+// commonResult.setFailed(resultContent.getMsg());
|
|
|
+// return ResultContent.buildSuccess(commonResult);
|
|
|
+// }
|
|
|
+//
|
|
|
+// GateWayInfoAddParam param = null;
|
|
|
+// try {
|
|
|
+// param = JSONUtil.toBean(dataStr, GateWayInfoAddParam.class);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error(e.getMessage());
|
|
|
+// commonResult.setFailed(resultContent.getMsg());
|
|
|
+// return ResultContent.buildSuccess(commonResult);
|
|
|
+// }
|
|
|
+// GateWayUserInfo gateWayUserInfo = resultContent.getContent();
|
|
|
+// param.setMqttUserName(gateWayUserInfo.getUserName());
|
|
|
+//
|
|
|
+// // 网关基本信息维护
|
|
|
+// ResultContent<GateWayInfo> content = addGateWayInfo(param);
|
|
|
+// if (content.isSuccess()) {
|
|
|
+// } else {
|
|
|
+// commonResult.setFailed(content.getMsg());
|
|
|
+// return ResultContent.buildSuccess(commonResult);
|
|
|
+// }
|
|
|
+// commonResult.setSuccess("注册成功");
|
|
|
+// return ResultContent.buildSuccess(commonResult);
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 添加网关
|
|
|
+// *
|
|
|
+// * @param param
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent<GateWayInfo> addGateWayInfo(GateWayInfoAddParam param) {
|
|
|
+// if (StringUtils.isEmpty(param.getGateWayId())) {
|
|
|
+// return ResultContent.buildFail("gateWayId不能为空");
|
|
|
+// }
|
|
|
+// if (StringUtils.isEmpty(param.getGateWayName())) {
|
|
|
+// return ResultContent.buildFail("gateWayName不能为空");
|
|
|
+// }
|
|
|
+// if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
|
+// return ResultContent.buildFail("projectInfoCode不能为空");
|
|
|
+// }
|
|
|
+// if (param.getHbInterval() != null && param.getHbInterval() <= 0) {
|
|
|
+// return ResultContent.buildFail("hbInterval不符合规范");
|
|
|
+// }
|
|
|
+// ResultContent checkIdContent = JMXUtil.checkDeviceIdLength(param.getGateWayId(), "gateWayId");
|
|
|
+// if (checkIdContent.isFailed()) {
|
|
|
+// return ResultContent.buildFail(checkIdContent.getMsg());
|
|
|
+// }
|
|
|
+// ResultContent checkNameContent = JMXUtil.checkDeviceNameLength(param.getGateWayName(), "gateWayName");
|
|
|
+// if (checkNameContent.isFailed()) {
|
|
|
+// return ResultContent.buildFail(checkNameContent.getMsg());
|
|
|
+// }
|
|
|
+//
|
|
|
+// ProjectInfo projectInfo = null;
|
|
|
+// if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
|
|
|
+// projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
|
+// }
|
|
|
+// if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
+// return ResultContent.buildFail("projectInfoCode不存在");
|
|
|
+// }
|
|
|
+// GateWayUserInfo gateWayUserInfo = gateWayUserInfoDao.findTopByUserName(param.getMqttUserName());
|
|
|
+// if (StringUtils.isNotEmpty(gateWayUserInfo.getProjectCode()) && !gateWayUserInfo.getProjectCode().equals(param.getProjectInfoCode())) {
|
|
|
+// return ResultContent.buildFail("projectInfoCode不匹配");
|
|
|
+// }
|
|
|
+//
|
|
|
+// GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
|
|
|
+// if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
+// gateWayInfo = new GateWayInfo();
|
|
|
+// gateWayInfo.setActivityTime(System.currentTimeMillis());
|
|
|
+// gateWayInfo.setState(DeviceState.Enable);
|
|
|
+// }
|
|
|
+//
|
|
|
+// BeanUtils.copyProperties(param, gateWayInfo, "id");
|
|
|
+// gateWayInfo.setOnLineState(OnLineState.OnLine);
|
|
|
+// gateWayInfo.setLastOnlineTime(System.currentTimeMillis());
|
|
|
+// if (ObjectUtils.isNotEmpty(projectInfo)) {
|
|
|
+// gateWayInfo.setProjectInfo(projectInfo);
|
|
|
+// }
|
|
|
+//
|
|
|
+// gateWayInfoDao.save(gateWayInfo);
|
|
|
+//
|
|
|
+// log.info("网关注册成功");
|
|
|
+// // 通知同步 (网关信息)
|
|
|
+// deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
|
|
|
+//
|
|
|
+// // 更新连接账号关联的设备数量
|
|
|
+// gateWayUserInfoService.updateBindNumber(gateWayInfo.getMqttUserName());
|
|
|
+//
|
|
|
+// // 同步权限
|
|
|
+// jmxSyncService.syncSecurityToMQTTService(gateWayInfo);
|
|
|
+// return ResultContent.buildSuccess(gateWayInfo);
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 注册设备
|
|
|
@@ -308,9 +301,9 @@ public class GateWayInfoService extends SuperService {
|
|
|
}
|
|
|
|
|
|
RegistType registType = RegistType.Gateway;
|
|
|
- GateWayInfo gateWayInfo;
|
|
|
+ DeviceInfo gateWayInfo;
|
|
|
if (StringUtils.isNotEmpty(param.getGateWayId())) {
|
|
|
- gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
|
|
|
+ gateWayInfo = deviceInfoDao.findTopByDeviceId(param.getGateWayId());
|
|
|
if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
return ResultContent.buildFail("gateWayId数据不存在");
|
|
|
}
|
|
|
@@ -366,7 +359,7 @@ public class GateWayInfoService extends SuperService {
|
|
|
* @param gateWayInfo
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent deviceBindGateWay(DeviceInfo deviceInfo, GateWayInfo gateWayInfo) {
|
|
|
+ public ResultContent deviceBindGateWay(DeviceInfo deviceInfo, DeviceInfo gateWayInfo) {
|
|
|
if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
return ResultContent.buildFail("设备信息为空");
|
|
|
}
|
|
|
@@ -392,7 +385,7 @@ public class GateWayInfoService extends SuperService {
|
|
|
} else {
|
|
|
}
|
|
|
gateWay2Device.setGateWayInfo(gateWayInfo);
|
|
|
- gateWay2Device.setGateWayId(gateWayInfo != null ? gateWayInfo.getGateWayId() : "");
|
|
|
+ gateWay2Device.setGateWayId(gateWayInfo != null ? gateWayInfo.getDeviceId() : "");
|
|
|
gateWay2Device.setDeviceInfo(deviceInfo);
|
|
|
gateWay2Device.setDeviceId(deviceInfo.getDeviceId());
|
|
|
|
|
|
@@ -402,165 +395,165 @@ public class GateWayInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 注册网关
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Deprecated
|
|
|
- public ResultContent<MqttInfoReturnModel> registerGateWay(GateWayInfoAddParam param) {
|
|
|
- ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
|
- if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
- return ResultContent.buildFail(String.format("分组不存在:%s", param.getProjectInfoCode()));
|
|
|
- }
|
|
|
- // 添加网关信息
|
|
|
- ResultContent<GateWayInfo> gateWayInfo = addGateWayInfo(param);
|
|
|
-
|
|
|
- // 给网关分配个mqtt账号
|
|
|
- MqttInfoReturnModel mqttInfoSimpleModel = mqttInfoService.getCommonMqttInfo(gateWayInfo.getContent());
|
|
|
-
|
|
|
- // 通知下发项目配置信息
|
|
|
- ProjectConfigQueryParam queryParam = new ProjectConfigQueryParam();
|
|
|
- queryParam.setProjectInfoCode(param.getProjectInfoCode());
|
|
|
- APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.iotQueryProjectConfig, queryParam);
|
|
|
- if (api.isSuccess()) {
|
|
|
- log.info("查询项目配置成功");
|
|
|
- } else {
|
|
|
- log.error("查询项目配置失败:{}", api.getMsg());
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess(mqttInfoSimpleModel);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 网关绑定设备、连接账号
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent gateWayBindDevice(GateWayBindDeviceParam param) {
|
|
|
- // 网关信息
|
|
|
- GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
|
|
|
- if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
- log.error("网关未注册");
|
|
|
- return ResultContent.buildFail(String.format("网关未注册,清先注册网关:%s", param.getGateWayId()));
|
|
|
- }
|
|
|
-
|
|
|
- String projectInfoCode = param.getProjectInfoCode();
|
|
|
- if (ObjectUtils.isEmpty(projectInfoCode)) {
|
|
|
- projectInfoCode = gateWayInfo.getProjectInfoCode();
|
|
|
- }
|
|
|
-
|
|
|
- ProjectInfo projectInfo = projectInfoDao.findTopByCode(projectInfoCode);
|
|
|
- if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
- log.error("分组不存在");
|
|
|
- return ResultContent.buildFail(String.format("分组不存在:%s", projectInfoCode));
|
|
|
- }
|
|
|
-
|
|
|
- List<DeviceInfoAddParam> devices = param.getDevices();
|
|
|
- if (ObjectUtils.isNotEmpty(devices)) {
|
|
|
- // 检查设备数据合法性
|
|
|
- for (DeviceInfoAddParam device : devices) {
|
|
|
- if (StringUtils.isEmpty(device.getDeviceId())) {
|
|
|
- return ResultContent.buildFail("deviceId不能为空");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- GateWay2User gateWay2User = gateWay2UserDao.findTopByGateWayInfo(gateWayInfo);
|
|
|
- if (ObjectUtils.isEmpty(gateWay2User)) {
|
|
|
- return ResultContent.buildFail(String.format("网关为分配连接账户: %S", gateWay2User.getGateWayId()));
|
|
|
- }
|
|
|
-
|
|
|
- // 设备列表
|
|
|
- List<DeviceInfo> deviceInfos = new ArrayList<>();
|
|
|
- if (ObjectUtils.isNotEmpty(devices)) {
|
|
|
- // 绑定网关和设备的关系
|
|
|
- for (DeviceInfoAddParam device : devices) {
|
|
|
- device.setProjectInfoCode(projectInfoCode);
|
|
|
- // 保存设备信息
|
|
|
- ResultContent<DeviceInfo> resultContent = deviceInfoService.addDeviceInfo(device);
|
|
|
- DeviceInfo deviceInfo = resultContent.getContent();
|
|
|
-
|
|
|
- // 设备可以绑定到多个网关,一个网关只能绑定设备一次
|
|
|
- GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByGateWayInfoAndDeviceInfo(gateWayInfo, deviceInfo);
|
|
|
- if (ObjectUtils.isEmpty(gateWay2Device)) {
|
|
|
- gateWay2Device = new GateWay2Device();
|
|
|
- gateWay2Device.setState(OnLineState.OffLine);
|
|
|
- } else {
|
|
|
- }
|
|
|
- gateWay2Device.setGateWayInfo(gateWayInfo);
|
|
|
- gateWay2Device.setDeviceInfo(deviceInfo);
|
|
|
- gateWay2Device.setGateWayId(gateWayInfo.getGateWayId());
|
|
|
- gateWay2Device.setDeviceId(deviceInfo.getDeviceId());
|
|
|
-
|
|
|
- gateWay2Device.setBindTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
- gateWay2DeviceDao.save(gateWay2Device);
|
|
|
- deviceInfos.add(deviceInfo);
|
|
|
-
|
|
|
- iotService.updateAllDeviceIotMainGateWayInfo(deviceInfo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 更新网关的权限
|
|
|
- jmxSyncService.syncSecurityToMQTTService(gateWayInfo);
|
|
|
- log.info("设备注册成功:{}", deviceInfos.size());
|
|
|
-
|
|
|
- // 同步设备
|
|
|
- deviceSyncFullCardService.noticeSyncDevice(deviceInfos);
|
|
|
- return ResultContent.buildSuccess();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除网关
|
|
|
- *
|
|
|
- * @param gateWayId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent deleteGateWayInfo(String gateWayId) {
|
|
|
- GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
|
|
|
- if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
- return ResultContent.buildFail(String.format("网关ID不存在:%s", gateWayId));
|
|
|
- }
|
|
|
- gateWayInfoDao.delete(gateWayInfo);
|
|
|
- return ResultContent.buildSuccess();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 网关列表
|
|
|
- *
|
|
|
- * @param pageable
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent<Page<GateWayInfoModel>> pageGateWay(Pageable pageable, GateWayInfoSearchParam param) {
|
|
|
- Page<GateWayInfo> page = gateWayInfoDao.page(pageable, param);
|
|
|
- return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询网关详情
|
|
|
- *
|
|
|
- * @param gateWayId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent<GateWayInfoModel> getById(String gateWayId) {
|
|
|
- GateWayInfoModel model = null;
|
|
|
- GateWayInfo deviceInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
|
|
|
- if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
- model = toModel(deviceInfo);
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess(model);
|
|
|
- }
|
|
|
-
|
|
|
- public GateWayInfoModel toModel(GateWayInfo entity) {
|
|
|
- GateWayInfoModel model = new GateWayInfoModel();
|
|
|
- if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
- BeanUtils.copyProperties(entity, model);
|
|
|
- model.setProjectInfo(projectInfoService.toModel(entity.getProjectInfo()));
|
|
|
- }
|
|
|
- return model;
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 注册网关
|
|
|
+// *
|
|
|
+// * @param param
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// @Deprecated
|
|
|
+// public ResultContent<MqttInfoReturnModel> registerGateWay(GateWayInfoAddParam param) {
|
|
|
+// ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
|
+// if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
+// return ResultContent.buildFail(String.format("分组不存在:%s", param.getProjectInfoCode()));
|
|
|
+// }
|
|
|
+// // 添加网关信息
|
|
|
+// ResultContent<GateWayInfo> gateWayInfo = addGateWayInfo(param);
|
|
|
+//
|
|
|
+// // 给网关分配个mqtt账号
|
|
|
+// MqttInfoReturnModel mqttInfoSimpleModel = mqttInfoService.getCommonMqttInfo(gateWayInfo.getContent());
|
|
|
+//
|
|
|
+// // 通知下发项目配置信息
|
|
|
+// ProjectConfigQueryParam queryParam = new ProjectConfigQueryParam();
|
|
|
+// queryParam.setProjectInfoCode(param.getProjectInfoCode());
|
|
|
+// APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.iotQueryProjectConfig, queryParam);
|
|
|
+// if (api.isSuccess()) {
|
|
|
+// log.info("查询项目配置成功");
|
|
|
+// } else {
|
|
|
+// log.error("查询项目配置失败:{}", api.getMsg());
|
|
|
+// }
|
|
|
+// return ResultContent.buildSuccess(mqttInfoSimpleModel);
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 网关绑定设备、连接账号
|
|
|
+// *
|
|
|
+// * @param param
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent gateWayBindDevice(GateWayBindDeviceParam param) {
|
|
|
+// // 网关信息
|
|
|
+// GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
|
|
|
+// if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
+// log.error("网关未注册");
|
|
|
+// return ResultContent.buildFail(String.format("网关未注册,清先注册网关:%s", param.getGateWayId()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// String projectInfoCode = param.getProjectInfoCode();
|
|
|
+// if (ObjectUtils.isEmpty(projectInfoCode)) {
|
|
|
+// projectInfoCode = gateWayInfo.getProjectInfoCode();
|
|
|
+// }
|
|
|
+//
|
|
|
+// ProjectInfo projectInfo = projectInfoDao.findTopByCode(projectInfoCode);
|
|
|
+// if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
+// log.error("分组不存在");
|
|
|
+// return ResultContent.buildFail(String.format("分组不存在:%s", projectInfoCode));
|
|
|
+// }
|
|
|
+//
|
|
|
+// List<DeviceInfoAddParam> devices = param.getDevices();
|
|
|
+// if (ObjectUtils.isNotEmpty(devices)) {
|
|
|
+// // 检查设备数据合法性
|
|
|
+// for (DeviceInfoAddParam device : devices) {
|
|
|
+// if (StringUtils.isEmpty(device.getDeviceId())) {
|
|
|
+// return ResultContent.buildFail("deviceId不能为空");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// GateWay2User gateWay2User = gateWay2UserDao.findTopByGateWayInfo(gateWayInfo);
|
|
|
+// if (ObjectUtils.isEmpty(gateWay2User)) {
|
|
|
+// return ResultContent.buildFail(String.format("网关为分配连接账户: %S", gateWay2User.getGateWayId()));
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 设备列表
|
|
|
+// List<DeviceInfo> deviceInfos = new ArrayList<>();
|
|
|
+// if (ObjectUtils.isNotEmpty(devices)) {
|
|
|
+// // 绑定网关和设备的关系
|
|
|
+// for (DeviceInfoAddParam device : devices) {
|
|
|
+// device.setProjectInfoCode(projectInfoCode);
|
|
|
+// // 保存设备信息
|
|
|
+// ResultContent<DeviceInfo> resultContent = deviceInfoService.addDeviceInfo(device);
|
|
|
+// DeviceInfo deviceInfo = resultContent.getContent();
|
|
|
+//
|
|
|
+// // 设备可以绑定到多个网关,一个网关只能绑定设备一次
|
|
|
+// GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByGateWayInfoAndDeviceInfo(gateWayInfo, deviceInfo);
|
|
|
+// if (ObjectUtils.isEmpty(gateWay2Device)) {
|
|
|
+// gateWay2Device = new GateWay2Device();
|
|
|
+// gateWay2Device.setState(OnLineState.OffLine);
|
|
|
+// } else {
|
|
|
+// }
|
|
|
+// gateWay2Device.setGateWayInfo(gateWayInfo);
|
|
|
+// gateWay2Device.setDeviceInfo(deviceInfo);
|
|
|
+// gateWay2Device.setGateWayId(gateWayInfo.getGateWayId());
|
|
|
+// gateWay2Device.setDeviceId(deviceInfo.getDeviceId());
|
|
|
+//
|
|
|
+// gateWay2Device.setBindTimeStr(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
|
|
|
+// gateWay2DeviceDao.save(gateWay2Device);
|
|
|
+// deviceInfos.add(deviceInfo);
|
|
|
+//
|
|
|
+// iotService.updateAllDeviceIotMainGateWayInfo(deviceInfo);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 更新网关的权限
|
|
|
+// jmxSyncService.syncSecurityToMQTTService(gateWayInfo);
|
|
|
+// log.info("设备注册成功:{}", deviceInfos.size());
|
|
|
+//
|
|
|
+// // 同步设备
|
|
|
+// deviceSyncFullCardService.noticeSyncDevice(deviceInfos);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 删除网关
|
|
|
+// *
|
|
|
+// * @param gateWayId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent deleteGateWayInfo(String gateWayId) {
|
|
|
+// GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
|
|
|
+// if (ObjectUtils.isEmpty(gateWayInfo)) {
|
|
|
+// return ResultContent.buildFail(String.format("网关ID不存在:%s", gateWayId));
|
|
|
+// }
|
|
|
+// gateWayInfoDao.delete(gateWayInfo);
|
|
|
+// return ResultContent.buildSuccess();
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 网关列表
|
|
|
+// *
|
|
|
+// * @param pageable
|
|
|
+// * @param param
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent<Page<GateWayInfoModel>> pageGateWay(Pageable pageable, GateWayInfoSearchParam param) {
|
|
|
+// Page<GateWayInfo> page = gateWayInfoDao.page(pageable, param);
|
|
|
+// return ResultContent.buildSuccess(PageEntityUtil.toPageModel(page, this::toModel));
|
|
|
+// }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 查询网关详情
|
|
|
+// *
|
|
|
+// * @param gateWayId
|
|
|
+// * @return
|
|
|
+// */
|
|
|
+// public ResultContent<GateWayInfoModel> getById(String gateWayId) {
|
|
|
+// GateWayInfoModel model = null;
|
|
|
+// GateWayInfo deviceInfo = gateWayInfoDao.findTopByGateWayId(gateWayId);
|
|
|
+// if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
+// model = toModel(deviceInfo);
|
|
|
+// }
|
|
|
+// return ResultContent.buildSuccess(model);
|
|
|
+// }
|
|
|
+
|
|
|
+// public GateWayInfoModel toModel(GateWayInfo entity) {
|
|
|
+// GateWayInfoModel model = new GateWayInfoModel();
|
|
|
+// if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+// BeanUtils.copyProperties(entity, model);
|
|
|
+// model.setProjectInfo(projectInfoService.toModel(entity.getProjectInfo()));
|
|
|
+// }
|
|
|
+// return model;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 绑定角色网关的权限
|
|
|
@@ -637,7 +630,7 @@ public class GateWayInfoService extends SuperService {
|
|
|
* @param deviceInfo
|
|
|
* @return
|
|
|
*/
|
|
|
- public GateWayInfo getDeviceGateWayInfo(DeviceInfo deviceInfo) {
|
|
|
+ public DeviceInfo getDeviceGateWayInfo(DeviceInfo deviceInfo) {
|
|
|
if (ObjectUtils.isEmpty(deviceInfo)) {
|
|
|
return null;
|
|
|
}
|