mirror of
https://gitee.com/pnoker/iot-dc3.git
synced 2026-11-02 19:21:51 +08:00
feat: 驱动注册逻辑更新
This commit is contained in:
+4
-3
@@ -25,6 +25,7 @@ import io.github.pnoker.common.constant.common.RequestConstant;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.constant.service.ManagerServiceConstant;
|
||||
import io.github.pnoker.common.entity.R;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.valid.Insert;
|
||||
import io.github.pnoker.common.valid.Update;
|
||||
@@ -71,7 +72,7 @@ public class DeviceController {
|
||||
Device add = deviceService.add(device);
|
||||
if (ObjectUtil.isNotNull(add)) {
|
||||
// 通知驱动新增设备
|
||||
notifyService.notifyDriverDevice(MetadataConstant.Device.ADD, add);
|
||||
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.ADD, add);
|
||||
return R.ok(add);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -92,7 +93,7 @@ public class DeviceController {
|
||||
Device device = deviceService.selectById(id);
|
||||
if (ObjectUtil.isNotNull(device) && deviceService.delete(id)) {
|
||||
// 通知驱动删除设备
|
||||
notifyService.notifyDriverDevice(MetadataConstant.Device.DELETE, device);
|
||||
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.DELETE, device);
|
||||
return R.ok();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -115,7 +116,7 @@ public class DeviceController {
|
||||
Device update = deviceService.update(device);
|
||||
if (ObjectUtil.isNotNull(update)) {
|
||||
// 通知驱动更新设备
|
||||
notifyService.notifyDriverDevice(MetadataConstant.Device.UPDATE, update);
|
||||
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.UPDATE, update);
|
||||
return R.ok(update);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+4
-3
@@ -24,6 +24,7 @@ import io.github.pnoker.center.manager.service.NotifyService;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.constant.service.ManagerServiceConstant;
|
||||
import io.github.pnoker.common.entity.R;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.model.DriverInfo;
|
||||
import io.github.pnoker.common.valid.Insert;
|
||||
import io.github.pnoker.common.valid.Update;
|
||||
@@ -63,7 +64,7 @@ public class DriverInfoController {
|
||||
try {
|
||||
DriverInfo add = driverInfoService.add(driverInfo);
|
||||
if (ObjectUtil.isNotNull(add)) {
|
||||
notifyService.notifyDriverDriverInfo(MetadataConstant.DriverInfo.ADD, add);
|
||||
notifyService.notifyDriverDriverInfo(MetadataCommandTypeEnum.ADD, add);
|
||||
return R.ok(add);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -83,7 +84,7 @@ public class DriverInfoController {
|
||||
try {
|
||||
DriverInfo driverInfo = driverInfoService.selectById(id);
|
||||
if (ObjectUtil.isNotNull(driverInfo) && driverInfoService.delete(id)) {
|
||||
notifyService.notifyDriverDriverInfo(MetadataConstant.DriverInfo.DELETE, driverInfo);
|
||||
notifyService.notifyDriverDriverInfo(MetadataCommandTypeEnum.DELETE, driverInfo);
|
||||
return R.ok();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -103,7 +104,7 @@ public class DriverInfoController {
|
||||
try {
|
||||
DriverInfo update = driverInfoService.update(driverInfo);
|
||||
if (ObjectUtil.isNotNull(update)) {
|
||||
notifyService.notifyDriverDriverInfo(MetadataConstant.DriverInfo.UPDATE, update);
|
||||
notifyService.notifyDriverDriverInfo(MetadataCommandTypeEnum.UPDATE, update);
|
||||
return R.ok(update);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+4
-3
@@ -26,6 +26,7 @@ import io.github.pnoker.common.constant.common.RequestConstant;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.constant.service.ManagerServiceConstant;
|
||||
import io.github.pnoker.common.entity.R;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.enums.UnitEnum;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.valid.Insert;
|
||||
@@ -73,7 +74,7 @@ public class PointController {
|
||||
point.setTenantId(tenantId);
|
||||
Point add = pointService.add(point);
|
||||
if (ObjectUtil.isNotNull(add)) {
|
||||
notifyService.notifyDriverPoint(MetadataConstant.Point.ADD, add);
|
||||
notifyService.notifyDriverPoint(MetadataCommandTypeEnum.ADD, add);
|
||||
return R.ok(add);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -93,7 +94,7 @@ public class PointController {
|
||||
try {
|
||||
Point point = pointService.selectById(id);
|
||||
if (ObjectUtil.isNotNull(point) && pointService.delete(id)) {
|
||||
notifyService.notifyDriverPoint(MetadataConstant.Point.DELETE, point);
|
||||
notifyService.notifyDriverPoint(MetadataCommandTypeEnum.DELETE, point);
|
||||
return R.ok();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -116,7 +117,7 @@ public class PointController {
|
||||
point.setTenantId(tenantId);
|
||||
Point update = pointService.update(point);
|
||||
if (ObjectUtil.isNotNull(update)) {
|
||||
notifyService.notifyDriverPoint(MetadataConstant.Point.UPDATE, update);
|
||||
notifyService.notifyDriverPoint(MetadataCommandTypeEnum.UPDATE, update);
|
||||
return R.ok(update);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+4
-3
@@ -24,6 +24,7 @@ import io.github.pnoker.center.manager.service.PointInfoService;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.constant.service.ManagerServiceConstant;
|
||||
import io.github.pnoker.common.entity.R;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.model.PointInfo;
|
||||
import io.github.pnoker.common.valid.Insert;
|
||||
import io.github.pnoker.common.valid.Update;
|
||||
@@ -63,7 +64,7 @@ public class PointInfoController {
|
||||
try {
|
||||
PointInfo add = pointInfoService.add(pointInfo);
|
||||
if (ObjectUtil.isNotNull(add)) {
|
||||
notifyService.notifyDriverPointInfo(MetadataConstant.PointInfo.ADD, add);
|
||||
notifyService.notifyDriverPointInfo(MetadataCommandTypeEnum.ADD, add);
|
||||
return R.ok(add);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -83,7 +84,7 @@ public class PointInfoController {
|
||||
try {
|
||||
PointInfo pointInfo = pointInfoService.selectById(id);
|
||||
if (ObjectUtil.isNotNull(pointInfo) && pointInfoService.delete(id)) {
|
||||
notifyService.notifyDriverPointInfo(MetadataConstant.PointInfo.DELETE, pointInfo);
|
||||
notifyService.notifyDriverPointInfo(MetadataCommandTypeEnum.DELETE, pointInfo);
|
||||
return R.ok();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -103,7 +104,7 @@ public class PointInfoController {
|
||||
try {
|
||||
PointInfo update = pointInfoService.update(pointInfo);
|
||||
if (ObjectUtil.isNotNull(update)) {
|
||||
notifyService.notifyDriverPointInfo(MetadataConstant.PointInfo.UPDATE, update);
|
||||
notifyService.notifyDriverPointInfo(MetadataCommandTypeEnum.UPDATE, update);
|
||||
return R.ok(update);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ import io.github.pnoker.center.manager.entity.query.ProfilePageQuery;
|
||||
import io.github.pnoker.center.manager.service.NotifyService;
|
||||
import io.github.pnoker.center.manager.service.ProfileService;
|
||||
import io.github.pnoker.common.constant.common.RequestConstant;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.constant.service.ManagerServiceConstant;
|
||||
import io.github.pnoker.common.entity.R;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.model.Profile;
|
||||
import io.github.pnoker.common.valid.Insert;
|
||||
import io.github.pnoker.common.valid.Update;
|
||||
@@ -90,7 +90,7 @@ public class ProfileController {
|
||||
try {
|
||||
Profile profile = profileService.selectById(id);
|
||||
if (ObjectUtil.isNotNull(profile) && profileService.delete(id)) {
|
||||
notifyService.notifyDriverProfile(MetadataConstant.Profile.DELETE, profile);
|
||||
notifyService.notifyDriverProfile(MetadataCommandTypeEnum.DELETE, profile);
|
||||
return R.ok();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -113,7 +113,7 @@ public class ProfileController {
|
||||
profile.setTenantId(tenantId);
|
||||
Profile update = profileService.update(profile);
|
||||
if (ObjectUtil.isNotNull(update)) {
|
||||
notifyService.notifyDriverProfile(MetadataConstant.Profile.UPDATE, update);
|
||||
notifyService.notifyDriverProfile(MetadataCommandTypeEnum.UPDATE, update);
|
||||
return R.ok(update);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+13
-6
@@ -16,20 +16,27 @@
|
||||
|
||||
package io.github.pnoker.center.manager.service;
|
||||
|
||||
import io.github.pnoker.common.entity.driver.DriverRegister;
|
||||
import io.github.pnoker.common.dto.DriverEventDTO;
|
||||
|
||||
/**
|
||||
* Driver Sdk Interface
|
||||
* 驱动事件相关接口
|
||||
*
|
||||
* @author pnoker
|
||||
* @since 2022.1.0
|
||||
*/
|
||||
public interface DriverSdkService {
|
||||
public interface DriverEventService {
|
||||
|
||||
/**
|
||||
* 驱动注册
|
||||
* 驱动注册事件
|
||||
*
|
||||
* @param driverRegister DriverRegister
|
||||
* @param entityDTO DriverEventDTO
|
||||
*/
|
||||
void register(DriverRegister driverRegister);
|
||||
void registerEvent(DriverEventDTO entityDTO);
|
||||
|
||||
/**
|
||||
* 驱动心跳事件
|
||||
*
|
||||
* @param entityDTO DriverEventDTO
|
||||
*/
|
||||
void heartbeatEvent(DriverEventDTO entityDTO);
|
||||
}
|
||||
+6
-5
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.github.pnoker.center.manager.service;
|
||||
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.model.*;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ public interface NotifyService {
|
||||
* @param command Operation Type
|
||||
* @param profile Profile
|
||||
*/
|
||||
void notifyDriverProfile(String command, Profile profile);
|
||||
void notifyDriverProfile(MetadataCommandTypeEnum command, Profile profile);
|
||||
|
||||
/**
|
||||
* 通知驱动 新增位号(ADD) / 删除位号(DELETE) / 修改位号(UPDATE)
|
||||
@@ -40,7 +41,7 @@ public interface NotifyService {
|
||||
* @param command Operation Type
|
||||
* @param point Point
|
||||
*/
|
||||
void notifyDriverPoint(String command, Point point);
|
||||
void notifyDriverPoint(MetadataCommandTypeEnum command, Point point);
|
||||
|
||||
/**
|
||||
* 通知驱动 新增设备(ADD) / 删除设备(DELETE) / 修改设备(UPDATE)
|
||||
@@ -48,7 +49,7 @@ public interface NotifyService {
|
||||
* @param command Operation Type
|
||||
* @param device Device
|
||||
*/
|
||||
void notifyDriverDevice(String command, Device device);
|
||||
void notifyDriverDevice(MetadataCommandTypeEnum command, Device device);
|
||||
|
||||
/**
|
||||
* 通知驱动 新增驱动配置(ADD) / 删除驱动配置(DELETE) / 更新驱动配置(UPDATE)
|
||||
@@ -56,7 +57,7 @@ public interface NotifyService {
|
||||
* @param command Operation Type
|
||||
* @param driverInfo Driver Info
|
||||
*/
|
||||
void notifyDriverDriverInfo(String command, DriverInfo driverInfo);
|
||||
void notifyDriverDriverInfo(MetadataCommandTypeEnum command, DriverInfo driverInfo);
|
||||
|
||||
/**
|
||||
* 通知驱动 新增位号配置(ADD) / 删除位号配置(DELETE) / 更新位号配置(UPDATE)
|
||||
@@ -64,6 +65,6 @@ public interface NotifyService {
|
||||
* @param command Operation Type
|
||||
* @param pointInfo PointInfo
|
||||
*/
|
||||
void notifyDriverPointInfo(String command, PointInfo pointInfo);
|
||||
void notifyDriverPointInfo(MetadataCommandTypeEnum command, PointInfo pointInfo);
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -18,8 +18,8 @@ package io.github.pnoker.center.manager.service.impl;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import io.github.pnoker.center.manager.service.*;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.entity.point.PointDetail;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.enums.ProfileShareFlagEnum;
|
||||
import io.github.pnoker.common.enums.ProfileTypeFlagEnum;
|
||||
import io.github.pnoker.common.exception.DuplicateException;
|
||||
@@ -69,7 +69,7 @@ public class AutoServiceImpl implements AutoService {
|
||||
device = deviceService.add(device);
|
||||
|
||||
// 通知驱动新增设备
|
||||
notifyService.notifyDriverDevice(MetadataConstant.Device.ADD, device);
|
||||
notifyService.notifyDriverDevice(MetadataCommandTypeEnum.ADD, device);
|
||||
} catch (DuplicateException duplicateException) {
|
||||
device = deviceService.selectByName(deviceName, tenantId);
|
||||
} catch (Exception ignored) {
|
||||
@@ -111,7 +111,7 @@ public class AutoServiceImpl implements AutoService {
|
||||
point = pointService.add(point);
|
||||
|
||||
// 同时驱动新增位号
|
||||
notifyService.notifyDriverPoint(MetadataConstant.Point.ADD, point);
|
||||
notifyService.notifyDriverPoint(MetadataCommandTypeEnum.ADD, point);
|
||||
} catch (DuplicateException duplicateException) {
|
||||
point = pointService.selectByNameAndProfileId(pointName, profile.getId());
|
||||
} catch (Exception ignored) {
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import io.github.pnoker.center.manager.mapper.DeviceMapper;
|
||||
import io.github.pnoker.center.manager.service.*;
|
||||
import io.github.pnoker.common.constant.driver.MetadataConstant;
|
||||
import io.github.pnoker.common.entity.common.Pages;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.exception.DuplicateException;
|
||||
import io.github.pnoker.common.exception.NotFoundException;
|
||||
import io.github.pnoker.common.exception.ServiceException;
|
||||
@@ -240,7 +241,7 @@ public class DeviceServiceImpl implements DeviceService {
|
||||
|
||||
List<Point> points = pointService.selectByProfileId(profileId);
|
||||
// 通知驱动新增位号
|
||||
points.forEach(point -> notifyService.notifyDriverPoint(MetadataConstant.Point.ADD, point));
|
||||
points.forEach(point -> notifyService.notifyDriverPoint(MetadataCommandTypeEnum.ADD, point));
|
||||
} catch (Exception ignored) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
+54
-11
@@ -21,15 +21,26 @@ import io.github.pnoker.api.center.auth.CodeQuery;
|
||||
import io.github.pnoker.api.center.auth.RTenantDTO;
|
||||
import io.github.pnoker.api.center.auth.TenantApiGrpc;
|
||||
import io.github.pnoker.center.manager.service.*;
|
||||
import io.github.pnoker.common.constant.common.PrefixConstant;
|
||||
import io.github.pnoker.common.constant.driver.RabbitConstant;
|
||||
import io.github.pnoker.common.constant.service.AuthServiceConstant;
|
||||
import io.github.pnoker.common.dto.DriverEventDTO;
|
||||
import io.github.pnoker.common.dto.DriverMetadataDTO;
|
||||
import io.github.pnoker.common.dto.DriverStatusDTO;
|
||||
import io.github.pnoker.common.entity.driver.DriverMetadata;
|
||||
import io.github.pnoker.common.entity.driver.DriverRegister;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.exception.NotFoundException;
|
||||
import io.github.pnoker.common.exception.ServiceException;
|
||||
import io.github.pnoker.common.model.Driver;
|
||||
import io.github.pnoker.common.model.DriverAttribute;
|
||||
import io.github.pnoker.common.model.PointAttribute;
|
||||
import io.github.pnoker.common.utils.JsonUtil;
|
||||
import io.github.pnoker.common.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.devh.boot.grpc.client.inject.GrpcClient;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -45,11 +56,14 @@ import java.util.Map;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DriverSdkServiceImpl implements DriverSdkService {
|
||||
public class DriverEventServiceImpl implements DriverEventService {
|
||||
|
||||
@GrpcClient(AuthServiceConstant.SERVICE_NAME)
|
||||
private TenantApiGrpc.TenantApiBlockingStub tenantApiBlockingStub;
|
||||
|
||||
@Resource
|
||||
private BatchService batchService;
|
||||
|
||||
@Resource
|
||||
private DriverService driverService;
|
||||
@Resource
|
||||
@@ -61,19 +75,48 @@ public class DriverSdkServiceImpl implements DriverSdkService {
|
||||
@Resource
|
||||
private PointInfoService pointInfoService;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public void register(DriverRegister driverRegister) {
|
||||
// register driver
|
||||
Driver driver = registerDriver(driverRegister);
|
||||
public void registerEvent(DriverEventDTO entityDTO) {
|
||||
DriverRegister driverRegister = JsonUtil.parseObject(entityDTO.getContent(), DriverRegister.class);
|
||||
if (ObjectUtil.isNull(driverRegister) || ObjectUtil.isNull(driverRegister.getDriver())) {
|
||||
return;
|
||||
}
|
||||
|
||||
//register driver attribute
|
||||
registerDriverAttribute(driverRegister, driver);
|
||||
DriverMetadataDTO driverConfiguration = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.DRIVER,
|
||||
MetadataCommandTypeEnum.SYNC,
|
||||
null
|
||||
);
|
||||
|
||||
// register point attribute
|
||||
registerPointAttribute(driverRegister, driver);
|
||||
try {
|
||||
Driver driver = registerDriver(driverRegister);
|
||||
registerDriverAttribute(driverRegister, driver);
|
||||
registerPointAttribute(driverRegister, driver);
|
||||
DriverMetadata driverMetadata = batchService.batchDriverMetadata(driverRegister.getDriver().getServiceName());
|
||||
driverConfiguration.setContent(JsonUtil.toJsonString(driverMetadata));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
rabbitTemplate.convertAndSend(
|
||||
RabbitConstant.TOPIC_EXCHANGE_METADATA,
|
||||
RabbitConstant.ROUTING_DRIVER_METADATA_PREFIX + driverRegister.getDriver().getServiceName(),
|
||||
driverConfiguration
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heartbeatEvent(DriverEventDTO entityDTO) {
|
||||
DriverStatusDTO driverStatusDTO = JsonUtil.parseObject(entityDTO.getContent(), DriverStatusDTO.class);
|
||||
if (ObjectUtil.isNull(driverStatusDTO)) {
|
||||
return;
|
||||
}
|
||||
redisUtil.setKey(PrefixConstant.DRIVER_STATUS_KEY_PREFIX + driverStatusDTO.getServiceName(), driverStatusDTO.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
+44
-37
@@ -18,10 +18,12 @@ package io.github.pnoker.center.manager.service.impl;
|
||||
|
||||
import io.github.pnoker.center.manager.service.DriverService;
|
||||
import io.github.pnoker.center.manager.service.NotifyService;
|
||||
import io.github.pnoker.common.constant.common.PrefixConstant;
|
||||
import io.github.pnoker.common.constant.driver.RabbitConstant;
|
||||
import io.github.pnoker.common.entity.driver.DriverConfiguration;
|
||||
import io.github.pnoker.common.dto.DriverMetadataDTO;
|
||||
import io.github.pnoker.common.enums.MetadataCommandTypeEnum;
|
||||
import io.github.pnoker.common.enums.MetadataTypeEnum;
|
||||
import io.github.pnoker.common.model.*;
|
||||
import io.github.pnoker.common.utils.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -49,15 +51,16 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void notifyDriverProfile(String command, Profile profile) {
|
||||
public void notifyDriverProfile(MetadataCommandTypeEnum command, Profile profile) {
|
||||
try {
|
||||
List<Driver> drivers = driverService.selectByProfileId(profile.getId());
|
||||
drivers.forEach(driver -> {
|
||||
DriverConfiguration operation = new DriverConfiguration();
|
||||
operation.setType(PrefixConstant.PROFILE);
|
||||
operation.setCommand(command);
|
||||
operation.setContent(profile);
|
||||
notifyDriver(driver, operation);
|
||||
DriverMetadataDTO entityDTO = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.PROFILE,
|
||||
command,
|
||||
JsonUtil.toJsonString(profile)
|
||||
);
|
||||
notifyDriver(driver, entityDTO);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.warn("Notify driver {} profile error: {}", command, e.getMessage());
|
||||
@@ -68,15 +71,16 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void notifyDriverPoint(String command, Point point) {
|
||||
public void notifyDriverPoint(MetadataCommandTypeEnum command, Point point) {
|
||||
try {
|
||||
List<Driver> drivers = driverService.selectByProfileId(point.getProfileId());
|
||||
drivers.forEach(driver -> {
|
||||
DriverConfiguration operation = new DriverConfiguration();
|
||||
operation.setType(PrefixConstant.POINT);
|
||||
operation.setCommand(command);
|
||||
operation.setContent(point);
|
||||
notifyDriver(driver, operation);
|
||||
DriverMetadataDTO entityDTO = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.POINT,
|
||||
command,
|
||||
JsonUtil.toJsonString(point)
|
||||
);
|
||||
notifyDriver(driver, entityDTO);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("Notify driver {} point: {}", command, e.getMessage());
|
||||
@@ -87,14 +91,15 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void notifyDriverDevice(String command, Device device) {
|
||||
public void notifyDriverDevice(MetadataCommandTypeEnum command, Device device) {
|
||||
try {
|
||||
Driver driver = driverService.selectById(device.getDriverId());
|
||||
DriverConfiguration operation = new DriverConfiguration();
|
||||
operation.setType(PrefixConstant.DEVICE);
|
||||
operation.setCommand(command);
|
||||
operation.setContent(device);
|
||||
notifyDriver(driver, operation);
|
||||
DriverMetadataDTO entityDTO = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.DEVICE,
|
||||
command,
|
||||
JsonUtil.toJsonString(device)
|
||||
);
|
||||
notifyDriver(driver, entityDTO);
|
||||
} catch (Exception e) {
|
||||
log.error("Notify driver {} device: {}", command, e.getMessage());
|
||||
}
|
||||
@@ -104,14 +109,15 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void notifyDriverDriverInfo(String command, DriverInfo driverInfo) {
|
||||
public void notifyDriverDriverInfo(MetadataCommandTypeEnum command, DriverInfo driverInfo) {
|
||||
try {
|
||||
Driver driver = driverService.selectByDeviceId(driverInfo.getDeviceId());
|
||||
DriverConfiguration operation = new DriverConfiguration();
|
||||
operation.setType(PrefixConstant.DRIVER_INFO);
|
||||
operation.setCommand(command);
|
||||
operation.setContent(driverInfo);
|
||||
notifyDriver(driver, operation);
|
||||
DriverMetadataDTO entityDTO = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.DRIVER_INFO,
|
||||
command,
|
||||
JsonUtil.toJsonString(driverInfo)
|
||||
);
|
||||
notifyDriver(driver, entityDTO);
|
||||
} catch (Exception e) {
|
||||
log.error("Notify driver {} driverInfo: {}", command, e.getMessage());
|
||||
}
|
||||
@@ -121,14 +127,15 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void notifyDriverPointInfo(String command, PointInfo pointInfo) {
|
||||
public void notifyDriverPointInfo(MetadataCommandTypeEnum command, PointInfo pointInfo) {
|
||||
try {
|
||||
Driver driver = driverService.selectByDeviceId(pointInfo.getDeviceId());
|
||||
DriverConfiguration operation = new DriverConfiguration();
|
||||
operation.setType(PrefixConstant.POINT_INFO);
|
||||
operation.setCommand(command);
|
||||
operation.setContent(pointInfo);
|
||||
notifyDriver(driver, operation);
|
||||
DriverMetadataDTO entityDTO = new DriverMetadataDTO(
|
||||
MetadataTypeEnum.POINT_INFO,
|
||||
command,
|
||||
JsonUtil.toJsonString(pointInfo)
|
||||
);
|
||||
notifyDriver(driver, entityDTO);
|
||||
} catch (Exception e) {
|
||||
log.error("Notify driver {} pointInfo: {}", command, e.getMessage());
|
||||
}
|
||||
@@ -137,12 +144,12 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
/**
|
||||
* notify driver
|
||||
*
|
||||
* @param driver Driver
|
||||
* @param driverConfiguration DriverConfiguration
|
||||
* @param driver Driver
|
||||
* @param entityDTO DriverMetadataDTO
|
||||
*/
|
||||
private void notifyDriver(Driver driver, DriverConfiguration driverConfiguration) {
|
||||
log.info("Notify driver[{}] : {}", driver.getServiceName(), driverConfiguration);
|
||||
rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE_METADATA, RabbitConstant.ROUTING_DRIVER_METADATA_PREFIX + driver.getServiceName(), driverConfiguration);
|
||||
private void notifyDriver(Driver driver, DriverMetadataDTO entityDTO) {
|
||||
log.info("Notify driver[{}]: {}", driver.getServiceName(), entityDTO);
|
||||
rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE_METADATA, RabbitConstant.ROUTING_DRIVER_METADATA_PREFIX + driver.getServiceName(), entityDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -25,7 +25,7 @@ import io.github.pnoker.center.manager.service.DriverService;
|
||||
import io.github.pnoker.center.manager.service.ProfileBindService;
|
||||
import io.github.pnoker.center.manager.service.StatusService;
|
||||
import io.github.pnoker.common.constant.common.PrefixConstant;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Driver;
|
||||
import io.github.pnoker.common.utils.RedisUtil;
|
||||
@@ -60,7 +60,7 @@ public class StatusServiceImpl implements StatusService {
|
||||
public String driver(String serviceName) {
|
||||
String key = PrefixConstant.DRIVER_STATUS_KEY_PREFIX + serviceName;
|
||||
String status = redisUtil.getKey(key);
|
||||
status = ObjectUtil.isNotNull(status) ? status : StatusEnum.OFFLINE.getCode();
|
||||
status = ObjectUtil.isNotNull(status) ? status : DriverStatusEnum.OFFLINE.getCode();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class StatusServiceImpl implements StatusService {
|
||||
page.getRecords().forEach(driver -> {
|
||||
String key = PrefixConstant.DRIVER_STATUS_KEY_PREFIX + driver.getServiceName();
|
||||
String status = redisUtil.getKey(key);
|
||||
status = ObjectUtil.isNotNull(status) ? status : StatusEnum.OFFLINE.getCode();
|
||||
status = ObjectUtil.isNotNull(status) ? status : DriverStatusEnum.OFFLINE.getCode();
|
||||
statusMap.put(driver.getId(), status);
|
||||
});
|
||||
return statusMap;
|
||||
@@ -82,7 +82,7 @@ public class StatusServiceImpl implements StatusService {
|
||||
public String device(String id) {
|
||||
String key = PrefixConstant.DEVICE_STATUS_KEY_PREFIX + id;
|
||||
String status = redisUtil.getKey(key);
|
||||
status = ObjectUtil.isNotNull(status) ? status : StatusEnum.OFFLINE.getCode();
|
||||
status = ObjectUtil.isNotNull(status) ? status : DriverStatusEnum.OFFLINE.getCode();
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class StatusServiceImpl implements StatusService {
|
||||
page.getRecords().forEach(device -> {
|
||||
String key = PrefixConstant.DEVICE_STATUS_KEY_PREFIX + device.getId();
|
||||
String status = redisUtil.getKey(key);
|
||||
status = ObjectUtil.isNotNull(status) ? status : StatusEnum.OFFLINE.getCode();
|
||||
status = ObjectUtil.isNotNull(status) ? status : DriverStatusEnum.OFFLINE.getCode();
|
||||
statusMap.put(device.getId(), status);
|
||||
});
|
||||
return statusMap;
|
||||
@@ -107,7 +107,7 @@ public class StatusServiceImpl implements StatusService {
|
||||
profileBindService.selectDeviceIdsByProfileId(profileId).forEach(id -> {
|
||||
String key = PrefixConstant.DEVICE_STATUS_KEY_PREFIX + id;
|
||||
String status = redisUtil.getKey(key);
|
||||
status = ObjectUtil.isNotNull(status) ? status : StatusEnum.OFFLINE.getCode();
|
||||
status = ObjectUtil.isNotNull(status) ? status : DriverStatusEnum.OFFLINE.getCode();
|
||||
statusMap.put(id, status);
|
||||
});
|
||||
return statusMap;
|
||||
|
||||
+19
-73
@@ -16,25 +16,16 @@
|
||||
|
||||
package io.github.pnoker.center.manager.service.rabbit;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import io.github.pnoker.center.manager.service.BatchService;
|
||||
import io.github.pnoker.center.manager.service.DriverSdkService;
|
||||
import io.github.pnoker.common.constant.common.PrefixConstant;
|
||||
import io.github.pnoker.common.constant.driver.EventConstant;
|
||||
import io.github.pnoker.common.constant.driver.RabbitConstant;
|
||||
import io.github.pnoker.common.entity.DriverEvent;
|
||||
import io.github.pnoker.common.entity.driver.DriverConfiguration;
|
||||
import io.github.pnoker.common.entity.driver.DriverRegister;
|
||||
import io.github.pnoker.common.utils.RedisUtil;
|
||||
import io.github.pnoker.center.manager.service.DriverEventService;
|
||||
import io.github.pnoker.common.dto.DriverEventDTO;
|
||||
import io.github.pnoker.common.utils.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageProperties;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -52,81 +43,36 @@ import java.io.IOException;
|
||||
public class DriverEventReceiver {
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private BatchService batchService;
|
||||
@Resource
|
||||
private DriverSdkService driverSdkService;
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
private DriverEventService driverEventService;
|
||||
|
||||
@RabbitHandler
|
||||
@RabbitListener(queues = "#{driverEventQueue.name}")
|
||||
public void driverEventReceive(Channel channel, Message message, DriverEvent driverEvent) {
|
||||
public void driverEventReceive(Channel channel, Message message, DriverEventDTO entityDTO) {
|
||||
try {
|
||||
MessageProperties properties = message.getMessageProperties();
|
||||
channel.basicAck(properties.getDeliveryTag(), true);
|
||||
if (ObjectUtil.isNull(driverEvent) || CharSequenceUtil.isEmpty(driverEvent.getServiceName())) {
|
||||
log.error("Invalid driver event {}", driverEvent);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
|
||||
log.debug("Receive driver event: {}", JsonUtil.toPrettyJsonString(entityDTO));
|
||||
if (ObjectUtil.isNull(entityDTO)
|
||||
|| ObjectUtil.isNull(entityDTO.getEventType())
|
||||
|| CharSequenceUtil.isEmpty(entityDTO.getContent())) {
|
||||
log.error("Invalid driver event: {}", entityDTO);
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Driver {} event, From: {}, Received: {}", driverEvent.getType(), message.getMessageProperties().getReceivedRoutingKey(), driverEvent);
|
||||
|
||||
switch (driverEvent.getType()) {
|
||||
case EventConstant.Driver.REGISTER:
|
||||
registerEvent(driverEvent);
|
||||
switch (entityDTO.getEventType()) {
|
||||
case REGISTER:
|
||||
driverEventService.registerEvent(entityDTO);
|
||||
break;
|
||||
case EventConstant.Driver.STATUS:
|
||||
statusEvent(driverEvent);
|
||||
case HEARTBEAT:
|
||||
driverEventService.heartbeatEvent(entityDTO);
|
||||
break;
|
||||
case ALARM:
|
||||
//statusEvent(entityDTO);
|
||||
break;
|
||||
default:
|
||||
log.error("Invalid event type, {}", driverEvent.getType());
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理注册事件
|
||||
*
|
||||
* @param driverEvent DriverEvent
|
||||
*/
|
||||
private void registerEvent(DriverEvent driverEvent) {
|
||||
DriverConfiguration driverConfiguration = new DriverConfiguration(
|
||||
PrefixConstant.DRIVER,
|
||||
EventConstant.Driver.REGISTER_BACK,
|
||||
null
|
||||
);
|
||||
|
||||
try {
|
||||
driverSdkService.register(Convert.convert(DriverRegister.class, driverEvent.getContent()));
|
||||
driverConfiguration.setContent(batchService.batchDriverMetadata(driverEvent.getServiceName()));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
rabbitTemplate.convertAndSend(
|
||||
RabbitConstant.TOPIC_EXCHANGE_METADATA,
|
||||
RabbitConstant.ROUTING_DRIVER_METADATA_PREFIX + driverEvent.getServiceName(),
|
||||
driverConfiguration
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理状态事件
|
||||
*
|
||||
* @param driverEvent DriverEvent
|
||||
*/
|
||||
private void statusEvent(DriverEvent driverEvent) {
|
||||
redisUtil.setKey(
|
||||
PrefixConstant.DRIVER_STATUS_KEY_PREFIX + driverEvent.getServiceName(),
|
||||
driverEvent.getContent(),
|
||||
driverEvent.getTimeOut(),
|
||||
driverEvent.getTimeUnit()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -18,10 +18,10 @@ package io.github.pnoker.driver.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.sdk.bean.driver.DriverContext;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
import io.github.pnoker.common.sdk.service.DriverCustomService;
|
||||
import io.github.pnoker.common.sdk.service.DriverService;
|
||||
import io.github.pnoker.common.utils.DecodeUtil;
|
||||
@@ -86,7 +86,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.github.pnoker.driver.service.netty;
|
||||
|
||||
import io.github.pnoker.common.sdk.bean.driver.DriverContext;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
import io.github.pnoker.common.sdk.service.DriverService;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
|
||||
@@ -30,24 +30,6 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Integration Stream -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Integration Mqtt -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-mqtt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Tls Cert 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk16</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- DC3 Common Mqtt -->
|
||||
<dependency>
|
||||
<groupId>io.github.pnoker</groupId>
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package io.github.pnoker.driver.service.impl;
|
||||
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
@@ -69,7 +69,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ package io.github.pnoker.driver.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
@@ -86,7 +86,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.github.pnoker.driver.server;
|
||||
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
import io.github.pnoker.common.sdk.service.DriverService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -220,7 +220,7 @@ public class Lwm2mServer {
|
||||
@Override
|
||||
public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObservations) {
|
||||
log.debug("new device {} registered", registration.getEndpoint());
|
||||
driverService.deviceStatusSender(registration.getEndpoint(), StatusEnum.ONLINE);
|
||||
driverService.deviceStatusSender(registration.getEndpoint(), DriverStatusEnum.ONLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,7 +232,7 @@ public class Lwm2mServer {
|
||||
@Override
|
||||
public void updated(RegistrationUpdate registrationUpdate, Registration updatedRegistration, Registration registration1) {
|
||||
log.debug("device is still here:{}", updatedRegistration.getEndpoint());
|
||||
driverService.deviceStatusSender(updatedRegistration.getEndpoint(), StatusEnum.ONLINE);
|
||||
driverService.deviceStatusSender(updatedRegistration.getEndpoint(), DriverStatusEnum.ONLINE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,7 +245,7 @@ public class Lwm2mServer {
|
||||
@Override
|
||||
public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
|
||||
log.debug("device left: " + registration.getEndpoint());
|
||||
driverService.deviceStatusSender(registration.getEndpoint(), StatusEnum.OFFLINE);
|
||||
driverService.deviceStatusSender(registration.getEndpoint(), DriverStatusEnum.OFFLINE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import com.serotonin.modbus4j.msg.WriteCoilRequest;
|
||||
import com.serotonin.modbus4j.msg.WriteCoilResponse;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import io.github.pnoker.common.exception.ReadPointException;
|
||||
import io.github.pnoker.common.exception.WritePointException;
|
||||
@@ -93,7 +93,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,20 +30,10 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Integration Stream -->
|
||||
<!-- DC3 Common Mqtt -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-stream</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Integration Mqtt -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-mqtt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<groupId>io.github.pnoker</groupId>
|
||||
<artifactId>dc3-common-mqtt</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import io.github.pnoker.common.constant.common.SymbolConstant;
|
||||
import io.github.pnoker.common.sdk.config.property.MqttProperties;
|
||||
import io.github.pnoker.common.mqtt.property.MqttProperties;
|
||||
import io.github.pnoker.common.sdk.utils.X509Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
|
||||
+4
-4
@@ -18,10 +18,10 @@ package io.github.pnoker.driver.mqtt.handler;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MessageHeader;
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MessagePayload;
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MessageType;
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MqttMessage;
|
||||
import io.github.pnoker.common.mqtt.bean.MessageHeader;
|
||||
import io.github.pnoker.common.mqtt.bean.MessagePayload;
|
||||
import io.github.pnoker.common.mqtt.bean.MessageType;
|
||||
import io.github.pnoker.common.mqtt.bean.MqttMessage;
|
||||
import io.github.pnoker.common.utils.JsonUtil;
|
||||
import io.github.pnoker.driver.mqtt.job.MqttScheduleJob;
|
||||
import io.github.pnoker.driver.mqtt.service.MqttReceiveService;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.github.pnoker.driver.mqtt.job;
|
||||
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MqttMessage;
|
||||
import io.github.pnoker.common.mqtt.bean.MqttMessage;
|
||||
import io.github.pnoker.driver.mqtt.service.MqttReceiveService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
+3
-1
@@ -16,7 +16,9 @@
|
||||
|
||||
package io.github.pnoker.driver.mqtt.service;
|
||||
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MqttMessage;
|
||||
|
||||
|
||||
import io.github.pnoker.common.mqtt.bean.MqttMessage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.github.pnoker.driver.mqtt.service.impl;
|
||||
|
||||
import io.github.pnoker.common.sdk.bean.mqtt.MqttMessage;
|
||||
import io.github.pnoker.common.mqtt.bean.MqttMessage;
|
||||
import io.github.pnoker.driver.mqtt.service.MqttReceiveService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package io.github.pnoker.driver.service.impl;
|
||||
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
@@ -89,7 +89,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.driver.service.impl;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import io.github.pnoker.common.exception.ReadPointException;
|
||||
import io.github.pnoker.common.exception.WritePointException;
|
||||
@@ -88,7 +88,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.driver.service.impl;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.exception.ConnectorException;
|
||||
import io.github.pnoker.common.exception.ReadPointException;
|
||||
import io.github.pnoker.common.exception.WritePointException;
|
||||
@@ -85,7 +85,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package io.github.pnoker.driver.service.impl;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.exception.ServiceException;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
@@ -129,7 +129,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, StatusEnum.ONLINE));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceStatusSender(id, DriverStatusEnum.ONLINE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import io.github.pnoker.common.constant.driver.EventConstant;
|
||||
import io.github.pnoker.common.entity.DeviceEvent;
|
||||
import io.github.pnoker.common.entity.driver.AttributeInfo;
|
||||
import io.github.pnoker.common.enums.PointTypeFlagEnum;
|
||||
import io.github.pnoker.common.enums.StatusEnum;
|
||||
import io.github.pnoker.common.enums.DriverStatusEnum;
|
||||
import io.github.pnoker.common.model.Device;
|
||||
import io.github.pnoker.common.model.Point;
|
||||
import io.github.pnoker.common.sdk.bean.DriverContext;
|
||||
@@ -82,7 +82,7 @@ public class DriverCustomServiceImpl implements DriverCustomService {
|
||||
MAINTAIN:维护
|
||||
FAULT:故障
|
||||
*/
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceEventSender(new DeviceEvent(id, EventConstant.Device.STATUS, StatusEnum.ONLINE, 25, TimeUnit.SECONDS)));
|
||||
driverContext.getDriverMetadata().getDeviceMap().keySet().forEach(id -> driverService.deviceEventSender(new DeviceEvent(id, EventConstant.Device.STATUS, DriverStatusEnum.ONLINE, 25, TimeUnit.SECONDS)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -123,12 +123,6 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.pnoker</groupId>
|
||||
<artifactId>dc3-api-driver</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user