mirror of https://github.com/elunez/eladmin
parent
8480f0e1d5
commit
7653da3d0d
|
@ -23,6 +23,6 @@ public class ElPermissionConfig {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 判断当前用户的所有权限是否包含接口上定义的权限
|
// 判断当前用户的所有权限是否包含接口上定义的权限
|
||||||
return Arrays.stream(permissions).filter(elPermissions::contains).collect(Collectors.toList()).size() > 0;
|
return Arrays.stream(permissions).anyMatch(elPermissions::contains);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import org.lionsoul.ip2region.DataBlock;
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
import org.lionsoul.ip2region.DbConfig;
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
import org.lionsoul.ip2region.DbSearcher;
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -13,6 +14,10 @@ import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
||||||
|
@ -123,7 +128,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
if (ip.contains(",")) {
|
if (ip.contains(",")) {
|
||||||
ip = ip.split(",")[0];
|
ip = ip.split(",")[0];
|
||||||
}
|
}
|
||||||
if ("127.0.0.1".equals(ip)) {
|
if ("127.0.0.1".equals(ip)) {
|
||||||
// 获取本机真正的ip地址
|
// 获取本机真正的ip地址
|
||||||
try {
|
try {
|
||||||
ip = InetAddress.getLocalHost().getHostAddress();
|
ip = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
@ -148,18 +153,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
method = searcher.getClass().getMethod("btreeSearch", String.class);
|
||||||
DataBlock dataBlock;
|
DataBlock dataBlock;
|
||||||
dataBlock = (DataBlock) method.invoke(searcher, ip);
|
dataBlock = (DataBlock) method.invoke(searcher, ip);
|
||||||
String address = dataBlock.getRegion().replace("0|","");
|
String address = dataBlock.getRegion().replace("0|", "");
|
||||||
if(address.charAt(address.length()-1) == '|'){
|
if (address.charAt(address.length() - 1) == '|') {
|
||||||
address = address.substring(0,address.length() - 1);
|
address = address.substring(0, address.length() - 1);
|
||||||
}
|
}
|
||||||
return address.equals(ElAdminConstant.REGION)?"内网IP":address;
|
return address.equals(ElAdminConstant.REGION) ? "内网IP" : address;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBrowser(HttpServletRequest request){
|
public static String getBrowser(HttpServletRequest request) {
|
||||||
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
|
||||||
Browser browser = userAgent.getBrowser();
|
Browser browser = userAgent.getBrowser();
|
||||||
return browser.getName();
|
return browser.getName();
|
||||||
|
@ -168,15 +173,25 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
/**
|
/**
|
||||||
* 获得当天是周几
|
* 获得当天是周几
|
||||||
*/
|
*/
|
||||||
public static String getWeekDay(){
|
public static String getWeekDay() {
|
||||||
String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
String[] weekDays = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(new Date());
|
cal.setTime(new Date());
|
||||||
|
|
||||||
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
if (w < 0){
|
if (w < 0) {
|
||||||
w = 0;
|
w = 0;
|
||||||
}
|
}
|
||||||
return weekDays[w];
|
return weekDays[w];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<String> findRoles(String roleStr) {
|
||||||
|
// String line = "hasAnyRole('ROLE_ANONYMOUS') or hasAnyRole('kkjd','ddd') or @el.check('dept:list')";
|
||||||
|
Set<String> roles = new HashSet<>();
|
||||||
|
Matcher m = Pattern.compile("'([\\w:]+)'").matcher(roleStr);
|
||||||
|
while (m.find()) {
|
||||||
|
roles.add(m.group(1));
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,4 +19,6 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
|
||||||
List<Menu> findByPid(long pid);
|
List<Menu> findByPid(long pid);
|
||||||
|
|
||||||
LinkedHashSet<Menu> findByRoles_IdAndTypeIsNotInOrderBySortAsc(Long id, Integer type);
|
LinkedHashSet<Menu> findByRoles_IdAndTypeIsNotInOrderBySortAsc(Long id, Integer type);
|
||||||
|
|
||||||
|
List<Menu> findMenusByType(Integer type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class MenuController {
|
||||||
@PreAuthorize("@el.check('menu:list')")
|
@PreAuthorize("@el.check('menu:list')")
|
||||||
public ResponseEntity getMenus(MenuQueryCriteria criteria){
|
public ResponseEntity getMenus(MenuQueryCriteria criteria){
|
||||||
List<MenuDTO> menuDTOList = menuService.queryAll(criteria);
|
List<MenuDTO> menuDTOList = menuService.queryAll(criteria);
|
||||||
|
menuService.autoRegisterSysMenu();
|
||||||
return new ResponseEntity<>(menuService.buildTree(menuDTOList),HttpStatus.OK);
|
return new ResponseEntity<>(menuService.buildTree(menuDTOList),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,4 +42,6 @@ public interface MenuService {
|
||||||
void delete(Set<Menu> menuSet);
|
void delete(Set<Menu> menuSet);
|
||||||
|
|
||||||
void download(List<MenuDTO> queryAll, HttpServletResponse response) throws IOException;
|
void download(List<MenuDTO> queryAll, HttpServletResponse response) throws IOException;
|
||||||
|
|
||||||
|
void autoRegisterSysMenu();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package me.zhengjie.modules.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import me.zhengjie.aop.log.Log;
|
||||||
import me.zhengjie.modules.system.domain.Menu;
|
import me.zhengjie.modules.system.domain.Menu;
|
||||||
import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
|
import me.zhengjie.modules.system.domain.vo.MenuMetaVo;
|
||||||
import me.zhengjie.modules.system.domain.vo.MenuVo;
|
import me.zhengjie.modules.system.domain.vo.MenuVo;
|
||||||
|
@ -22,9 +24,15 @@ import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||||
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -40,6 +48,8 @@ public class MenuServiceImpl implements MenuService {
|
||||||
private final MenuMapper menuMapper;
|
private final MenuMapper menuMapper;
|
||||||
|
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
@Resource
|
||||||
|
private RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||||
|
|
||||||
public MenuServiceImpl(MenuRepository menuRepository, MenuMapper menuMapper, RoleService roleService) {
|
public MenuServiceImpl(MenuRepository menuRepository, MenuMapper menuMapper, RoleService roleService) {
|
||||||
this.menuRepository = menuRepository;
|
this.menuRepository = menuRepository;
|
||||||
|
@ -49,16 +59,16 @@ public class MenuServiceImpl implements MenuService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable
|
@Cacheable
|
||||||
public List<MenuDTO> queryAll(MenuQueryCriteria criteria){
|
public List<MenuDTO> queryAll(MenuQueryCriteria criteria) {
|
||||||
// Sort sort = new Sort(Sort.Direction.DESC,"id");
|
// Sort sort = new Sort(Sort.Direction.DESC,"id");
|
||||||
return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "#p0")
|
@Cacheable(key = "#p0")
|
||||||
public MenuDTO findById(long id) {
|
public MenuDTO findById(long id) {
|
||||||
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
||||||
ValidationUtil.isNull(menu.getId(),"Menu","id",id);
|
ValidationUtil.isNull(menu.getId(), "Menu", "id", id);
|
||||||
return menuMapper.toDto(menu);
|
return menuMapper.toDto(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,16 +85,16 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
public MenuDTO create(Menu resources) {
|
public MenuDTO create(Menu resources) {
|
||||||
if(menuRepository.findByName(resources.getName()) != null){
|
if (menuRepository.findByName(resources.getName()) != null) {
|
||||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
throw new EntityExistException(Menu.class, "name", resources.getName());
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
if (StringUtils.isNotBlank(resources.getComponentName())) {
|
||||||
if(menuRepository.findByComponentName(resources.getComponentName()) != null){
|
if (menuRepository.findByComponentName(resources.getComponentName()) != null) {
|
||||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(resources.getIFrame()){
|
if (resources.getIFrame()) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith("http://")||resources.getPath().toLowerCase().startsWith("https://"))) {
|
if (!(resources.getPath().toLowerCase().startsWith("http://") || resources.getPath().toLowerCase().startsWith("https://"))) {
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,27 +104,27 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(allEntries = true)
|
@CacheEvict(allEntries = true)
|
||||||
public void update(Menu resources) {
|
public void update(Menu resources) {
|
||||||
if(resources.getId().equals(resources.getPid())) {
|
if (resources.getId().equals(resources.getPid())) {
|
||||||
throw new BadRequestException("上级不能为自己");
|
throw new BadRequestException("上级不能为自己");
|
||||||
}
|
}
|
||||||
Menu menu = menuRepository.findById(resources.getId()).orElseGet(Menu::new);
|
Menu menu = menuRepository.findById(resources.getId()).orElseGet(Menu::new);
|
||||||
ValidationUtil.isNull(menu.getId(),"Permission","id",resources.getId());
|
ValidationUtil.isNull(menu.getId(), "Permission", "id", resources.getId());
|
||||||
|
|
||||||
if(resources.getIFrame()){
|
if (resources.getIFrame()) {
|
||||||
if (!(resources.getPath().toLowerCase().startsWith("http://")||resources.getPath().toLowerCase().startsWith("https://"))) {
|
if (!(resources.getPath().toLowerCase().startsWith("http://") || resources.getPath().toLowerCase().startsWith("https://"))) {
|
||||||
throw new BadRequestException("外链必须以http://或者https://开头");
|
throw new BadRequestException("外链必须以http://或者https://开头");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Menu menu1 = menuRepository.findByName(resources.getName());
|
Menu menu1 = menuRepository.findByName(resources.getName());
|
||||||
|
|
||||||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||||
throw new EntityExistException(Menu.class,"name",resources.getName());
|
throw new EntityExistException(Menu.class, "name", resources.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(resources.getComponentName())){
|
if (StringUtils.isNotBlank(resources.getComponentName())) {
|
||||||
menu1 = menuRepository.findByComponentName(resources.getComponentName());
|
menu1 = menuRepository.findByComponentName(resources.getComponentName());
|
||||||
if(menu1 != null && !menu1.getId().equals(menu.getId())){
|
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
|
||||||
throw new EntityExistException(Menu.class,"componentName",resources.getComponentName());
|
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.setName(resources.getName());
|
menu.setName(resources.getName());
|
||||||
|
@ -138,7 +148,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
for (Menu menu1 : menuList) {
|
for (Menu menu1 : menuList) {
|
||||||
menuSet.add(menu1);
|
menuSet.add(menu1);
|
||||||
List<Menu> menus = menuRepository.findByPid(menu1.getId());
|
List<Menu> menus = menuRepository.findByPid(menu1.getId());
|
||||||
if(menus!=null && menus.size()!=0){
|
if (menus != null && menus.size() != 0) {
|
||||||
getDeleteMenus(menus, menuSet);
|
getDeleteMenus(menus, menuSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,15 +168,15 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'tree'")
|
@Cacheable(key = "'tree'")
|
||||||
public Object getMenuTree(List<Menu> menus) {
|
public Object getMenuTree(List<Menu> menus) {
|
||||||
List<Map<String,Object>> list = new LinkedList<>();
|
List<Map<String, Object>> list = new LinkedList<>();
|
||||||
menus.forEach(menu -> {
|
menus.forEach(menu -> {
|
||||||
if (menu!=null){
|
if (menu != null) {
|
||||||
List<Menu> menuList = menuRepository.findByPid(menu.getId());
|
List<Menu> menuList = menuRepository.findByPid(menu.getId());
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("id",menu.getId());
|
map.put("id", menu.getId());
|
||||||
map.put("label",menu.getName());
|
map.put("label", menu.getName());
|
||||||
if(menuList!=null && menuList.size()!=0){
|
if (menuList != null && menuList.size() != 0) {
|
||||||
map.put("children",getMenuTree(menuList));
|
map.put("children", getMenuTree(menuList));
|
||||||
}
|
}
|
||||||
list.add(map);
|
list.add(map);
|
||||||
}
|
}
|
||||||
|
@ -182,7 +192,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> buildTree(List<MenuDTO> menuDTOS) {
|
public Map<String, Object> buildTree(List<MenuDTO> menuDTOS) {
|
||||||
List<MenuDTO> trees = new ArrayList<>();
|
List<MenuDTO> trees = new ArrayList<>();
|
||||||
Set<Long> ids = new HashSet<>();
|
Set<Long> ids = new HashSet<>();
|
||||||
for (MenuDTO menuDTO : menuDTOS) {
|
for (MenuDTO menuDTO : menuDTOS) {
|
||||||
|
@ -199,11 +209,11 @@ public class MenuServiceImpl implements MenuService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
if(trees.size() == 0){
|
if (trees.size() == 0) {
|
||||||
trees = menuDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
trees = menuDTOS.stream().filter(s -> !ids.contains(s.getId())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
map.put("content",trees);
|
map.put("content", trees);
|
||||||
map.put("totalElements", menuDTOS.size());
|
map.put("totalElements", menuDTOS.size());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -212,48 +222,48 @@ public class MenuServiceImpl implements MenuService {
|
||||||
public List<MenuVo> buildMenus(List<MenuDTO> menuDTOS) {
|
public List<MenuVo> buildMenus(List<MenuDTO> menuDTOS) {
|
||||||
List<MenuVo> list = new LinkedList<>();
|
List<MenuVo> list = new LinkedList<>();
|
||||||
menuDTOS.forEach(menuDTO -> {
|
menuDTOS.forEach(menuDTO -> {
|
||||||
if (menuDTO!=null){
|
if (menuDTO != null) {
|
||||||
List<MenuDTO> menuDTOList = menuDTO.getChildren();
|
List<MenuDTO> menuDTOList = menuDTO.getChildren();
|
||||||
MenuVo menuVo = new MenuVo();
|
MenuVo menuVo = new MenuVo();
|
||||||
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getName());
|
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponentName()) ? menuDTO.getComponentName() : menuDTO.getName());
|
||||||
// 一级目录需要加斜杠,不然会报警告
|
// 一级目录需要加斜杠,不然会报警告
|
||||||
menuVo.setPath(menuDTO.getPid() == 0 ? "/" + menuDTO.getPath() :menuDTO.getPath());
|
menuVo.setPath(menuDTO.getPid() == 0 ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||||
menuVo.setHidden(menuDTO.getHidden());
|
menuVo.setHidden(menuDTO.getHidden());
|
||||||
// 如果不是外链
|
// 如果不是外链
|
||||||
if(!menuDTO.getIFrame()){
|
if (!menuDTO.getIFrame()) {
|
||||||
if(menuDTO.getPid() == 0){
|
if (menuDTO.getPid() == 0) {
|
||||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent())?"Layout":menuDTO.getComponent());
|
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||||
}else if(!StrUtil.isEmpty(menuDTO.getComponent())){
|
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
||||||
menuVo.setComponent(menuDTO.getComponent());
|
menuVo.setComponent(menuDTO.getComponent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menuVo.setMeta(new MenuMetaVo(menuDTO.getName(), menuDTO.getIcon(), !menuDTO.getCache()));
|
||||||
|
if (menuDTOList != null && menuDTOList.size() != 0) {
|
||||||
|
menuVo.setAlwaysShow(true);
|
||||||
|
menuVo.setRedirect("noredirect");
|
||||||
|
menuVo.setChildren(buildMenus(menuDTOList));
|
||||||
|
// 处理是一级菜单并且没有子菜单的情况
|
||||||
|
} else if (menuDTO.getPid() == 0) {
|
||||||
|
MenuVo menuVo1 = new MenuVo();
|
||||||
|
menuVo1.setMeta(menuVo.getMeta());
|
||||||
|
// 非外链
|
||||||
|
if (!menuDTO.getIFrame()) {
|
||||||
|
menuVo1.setPath("index");
|
||||||
|
menuVo1.setName(menuVo.getName());
|
||||||
|
menuVo1.setComponent(menuVo.getComponent());
|
||||||
|
} else {
|
||||||
|
menuVo1.setPath(menuDTO.getPath());
|
||||||
|
}
|
||||||
|
menuVo.setName(null);
|
||||||
|
menuVo.setMeta(null);
|
||||||
|
menuVo.setComponent("Layout");
|
||||||
|
List<MenuVo> list1 = new ArrayList<>();
|
||||||
|
list1.add(menuVo1);
|
||||||
|
menuVo.setChildren(list1);
|
||||||
|
}
|
||||||
|
list.add(menuVo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menuVo.setMeta(new MenuMetaVo(menuDTO.getName(),menuDTO.getIcon(),!menuDTO.getCache()));
|
|
||||||
if(menuDTOList!=null && menuDTOList.size()!=0){
|
|
||||||
menuVo.setAlwaysShow(true);
|
|
||||||
menuVo.setRedirect("noredirect");
|
|
||||||
menuVo.setChildren(buildMenus(menuDTOList));
|
|
||||||
// 处理是一级菜单并且没有子菜单的情况
|
|
||||||
} else if(menuDTO.getPid() == 0){
|
|
||||||
MenuVo menuVo1 = new MenuVo();
|
|
||||||
menuVo1.setMeta(menuVo.getMeta());
|
|
||||||
// 非外链
|
|
||||||
if(!menuDTO.getIFrame()){
|
|
||||||
menuVo1.setPath("index");
|
|
||||||
menuVo1.setName(menuVo.getName());
|
|
||||||
menuVo1.setComponent(menuVo.getComponent());
|
|
||||||
} else {
|
|
||||||
menuVo1.setPath(menuDTO.getPath());
|
|
||||||
}
|
|
||||||
menuVo.setName(null);
|
|
||||||
menuVo.setMeta(null);
|
|
||||||
menuVo.setComponent("Layout");
|
|
||||||
List<MenuVo> list1 = new ArrayList<>();
|
|
||||||
list1.add(menuVo1);
|
|
||||||
menuVo.setChildren(list1);
|
|
||||||
}
|
|
||||||
list.add(menuVo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +271,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
@Override
|
@Override
|
||||||
public Menu findOne(Long id) {
|
public Menu findOne(Long id) {
|
||||||
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
||||||
ValidationUtil.isNull(menu.getId(),"Menu","id",id);
|
ValidationUtil.isNull(menu.getId(), "Menu", "id", id);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +279,7 @@ public class MenuServiceImpl implements MenuService {
|
||||||
public void download(List<MenuDTO> menuDTOS, HttpServletResponse response) throws IOException {
|
public void download(List<MenuDTO> menuDTOS, HttpServletResponse response) throws IOException {
|
||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (MenuDTO menuDTO : menuDTOS) {
|
for (MenuDTO menuDTO : menuDTOS) {
|
||||||
Map<String,Object> map = new LinkedHashMap<>();
|
Map<String, Object> map = new LinkedHashMap<>();
|
||||||
map.put("菜单名称", menuDTO.getName());
|
map.put("菜单名称", menuDTO.getName());
|
||||||
map.put("菜单类型", menuDTO.getType() == 0 ? "目录" : menuDTO.getType() == 1 ? "菜单" : "按钮");
|
map.put("菜单类型", menuDTO.getType() == 0 ? "目录" : menuDTO.getType() == 1 ? "菜单" : "按钮");
|
||||||
map.put("权限标识", menuDTO.getPermission());
|
map.put("权限标识", menuDTO.getPermission());
|
||||||
|
@ -281,4 +291,36 @@ public class MenuServiceImpl implements MenuService {
|
||||||
}
|
}
|
||||||
FileUtil.downloadExcel(list, response);
|
FileUtil.downloadExcel(list, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void autoRegisterSysMenu() {
|
||||||
|
Set<String> permissionCollect = menuRepository.findMenusByType(2).stream().map(it -> it.getPermission()).collect(Collectors.toSet());
|
||||||
|
Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods();
|
||||||
|
for (Map.Entry<RequestMappingInfo, HandlerMethod> infoEntry : handlerMethodMap.entrySet()) {
|
||||||
|
HandlerMethod handlerMethod = infoEntry.getValue();
|
||||||
|
PreAuthorize preAuthorize = handlerMethod.getMethodAnnotation(PreAuthorize.class);
|
||||||
|
if (null != preAuthorize) {
|
||||||
|
Set<String> roles = StringUtils.findRoles(preAuthorize.value());
|
||||||
|
roles.forEach(role -> {
|
||||||
|
if (!permissionCollect.contains(role)) {
|
||||||
|
String apiOperation = "";
|
||||||
|
ApiOperation operationAno = handlerMethod.getMethodAnnotation(ApiOperation.class);
|
||||||
|
Log logAno = handlerMethod.getMethodAnnotation(Log.class);
|
||||||
|
apiOperation = null != operationAno ? operationAno.value() : null != logAno ? logAno.value() : role;
|
||||||
|
Menu registerMenu = new Menu();
|
||||||
|
registerMenu.setPid(21L);
|
||||||
|
registerMenu.setSort(999L);
|
||||||
|
registerMenu.setType(2);
|
||||||
|
registerMenu.setName("");
|
||||||
|
registerMenu.setIFrame(false);
|
||||||
|
registerMenu.setPermission("");
|
||||||
|
registerMenu.setPermission(role);
|
||||||
|
registerMenu.setName(String.format("%s(%s)", apiOperation, role) + "-自动注册");
|
||||||
|
this.create(registerMenu);
|
||||||
|
permissionCollect.add(role);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<#if column.changeColumnName != '${pkChangeColName}'>
|
<#if column.changeColumnName != '${pkChangeColName}'>
|
||||||
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnKey = 'UNI'>prop="${column.changeColumnName}"</#if>>
|
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnKey = 'UNI'>prop="${column.changeColumnName}"</#if>>
|
||||||
<#if column.columnType != 'Timestamp'>
|
<#if column.columnType != 'Timestamp'>
|
||||||
<el-input v-model="form.${column.changeColumnName}" :type="(form.${column.changeColumnName} && form.${column.changeColumnName}.length ) > 35 ? 'textarea': 'text'" style="width: 370px;"/>
|
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
||||||
<#else >
|
<#else >
|
||||||
<el-date-picker type="datetime" v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
<el-date-picker type="datetime" v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
||||||
</#if>
|
</#if>
|
||||||
|
|
Loading…
Reference in New Issue