diff --git a/boot-service/src/main/java/com/xwbing/domain/repository/sys/SysAuthorityRepository.java b/boot-service/src/main/java/com/xwbing/domain/repository/sys/SysAuthorityRepository.java index 8e46407..538dc5a 100644 --- a/boot-service/src/main/java/com/xwbing/domain/repository/sys/SysAuthorityRepository.java +++ b/boot-service/src/main/java/com/xwbing/domain/repository/sys/SysAuthorityRepository.java @@ -14,15 +14,15 @@ import java.util.List; public interface SysAuthorityRepository extends JpaRepository { SysAuthority getByCode(String code); - List getByEnable(String enable); + List getByEnableOrderBySort(String enable); - List getByParentIdAndEnable(String parentId, String enable); + List getByParentIdAndEnableOrderBySort(String parentId, String enable); - List getByParentId(String parentId); + List getByParentIdOrderBySort(String parentId); - List getByEnableAndIdIn(String enable, List ids); + List getByEnableAndIdInOrderBySort(String enable, List ids); - List getByIdIn(List ids); + List getByIdInOrderBySort(List ids); SysAuthority getBySort(int sort); } diff --git a/boot-service/src/main/java/com/xwbing/service/sys/SysAuthorityService.java b/boot-service/src/main/java/com/xwbing/service/sys/SysAuthorityService.java index 5331856..e5b4870 100644 --- a/boot-service/src/main/java/com/xwbing/service/sys/SysAuthorityService.java +++ b/boot-service/src/main/java/com/xwbing/service/sys/SysAuthorityService.java @@ -145,9 +145,9 @@ public class SysAuthorityService { */ public List listByEnable(String enable) { if (StringUtils.isNotEmpty(enable)) - return sysAuthorityRepository.getByEnable(enable); + return sysAuthorityRepository.getByEnableOrderBySort(enable); else - return sysAuthorityRepository.findAll(); + return sysAuthorityRepository.findAll(new Sort(Sort.Direction.ASC, "sort")); } /** @@ -158,12 +158,10 @@ public class SysAuthorityService { * @return */ public List listByParentEnable(String parentId, String enable) { - if (StringUtils.isEmpty(parentId)) - parentId = CommonConstant.ROOT; if (StringUtils.isNotEmpty(enable)) - return sysAuthorityRepository.getByParentIdAndEnable(parentId, enable); + return sysAuthorityRepository.getByParentIdAndEnableOrderBySort(parentId, enable); else - return sysAuthorityRepository.getByParentId(parentId); + return sysAuthorityRepository.getByParentIdOrderBySort(parentId); } /** @@ -181,9 +179,9 @@ public class SysAuthorityService { List authorityIds = roleAuthorities.stream().map(SysRoleAuthority::getAuthorityId).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(authorityIds)) if (StringUtils.isNotEmpty(enable)) - list = sysAuthorityRepository.getByEnableAndIdIn(enable, authorityIds); + list = sysAuthorityRepository.getByEnableAndIdInOrderBySort(enable, authorityIds); else - list = sysAuthorityRepository.getByIdIn(authorityIds); + list = sysAuthorityRepository.getByIdInOrderBySort(authorityIds); return list; } @@ -214,9 +212,9 @@ public class SysAuthorityService { List list = new ArrayList<>(); List authoritys; if (StringUtils.isNotEmpty(enable)) - authoritys = sysAuthorityRepository.getByParentIdAndEnable(parentId, enable); + authoritys = sysAuthorityRepository.getByParentIdAndEnableOrderBySort(parentId, enable); else - authoritys = sysAuthorityRepository.getByParentId(parentId); + authoritys = sysAuthorityRepository.getByParentIdOrderBySort(parentId); if (CollectionUtils.isEmpty(authoritys)) return list; SysAuthVo vo; diff --git a/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java b/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java index ee8768d..0eb4dc9 100644 --- a/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/sys/SysAuthorityControl.java @@ -101,6 +101,8 @@ public class SysAuthorityControl { @ApiOperation(value = "根据父节点查询子节点") @ApiImplicitParam(name = "parentId", value = "父id,可为空", paramType = "query", dataType = "string") public JSONObject listByParentId(String parentId) { + if(StringUtils.isEmpty(parentId)) + parentId=CommonConstant.ROOT; if (!CommonConstant.ROOT.equals(parentId) && sysAuthorityService.getById(parentId) == null) return JSONObjResult.toJSONObj("父节点不存在"); List queryByParentId = sysAuthorityService.listByParentEnable(parentId, null);