diff --git a/hmily-common/src/main/java/org/dromara/hmily/common/enums/EventTypeEnum.java b/hmily-common/src/main/java/org/dromara/hmily/common/enums/EventTypeEnum.java index 6ff858e8..d2a5f8de 100644 --- a/hmily-common/src/main/java/org/dromara/hmily/common/enums/EventTypeEnum.java +++ b/hmily-common/src/main/java/org/dromara/hmily/common/enums/EventTypeEnum.java @@ -18,6 +18,9 @@ package org.dromara.hmily.common.enums; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.dromara.hmily.common.exception.HmilyRuntimeException; + +import java.util.Arrays; /** * The enum Coordinator action enum. @@ -52,4 +55,15 @@ public enum EventTypeEnum { private final String desc; + /** + * Build by code event type enum. + * + * @param code the code + * @return the event type enum + */ + public static EventTypeEnum buildByCode(int code) { + return Arrays.stream(EventTypeEnum.values()).filter(e -> e.code == code).findFirst() + .orElseThrow(() -> new HmilyRuntimeException("can not support this code!")); + } + } diff --git a/hmily-core/src/main/java/org/dromara/hmily/core/disruptor/handler/HmilyConsumerLogDataHandler.java b/hmily-core/src/main/java/org/dromara/hmily/core/disruptor/handler/HmilyConsumerLogDataHandler.java index 348b5c0d..7d3480b7 100644 --- a/hmily-core/src/main/java/org/dromara/hmily/core/disruptor/handler/HmilyConsumerLogDataHandler.java +++ b/hmily-core/src/main/java/org/dromara/hmily/core/disruptor/handler/HmilyConsumerLogDataHandler.java @@ -38,15 +38,23 @@ public class HmilyConsumerLogDataHandler extends AbstractDisruptorConsumerExecut public void executor(final HmilyTransactionEvent event) { String transId = event.getHmilyTransaction().getTransId(); executor.select(transId).execute(() -> { - if (event.getType() == EventTypeEnum.SAVE.getCode()) { - coordinatorService.save(event.getHmilyTransaction()); - } else if (event.getType() == EventTypeEnum.UPDATE_PARTICIPANT.getCode()) { - coordinatorService.updateParticipant(event.getHmilyTransaction()); - } else if (event.getType() == EventTypeEnum.UPDATE_STATUS.getCode()) { - final HmilyTransaction hmilyTransaction = event.getHmilyTransaction(); - coordinatorService.updateStatus(hmilyTransaction.getTransId(), hmilyTransaction.getStatus()); - } else if (event.getType() == EventTypeEnum.DELETE.getCode()) { - coordinatorService.remove(event.getHmilyTransaction().getTransId()); + EventTypeEnum eventTypeEnum = EventTypeEnum.buildByCode(event.getType()); + switch (eventTypeEnum) { + case SAVE: + coordinatorService.save(event.getHmilyTransaction()); + break; + case DELETE: + coordinatorService.remove(event.getHmilyTransaction().getTransId()); + break; + case UPDATE_STATUS: + final HmilyTransaction hmilyTransaction = event.getHmilyTransaction(); + coordinatorService.updateStatus(hmilyTransaction.getTransId(), hmilyTransaction.getStatus()); + break; + case UPDATE_PARTICIPANT: + coordinatorService.updateParticipant(event.getHmilyTransaction()); + break; + default: + break; } event.clear(); });