diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java index b2c8ea6..b96c91a 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java @@ -43,4 +43,8 @@ public class SysAuthority extends BaseEntity { * 类型 2按钮 1菜单 */ private Integer type; + /** + * 排序 + */ + private Integer sort; } 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 a11ec06..8e46407 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 @@ -23,4 +23,6 @@ public interface SysAuthorityRepository extends JpaRepository getByEnableAndIdIn(String enable, List ids); List getByIdIn(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 5ed7153..5331856 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 @@ -10,6 +10,7 @@ import com.xwbing.util.PassWordUtil; import com.xwbing.util.RestMessage; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -39,9 +40,19 @@ public class SysAuthorityService { */ public RestMessage save(SysAuthority sysAuthority) { RestMessage result = new RestMessage(); + //检查编码 boolean b = uniqueCode(sysAuthority.getCode(), null); if (!b) throw new BusinessException("该编码已存在"); + //排序处理 + if (sysAuthority.getSort() == null) { + int sort = getSort() + 1; + sysAuthority.setSort(sort); + } else { + boolean sorted = uniqueSort(sysAuthority.getSort(), null); + if (!sorted) + throw new BusinessException("该排序编号已存在"); + } String id = PassWordUtil.createId(); sysAuthority.setId(id); sysAuthority.setCreateTime(new Date()); @@ -92,11 +103,16 @@ public class SysAuthorityService { SysAuthority old = getById(id); if (old == null) throw new BusinessException("该权限不存在"); - boolean b = uniqueCode(sysAuthority.getCode(), id); - if (!b) - throw new BusinessException("该编码已存在"); +// boolean b = uniqueCode(sysAuthority.getCode(), id); +// if (!b) +// throw new BusinessException("该编码已存在"); +// old.setCode(sysAuthority.getCode()); + //检查排序 + boolean sorted = uniqueSort(sysAuthority.getSort(), id); + if (!sorted) + throw new BusinessException("该排序编号已存在"); + old.setSort(sysAuthority.getSort()); old.setName(sysAuthority.getName()); - old.setCode(sysAuthority.getCode()); old.setEnable(sysAuthority.getEnable()); old.setUrl(sysAuthority.getUrl()); old.setType(sysAuthority.getType()); @@ -142,8 +158,8 @@ public class SysAuthorityService { * @return */ public List listByParentEnable(String parentId, String enable) { - if(StringUtils.isEmpty(parentId)) - parentId=CommonConstant.ROOT; + if (StringUtils.isEmpty(parentId)) + parentId = CommonConstant.ROOT; if (StringUtils.isNotEmpty(enable)) return sysAuthorityRepository.getByParentIdAndEnable(parentId, enable); else @@ -212,6 +228,21 @@ public class SysAuthorityService { return list; } + /** + * 获取最大顺序 + * + * @return + */ + private int getSort() { + Sort sort = new Sort(Sort.Direction.DESC, "sort"); + List all = sysAuthorityRepository.findAll(sort); + if (CollectionUtils.isNotEmpty(all)) { + return all.get(0).getSort(); + } else { + return 0; + } + } + /** * 递归查询父节点下所有权限的id集合,并将状态设置为禁用(禁用权限时用) * @@ -271,4 +302,22 @@ public class SysAuthorityService { return true; } } + + /** + * 检查排序是否存在 + * + * @param sort + * @param id + * @return + */ + private boolean uniqueSort(Integer sort, String id) { + if (sort == null) + throw new BusinessException("sort不能为空"); + SysAuthority one = sysAuthorityRepository.getBySort(sort); + if (one != null) { + return StringUtils.isNotEmpty(id) && id.equals(one.getId()); + } else { + return true; + } + } } diff --git a/boot-service/src/main/java/com/xwbing/service/sys/SysRoleService.java b/boot-service/src/main/java/com/xwbing/service/sys/SysRoleService.java index 7a40279..deac922 100644 --- a/boot-service/src/main/java/com/xwbing/service/sys/SysRoleService.java +++ b/boot-service/src/main/java/com/xwbing/service/sys/SysRoleService.java @@ -40,6 +40,7 @@ public class SysRoleService { */ public RestMessage save(SysRole sysRole) { RestMessage result = new RestMessage(); + //检查编码 boolean b = uniqueCode(sysRole.getCode(), null); if (!b) throw new BusinessException("该编码已存在"); @@ -91,6 +92,7 @@ public class SysRoleService { SysRole old = getById(id); if (old == null) throw new BusinessException("该角色不存在"); + //检查编码 boolean b = uniqueCode(sysRole.getCode(), id); if (!b) throw new BusinessException("该编码已存在"); diff --git a/boot-web/src/main/java/com/xwbing/controller/TestControl.java b/boot-web/src/main/java/com/xwbing/controller/TestControl.java index 777f787..09a1f8a 100644 --- a/boot-web/src/main/java/com/xwbing/controller/TestControl.java +++ b/boot-web/src/main/java/com/xwbing/controller/TestControl.java @@ -113,4 +113,6 @@ public class TestControl { String url = "http://localhost:8080/user/save"; return HttpClientUtil.postByJson(url, param); } + + }