|
|
@@ -2,7 +2,9 @@ package com.zswl.dataservice.service.mqtt;
|
|
|
|
|
|
import com.zswl.dataservice.dao.mqtt.DeviceInfoDao;
|
|
|
import com.zswl.dataservice.dao.mqtt.GateWayInfoDao;
|
|
|
+import com.zswl.dataservice.domain.mqtt.DeviceInfo;
|
|
|
import com.zswl.dataservice.domain.mqtt.GateWayInfo;
|
|
|
+import com.zswl.dataservice.event.DeviceSyncEvent;
|
|
|
import com.zswl.dataservice.event.GateWaySyncEvent;
|
|
|
import com.zswl.dataservice.httpRequest.ApiRequestService;
|
|
|
import com.zswl.dataservice.service.base.SuperService;
|
|
|
@@ -17,7 +19,10 @@ import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 物联网平台 设备 网关同步到全卡项目
|
|
|
@@ -44,17 +49,71 @@ public class DeviceSyncFullCardService extends SuperService {
|
|
|
@Autowired
|
|
|
ApplicationContext applicationContext;
|
|
|
|
|
|
- public ResultContent syncDevices() {
|
|
|
+ /**
|
|
|
+ * 通知同步设备
|
|
|
+ *
|
|
|
+ * @param deviceInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent noticeSyncDevice(DeviceInfo deviceInfo) {
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfo)) {
|
|
|
+ List<String> deviceIds = new ArrayList<>();
|
|
|
+ deviceIds.add(deviceInfo.getDeviceId());
|
|
|
+ DeviceSyncEvent event = new DeviceSyncEvent(this, deviceIds);
|
|
|
+ applicationContext.publishEvent(event);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 通知同步设备
|
|
|
+ *
|
|
|
+ * @param deviceInfos
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent noticeSyncDevice(List<DeviceInfo> deviceInfos) {
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceInfos)) {
|
|
|
+ List<String> deviceIds = deviceInfos.stream().map(it -> it.getDeviceId()).collect(Collectors.toList());
|
|
|
+ DeviceSyncEvent event = new DeviceSyncEvent(this, deviceIds);
|
|
|
+ applicationContext.publishEvent(event);
|
|
|
+ }
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 通知同步设备
|
|
|
+ * @param deviceIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent noticeSyncDeviceIds(List<String> deviceIds) {
|
|
|
+ if (ObjectUtils.isNotEmpty(deviceIds)) {
|
|
|
+ DeviceSyncEvent event = new DeviceSyncEvent(this, deviceIds);
|
|
|
+ applicationContext.publishEvent(event);
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 接收到同步设备的事件
|
|
|
+ *
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+ @EventListener(classes = DeviceSyncEvent.class)
|
|
|
+ @Async
|
|
|
+ @SneakyThrows
|
|
|
+ public void syncDeviceInfo(DeviceSyncEvent event) {
|
|
|
+ List<String> deviceIds = event.getDeviceIds();
|
|
|
+ log.info("event syncDeviceInfo: {}", deviceIds);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通知同步网关信息
|
|
|
+ *
|
|
|
* @param gateWayInfo
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent noticeSyncGateWay(GateWayInfo gateWayInfo){
|
|
|
+ public ResultContent noticeSyncGateWay(GateWayInfo gateWayInfo) {
|
|
|
if (ObjectUtils.isNotEmpty(gateWayInfo)) {
|
|
|
GateWaySyncEvent event = new GateWaySyncEvent(this, gateWayInfo.getGateWayId());
|
|
|
applicationContext.publishEvent(event);
|
|
|
@@ -65,14 +124,14 @@ public class DeviceSyncFullCardService extends SuperService {
|
|
|
/**
|
|
|
* 同步网关信息
|
|
|
*
|
|
|
- * @param testEvent
|
|
|
+ * @param event
|
|
|
*/
|
|
|
@EventListener(classes = GateWaySyncEvent.class)
|
|
|
@Async
|
|
|
@SneakyThrows
|
|
|
- public void syncGateWayInfo(GateWaySyncEvent testEvent) {
|
|
|
- String gatewayId = testEvent.getGateWayId();
|
|
|
- log.info("syncGateWayInfo: {}", gatewayId);
|
|
|
+ public void syncGateWayInfo(GateWaySyncEvent event) {
|
|
|
+ String gatewayId = event.getGateWayId();
|
|
|
+ log.info("event syncGateWayInfo: {}", gatewayId);
|
|
|
|
|
|
}
|
|
|
}
|