add:增加退料入库
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package org.nl.common.base;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -28,8 +31,9 @@ public class TableDataInfo<T> implements Serializable {
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private List<T> content = new ArrayList<>();
|
||||
|
||||
private Object content = new ArrayList<>();
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime timestamp = LocalDateTime.now();
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
@@ -38,11 +42,9 @@ public class TableDataInfo<T> implements Serializable {
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 反馈数据
|
||||
*/
|
||||
private Object data;
|
||||
private String message;
|
||||
private Integer respCode;
|
||||
private String respMsg;
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
@@ -57,34 +59,30 @@ public class TableDataInfo<T> implements Serializable {
|
||||
public static <T> TableDataInfo<T> build(IPage<T> page) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(String.valueOf(HttpStatus.HTTP_OK));
|
||||
rspData.setMsg("操作成功");
|
||||
rspData.setMessage("操作成功");
|
||||
rspData.setRespMsg("操作成功");
|
||||
rspData.setRespCode(0);
|
||||
rspData.setContent(page.getRecords());
|
||||
rspData.setTotalElements(page.getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build(List<T> list) {
|
||||
public static <T> TableDataInfo<T> build(Object list) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(String.valueOf(HttpStatus.HTTP_OK));
|
||||
rspData.setMsg("操作成功");
|
||||
rspData.setMessage("操作成功");
|
||||
rspData.setContent(list);
|
||||
rspData.setTotalElements(list.size());
|
||||
rspData.setRespMsg("操作成功");
|
||||
rspData.setRespCode(0);
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build() {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(String.valueOf(HttpStatus.HTTP_OK));
|
||||
rspData.setMsg("操作成功");
|
||||
rspData.setMessage("操作成功");
|
||||
rspData.setRespMsg("操作成功");
|
||||
rspData.setRespCode(0);
|
||||
return rspData;
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> buildJson(Object result) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(String.valueOf(HttpStatus.HTTP_OK));
|
||||
rspData.setData(result);
|
||||
rspData.setMsg("操作成功");
|
||||
return rspData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
@Getter
|
||||
public class BadRequestException extends RuntimeException{
|
||||
|
||||
private Integer status = BAD_REQUEST.value();
|
||||
private String code = "400";
|
||||
|
||||
public BadRequestException(String msg){
|
||||
super(msg);
|
||||
@@ -40,6 +40,6 @@ public class BadRequestException extends RuntimeException{
|
||||
|
||||
public BadRequestException(HttpStatus status,String msg){
|
||||
super(msg);
|
||||
this.status = status.value();
|
||||
this.code = String.valueOf(status.value());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
@@ -27,9 +28,26 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
class ApiError {
|
||||
|
||||
private Integer status = 400;
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private long totalElements = 0;
|
||||
/**
|
||||
* 列表数据
|
||||
*/
|
||||
private Object content = new ArrayList<>();
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime timestamp;
|
||||
/**
|
||||
* 消息状态码
|
||||
*/
|
||||
private String code;
|
||||
private Integer respCode;
|
||||
private String respMsg;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
private String message;
|
||||
|
||||
private ApiError() {
|
||||
@@ -38,14 +56,19 @@ class ApiError {
|
||||
|
||||
public static ApiError error(String message) {
|
||||
ApiError apiError = new ApiError();
|
||||
apiError.setCode("400");
|
||||
apiError.setRespCode(1);
|
||||
apiError.setMessage(message);
|
||||
apiError.setRespMsg(message);
|
||||
return apiError;
|
||||
}
|
||||
|
||||
public static ApiError error(Integer status, String message) {
|
||||
public static ApiError error(String status, String message) {
|
||||
ApiError apiError = new ApiError();
|
||||
apiError.setStatus(status);
|
||||
apiError.setCode(status);
|
||||
apiError.setMessage(message);
|
||||
apiError.setMessage(message);
|
||||
apiError.setRespMsg(message);
|
||||
return apiError;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(value = NotLoginException.class)
|
||||
public ResponseEntity<ApiError> notLoginException(Exception e) {
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
return buildResponseEntity(ApiError.error(401, "token 失效"));
|
||||
return buildResponseEntity(ApiError.error("401", "token 失效"));
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class GlobalExceptionHandler {
|
||||
public ResponseEntity<ApiError> badRequestException(BadRequestException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
return buildResponseEntity(ApiError.error(e.getStatus(), e.getMessage()));
|
||||
return buildResponseEntity(ApiError.error(e.getCode(), e.getMessage()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ public class GlobalExceptionHandler {
|
||||
public ResponseEntity<ApiError> entityNotFoundException(EntityNotFoundException e) {
|
||||
// 打印堆栈信息
|
||||
log.error(ThrowableUtil.getStackTrace(e));
|
||||
return buildResponseEntity(ApiError.error(NOT_FOUND.value(), e.getMessage()));
|
||||
return buildResponseEntity(ApiError.error("404", e.getMessage()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +112,6 @@ public class GlobalExceptionHandler {
|
||||
* 统一返回
|
||||
*/
|
||||
private ResponseEntity<ApiError> buildResponseEntity(ApiError apiError) {
|
||||
return new ResponseEntity<>(apiError, HttpStatus.valueOf(apiError.getStatus()));
|
||||
return new ResponseEntity<>(apiError, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user