|
|
@@ -1,5 +1,6 @@
|
|
|
package com.nb.im.listener;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.nb.im.entity.ImRoomEntity;
|
|
|
import com.nb.im.enums.ImStatusEnum;
|
|
|
@@ -7,9 +8,12 @@ import com.nb.im.service.LocalImRoomService;
|
|
|
import com.nb.web.api.event.ClinicFinishedEvent;
|
|
|
import com.nb.web.api.event.ClinicRestartEvent;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
@@ -25,37 +29,44 @@ import java.util.Date;
|
|
|
*/
|
|
|
@Configuration
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class MonitorStatusListener {
|
|
|
private final LocalImRoomService roomService;
|
|
|
@EventListener
|
|
|
@Async
|
|
|
+ @Transactional(isolation = Isolation.SERIALIZABLE)
|
|
|
public void monitorFinished(ClinicFinishedEvent event){
|
|
|
- String patientId = event.getPatientId();
|
|
|
+ synchronized (event.getPatientId()){
|
|
|
+ log.info("临床结束事件监听,{}", JSONUtil.toJsonStr(event));
|
|
|
+ String patientId = event.getPatientId();
|
|
|
|
|
|
- roomService.update(new UpdateWrapper<ImRoomEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(ImRoomEntity::getPatientId,patientId)
|
|
|
- .in(ImRoomEntity::getStatus, ImStatusEnum.WAITING,ImStatusEnum.SUCCESS)
|
|
|
- .set(ImRoomEntity::getMonitorFinishedTime,new Date())
|
|
|
- .set(ImRoomEntity::getMonitorFinished,true)
|
|
|
- );
|
|
|
+ roomService.update(new UpdateWrapper<ImRoomEntity>()
|
|
|
+ .lambda()
|
|
|
+ .eq(ImRoomEntity::getPatientId,patientId)
|
|
|
+ .in(ImRoomEntity::getStatus, ImStatusEnum.WAITING,ImStatusEnum.SUCCESS)
|
|
|
+ .set(ImRoomEntity::getMonitorFinishedTime,new Date())
|
|
|
+ .set(ImRoomEntity::getMonitorFinished,true));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@EventListener
|
|
|
@Async
|
|
|
public void monitorReset(ClinicRestartEvent event){
|
|
|
- String patientId = event.getPatientId();
|
|
|
- //两小时前的时间
|
|
|
- LocalDateTime dateTime = LocalDateTime.now().plus(-2, ChronoUnit.HOURS);
|
|
|
- Date date = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
- //临床结束未满两小时的进行处理
|
|
|
- roomService.update(new UpdateWrapper<ImRoomEntity>()
|
|
|
- .lambda()
|
|
|
- .eq(ImRoomEntity::getPatientId,patientId)
|
|
|
- .in(ImRoomEntity::getStatus, ImStatusEnum.WAITING,ImStatusEnum.SUCCESS)
|
|
|
- .eq(ImRoomEntity::getMonitorFinished,true)
|
|
|
- .gt(ImRoomEntity::getMonitorFinishedTime,date)
|
|
|
- .set(ImRoomEntity::getMonitorFinished,false)
|
|
|
- );
|
|
|
+ synchronized (event.getPatientId()){
|
|
|
+ log.info("临床重启事件监听,{}", JSONUtil.toJsonStr(event));
|
|
|
+ String patientId = event.getPatientId();
|
|
|
+ //两小时前的时间
|
|
|
+ LocalDateTime dateTime = LocalDateTime.now().plus(-2, ChronoUnit.HOURS);
|
|
|
+ Date date = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ //临床结束未满两小时的进行处理
|
|
|
+ roomService.update(new UpdateWrapper<ImRoomEntity>()
|
|
|
+ .lambda()
|
|
|
+ .eq(ImRoomEntity::getPatientId,patientId)
|
|
|
+ .in(ImRoomEntity::getStatus, ImStatusEnum.WAITING,ImStatusEnum.SUCCESS)
|
|
|
+ .eq(ImRoomEntity::getMonitorFinished,true)
|
|
|
+ .gt(ImRoomEntity::getMonitorFinishedTime,date)
|
|
|
+ .set(ImRoomEntity::getMonitorFinished,false)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
}
|