Browse Source

修改设备状态加锁

master
白凤吉 2 months ago
parent
commit
cb34fb6d0b
  1. 13
      src/main/java/com/iflytop/sgs/app/core/aspect/DeviceStateChangeAspect.java

13
src/main/java/com/iflytop/sgs/app/core/aspect/DeviceStateChangeAspect.java

@ -8,8 +8,12 @@ import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j @Slf4j
@Aspect @Aspect
@Component @Component
@ -18,6 +22,13 @@ public class DeviceStateChangeAspect {
private final WebSocketSender webSocketService; private final WebSocketSender webSocketService;
private final DeviceStateService deviceStateService; private final DeviceStateService deviceStateService;
private final Lock lock = new ReentrantLock();
@Before("execution(* com.iflytop.sgs.app.model.bo.status..set*(..))")
public void beforeSetMethod(JoinPoint joinPoint) {
lock.lock();
}
@After("execution(* com.iflytop.sgs.app.model.bo.status.device.*.set*(..))") @After("execution(* com.iflytop.sgs.app.model.bo.status.device.*.set*(..))")
public void afterSetMethod(JoinPoint joinPoint) { public void afterSetMethod(JoinPoint joinPoint) {
try { try {
@ -32,6 +43,8 @@ public class DeviceStateChangeAspect {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("处理状态变更后的值失败", e); log.error("处理状态变更后的值失败", e);
} finally {
lock.unlock();
} }
} }
} }
Loading…
Cancel
Save