diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HttpStatus.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HttpStatus.java index a15743d9..1bcb7839 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HttpStatus.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HttpStatus.java @@ -1,88 +1,93 @@ -package com.ruoyi.common.core.constant; - -/** - * 返回状态码 - * - * @author Lion Li - */ -public interface HttpStatus { - /** - * 操作成功 - */ - int SUCCESS = 200; - - /** - * 对象创建成功 - */ - int CREATED = 201; - - /** - * 请求已经被接受 - */ - int ACCEPTED = 202; - - /** - * 操作已经执行成功,但是没有返回数据 - */ - int NO_CONTENT = 204; - - /** - * 资源已被移除 - */ - int MOVED_PERM = 301; - - /** - * 重定向 - */ - int SEE_OTHER = 303; - - /** - * 资源没有被修改 - */ - int NOT_MODIFIED = 304; - - /** - * 参数列表错误(缺少,格式不匹配) - */ - int BAD_REQUEST = 400; - - /** - * 未授权 - */ - int UNAUTHORIZED = 401; - - /** - * 访问受限,授权过期 - */ - int FORBIDDEN = 403; - - /** - * 资源,服务未找到 - */ - int NOT_FOUND = 404; - - /** - * 不允许的http方法 - */ - int BAD_METHOD = 405; - - /** - * 资源冲突,或者资源被锁 - */ - int CONFLICT = 409; - - /** - * 不支持的数据,媒体类型 - */ - int UNSUPPORTED_TYPE = 415; - - /** - * 系统内部错误 - */ - int ERROR = 500; - - /** - * 接口未实现 - */ - int NOT_IMPLEMENTED = 501; -} +package com.ruoyi.common.core.constant; + +/** + * 返回状态码 + * + * @author Lion Li + */ +public interface HttpStatus { + /** + * 操作成功 + */ + int SUCCESS = 200; + + /** + * 对象创建成功 + */ + int CREATED = 201; + + /** + * 请求已经被接受 + */ + int ACCEPTED = 202; + + /** + * 操作已经执行成功,但是没有返回数据 + */ + int NO_CONTENT = 204; + + /** + * 资源已被移除 + */ + int MOVED_PERM = 301; + + /** + * 重定向 + */ + int SEE_OTHER = 303; + + /** + * 资源没有被修改 + */ + int NOT_MODIFIED = 304; + + /** + * 参数列表错误(缺少,格式不匹配) + */ + int BAD_REQUEST = 400; + + /** + * 未授权 + */ + int UNAUTHORIZED = 401; + + /** + * 访问受限,授权过期 + */ + int FORBIDDEN = 403; + + /** + * 资源,服务未找到 + */ + int NOT_FOUND = 404; + + /** + * 不允许的http方法 + */ + int BAD_METHOD = 405; + + /** + * 资源冲突,或者资源被锁 + */ + int CONFLICT = 409; + + /** + * 不支持的数据,媒体类型 + */ + int UNSUPPORTED_TYPE = 415; + + /** + * 系统内部错误 + */ + int ERROR = 500; + + /** + * 接口未实现 + */ + int NOT_IMPLEMENTED = 501; + + /** + * 系统警告消息 + */ + public static final int WARN = 601; +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/domain/R.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/domain/R.java index 63473376..2f0d0d83 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/domain/R.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/domain/R.java @@ -1,6 +1,7 @@ package com.ruoyi.common.core.domain; import com.ruoyi.common.core.constant.Constants; +import com.ruoyi.common.core.constant.HttpStatus; import lombok.Data; import lombok.NoArgsConstructor; @@ -77,6 +78,27 @@ public class R implements Serializable { return restResult(null, code, msg); } + /** + * 返回警告消息 + * + * @param msg 返回内容 + * @return 警告消息 + */ + public static R warn(String msg) { + return restResult(null, HttpStatus.WARN, msg); + } + + /** + * 返回警告消息 + * + * @param msg 返回内容 + * @param data 数据对象 + * @return 警告消息 + */ + public static R warn(String msg, T data) { + return restResult(data, HttpStatus.WARN, msg); + } + private static R restResult(T data, int code, String msg) { R r = new R<>(); r.setCode(code); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java index 4eaa2dc0..b2bda6b2 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java @@ -1,7 +1,6 @@ package com.ruoyi.system.controller; import cn.dev33.satoken.annotation.SaCheckPermission; -import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.util.ArrayUtil; import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.domain.R; @@ -15,9 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * 部门信息 @@ -108,10 +105,10 @@ public class SysDeptController extends BaseController { @DeleteMapping("/{deptId}") public R remove(@PathVariable Long deptId) { if (deptService.hasChildByDeptId(deptId)) { - return R.fail("存在下级部门,不允许删除"); + return R.warn("存在下级部门,不允许删除"); } if (deptService.checkDeptExistUser(deptId)) { - return R.fail("部门存在用户,不允许删除"); + return R.warn("部门存在用户,不允许删除"); } deptService.checkDeptDataScope(deptId); return toAjax(deptService.deleteDeptById(deptId)); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysMenuController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysMenuController.java index a79aa034..efff7554 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysMenuController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysMenuController.java @@ -122,10 +122,10 @@ public class SysMenuController extends BaseController { @DeleteMapping("/{menuId}") public R remove(@PathVariable("menuId") Long menuId) { if (menuService.hasChildByMenuId(menuId)) { - return R.fail("存在子菜单,不允许删除"); + return R.warn("存在子菜单,不允许删除"); } if (menuService.checkMenuExistRole(menuId)) { - return R.fail("菜单已分配,不允许删除"); + return R.warn("菜单已分配,不允许删除"); } return toAjax(menuService.deleteMenuById(menuId)); }