mirror of
https://gitee.com/dromara/hmily.git
synced 2024-12-09 14:54:16 +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.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.dromara.hmily.common.exception.HmilyRuntimeException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The enum Coordinator action enum.
|
* The enum Coordinator action enum.
|
||||||
@ -52,4 +55,15 @@ public enum EventTypeEnum {
|
|||||||
|
|
||||||
private final String desc;
|
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) {
|
public void executor(final HmilyTransactionEvent event) {
|
||||||
String transId = event.getHmilyTransaction().getTransId();
|
String transId = event.getHmilyTransaction().getTransId();
|
||||||
executor.select(transId).execute(() -> {
|
executor.select(transId).execute(() -> {
|
||||||
if (event.getType() == EventTypeEnum.SAVE.getCode()) {
|
EventTypeEnum eventTypeEnum = EventTypeEnum.buildByCode(event.getType());
|
||||||
coordinatorService.save(event.getHmilyTransaction());
|
switch (eventTypeEnum) {
|
||||||
} else if (event.getType() == EventTypeEnum.UPDATE_PARTICIPANT.getCode()) {
|
case SAVE:
|
||||||
coordinatorService.updateParticipant(event.getHmilyTransaction());
|
coordinatorService.save(event.getHmilyTransaction());
|
||||||
} else if (event.getType() == EventTypeEnum.UPDATE_STATUS.getCode()) {
|
break;
|
||||||
final HmilyTransaction hmilyTransaction = event.getHmilyTransaction();
|
case DELETE:
|
||||||
coordinatorService.updateStatus(hmilyTransaction.getTransId(), hmilyTransaction.getStatus());
|
coordinatorService.remove(event.getHmilyTransaction().getTransId());
|
||||||
} else if (event.getType() == EventTypeEnum.DELETE.getCode()) {
|
break;
|
||||||
coordinatorService.remove(event.getHmilyTransaction().getTransId());
|
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();
|
event.clear();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user