From e180e151ee8369fcff917d878b3fb15b72d06d31 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期一, 27 二月 2023 18:16:31 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/ResultUtil.java | 187 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 187 insertions(+), 0 deletions(-) diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/ResultUtil.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/ResultUtil.java new file mode 100644 index 0000000..8134c57 --- /dev/null +++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/util/ResultUtil.java @@ -0,0 +1,187 @@ +package com.supersavedriving.user.modular.system.util; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * 定义统一返回对象 + */ +@ApiModel(value = "统一返回结果集") +public class ResultUtil<T> { + + public static final Integer SUCCESS = 10000; + + public static final Integer PARAM_ERROR = 10010; + + public static final Integer SYSTEM_INFO = 10020; + + public static final Integer TOKEN_ERROR = 10030; + + public static final Integer SIGN_ERROR = 10040; + + public static final Integer RUNTIME_ERROR = 10050; + + public static final String Token = "token无效"; + + public static final String SIGN = "签名无效"; + + @ApiModelProperty(name = "code", value = "业务状态码 10000:成功,10010:参数错误,10020:系统提示, 10030:身份校验异常,10040:签名不通过,10050:系统运行异常") + private Integer code;//备用状态码 + + @ApiModelProperty(name = "msg", value = "返回结果说明") + private String msg;//返回说明 + + @ApiModelProperty(name = "data", value = "返回结果值") + private T data;//返回数据 + + + + public String getMsg() { + return msg; + } + + public T getData() { + return data; + } + + + public Integer getCode() { + return code; + } + + private ResultUtil(Integer code, String msg) { + this.code = code; + this.msg = msg; + } + + private ResultUtil(Integer code, String msg, T data) { + this.code = code; + this.msg = msg; + this.data = data; + } + + + public static <T> ResultUtil<T> getResult(Integer code, String msg){ + return new ResultUtil<>(code, msg); + } + + public static <T> ResultUtil<T> getResult(Integer code, String msg, T data){ + return new ResultUtil<>(code, msg, data); + } + + /** + * 错误信息 + * @return + */ + public static ResultUtil error(String mag){ + return ResultUtil.getResult(ResultUtil.SYSTEM_INFO, mag, new Object()); + } + + /** + * 错误信息 + * @return + */ + public static <T> ResultUtil <T> error(String mag, T obj){ + return ResultUtil.getResult(ResultUtil.SYSTEM_INFO, mag, obj); + } + + /** + * token失效 + * @return + */ + public static ResultUtil tokenErr(){ + return ResultUtil.getResult(ResultUtil.TOKEN_ERROR, ResultUtil.Token, new Object()); + } + + /** + * token失效 + * @return + */ + public static ResultUtil tokenErr(String msg){ + return ResultUtil.getResult(ResultUtil.TOKEN_ERROR, msg, new Object()); + } + + /** + * 参数异常 + * @return + */ + public static ResultUtil paranErr(String...ages){ + return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "【" + ages + "】参数异常", new Object()); + } + + /** + * 参数异常 + * @return + */ + public static ResultUtil paranErr(){ + return ResultUtil.getResult(ResultUtil.PARAM_ERROR, "参数异常", new Object()); + } + + /** + * 运行异常 + * @return + */ + public static ResultUtil runErr(){ + return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "系统运行异常", new Object()); + } + + + /** + * 运行异常 + * @return + */ + public static <T>ResultUtil<T> runErr(T data){ + return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, "系统运行异常", data); + } + + /** + * 运行异常 + * @return + */ + public static <T>ResultUtil<T> runErr(T data, String msg){ + return ResultUtil.getResult(ResultUtil.RUNTIME_ERROR, msg, data); + } + + + /** + * 返回成功 + * @param + * @return + */ + public static ResultUtil success(){ + return ResultUtil.getResult(ResultUtil.SUCCESS, "成功", new Object()); + } + + + /** + * 返回成功 + * @param data + * @param <T> + * @return + */ + public static <T> ResultUtil<T> success(T data){ + return ResultUtil.getResult(ResultUtil.SUCCESS, "成功", data); + } + + /** + * 返回成功 + * @param msg + * @param data + * @param <T> + * @return + */ + public static <T> ResultUtil<T> success(String msg, T data){ + return ResultUtil.getResult(ResultUtil.SUCCESS, msg, data); + } + + + /** + * 签名无效 + * @param <T> + * @return + */ + public static <T> ResultUtil<T> sign(){ + return ResultUtil.getResult(ResultUtil.SIGN_ERROR, SIGN); + } + +} -- Gitblit v1.7.1