mirror of
https://gitee.com/dromara/hmily.git
synced 2024-12-05 04:39:09 +08:00
to switch enum.
This commit is contained in:
parent
6ca6dac6cf
commit
43069fd4bb
@ -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!"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user