package com.cz.business.demo.enums;
import com.cz.core.web.exception.BusinessException;
/**
* @ClassName DataStatus
* @Description 枚举
* @Date 2023/5/17 17:00
* @Version 1.0
*/
public enum DataStatus {
/**
* 成功
*/
SUCCESS_HANDlER("4",sql -> sql),
/**
* 处理中
*/
DEAL_HANDlER("2",sql -> sql),
/**
* 没有
*/
TRADE_HANDlER("3",sql -> sql),
/**
* 失败
*/
FAILED_HANDlER("5",sql -> sql);
public static DataStatus create(String type) {
for (DataStatus status: DataStatus.values()) {
if (status.getValue().equals(type)) {
return status;
}
}
throw new BusinessException("无该分类");
}
private String type;
private Handler handler;
DataStatus(String type,Handler handler) {
this.type = type;
this.handler = handler;
}
public String getValue() {
return type;
}
public String handler(String sql) {
return this.handler.handler(sql);
}
private interface Handler {
String handler(String sql);
}
}
handler接口参数根据实际情况调整,接口的lamdba实现也根据业务需求编写 如果参数过多可另用一个类来包装传递
调用:
DataStatus.create("4").handler("sql");