public enum TaskType { INVITE_ONLINE ( "inviteOnline" , " Send a marketing message to invite users to go online " ), MARKETING_SEND_VOUCHER ( "marketingSendVoucher" , " Send 5 yuan X10 coupons to existing users " ); private String value; private String desc; TaskType(final String value, final String desc) { this.value = value; this.desc = desc; } public String getValue() { return value; } public String getDesc() { return desc; } public static TaskType instanceOf(String value) { for (TaskType taskType : TaskType.values()) { if (taskType.getValue().equals(value)) { return taskType; } } return null; } }
@Component public class BfFunctionalTaskActualServiceFactory { @Autowired private BfMarketingSendVoucherServiceImpl marketingSendVoucherServiceImpl; @Autowired private BfSmsInviteOnlineServiceImpl smsInviteOnlineServiceImpl; public BfFunctionalTaskActualService getService(String type) { TaskType taskType = TaskType.instanceOf(type); if (taskType == null) { return null; } switch (taskType) { case INVITE_ONLINE: return smsInviteOnlineServiceImpl; case MARKETING_SEND_VOUCHER: return marketingSendVoucherServiceImpl; default: return null; } } }
@Override public List<BfFunctionalTaskTypeDTO> obtainTaskType() { List<BfFunctionalTaskTypeDTO> list = new ArrayList<BfFunctionalTaskTypeDTO>(); // 将枚举存放到list里面 for (TaskType taskType : TaskType.values()) { BfFunctionalTaskTypeDTO taskTypeDTO = new BfFunctionalTaskTypeDTO(); taskTypeDTO.setValue(taskType.getValue()); taskTypeDTO.setDesc(taskType.getDesc()); list.add(taskTypeDTO); } return list; }