|
|
@ -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); |
|
|
|
|
|
} |
|
|
|
|
|
} |