merge
This commit is contained in:
@@ -53,11 +53,13 @@ public class SysAuthorityService {
|
||||
if (!sorted)
|
||||
throw new BusinessException("该排序编号已存在");
|
||||
}
|
||||
//添加必要参数
|
||||
String id = PassWordUtil.createId();
|
||||
sysAuthority.setId(id);
|
||||
sysAuthority.setCreateTime(new Date());
|
||||
if (StringUtils.isEmpty(sysAuthority.getParentId()))
|
||||
sysAuthority.setParentId(CommonConstant.ROOT);
|
||||
//保存
|
||||
SysAuthority save = sysAuthorityRepository.save(sysAuthority);
|
||||
if (save != null) {
|
||||
result.setSuccess(true);
|
||||
@@ -77,6 +79,7 @@ public class SysAuthorityService {
|
||||
*/
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
//判断该权限是否存在
|
||||
SysAuthority one = getById(id);
|
||||
if (one == null)
|
||||
throw new BusinessException("该权限不存在");
|
||||
@@ -100,17 +103,20 @@ public class SysAuthorityService {
|
||||
public RestMessage update(SysAuthority sysAuthority) {
|
||||
RestMessage result = new RestMessage();
|
||||
String id = sysAuthority.getId();
|
||||
//判断该权限是否存在
|
||||
SysAuthority old = getById(id);
|
||||
if (old == null)
|
||||
throw new BusinessException("该权限不存在");
|
||||
//检查排序
|
||||
//检查排序是否重复
|
||||
boolean sorted = uniqueSort(sysAuthority.getSort(), id);
|
||||
if (!sorted)
|
||||
throw new BusinessException("该排序编号已存在");
|
||||
old.setSort(sysAuthority.getSort());
|
||||
//其他参数更新
|
||||
old.setName(sysAuthority.getName());
|
||||
old.setEnable(sysAuthority.getEnable());
|
||||
old.setUrl(sysAuthority.getUrl());
|
||||
// old.setCode(sysAuthority.getCode());编码不能修改
|
||||
old.setType(sysAuthority.getType());
|
||||
SysAuthority save = sysAuthorityRepository.save(old);
|
||||
if (save != null) {
|
||||
@@ -169,9 +175,11 @@ public class SysAuthorityService {
|
||||
*/
|
||||
public List<SysAuthority> listByRoleIdEnable(String roleId, String enable) {
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
// 从角色权限表中获取所有该角色id的权限
|
||||
List<SysRoleAuthority> roleAuthorities = sysRoleAuthorityService.listByRoleId(roleId);
|
||||
if (CollectionUtils.isEmpty(roleAuthorities))
|
||||
return list;
|
||||
//根据权限id获取对应权限列表
|
||||
List<String> authorityIds = roleAuthorities.stream().map(SysRoleAuthority::getAuthorityId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(authorityIds))
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
@@ -189,7 +197,9 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
public boolean disableChildrenByParentId(String parentId) {
|
||||
//递归查询父节点下所有权限的id集合,并将状态设置为禁用
|
||||
List<SysAuthority> sysAuthorities = disableChildren(parentId);
|
||||
//批量修改权限
|
||||
if (CollectionUtils.isNotEmpty(sysAuthorities)) {
|
||||
List<SysAuthority> save = sysAuthorityRepository.save(sysAuthorities);
|
||||
return CollectionUtils.isNotEmpty(save);
|
||||
@@ -244,7 +254,7 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
private List<SysAuthority> disableChildren(String parentId) {
|
||||
//获取结果
|
||||
//根据状态查询所有子节点
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, CommonConstant.IS_ENABLE);
|
||||
//遍历子集
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
@@ -266,7 +276,7 @@ public class SysAuthorityService {
|
||||
* @return
|
||||
*/
|
||||
private List<SysAuthority> listChildrenForRemove(String parentId) {
|
||||
//获取结果
|
||||
//根据状态查询所有子节点
|
||||
List<SysAuthority> sysAuthoritys = listByParentEnable(parentId, null);
|
||||
//遍历子集
|
||||
List<SysAuthority> list = new ArrayList<>();
|
||||
@@ -286,7 +296,7 @@ public class SysAuthorityService {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private boolean uniqueCode(String code, String id) {
|
||||
private boolean uniqueCode(String code, String id) {
|
||||
if (StringUtils.isEmpty(code))
|
||||
throw new BusinessException("code不能为空");
|
||||
SysAuthority one = sysAuthorityRepository.getByCode(code);
|
||||
|
||||
@@ -25,12 +25,19 @@ public class SysConfigService {
|
||||
private SysConfigRepository sysConfigRepository;
|
||||
private static Logger logger = LoggerFactory.getLogger(SysConfigService.class);
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param sysConfig
|
||||
* @return
|
||||
*/
|
||||
public RestMessage save(SysConfig sysConfig) {
|
||||
logger.info("保存配置信息");
|
||||
RestMessage result = new RestMessage();
|
||||
if (sysConfig == null) {
|
||||
throw new BusinessException("配置数据不能为空");
|
||||
}
|
||||
//检查code是否存在
|
||||
SysConfig old = getByCode(sysConfig.getCode());
|
||||
if (old != null) {
|
||||
throw new BusinessException(sysConfig.getCode() + "已存在");
|
||||
@@ -47,6 +54,12 @@ public class SysConfigService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code删除配置
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public RestMessage removeByCode(String code) {
|
||||
logger.info("删除配置信息");
|
||||
RestMessage result = new RestMessage();
|
||||
@@ -60,6 +73,12 @@ public class SysConfigService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*
|
||||
* @param sysConfig
|
||||
* @return
|
||||
*/
|
||||
public RestMessage update(SysConfig sysConfig) {
|
||||
RestMessage result = new RestMessage();
|
||||
SysConfig old = getByCode(sysConfig.getCode());
|
||||
@@ -79,10 +98,22 @@ public class SysConfigService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code查找配置
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
public SysConfig getByCode(String code) {
|
||||
return sysConfigRepository.getByCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态获取配置列表
|
||||
*
|
||||
* @param enable
|
||||
* @return
|
||||
*/
|
||||
public List<SysConfig> listByEnable(String enable) {
|
||||
return sysConfigRepository.getByEnable(enable);
|
||||
}
|
||||
|
||||
@@ -144,9 +144,11 @@ public class SysRoleService {
|
||||
*/
|
||||
public List<SysRole> listByUserIdEnable(String userId, String enable) {
|
||||
List<SysRole> list = new ArrayList<>();
|
||||
//从用户角色表中获取所有该用户id的角色
|
||||
List<SysUserRole> sysUserRoles = sysUserRoleService.listByUserId(userId);
|
||||
if (sysUserRoles == null)
|
||||
return list;
|
||||
//根据角色id获取对应角色列表
|
||||
List<String> roleIds = sysUserRoles.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(roleIds))
|
||||
if (StringUtils.isNotEmpty(enable))
|
||||
|
||||
@@ -52,6 +52,7 @@ public class SysUserService {
|
||||
*/
|
||||
public RestMessage save(SysUser sysUser) {
|
||||
RestMessage result = new RestMessage();
|
||||
//检查用户名是否存在
|
||||
SysUser old = getByUserName(sysUser.getUserName());
|
||||
if (old != null) {
|
||||
throw new BusinessException("已经存在此用户名");
|
||||
@@ -63,7 +64,7 @@ public class SysUserService {
|
||||
String[] res = PassWordUtil.getUserSecret(null, null);
|
||||
sysUser.setSalt(res[1]);
|
||||
sysUser.setPassword(res[2]);
|
||||
// 设置否管理员
|
||||
// 设置为非管理员
|
||||
sysUser.setAdmin(CommonEnum.YesOrNoEnum.NO.getCode());
|
||||
SysUser one = sysUserRepository.save(sysUser);
|
||||
if (one == null) {
|
||||
@@ -88,6 +89,7 @@ public class SysUserService {
|
||||
*/
|
||||
public RestMessage removeById(String id) {
|
||||
RestMessage result = new RestMessage();
|
||||
//检查该用户是否存在
|
||||
SysUser old = getById(id);
|
||||
if (old == null) {
|
||||
throw new BusinessException("该用户不存在");
|
||||
@@ -119,6 +121,7 @@ public class SysUserService {
|
||||
*/
|
||||
public RestMessage update(SysUser sysUser) {
|
||||
RestMessage result = new RestMessage();
|
||||
//检查该用户是否存在
|
||||
SysUser old = getById(sysUser.getId());
|
||||
if (old == null) {
|
||||
throw new BusinessException("该用户不存在");
|
||||
@@ -192,6 +195,7 @@ public class SysUserService {
|
||||
if (CommonEnum.YesOrNoEnum.YES.getCode().equals(old.getAdmin())) {
|
||||
throw new BusinessException("管理员密码不能重置");
|
||||
}
|
||||
//生成密码
|
||||
String[] str = PassWordUtil.getUserSecret(null, null);
|
||||
old.setSalt(str[1]);
|
||||
old.setPassword(str[2]);
|
||||
@@ -222,6 +226,7 @@ public class SysUserService {
|
||||
boolean flag = checkPassWord(oldPassWord, sysUser.getPassword(), sysUser.getSalt());
|
||||
if (!flag)
|
||||
throw new BusinessException("原密码错误,请重新输入");
|
||||
//生成密码
|
||||
String[] str = PassWordUtil.getUserSecret(newPassWord, null);
|
||||
sysUser.setSalt(str[1]);
|
||||
sysUser.setPassword(str[2]);
|
||||
@@ -258,6 +263,7 @@ public class SysUserService {
|
||||
boolean flag = checkPassWord(passWord, user.getPassword(), user.getSalt());
|
||||
if (!flag)
|
||||
throw new BusinessException("密码错误");
|
||||
//保存登录数据
|
||||
CommonDataUtil.setToken(CommonConstant.CURRENT_USER, userName);
|
||||
CommonDataUtil.setToken(CommonConstant.CURRENT_USER_ID, user.getId());
|
||||
//保存登录信息
|
||||
|
||||
@@ -64,7 +64,7 @@ public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addViewController("/").setViewName("login.html");
|
||||
registry.addRedirectViewController("doc", "swagger-ui.html");
|
||||
//添加更多
|
||||
//添加更多......
|
||||
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
super.addViewControllers(registry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user