diff --git a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java index 30c7db8..e72bdcc 100644 --- a/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java +++ b/src/main/java/club/joylink/xiannccda/alert/AlertListenerJob.java @@ -10,7 +10,11 @@ import club.joylink.xiannccda.event.Listener; import club.joylink.xiannccda.repository.IAlertRecordRepository; import club.joylink.xiannccda.ws.NccAlertMessageServer; import club.joylink.xiannccda.ws.WsMessageServerManager; +import io.netty.util.internal.ObjectUtil; +import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -61,14 +65,14 @@ public class AlertListenerJob implements ApplicationRunner { OccClientMessage clientMessage = serverProto.getClientMessage(alertInfo.getLineId()); for (LineTypeEnum lineType : clientMessage.getLineTypes()) { - - NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getInstance(lineType); - alertInfo.setLineType(lineType); - AlertRecord record = convertToRecord(alertInfo); - + NccAlertInfo cloned = alertInfo.clone2(); +// NccAlertInfo cloneNcc = ObjectUtils.clone(alertInfo); + cloned.setLineType(lineType); + AlertRecord record = convertToRecord(cloned); alertRecordRepository.save(record); - alertInfo.setId(record.getId()); - nccAlertMessageServer.addMsg(alertInfo); + cloned.setId(record.getId()); + NccAlertMessageServer nccAlertMessageServer = NccAlertMessageServer.getInstance(lineType); + nccAlertMessageServer.addMsg(cloned); } } }); diff --git a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java index a24c5f3..b5cc0c2 100644 --- a/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java +++ b/src/main/java/club/joylink/xiannccda/alert/NccAlertInfo.java @@ -11,8 +11,11 @@ import lombok.Getter; import lombok.Setter; @Getter -public class NccAlertInfo implements AlertInfo { +public class NccAlertInfo implements AlertInfo, Cloneable { + public NccAlertInfo() { + + } @Setter private Integer id; @@ -53,6 +56,19 @@ public class NccAlertInfo implements AlertInfo { this.alertDeviceType = alertDeviceType; } + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public NccAlertInfo clone2() { + try { + return (NccAlertInfo) this.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + public NccAlertInfo(LocalDateTime alertTime, AlertType alertType, Integer alertTipId, Integer lineId, String alertObject, String locatorDeviceId, Long alertLocationId, AlertDeviceType alertDeviceType) {