|
|
|
@ -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<TbRole> list = roleMapper.selectByExample(example);
|
|
|
|
|
TbRole item = new TbRole();
|
|
|
|
|
item.setId(SUPER_ADMIN);
|
|
|
|
|
item.setName(SUPER_ADMIN_NAME);
|
|
|
|
|
list.add(0, 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<TbRole> 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<TbRole> list = roleMapper.selectByExample(example);
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
throw new ApiException("名称已存在");
|
|
|
|
|
}
|
|
|
|
|
roleMapper.updateByPrimaryKey(item);
|
|
|
|
|
}
|
|
|
|
@ -68,9 +94,13 @@ 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);
|
|
|
|
|
TbPermissionExample example = new TbPermissionExample();
|
|
|
|
|
TbPermissionExample.Criteria criteria = example.createCriteria();
|
|
|
|
|
criteria.andRoleIdEqualTo(id);
|
|
|
|
|
permissionMapper.deleteByExample(example);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -112,7 +142,7 @@ public class RoleServiceImpl implements RoleService {
|
|
|
|
|
@Override
|
|
|
|
|
public void changePermission(Integer roleId, List<TbPermission> 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();
|
|
|
|
|