to switch enum.

This commit is contained in:
yu199195 2019-11-07 16:51:00 +08:00
parent 6ca6dac6cf
commit 43069fd4bb
2 changed files with 31 additions and 9 deletions

View File

@ -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!"));
}
}

View File

@ -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();
});