From d52ece745ebe19f97d24d807d64e9a7a601b77ce Mon Sep 17 00:00:00 2001 From: KonBAI <1527468660@qq.com> Date: Sat, 22 Jan 2022 07:00:58 +0000 Subject: [PATCH] =?UTF-8?q?!132=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E6=9B=BF=E6=8D=A2=E9=AD=94=E6=B3=95=E5=80=BC=E4=B8=BA?= =?UTF-8?q?=E5=B7=B2=E5=AE=9A=E4=B9=89=E7=9A=84=E5=B8=B8=E9=87=8F=20*=20fi?= =?UTF-8?q?x=20=E6=9B=BF=E6=8D=A2=E6=9F=A5=E8=AF=A2=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=AD=90=E9=83=A8=E9=97=A8=E6=95=B0=E4=B8=AD=E9=AD=94=E6=B3=95?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E5=B7=B2=E5=AE=9A=E4=B9=89=E7=9A=84=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=20*=20fix=201.=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=94=B9=E4=B8=BAbaseMapper.exists()=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E3=80=82=202.=E5=B0=86=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=AD=94=E6=B3=95=E5=80=BC=E6=94=B9=E4=B8=BA=E5=B7=B2=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E5=B8=B8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/mapper/SysDictDataMapper.java | 3 ++- .../com/ruoyi/system/service/ISysDeptService.java | 2 +- .../system/service/impl/SysDeptServiceImpl.java | 15 +++++++-------- .../service/impl/SysDictTypeServiceImpl.java | 13 ++++++------- .../system/service/impl/SysMenuServiceImpl.java | 7 +++---- .../system/service/impl/SysPostServiceImpl.java | 14 ++++++-------- .../system/service/impl/SysRoleServiceImpl.java | 14 ++++++-------- 7 files changed, 31 insertions(+), 37 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java index 9b0074441..0d506bc06 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDictDataMapper.java @@ -1,6 +1,7 @@ package com.ruoyi.system.mapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.mapper.BaseMapperPlus; @@ -16,7 +17,7 @@ public interface SysDictDataMapper extends BaseMapperPlus selectDictDataByType(String dictType) { return selectList( new LambdaQueryWrapper() - .eq(SysDictData::getStatus, "0") + .eq(SysDictData::getStatus, UserConstants.DICT_NORMAL) .eq(SysDictData::getDictType, dictType) .orderByAsc(SysDictData::getDictSort)); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index 70fda9a24..8508d4f86 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -44,7 +44,7 @@ public interface ISysDeptService { SysDept selectDeptById(Long deptId); /** - * 根据ID查询所有子部门(正常状态) + * 根据ID查询所有子部门数(正常状态) * * @param deptId 部门ID * @return 子部门数 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 362e5ef03..0dd441baf 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -92,7 +92,7 @@ public class SysDeptServiceImpl implements ISysDeptService { } /** - * 根据ID查询所有子部门(正常状态) + * 根据ID查询所有子部门数(正常状态) * * @param deptId 部门ID * @return 子部门数 @@ -100,7 +100,7 @@ public class SysDeptServiceImpl implements ISysDeptService { @Override public long selectNormalChildrenDeptById(Long deptId) { return baseMapper.selectCount(new LambdaQueryWrapper() - .eq(SysDept::getStatus, 0) + .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL) .apply("find_in_set({0}, ancestors)", deptId)); } @@ -136,12 +136,11 @@ public class SysDeptServiceImpl implements ISysDeptService { */ @Override public String checkDeptNameUnique(SysDept dept) { - Long deptId = ObjectUtil.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysDept::getDeptName, dept.getDeptName()) .eq(SysDept::getParentId, dept.getParentId()) - .ne(SysDept::getDeptId, deptId)); - if (count) { + .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -199,7 +198,7 @@ public class SysDeptServiceImpl implements ISysDeptService { } int result = baseMapper.updateById(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) - && !StringUtils.equals("0", dept.getAncestors())) { + && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) { // 如果该部门是启用状态,则启用该部门的所有上级部门 updateParentDeptStatusNormal(dept); } @@ -215,7 +214,7 @@ public class SysDeptServiceImpl implements ISysDeptService { String ancestors = dept.getAncestors(); Long[] deptIds = Convert.toLongArray(ancestors); baseMapper.update(null, new LambdaUpdateWrapper() - .set(SysDept::getStatus, "0") + .set(SysDept::getStatus, UserConstants.DEPT_NORMAL) .in(SysDept::getDeptId, Arrays.asList(deptIds))); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index 42ef2c990..00a491c31 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -129,8 +129,8 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService public void deleteDictTypeByIds(Long[] dictIds) { for (Long dictId : dictIds) { SysDictType dictType = selectDictTypeById(dictId); - if (dictDataMapper.selectCount(new LambdaQueryWrapper() - .eq(SysDictData::getDictType, dictType.getDictType())) > 0) { + if (dictDataMapper.exists(new LambdaQueryWrapper() + .eq(SysDictData::getDictType, dictType.getDictType()))) { throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName())); } RedisUtils.deleteObject(getCacheKey(dictType.getDictType())); @@ -144,7 +144,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService @Override public void loadingDictCache() { List dictDataList = dictDataMapper.selectList( - new LambdaQueryWrapper().eq(SysDictData::getStatus, "0")); + new LambdaQueryWrapper().eq(SysDictData::getStatus, UserConstants.DICT_NORMAL)); Map> dictDataMap = dictDataList.stream().collect(Collectors.groupingBy(SysDictData::getDictType)); dictDataMap.forEach((k,v) -> { String dictKey = getCacheKey(k); @@ -217,11 +217,10 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService, DictService */ @Override public String checkDictTypeUnique(SysDictType dict) { - Long dictId = ObjectUtil.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - long count = baseMapper.selectCount(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysDictType::getDictType, dict.getDictType()) - .ne(SysDictType::getDictId, dictId)); - if (count > 0) { + .ne(ObjectUtil.isNotNull(dict.getDictId()), SysDictType::getDictId, dict.getDictId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 4fe4b5d87..431ec95f3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -263,12 +263,11 @@ public class SysMenuServiceImpl implements ISysMenuService { */ @Override public String checkMenuNameUnique(SysMenu menu) { - Long menuId = ObjectUtil.isNull(menu.getMenuId()) ? -1L : menu.getMenuId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysMenu::getMenuName, menu.getMenuName()) .eq(SysMenu::getParentId, menu.getParentId()) - .ne(SysMenu::getMenuId, menuId)); - if (count) { + .ne(ObjectUtil.isNotNull(menu.getMenuId()), SysMenu::getMenuId, menu.getMenuId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index eb08fb136..31071d16d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -95,11 +95,10 @@ public class SysPostServiceImpl implements ISysPostService { */ @Override public String checkPostNameUnique(SysPost post) { - Long postId = ObjectUtil.isNull(post.getPostId()) ? -1L : post.getPostId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysPost::getPostName, post.getPostName()) - .ne(SysPost::getPostId, postId)); - if (count) { + .ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -113,11 +112,10 @@ public class SysPostServiceImpl implements ISysPostService { */ @Override public String checkPostCodeUnique(SysPost post) { - Long postId = ObjectUtil.isNull(post.getPostId()) ? -1L : post.getPostId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysPost::getPostCode, post.getPostCode()) - .ne(SysPost::getPostId, postId)); - if (count) { + .ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index 8b61b2d5f..81b8d66fe 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -136,11 +136,10 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public String checkRoleNameUnique(SysRole role) { - Long roleId = ObjectUtil.isNull(role.getRoleId()) ? -1L : role.getRoleId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysRole::getRoleName, role.getRoleName()) - .ne(SysRole::getRoleId, roleId)); - if (count) { + .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -154,11 +153,10 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public String checkRoleKeyUnique(SysRole role) { - Long roleId = ObjectUtil.isNull(role.getRoleId()) ? -1L : role.getRoleId(); - boolean count = baseMapper.exists(new LambdaQueryWrapper() + boolean exist = baseMapper.exists(new LambdaQueryWrapper() .eq(SysRole::getRoleKey, role.getRoleKey()) - .ne(SysRole::getRoleId, roleId)); - if (count) { + .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE;