From 9c283297769248143f9f52a5f815b20473822c79 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Thu, 29 Feb 2024 09:41:38 +0800 Subject: [PATCH 1/4] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98=E5=A4=84=E7=90=86=E5=92=8C?= =?UTF-8?q?=E9=87=8D=E5=90=8D=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xymanager_common/constant/Constants.java | 1 + .../impl/RoleServiceImpl.java | 32 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java index de55f17..13ba7b2 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/constant/Constants.java @@ -203,5 +203,6 @@ public class Constants { * 超级管理员 */ public static int SUPER_ADMIN = 0; + public static String SUPER_ADMIN_NAME = "超级管理员"; } \ No newline at end of file diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java index 1269374..ccf230a 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java @@ -28,6 +28,7 @@ import java.util.Date; import java.util.List; import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN; +import static com.shxy.xymanager_common.constant.Constants.SUPER_ADMIN_NAME; @Service @Slf4j @@ -47,11 +48,25 @@ public class RoleServiceImpl implements RoleService { TbRoleExample example = new TbRoleExample(); TbRoleExample.Criteria criteria = example.createCriteria(); List list = roleMapper.selectByExample(example); + TbRole item = new TbRole(); + item.setId(SUPER_ADMIN); + item.setName(SUPER_ADMIN_NAME); + list.add(item); return list; } @Override public boolean add(TbRole item) throws Exception { + if (SUPER_ADMIN_NAME.equals(item.getName())) { + throw new ApiException("名称不能使用" + SUPER_ADMIN_NAME); + } + TbRoleExample example = new TbRoleExample(); + TbRoleExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo(item.getName()); + List list = roleMapper.selectByExample(example); + if (list.size() > 0) { + throw new ApiException("名称已存在"); + } item.setCreateTime(new Date()); int r = roleMapper.insertSelective(item); return r > 0; @@ -59,8 +74,19 @@ public class RoleServiceImpl implements RoleService { @Override public void update(TbRole item) throws Exception { + if (SUPER_ADMIN_NAME.equals(item.getName())) { + throw new ApiException("名称不能使用" + SUPER_ADMIN_NAME); + } if (item.getId() == SUPER_ADMIN) { - throw new ApiException("不能修改超级管理员"); + throw new ApiException("不能修改" + SUPER_ADMIN_NAME); + } + TbRoleExample example = new TbRoleExample(); + TbRoleExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo(item.getName()); + criteria.andIdNotEqualTo(item.getId()); + List list = roleMapper.selectByExample(example); + if (list.size() > 0) { + throw new ApiException("名称已存在"); } roleMapper.updateByPrimaryKey(item); } @@ -68,7 +94,7 @@ public class RoleServiceImpl implements RoleService { @Override public void delete(Integer id) throws Exception { if (id == SUPER_ADMIN) { - throw new ApiException("不能删除超级管理员"); + throw new ApiException("不能删除" + SUPER_ADMIN_NAME); } roleMapper.deleteByPrimaryKey(id); } @@ -112,7 +138,7 @@ public class RoleServiceImpl implements RoleService { @Override public void changePermission(Integer roleId, List list) throws Exception { if (roleId == SUPER_ADMIN) { - throw new ApiException("不能修改超级管理员的权限"); + throw new ApiException("不能修改" + SUPER_ADMIN_NAME + "的权限"); } TbPermissionExample example = new TbPermissionExample(); TbPermissionExample.Criteria criteria = example.createCriteria(); From 23928633e84a92636043fc739e17507ab1c678ae Mon Sep 17 00:00:00 2001 From: huangfeng Date: Thu, 29 Feb 2024 09:58:01 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4id=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xymanager_admin/controller/RoleController.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/RoleController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/RoleController.java index 24e7dcf..5987b94 100644 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/RoleController.java +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/RoleController.java @@ -6,6 +6,7 @@ import com.shxy.xymanager_common.bean.ServiceBody; import com.shxy.xymanager_common.bean.ServiceStatus; import com.shxy.xymanager_common.entity.TbPermission; import com.shxy.xymanager_common.entity.TbRole; +import com.shxy.xymanager_common.exception.ApiException; import com.shxy.xymanager_common.model.DyLineTreeListModel; import com.shxy.xymanager_common.model.PermissionDyLineTreeListModel; import com.shxy.xymanager_common.model.PermissionModel; @@ -48,7 +49,7 @@ public class RoleController extends BaseController { @ApiOperation("更新") public ResponseReult update(@Validated @RequestBody TbRole item) throws Exception { if (item.getId() == null) { - throw new Exception("ID不能为空!"); + throw new ApiException("id不能为空!"); } service.update(item); return ResponseReult.success("OK"); @@ -56,14 +57,17 @@ public class RoleController extends BaseController { @PostMapping("delete") @ApiOperation("删除") - public ResponseReult delete(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + public ResponseReult delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception { + if (id == null) { + throw new ApiException("id不能为空!"); + } service.delete(id); return ResponseReult.success("OK"); } @GetMapping("getPermission") @ApiOperation("查询权限") - public ResponseReult> getPermission(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception { + public ResponseReult> getPermission(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception { List result = service.getPermission(id); return ResponseReult.success(result); } From 24de635713a9e253b0cb4ee7c73d3d731092d15c Mon Sep 17 00:00:00 2001 From: huangfeng Date: Thu, 29 Feb 2024 10:09:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E8=B6=85=E7=AE=A1?= =?UTF-8?q?=E6=94=BE=E7=AC=AC=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shxy/xymanager_service/impl/RoleServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java index ccf230a..fef61df 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java @@ -51,7 +51,7 @@ public class RoleServiceImpl implements RoleService { TbRole item = new TbRole(); item.setId(SUPER_ADMIN); item.setName(SUPER_ADMIN_NAME); - list.add(item); + list.add(0, item); return list; } From e480c58bbfd5a2e85e1b9e17caeb515fea951242 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Thu, 29 Feb 2024 11:43:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E8=BF=9E=E5=90=8C=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/shxy/xymanager_service/impl/RoleServiceImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java index fef61df..9b3195d 100644 --- a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/RoleServiceImpl.java @@ -97,6 +97,10 @@ public class RoleServiceImpl implements RoleService { throw new ApiException("不能删除" + SUPER_ADMIN_NAME); } roleMapper.deleteByPrimaryKey(id); + TbPermissionExample example = new TbPermissionExample(); + TbPermissionExample.Criteria criteria = example.createCriteria(); + criteria.andRoleIdEqualTo(id); + permissionMapper.deleteByExample(example); } @Override