|
@@ -0,0 +1,45 @@
|
|
|
+package org.jetlinks.pro.cqfire.listener;
|
|
|
+
|
|
|
+
|
|
|
+import org.hswebframework.web.crud.events.EntityBeforeModifyEvent;
|
|
|
+import org.jetlinks.core.event.EventBus;
|
|
|
+import org.jetlinks.pro.media.entity.MediaChannelEntity;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.event.EventListener;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class MediaChannelEntityListener {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EventBus eventBus;
|
|
|
+
|
|
|
+ @EventListener
|
|
|
+ public void handleEntityBeforeModifyEvent(EntityBeforeModifyEvent<MediaChannelEntity> event) {
|
|
|
+ if (!CollectionUtils.isEmpty(event.getAfter())) {
|
|
|
+ event.async(
|
|
|
+ publishMediaChannelStatus(event.getAfter())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<Void> publishMediaChannelStatus(List<MediaChannelEntity> list){
|
|
|
+ return Flux.fromIterable(list)
|
|
|
+ .flatMap(mediaChannelEntity -> eventBus.publish("/media-channel-status",
|
|
|
+ new HashMap<String, String>() {{
|
|
|
+ put("deviceId",mediaChannelEntity.getDeviceId());
|
|
|
+ put("channelId", mediaChannelEntity.getChannelId());
|
|
|
+ put("status", mediaChannelEntity.getStatus().getValue());
|
|
|
+ }}
|
|
|
+ )).then();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|