no message
This commit is contained in:
12
src/main/java/com/sczx/pay/common/IApiCode.java
Normal file
12
src/main/java/com/sczx/pay/common/IApiCode.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.sczx.pay.common;
|
||||
|
||||
/**
|
||||
* @Author: 张黎
|
||||
* @Date: 2025/07/09/20:20
|
||||
* @Description:
|
||||
*/
|
||||
public interface IApiCode {
|
||||
String getCode();
|
||||
|
||||
String getMsg();
|
||||
}
|
||||
121
src/main/java/com/sczx/pay/common/Result.java
Normal file
121
src/main/java/com/sczx/pay/common/Result.java
Normal file
@ -0,0 +1,121 @@
|
||||
package com.sczx.pay.common;
|
||||
|
||||
|
||||
import com.sczx.pay.common.enums.ApiErrorCode;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author: 张黎
|
||||
* @Date: 2025/07/09/20:25
|
||||
* @Description:
|
||||
*/
|
||||
@ApiModel(value = "公共返回结果")
|
||||
@Builder
|
||||
@Data
|
||||
public class Result<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1331134667810352183L;
|
||||
@ApiModelProperty(value = "成功标识")
|
||||
private boolean success;
|
||||
@ApiModelProperty(value = "返回编码")
|
||||
private String code;
|
||||
@ApiModelProperty(value = "返回信息说明")
|
||||
private String msg;
|
||||
private String issue;
|
||||
@ApiModelProperty(value = "返回数据")
|
||||
private T data;
|
||||
|
||||
public Result(boolean success, String code, String msg, String issue, T data) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.issue = issue;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static Result result(IApiCode apiCode) {
|
||||
return result(apiCode, (Object)null);
|
||||
}
|
||||
|
||||
public static Result result(IApiCode apiCode, Object data) {
|
||||
return result(apiCode, apiCode.getMsg(), data);
|
||||
}
|
||||
|
||||
public static Result result(IApiCode apiCode, String issue, Object data) {
|
||||
return result((IApiCode)apiCode, (String)null, issue, data);
|
||||
}
|
||||
|
||||
public static Result result(IApiCode apiCode, String msg, String issue, Object data) {
|
||||
String message = apiCode.getMsg();
|
||||
if (StringUtils.isNotBlank(msg)) {
|
||||
message = msg;
|
||||
}
|
||||
|
||||
return result(apiCode.getCode(), message, issue, data);
|
||||
}
|
||||
|
||||
public static Result result(String code, String msg, String issue, Object data) {
|
||||
return builder().code(code).success("0".equals(code)).msg(msg).issue(issue).data(data).build();
|
||||
}
|
||||
|
||||
public static Result ok() {
|
||||
return ok((Object)null);
|
||||
}
|
||||
|
||||
public static Result ok(Object data) {
|
||||
return result(ApiErrorCode.SUCCESS, data);
|
||||
}
|
||||
|
||||
public static Result ok(String key, Object value) {
|
||||
Map<String, Object> map = new HashMap(1);
|
||||
map.put(key, value);
|
||||
return ok(map);
|
||||
}
|
||||
|
||||
public static Result fail(String msg) {
|
||||
return result((IApiCode)ApiErrorCode.FAIL, msg, msg, (Object)null);
|
||||
}
|
||||
|
||||
public static Result fail(IApiCode apiCode) {
|
||||
return result(apiCode, (Object)null);
|
||||
}
|
||||
|
||||
public static Result fail(IApiCode apiCode, String issue) {
|
||||
return result(apiCode, issue, (Object)null);
|
||||
}
|
||||
|
||||
public static Result fail(String code, String msg) {
|
||||
return result((String)code, msg, msg, (Object)null);
|
||||
}
|
||||
|
||||
public static Result fail(String code, String msg, String issue) {
|
||||
return result((String)code, msg, issue, (Object)null);
|
||||
}
|
||||
|
||||
public static Result fail(String code, String msg, String issue, Object data) {
|
||||
return result(code, msg, issue, data);
|
||||
}
|
||||
|
||||
public static Result fail(IApiCode apiCode, String issue, Object data) {
|
||||
if (ApiErrorCode.SUCCESS == apiCode) {
|
||||
throw new RuntimeException("失败结果状态码不能为" + ApiErrorCode.SUCCESS.getCode());
|
||||
} else {
|
||||
return result(apiCode, issue, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static Result fail(String key, Object value) {
|
||||
Map<String, Object> map = new HashMap();
|
||||
map.put(key, value);
|
||||
return result(ApiErrorCode.FAIL, map);
|
||||
}
|
||||
public Result() {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.sczx.pay.common.constant;
|
||||
|
||||
|
||||
public interface SystemConstants {
|
||||
|
||||
/***
|
||||
* feign客户端所在包路径
|
||||
*/
|
||||
String FEIGN_CLIENT_BASE_PACKAGE = "com.sczx.pay.thirdpart.facade";
|
||||
|
||||
}
|
||||
55
src/main/java/com/sczx/pay/common/enums/ApiErrorCode.java
Normal file
55
src/main/java/com/sczx/pay/common/enums/ApiErrorCode.java
Normal file
@ -0,0 +1,55 @@
|
||||
package com.sczx.pay.common.enums;
|
||||
|
||||
|
||||
import com.sczx.pay.common.IApiCode;
|
||||
|
||||
/**
|
||||
* @Author: 张黎
|
||||
* @Date: 2025/07/09/20:22
|
||||
* @Description:
|
||||
*/
|
||||
public enum ApiErrorCode implements IApiCode {
|
||||
SUCCESS("0", "操作成功"),
|
||||
ARG_ERROR("401000", "参数错误"),
|
||||
NOT_PERMISSION("401001", "没有权限"),
|
||||
HTTP_MEDIA_TYPE_NOT_SUPPORTED_ERROR("401002", "media类型出错"),
|
||||
HTTP_METHOD_NOT_ALLOW_ERROR("401003", "http请求method错误"),
|
||||
BODY_NOT_MATCH("401004", "请求的数据格式不符!"),
|
||||
NOT_FOUND("404000", "你请求的路径不存在"),
|
||||
UNAUTHORIZED("404001", "非法访问"),
|
||||
FAIL("500000", "操作失败"),
|
||||
INNER_ERROR("500001", "服务器内部异常");
|
||||
|
||||
private final String code;
|
||||
private final String msg;
|
||||
|
||||
private ApiErrorCode(String code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static ApiErrorCode getApiCode(String code) {
|
||||
ApiErrorCode[] ecs = values();
|
||||
ApiErrorCode[] var2 = ecs;
|
||||
int var3 = ecs.length;
|
||||
|
||||
for(int var4 = 0; var4 < var3; ++var4) {
|
||||
ApiErrorCode ec = var2[var4];
|
||||
if (ec.getCode().equals(code)) {
|
||||
return ec;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user