feature(权限点): 增加BizEx异常处理
This commit is contained in:
parent
abf3bd7c0a
commit
5909b04e27
@ -14,8 +14,8 @@ import cn.axzo.framework.domain.web.code.IRespCode;
|
|||||||
*/
|
*/
|
||||||
public class Throws {
|
public class Throws {
|
||||||
|
|
||||||
/** 用于抛出请求参数类异常 **/
|
/** 用于抛出请求参数类异常 - 避免msg丢失 **/
|
||||||
public static BizException paramException(IRespCode code, String message) {
|
public static BizException bizException(IRespCode code, String message) {
|
||||||
throw new BizException(ErrorLevel.P2, ErrorType.ERROR_BUSINESS, code, message);
|
throw new BizException(ErrorLevel.P2, ErrorType.ERROR_BUSINESS, code, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,33 @@
|
|||||||
|
package cn.axzo.tyr.server.config.exception;
|
||||||
|
|
||||||
|
import cn.axzo.framework.autoconfigure.web.exception.RespErrorCodeMappingProperties;
|
||||||
|
import cn.axzo.framework.autoconfigure.web.exception.handler.AbstractExceptionApiResultHandler;
|
||||||
|
import cn.axzo.framework.domain.web.BizException;
|
||||||
|
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||||
|
import cn.axzo.framework.domain.web.code.RespCode;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务异常处理器
|
||||||
|
* 避免返回http 500,造成封装多余的消息
|
||||||
|
* @version V1.0
|
||||||
|
* @author: ZhanSiHu
|
||||||
|
* @date: 2023/9/19 16:12
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BizExceptionResultHandler extends AbstractExceptionApiResultHandler<BizException> {
|
||||||
|
public BizExceptionResultHandler(RespErrorCodeMappingProperties properties) {
|
||||||
|
super(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IRespCode decode(BizException ex, IRespCode fallbackCode) {
|
||||||
|
return new RespCode(ex.getCode(), ex.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HttpStatus mappingHttpStatus(String code, BizException ex) {
|
||||||
|
return HttpStatus.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -171,7 +171,7 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
|||||||
SaasFeature parent = this.saasFeatureDao.getById(request.getParentId());
|
SaasFeature parent = this.saasFeatureDao.getById(request.getParentId());
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
log.error("指定的父级节点不存在:{}", request.getParentId());
|
log.error("指定的父级节点不存在:{}", request.getParentId());
|
||||||
throw new BizException(BaseCode.BAD_REQUEST);
|
Throws.bizException(BaseCode.BAD_REQUEST, "父级节点不存在");
|
||||||
}
|
}
|
||||||
//追加条件path左匹配
|
//追加条件path左匹配
|
||||||
queryWrapper.likeRight(SaasFeature::getPath, parent.getPath() + parent.getId() + FEATURE_PATH_DELIMITER);
|
queryWrapper.likeRight(SaasFeature::getPath, parent.getPath() + parent.getId() + FEATURE_PATH_DELIMITER);
|
||||||
@ -326,7 +326,7 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
|||||||
SaasFeature feature = this.saasFeatureDao.getById(permissionId);
|
SaasFeature feature = this.saasFeatureDao.getById(permissionId);
|
||||||
if (feature == null) {
|
if (feature == null) {
|
||||||
log.error("未查询到权限点:{}", permissionId);
|
log.error("未查询到权限点:{}", permissionId);
|
||||||
throw new BizException(BaseCode.BAD_REQUEST, "未查询到权限点");
|
Throws.bizException(BaseCode.BAD_REQUEST, "未查询到权限点");
|
||||||
}
|
}
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
|||||||
switch (featureType) {
|
switch (featureType) {
|
||||||
case MODULE:
|
case MODULE:
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
Throws.paramException(BaseCode.BAD_REQUEST, "菜单必须为顶级");
|
Throws.bizException(BaseCode.BAD_REQUEST, "菜单必须为顶级");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MENU:
|
case MENU:
|
||||||
@ -371,18 +371,18 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
|||||||
case PAGE:
|
case PAGE:
|
||||||
if (parent == null
|
if (parent == null
|
||||||
|| FeatureType.apply(parent.getFeatureType()) == BUTTON) {
|
|| FeatureType.apply(parent.getFeatureType()) == BUTTON) {
|
||||||
Throws.paramException(BaseCode.BAD_REQUEST, "页面层级错误");
|
Throws.bizException(BaseCode.BAD_REQUEST, "页面层级错误");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON:
|
case BUTTON:
|
||||||
if (parent == null
|
if (parent == null
|
||||||
|| FeatureType.apply(parent.getFeatureType()) == MODULE
|
|| FeatureType.apply(parent.getFeatureType()) == MODULE
|
||||||
|| FeatureType.apply(parent.getFeatureType()) == BUTTON) {
|
|| FeatureType.apply(parent.getFeatureType()) == BUTTON) {
|
||||||
Throws.paramException(BaseCode.BAD_REQUEST, "按钮层级错误");
|
Throws.bizException(BaseCode.BAD_REQUEST, "按钮层级错误");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Throws.paramException(BaseCode.BAD_REQUEST, "不支持的元素类型");
|
Throws.bizException(BaseCode.BAD_REQUEST, "不支持的元素类型");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,10 +489,10 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
|||||||
if (parentId > 0) {
|
if (parentId > 0) {
|
||||||
parent = this.saasFeatureDao.getById(parentId);
|
parent = this.saasFeatureDao.getById(parentId);
|
||||||
if (!StrUtil.equals(feature.getTerminal(), parent.getTerminal())) {
|
if (!StrUtil.equals(feature.getTerminal(), parent.getTerminal())) {
|
||||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许跨工作台");
|
Throws.bizException(BaseCode.BAD_REQUEST, "不允许跨工作台");
|
||||||
}
|
}
|
||||||
if (parent.getPath().contains(String.valueOf(request.getPermissionId()))) {
|
if (parent.getPath().contains(String.valueOf(request.getPermissionId()))) {
|
||||||
throw new BizException(BaseCode.BAD_REQUEST, "不允许移到子级");
|
Throws.bizException(BaseCode.BAD_REQUEST, "不允许移到子级");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//检查元素类型层级
|
//检查元素类型层级
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user