bug--完善代码
This commit is contained in:
@ -49,6 +49,7 @@ public class Role implements Serializable {
|
||||
/** 角色级别 */
|
||||
private Integer level;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Set<Menu> menus;
|
||||
|
||||
/** 创建日期 */
|
||||
|
@ -44,10 +44,11 @@ public class User implements Serializable {
|
||||
/** 状态:1启用、0禁用 */
|
||||
private Long enabled;
|
||||
|
||||
/** 用户头像ID */
|
||||
@TableId
|
||||
/** 用户头像 */
|
||||
@TableField(exist = false)
|
||||
private UserAvatar userAvatar;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Set<Role> roles;
|
||||
|
||||
/** 密码 */
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
package co.yixiang.modules.system.rest;
|
||||
|
||||
import co.yixiang.exception.EntityExistException;
|
||||
import co.yixiang.logging.aop.log.Log;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
@ -20,6 +21,7 @@ import co.yixiang.modules.system.service.dto.MenuDto;
|
||||
import co.yixiang.modules.system.service.dto.MenuQueryCriteria;
|
||||
import co.yixiang.modules.system.service.dto.UserDto;
|
||||
import co.yixiang.utils.SecurityUtils;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -105,6 +107,22 @@ public class MenuController {
|
||||
if (resources.getId() != null) {
|
||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||
}
|
||||
Menu menu = menuService.getOne(new QueryWrapper<Menu>().eq("name",resources.getName()));
|
||||
if(menu != null){
|
||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
||||
}
|
||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
||||
menu = menuService.getOne(new QueryWrapper<Menu>().eq("componentName",resources.getComponentName()));
|
||||
if(menu != null){
|
||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||
}
|
||||
}
|
||||
if(resources.getIFrame()){
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(menuService.save(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ -114,7 +132,7 @@ public class MenuController {
|
||||
@PreAuthorize("@el.check('menu:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody Menu resources){
|
||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||
menuService.saveOrUpdate(resources);
|
||||
menuService.update(resources);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@ -130,7 +148,7 @@ public class MenuController {
|
||||
menuSet.add(menuService.getOne(new QueryWrapper<Menu>().eq("pid",id)));
|
||||
menuSet = menuService.getDeleteMenus(menuList, menuSet);
|
||||
}
|
||||
menuService.removeByIds(menuSet);
|
||||
menuService.delete(menuSet);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -91,4 +91,16 @@ public interface MenuService extends BaseService<Menu>{
|
||||
* @return /
|
||||
*/
|
||||
List<MenuDto> findByRoles(List<RoleSmallDto> roles);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param menuSet /
|
||||
*/
|
||||
void delete(Set<Menu> menuSet);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
*/
|
||||
void update(Menu resources);
|
||||
}
|
||||
|
@ -10,11 +10,17 @@ package co.yixiang.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.exception.BadRequestException;
|
||||
import co.yixiang.exception.EntityExistException;
|
||||
import co.yixiang.modules.system.domain.Menu;
|
||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||
import co.yixiang.modules.system.domain.vo.MenuMetaVo;
|
||||
import co.yixiang.modules.system.domain.vo.MenuVo;
|
||||
import co.yixiang.modules.system.service.dto.RoleSmallDto;
|
||||
import co.yixiang.modules.system.service.mapper.RoleMapper;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import co.yixiang.dozer.service.IGenerator;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
@ -24,6 +30,7 @@ import co.yixiang.modules.system.service.MenuService;
|
||||
import co.yixiang.modules.system.service.dto.MenuDto;
|
||||
import co.yixiang.modules.system.service.dto.MenuQueryCriteria;
|
||||
import co.yixiang.modules.system.service.mapper.MenuMapper;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -57,6 +64,7 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
||||
|
||||
private final IGenerator generator;
|
||||
private final MenuMapper menuMapper;
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
@ -255,4 +263,64 @@ public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implement
|
||||
public List<MenuDto> findByRoles(List<RoleSmallDto> roles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param menuSet /
|
||||
*/
|
||||
@Override
|
||||
public void delete(Set<Menu> menuSet) {
|
||||
for (Menu menu : menuSet) {
|
||||
roleMapper.untiedMenu(menu.getId());
|
||||
this.removeById(menu.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param resources /
|
||||
*/
|
||||
@Override
|
||||
@CacheEvict(allEntries = true)
|
||||
public void update(Menu resources) {
|
||||
if(resources.getId().equals(resources.getPid())) {
|
||||
throw new BadRequestException("上级不能为自己");
|
||||
}
|
||||
Menu menu = this.getById(resources.getId());
|
||||
ValidationUtil.isNull(menu.getId(),"Permission","id",resources.getId());
|
||||
|
||||
if(resources.getIFrame()){
|
||||
String http = "http://", https = "https://";
|
||||
if (!(resources.getPath().toLowerCase().startsWith(http)||resources.getPath().toLowerCase().startsWith(https))) {
|
||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||
}
|
||||
}
|
||||
Menu menu1 = this.getOne(new QueryWrapper<Menu>().eq("name",resources.getName()));
|
||||
|
||||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
||||
menu1 = this.getOne(new QueryWrapper<Menu>().eq("componentName",resources.getComponentName()));
|
||||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
||||
}
|
||||
}
|
||||
menu.setName(resources.getName());
|
||||
menu.setComponent(resources.getComponent());
|
||||
menu.setPath(resources.getPath());
|
||||
menu.setIcon(resources.getIcon());
|
||||
menu.setIFrame(resources.getIFrame());
|
||||
menu.setPid(resources.getPid());
|
||||
menu.setSort(resources.getSort());
|
||||
menu.setCache(resources.getCache());
|
||||
menu.setHidden(resources.getHidden());
|
||||
menu.setComponentName(resources.getComponentName());
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
this.save(menu);
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ import java.util.stream.Collectors;
|
||||
public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implements RoleService {
|
||||
|
||||
private final IGenerator generator;
|
||||
private final RoleMapper roleMapper;
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
@ -161,9 +162,9 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
||||
* @return 权限信息
|
||||
*/
|
||||
@Override
|
||||
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
//@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(UserDto user) {
|
||||
Set<Role> roles = (Set<Role>) this.getOne(new QueryWrapper<Role>().eq("id",user.getId()));
|
||||
Set<Role> roles = roleMapper.findByUsers_Id(user.getId());
|
||||
Set<String> permissions = roles.stream().filter(role -> StringUtils.isNotBlank(role.getPermission())).map(Role::getPermission).collect(Collectors.toSet());
|
||||
permissions.addAll(
|
||||
roles.stream().flatMap(role -> role.getMenus().stream())
|
||||
|
@ -10,7 +10,10 @@ package co.yixiang.modules.system.service.mapper;
|
||||
|
||||
import co.yixiang.common.mapper.CoreMapper;
|
||||
import co.yixiang.modules.system.domain.Role;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Set;
|
||||
@ -28,6 +31,17 @@ public interface RoleMapper extends CoreMapper<Role> {
|
||||
* @param id 用户ID
|
||||
* @return
|
||||
*/
|
||||
Set<Role> findByUsers_Id(Long id);
|
||||
@Select( "SELECT r.id,r.create_time,r.data_scope,r.`level`,r.`name`,r.permission,r.remark " +
|
||||
"FROM role r LEFT OUTER JOIN users_roles u1 ON r.id = u1.role_id " +
|
||||
"LEFT OUTER JOIN USER u2 ON u1.user_id = u2.id "+
|
||||
"WHERE u2.id = #{id}")
|
||||
Set<Role> findByUsers_Id(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 解绑角色菜单
|
||||
* @param id 菜单ID
|
||||
*/
|
||||
@Delete("delete from roles_menus where menu_id = #{id}")
|
||||
void untiedMenu(@Param("id") Long id);
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,6 @@ public interface SysUserMapper extends CoreMapper<User> {
|
||||
* @param email 邮箱
|
||||
*/
|
||||
@Update("update `user` set email = email+ ${email} where username = #{username}")
|
||||
void updateEmail(@Param("username") String email, @Param("username") String username);
|
||||
void updateEmail(@Param("email") String email, @Param("username") String username);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user