| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- 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;
- import com.zswl.dataservice.utils.result.ResultContent;
- import lombok.SneakyThrows;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.ObjectUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.ApplicationContext;
- 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.stream.Collectors;
- /**
- * 物联网平台 设备 网关同步到全卡项目
- *
- * @author TRX
- * @date 2024/6/26
- */
- @Slf4j
- @Service
- public class DeviceSyncFullCardService extends SuperService {
- @Autowired
- DeviceInfoDao deviceInfoDao;
- @Autowired
- GateWayInfoDao gateWayInfoDao;
- @Autowired
- OperationLogsService operationLogsService;
- @Autowired
- ApiRequestService apiRequestService;
- @Autowired
- ApplicationContext applicationContext;
- /**
- * 通知同步设备
- *
- * @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) {
- if (ObjectUtils.isNotEmpty(gateWayInfo)) {
- GateWaySyncEvent event = new GateWaySyncEvent(this, gateWayInfo.getGateWayId());
- applicationContext.publishEvent(event);
- }
- return ResultContent.buildSuccess();
- }
- /**
- * 同步网关信息
- *
- * @param event
- */
- @EventListener(classes = GateWaySyncEvent.class)
- @Async
- @SneakyThrows
- public void syncGateWayInfo(GateWaySyncEvent event) {
- String gatewayId = event.getGateWayId();
- log.info("event syncGateWayInfo: {}", gatewayId);
- }
- }
|