5 changed files with 93 additions and 0 deletions
-
25modules/thing/src/main/java/com/thing/event/ThingRelationDetailUpdateEvent.java
-
54modules/thing/src/main/java/com/thing/listener/ThingChangedUpdateRelationEventListener.java
-
5modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java
-
2modules/thing/src/main/java/com/thing/thing/relation/detail/service/IotThingRelationDetailService.java
-
7modules/thing/src/main/java/com/thing/thing/relation/detail/service/impl/IotThingRelationDetailServiceImpl.java
@ -0,0 +1,25 @@ |
|||
package com.thing.event; |
|||
|
|||
import com.thing.thing.entity.entity.IotThingEntity; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
import org.springframework.context.ApplicationEvent; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* Author: SiYang |
|||
* Date: 2023/12/01 14:39 |
|||
* Description: 新增物关系子节点事件 |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
public class ThingRelationDetailUpdateEvent extends ApplicationEvent { |
|||
|
|||
private List<IotThingEntity> list; |
|||
|
|||
public ThingRelationDetailUpdateEvent(Object source, List<IotThingEntity> list) { |
|||
super(source); |
|||
this.list = list; |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
package com.thing.listener; |
|||
|
|||
import com.thing.common.cache.constants.CacheNameEnum; |
|||
import com.thing.event.ThingRelationDetailUpdateEvent; |
|||
import com.thing.thing.cache.service.ThingCache; |
|||
import com.thing.thing.entity.entity.IotThingEntity; |
|||
import com.thing.thing.relation.detail.entity.IotThingRelationDetailEntity; |
|||
import com.thing.thing.relation.detail.service.IotThingRelationDetailService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections4.CollectionUtils; |
|||
import org.springframework.context.event.EventListener; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @author siyang |
|||
* @date 2024/9/10 10:34 |
|||
* @description 物变更事件监听器 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ThingChangedUpdateRelationEventListener { |
|||
|
|||
private final IotThingRelationDetailService thingRelationDetailService; |
|||
|
|||
private final ThingCache cache; |
|||
|
|||
@EventListener(ThingRelationDetailUpdateEvent.class) |
|||
public void onThingChangedEvent(ThingRelationDetailUpdateEvent event) { |
|||
List<IotThingEntity> list = event.getList(); |
|||
for (IotThingEntity thing : list) { |
|||
List<IotThingRelationDetailEntity> fromEntities = thingRelationDetailService.findByFromIdAndToId(thing.getId(),null); |
|||
if(CollectionUtils.isNotEmpty(fromEntities)){ |
|||
for (IotThingRelationDetailEntity entity : fromEntities) { |
|||
entity.setFromName(thing.getName()); |
|||
} |
|||
thingRelationDetailService.updateBatch(fromEntities); |
|||
} |
|||
|
|||
List<IotThingRelationDetailEntity> toEntities = thingRelationDetailService.findByFromIdAndToId(null, thing.getId()); |
|||
|
|||
if(CollectionUtils.isNotEmpty(toEntities)){ |
|||
for (IotThingRelationDetailEntity entity : toEntities) { |
|||
entity.setToName(thing.getName()); |
|||
} |
|||
thingRelationDetailService.updateBatch(toEntities); |
|||
} |
|||
} |
|||
cache.clearTopic(CacheNameEnum.THING_DETAIL_RELATION); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue