|
@@ -4,20 +4,22 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.github.microservice.http.APIResponseModel;
|
|
import com.github.microservice.http.APIResponseModel;
|
|
|
import com.github.microservice.models.common.CommonResult;
|
|
import com.github.microservice.models.common.CommonResult;
|
|
|
import com.github.microservice.models.project.ProjectConfigQueryParam;
|
|
import com.github.microservice.models.project.ProjectConfigQueryParam;
|
|
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
import com.github.microservice.types.deviceUse.DeviceState;
|
|
import com.github.microservice.types.deviceUse.DeviceState;
|
|
|
-import com.github.microservice.types.deviceUse.DeviceType;
|
|
|
|
|
import com.github.microservice.types.deviceUse.OnLineState;
|
|
import com.github.microservice.types.deviceUse.OnLineState;
|
|
|
import com.github.microservice.types.deviceUse.RegistType;
|
|
import com.github.microservice.types.deviceUse.RegistType;
|
|
|
-import com.github.microservice.net.ResultContent;
|
|
|
|
|
import com.zhongshu.iot.client.model.mqtt.*;
|
|
import com.zhongshu.iot.client.model.mqtt.*;
|
|
|
|
|
+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.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.domain.iot.mqtt.*;
|
|
|
import com.zhongshu.iot.server.core.httpRequest.ApiRequestService;
|
|
import com.zhongshu.iot.server.core.httpRequest.ApiRequestService;
|
|
|
import com.zhongshu.iot.server.core.httpRequest.conf.FullCardAPIConfig;
|
|
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.base.SuperService;
|
|
|
import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
|
|
import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
|
|
|
|
|
+import com.zhongshu.iot.server.core.service.iot.IotThingService;
|
|
|
import com.zhongshu.iot.server.core.service.sync.DeviceSyncFullCardService;
|
|
import com.zhongshu.iot.server.core.service.sync.DeviceSyncFullCardService;
|
|
|
-import com.zhongshu.iot.server.core.util.CommonUtil;
|
|
|
|
|
import com.zhongshu.iot.server.core.util.DateUtils;
|
|
import com.zhongshu.iot.server.core.util.DateUtils;
|
|
|
import com.zhongshu.iot.server.core.util.JMXUtil;
|
|
import com.zhongshu.iot.server.core.util.JMXUtil;
|
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
import com.zhongshu.iot.server.core.util.bean.BeanUtils;
|
|
@@ -97,6 +99,11 @@ public class GateWayInfoService extends SuperService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private GateWayUserInfoDao gateWayUserInfoDao;
|
|
private GateWayUserInfoDao gateWayUserInfoDao;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotTemplateDao iotTemplateDao;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotThingService iotThingService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 注册 网关
|
|
* 注册 网关
|
|
|
*
|
|
*
|
|
@@ -168,7 +175,6 @@ public class GateWayInfoService extends SuperService {
|
|
|
return ResultContent.buildFail(checkNameContent.getMsg());
|
|
return ResultContent.buildFail(checkNameContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
ProjectInfo projectInfo = null;
|
|
ProjectInfo projectInfo = null;
|
|
|
if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
|
|
if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {
|
|
|
projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
@@ -196,6 +202,10 @@ public class GateWayInfoService extends SuperService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
gateWayInfoDao.save(gateWayInfo);
|
|
gateWayInfoDao.save(gateWayInfo);
|
|
|
|
|
+
|
|
|
|
|
+ // 初始网关关联的物模型
|
|
|
|
|
+ iotThingService.initAutoThingByGateWay(gateWayInfo);
|
|
|
|
|
+
|
|
|
log.info("网关注册成功");
|
|
log.info("网关注册成功");
|
|
|
// 通知同步 (网关信息)
|
|
// 通知同步 (网关信息)
|
|
|
deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
|
|
deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
|
|
@@ -261,15 +271,17 @@ public class GateWayInfoService extends SuperService {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public ResultContent<DeviceInfo> addDevice(DeviceInfoRegistParam param) {
|
|
public ResultContent<DeviceInfo> addDevice(DeviceInfoRegistParam param) {
|
|
|
|
|
+ // 产品code
|
|
|
|
|
+ if (StringUtils.isEmpty(param.getProductCode())) {
|
|
|
|
|
+ return ResultContent.buildFail("productCode不能为空");
|
|
|
|
|
+ }
|
|
|
if (StringUtils.isEmpty(param.getDeviceId())) {
|
|
if (StringUtils.isEmpty(param.getDeviceId())) {
|
|
|
return ResultContent.buildFail("deviceId不能为空");
|
|
return ResultContent.buildFail("deviceId不能为空");
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isEmpty(param.getDeviceName())) {
|
|
if (StringUtils.isEmpty(param.getDeviceName())) {
|
|
|
return ResultContent.buildFail("deviceName不能为空");
|
|
return ResultContent.buildFail("deviceName不能为空");
|
|
|
}
|
|
}
|
|
|
- if (StringUtils.isEmpty(param.getDeviceCate())) {
|
|
|
|
|
- return ResultContent.buildFail("deviceCate不能为空");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 分组code
|
|
|
if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
if (StringUtils.isEmpty(param.getProjectInfoCode())) {
|
|
|
return ResultContent.buildFail("projectInfoCode不能为空");
|
|
return ResultContent.buildFail("projectInfoCode不能为空");
|
|
|
}
|
|
}
|
|
@@ -282,6 +294,13 @@ public class GateWayInfoService extends SuperService {
|
|
|
return ResultContent.buildFail(checkNameContent.getMsg());
|
|
return ResultContent.buildFail(checkNameContent.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 检查产品是否存在
|
|
|
|
|
+ IotTemplate iotTemplate = iotTemplateDao.findTopByProductCodeAndIotDataType(param.getProductCode(), IotDataType.IotTemplate);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(iotTemplate)) {
|
|
|
|
|
+ return ResultContent.buildFail(String.format("productCode不存在", param.getProductCode()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 检查分组是否存在
|
|
|
ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
ProjectInfo projectInfo = projectInfoDao.findTopByCode(param.getProjectInfoCode());
|
|
|
if (ObjectUtils.isEmpty(projectInfo)) {
|
|
if (ObjectUtils.isEmpty(projectInfo)) {
|
|
|
return ResultContent.buildFail("projectInfoCode不存在");
|
|
return ResultContent.buildFail("projectInfoCode不存在");
|
|
@@ -309,15 +328,7 @@ public class GateWayInfoService extends SuperService {
|
|
|
DeviceInfoAddParam deviceInfoAddParam = new DeviceInfoAddParam();
|
|
DeviceInfoAddParam deviceInfoAddParam = new DeviceInfoAddParam();
|
|
|
BeanUtils.copyProperties(param, deviceInfoAddParam);
|
|
BeanUtils.copyProperties(param, deviceInfoAddParam);
|
|
|
deviceInfoAddParam.setRegistType(registType);
|
|
deviceInfoAddParam.setRegistType(registType);
|
|
|
- if (StringUtils.isNotEmpty(param.getDeviceCate())) {
|
|
|
|
|
- DeviceType deviceType = CommonUtil.getEnumByName(DeviceType.class, param.getDeviceCate());
|
|
|
|
|
- if (deviceType == null) {
|
|
|
|
|
- return ResultContent.buildFail("deviceCate不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (deviceType != null) {
|
|
|
|
|
- deviceInfoAddParam.setDeviceType(deviceType);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ deviceInfoAddParam.setDeviceCategory(iotTemplate.getDeviceCategory());
|
|
|
devices.add(deviceInfoAddParam);
|
|
devices.add(deviceInfoAddParam);
|
|
|
|
|
|
|
|
// 设备列表
|
|
// 设备列表
|
|
@@ -595,4 +606,17 @@ public class GateWayInfoService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 得到设备的网关信息
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceInfo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public GateWayInfo getDeviceGateWayInfo(DeviceInfo deviceInfo) {
|
|
|
|
|
+ GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(deviceInfo);
|
|
|
|
|
+ if (gateWay2Device == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return gateWay2Device.getGateWayInfo();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|