20231126-yw
wj 2 years ago
parent 426b966cb3
commit 08d4462530

@ -9,7 +9,7 @@ import lombok.Getter;
public enum ResultEnum { public enum ResultEnum {
SUCCESS(20000, "success"), SUCCESS(20000, "success"),
NOT_NETWORK(1, "系统繁忙,请稍后再试。"), NOT_NETWORK(500, "系统繁忙,请稍后再试。"),
LOGIN_VERIFY_FALL(2, "登录失效"), LOGIN_VERIFY_FALL(2, "登录失效"),
PARAM_VERIFY_FALL(3, "参数验证错误"), PARAM_VERIFY_FALL(3, "参数验证错误"),
AUTH_FAILED(4, "权限验证失败"), AUTH_FAILED(4, "权限验证失败"),

@ -33,7 +33,7 @@ public class ResultVOUtils {
* @param data data * @param data data
* @return {@link BaseResponse} * @return {@link BaseResponse}
*/ */
public static BaseResponse success(String msg,Object data) { public static BaseResponse success(String msg, Object data) {
BaseResponse<Object> baseResponse = new BaseResponse<>(); BaseResponse<Object> baseResponse = new BaseResponse<>();
baseResponse.setCode(ResultEnum.SUCCESS.getCode()); baseResponse.setCode(ResultEnum.SUCCESS.getCode());
baseResponse.setMessage(msg); baseResponse.setMessage(msg);
@ -122,6 +122,16 @@ public class ResultVOUtils {
return error(resultEnum.getCode(), message); return error(resultEnum.getCode(), message);
} }
/**
*
*
* @param message
* @return {@link BaseResponse}
*/
public static BaseResponse error(String message) {
return error(ResultEnum.NOT_NETWORK.getCode(), message);
}
/** /**
* PageHelper * PageHelper
* *

@ -7,7 +7,7 @@ import lombok.Getter;
* *
*/ */
@Getter @Getter
public class JsonException extends RuntimeException{ public class JsonException extends RuntimeException {
private Integer code; private Integer code;
@ -25,4 +25,9 @@ public class JsonException extends RuntimeException{
super(message); super(message);
this.code = code; this.code = code;
} }
public JsonException(String message) {
super(message);
this.code = ResultEnum.NOT_NETWORK.getCode();
}
} }

@ -7,6 +7,7 @@ import com.glxp.api.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
@ -34,12 +35,21 @@ public class GlobalExceptionHandler {
} }
@ExceptionHandler({BindException.class}) @ExceptionHandler({BindException.class})
public BaseResponse handlerBindException(BindException e) { public BaseResponse handlerBindException(BindException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
boolean bindingFailure = e.getFieldError().isBindingFailure(); boolean bindingFailure = e.getFieldError().isBindingFailure();
if(bindingFailure){ if (bindingFailure) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
}
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, e.getBindingResult().getFieldError().getDefaultMessage());
}
@ExceptionHandler({MethodArgumentNotValidException.class})
public BaseResponse handlerBindException(MethodArgumentNotValidException e) {
log.error(e.getMessage(), e);
boolean bindingFailure = e.getBindingResult().getFieldError().isBindingFailure();
if (bindingFailure) {
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL);
} }
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, e.getBindingResult().getFieldError().getDefaultMessage()); return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, e.getBindingResult().getFieldError().getDefaultMessage());

@ -1,13 +1,11 @@
package com.glxp.api.service; package com.glxp.api.service;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.dao.BaseMapperPlus;
import org.apache.poi.ss.formula.functions.T;
import java.util.List; import java.util.List;
public class CustomServiceImpl<M extends BaseMapperPlus<M,T, T>, T> extends ServiceImpl<M, T> implements CustomService<T>{ public class CustomServiceImpl<M extends BaseMapperPlus<M, T, T>, T> extends ServiceImpl<M, T> implements CustomService<T> {
@Override @Override
public int insertIgnore(T entity) { public int insertIgnore(T entity) {
return baseMapper.insertIgnore(entity); return baseMapper.insertIgnore(entity);

Loading…
Cancel
Save