first commit

This commit is contained in:
2025-04-01 11:48:31 +08:00
commit fcebd8474e
49 changed files with 2804 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package com.greenorange.promotion.common;
import lombok.Data;
import java.io.Serializable;
/**
* 通用返回类
*/
@Data
@SuppressWarnings("all")
public class BaseResponse<T> implements Serializable {
private int code;
private T data;
private String message;
public BaseResponse(int code, T data ,String message) {
this.code = code;
this.data = data;
this.message = message;
}
public BaseResponse(int code , T data) {
this(code, data, "");
}
public BaseResponse(ErrorCode errorCode) {
this(errorCode.getCode(), null, errorCode.getMessage());
}
}

View File

@ -0,0 +1,30 @@
package com.greenorange.promotion.common;
import lombok.Getter;
@Getter
public enum ErrorCode {
SUCCESS(1,"ok"),
PARAMS_ERROR(40000,"请求参数错误"),
NOT_LOGIN_ERROR(40100,"未登录"),
NO_AUTH_ERROR(40101, "无权限"),
NOT_FOUND_ERROR(40400,"请求数据不存在"),
FORBIDDEN_ERROR(40300,"禁止访问"),
SYSTEM_ERROR(50000,"系统内部异常"),
OPERATION_ERROR(50001,"操作失败"),
DATABASE_ERROR(50002, "数据库内部异常"),
LOGIN_ERROR(40110,"登陆状态变更");
/**
* 状态码
*/
private final int code;
private final String message;
ErrorCode(int code,String message) {
this.code = code;
this.message = message;
}
}

View File

@ -0,0 +1,36 @@
package com.greenorange.promotion.common;
import com.greenorange.promotion.constant.CommonConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 分页请求
*/
@Data
public class PageRequest {
/**
* 当前页号
*/
@Schema(description = "当前页码", example = "1")
private long current = 1;
/**
* 页面大小
*/
@Schema(description = "每页展示的记录条数", example = "10")
private long pageSize = 10;
/**
* 排序字段
*/
@Schema(description = "排序字段", example = "id")
private String sortField;
/**
* 排序顺序(默认升序)
*/
@Schema(description = "排序顺序((升:ascend;降:descend", example = "ascend")
private String sortOrder = CommonConstant.SORT_ORDER_ASC;
}

View File

@ -0,0 +1,58 @@
package com.greenorange.promotion.common;
@SuppressWarnings("all")
public class ResultUtils {
/**
* 成功
*
* @param data 数据
* @param <T> 泛型
* @return 成功信息
*/
public static <T> BaseResponse<T> success(T data) {
return new BaseResponse<>(1, data , "ok");
}
/**
* 成功
*
* @param data 数据
* @param message 成功消息
* @return 成功
*/
public static <T> BaseResponse<T> success(T data, String message) {
return new BaseResponse<>(1, data, message);
}
/**
* 失败
*
* @param errorCode 自定义错误码
* @return 失败信息
*/
public static <T> BaseResponse<T> error(ErrorCode errorCode) {
return new BaseResponse<>(errorCode);
}
/**
* 失败
*
* @param code 错误码
* @param message 消息
* @return 失败信息
*/
public static <T> BaseResponse<T> error(int code, String message) {
return new BaseResponse(code, null, message);
}
/**
* 失败
*
* @param errorCode 自定义错误码
* @return 失败信息
*/
public static <T> BaseResponse<T> error(ErrorCode errorCode, String message) {
return new BaseResponse(errorCode.getCode(), null, message);
}
}