3 changed files with 75 additions and 0 deletions
-
29modules/thing/src/main/java/com/thing/event/ThingChangedEvent.java
-
33modules/thing/src/main/java/com/thing/listener/ThingChangedEventListener.java
-
13modules/thing/src/main/java/com/thing/thing/entity/service/impl/IotThingEntityServiceImpl.java
@ -0,0 +1,29 @@ |
|||
package com.thing.event; |
|||
|
|||
import com.thing.thing.entity.entity.IotThingEntity; |
|||
|
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import org.springframework.context.ApplicationEvent; |
|||
|
|||
import java.io.Serial; |
|||
|
|||
/** |
|||
* @author siyang |
|||
* @date 2024/9/10 10:28 |
|||
* @description 物变更事件 |
|||
*/ |
|||
@Getter |
|||
@Setter |
|||
public class ThingChangedEvent extends ApplicationEvent { |
|||
|
|||
@Serial private static final long serialVersionUID = 6767577249634996931L; |
|||
|
|||
private IotThingEntity thing; |
|||
|
|||
public ThingChangedEvent(Object source, IotThingEntity thing) { |
|||
super(source); |
|||
this.thing = thing; |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.thing.listener; |
|||
|
|||
import com.mybatisflex.core.update.UpdateChain; |
|||
import com.thing.device.source.entity.IotThingSourceEntity; |
|||
import com.thing.event.ThingChangedEvent; |
|||
import com.thing.thing.entity.entity.IotThingEntity; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import org.springframework.context.event.EventListener; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @author siyang |
|||
* @date 2024/9/10 10:34 |
|||
* @description 物变更事件监听器 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class ThingChangedEventListener { |
|||
|
|||
@EventListener(ThingChangedEvent.class) |
|||
public void onThingChangedEvent(ThingChangedEvent event) { |
|||
IotThingEntity thing = event.getThing(); |
|||
UpdateChain.of(IotThingSourceEntity.class) |
|||
.set(IotThingSourceEntity::getThingName, thing.getName()) |
|||
.where(IotThingSourceEntity::getThingId).eq(thing.getId()) |
|||
.and(IotThingSourceEntity::getTenantCode).eq(thing.getTenantCode()) |
|||
.update(); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue