菜单功能修改
This commit is contained in:
@@ -45,8 +45,8 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author ludj
|
||||||
* @date 2018-12-03
|
* @date 2022-12-30
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -56,8 +56,6 @@ import java.util.stream.Collectors;
|
|||||||
public class MenuController {
|
public class MenuController {
|
||||||
|
|
||||||
private final MenuService menuService;
|
private final MenuService menuService;
|
||||||
private final MenuMapper menuMapper;
|
|
||||||
private static final String ENTITY_NAME = "menu";
|
|
||||||
|
|
||||||
@GetMapping(value = "/build")
|
@GetMapping(value = "/build")
|
||||||
@ApiOperation("根据用户获取菜单")
|
@ApiOperation("根据用户获取菜单")
|
||||||
@@ -95,12 +93,12 @@ public class MenuController {
|
|||||||
@GetMapping(value = "/child")
|
@GetMapping(value = "/child")
|
||||||
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
|
||||||
public ResponseEntity<Object> child(@RequestParam Long id) {
|
public ResponseEntity<Object> child(@RequestParam Long id) {
|
||||||
/* Set<Menu> menuSet = new HashSet<>();
|
Set<MenuDto> menuSet = new HashSet<>();
|
||||||
List<MenuDto> menuList = menuService.getMenus(id);
|
List<MenuDto> menuList = menuService.getMenus(id);
|
||||||
menuSet.add(menuService.findOne(id));
|
menuSet.add(menuService.findById(id));
|
||||||
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
|
menuSet = menuService.getChildMenus(menuList, menuSet);
|
||||||
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());*/
|
Set<Long> ids = menuSet.stream().map(MenuDto::getMenu_id).collect(Collectors.toSet());
|
||||||
return new ResponseEntity<>(id, HttpStatus.OK);
|
return new ResponseEntity<>(ids, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@@ -150,10 +148,10 @@ public class MenuController {
|
|||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@SaCheckPermission("menu:del")
|
@SaCheckPermission("menu:del")
|
||||||
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
|
||||||
Set<Menu> menuSet = new HashSet<>();
|
Set<MenuDto> menuSet = new HashSet<>();
|
||||||
for (Long id : ids) {
|
for (Long id : ids) {
|
||||||
/* List<MenuDto> menuList = menuService.getMenus(id);*/
|
/* List<MenuDto> menuList = menuService.getMenus(id);*/
|
||||||
menuSet.add(menuService.findOne(id));
|
menuSet.add(menuService.findById(id));
|
||||||
/*menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);*/
|
/*menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);*/
|
||||||
}
|
}
|
||||||
menuService.delete(menuSet);
|
menuService.delete(menuSet);
|
||||||
|
|||||||
@@ -58,6 +58,13 @@ public interface MenuService {
|
|||||||
*/
|
*/
|
||||||
JSONArray getMenusByRole(String role_id, String system_type, String category);
|
JSONArray getMenusByRole(String role_id, String system_type, String category);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单json对象转实体对象
|
||||||
|
* @param menuJson
|
||||||
|
*/
|
||||||
|
MenuDto menuJsonToMenuDto(JSONObject menuJson);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询
|
* 根据ID查询
|
||||||
*
|
*
|
||||||
@@ -87,7 +94,7 @@ public interface MenuService {
|
|||||||
* @param menuSet /
|
* @param menuSet /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet);
|
Set<MenuDto> getChildMenus(List<MenuDto> menuList, Set<MenuDto> menuSet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建菜单树
|
* 构建菜单树
|
||||||
@@ -105,20 +112,13 @@ public interface MenuService {
|
|||||||
*/
|
*/
|
||||||
Object buildMenus(List<MenuDto> menuDtos);
|
Object buildMenus(List<MenuDto> menuDtos);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID查询
|
|
||||||
*
|
|
||||||
* @param id /
|
|
||||||
* @return /
|
|
||||||
*/
|
|
||||||
Menu findOne(Long id);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
*
|
||||||
* @param menuSet /
|
* @param menuSet /
|
||||||
*/
|
*/
|
||||||
void delete(Set<Menu> menuSet);
|
void delete(Set<MenuDto> menuSet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 懒加载菜单数据
|
* 懒加载菜单数据
|
||||||
@@ -126,7 +126,7 @@ public interface MenuService {
|
|||||||
* @param pid /
|
* @param pid /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
JSONArray getMenus(Long pid);
|
List<MenuDto> getMenus(Long pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID获取同级与上级数据
|
* 根据ID获取同级与上级数据
|
||||||
@@ -135,7 +135,7 @@ public interface MenuService {
|
|||||||
* @param objects /
|
* @param objects /
|
||||||
* @return /
|
* @return /
|
||||||
*/
|
*/
|
||||||
List<MenuDto> getSuperior(MenuDto menuDto, List<Menu> objects);
|
List<MenuDto> getSuperior(MenuDto menuDto, List<MenuDto> objects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据当前用户获取菜单
|
* 根据当前用户获取菜单
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.nl.modules.system.service.dto;
|
package org.nl.modules.system.service.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.nl.modules.common.base.BaseDTO;
|
import org.nl.modules.common.base.BaseDTO;
|
||||||
@@ -31,7 +32,7 @@ import java.util.Objects;
|
|||||||
@Setter
|
@Setter
|
||||||
public class MenuDto extends BaseDTO implements Serializable {
|
public class MenuDto extends BaseDTO implements Serializable {
|
||||||
|
|
||||||
private Long id;
|
private Long menu_id;
|
||||||
|
|
||||||
private List<MenuDto> children;
|
private List<MenuDto> children;
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public class MenuDto extends BaseDTO implements Serializable {
|
|||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private Integer menuSort;
|
private Integer menu_sort;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@@ -49,25 +50,29 @@ public class MenuDto extends BaseDTO implements Serializable {
|
|||||||
|
|
||||||
private Long pid;
|
private Long pid;
|
||||||
|
|
||||||
private Integer subCount;
|
private Integer sub_count;
|
||||||
|
|
||||||
private Boolean iFrame;
|
private Boolean i_frame;
|
||||||
|
|
||||||
|
|
||||||
private Boolean cache;
|
private Boolean cache;
|
||||||
|
|
||||||
private Boolean hidden;
|
private Boolean hidden;
|
||||||
|
|
||||||
private String componentName;
|
private String component_name;
|
||||||
|
|
||||||
private String icon;
|
private String icon;
|
||||||
|
|
||||||
|
private boolean hasChildren;
|
||||||
|
|
||||||
|
private boolean leaf;
|
||||||
|
|
||||||
public Boolean getHasChildren() {
|
public Boolean getHasChildren() {
|
||||||
return subCount > 0;
|
return sub_count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getLeaf() {
|
public Boolean getLeaf() {
|
||||||
return subCount <= 0;
|
return sub_count <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
@@ -83,11 +88,11 @@ public class MenuDto extends BaseDTO implements Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MenuDto menuDto = (MenuDto) o;
|
MenuDto menuDto = (MenuDto) o;
|
||||||
return Objects.equals(id, menuDto.id);
|
return Objects.equals(menu_id, menuDto.menu_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id);
|
return Objects.hash(menu_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,35 +21,25 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
|
||||||
import org.nl.modules.common.exception.EntityExistException;
|
|
||||||
import org.nl.modules.common.utils.*;
|
import org.nl.modules.common.utils.*;
|
||||||
import org.nl.modules.system.domain.Menu;
|
import org.nl.modules.system.domain.Menu;
|
||||||
import org.nl.modules.system.domain.Role;
|
import org.nl.modules.system.domain.Role;
|
||||||
import org.nl.modules.system.domain.User;
|
import org.nl.modules.system.domain.User;
|
||||||
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
||||||
import org.nl.modules.system.domain.vo.MenuVo;
|
import org.nl.modules.system.domain.vo.MenuVo;
|
||||||
import org.nl.modules.system.repository.MenuRepository;
|
|
||||||
import org.nl.modules.system.repository.UserRepository;
|
import org.nl.modules.system.repository.UserRepository;
|
||||||
import org.nl.modules.system.service.MenuService;
|
import org.nl.modules.system.service.MenuService;
|
||||||
import org.nl.modules.system.service.RoleService;
|
import org.nl.modules.system.service.RoleService;
|
||||||
import org.nl.modules.system.service.dto.MenuDto;
|
import org.nl.modules.system.service.dto.MenuDto;
|
||||||
import org.nl.modules.system.service.dto.MenuQueryCriteria;
|
|
||||||
import org.nl.modules.system.service.dto.RoleSmallDto;
|
|
||||||
import org.nl.modules.system.service.mapstruct.MenuMapper;
|
|
||||||
import org.nl.modules.wql.WQL;
|
import org.nl.modules.wql.WQL;
|
||||||
import org.nl.modules.wql.core.bean.ResultBean;
|
|
||||||
import org.nl.modules.wql.core.bean.WQLObject;
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.nl.modules.wql.util.WqlUtil;
|
import org.nl.modules.wql.util.WqlUtil;
|
||||||
import org.nl.wms.util.IdUtil;
|
import org.nl.wms.util.IdUtil;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -61,16 +51,35 @@ import java.util.stream.Collectors;
|
|||||||
@CacheConfig(cacheNames = "menu")
|
@CacheConfig(cacheNames = "menu")
|
||||||
public class MenuServiceImpl implements MenuService {
|
public class MenuServiceImpl implements MenuService {
|
||||||
|
|
||||||
private final MenuRepository menuRepository;
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final MenuMapper menuMapper;
|
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final RedisUtils redisUtils;
|
private final RedisUtils redisUtils;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
|
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
|
||||||
ResultBean rb = WQLObject.getWQLObject("sys_menu").pagequery(WqlUtil.getHttpContext(page), "pid is null", "");
|
JSONObject json = WQL.getWO("QSYS_MENU01").addParam("flag", "0").addParam("pid", param.getString("pid")).pageQuery(WqlUtil.getHttpContext(page), "");
|
||||||
return rb.pageResult();
|
|
||||||
|
JSONArray content = json.getJSONArray("content");
|
||||||
|
JSONArray res = new JSONArray();
|
||||||
|
for (int i = 0; i < content.size(); i++) {
|
||||||
|
JSONObject obj = content.getJSONObject(i);
|
||||||
|
obj.put("menu_id", obj.getLong("menu_id"));
|
||||||
|
obj.put("pid", obj.getLong("pid"));
|
||||||
|
|
||||||
|
//构建前端需要的数据结构树
|
||||||
|
Integer sub_count = obj.getInteger("sub_count");
|
||||||
|
if (sub_count <= 0) {
|
||||||
|
obj.put("leaf", true);
|
||||||
|
obj.put("hasChildren", false);
|
||||||
|
} else {
|
||||||
|
obj.put("leaf", false);
|
||||||
|
obj.put("hasChildren", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.add(obj);
|
||||||
|
}
|
||||||
|
json.put("content", res);
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,11 +121,42 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Cacheable(key = "'id:' + #p0")
|
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
||||||
|
MenuDto menuDto = new MenuDto();
|
||||||
|
menuDto.setMenu_id(json.getLong("menu_id"));
|
||||||
|
menuDto.setType(json.getInteger("type"));
|
||||||
|
menuDto.setPermission(json.getString("permission"));
|
||||||
|
menuDto.setTitle(json.getString("title"));
|
||||||
|
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
||||||
|
menuDto.setPath(json.getString("path"));
|
||||||
|
menuDto.setComponent(json.getString("component"));
|
||||||
|
menuDto.setPid(json.getLong("pid"));
|
||||||
|
menuDto.setSub_count(json.getInteger("sub_count"));
|
||||||
|
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
||||||
|
menuDto.setCache("1".equals(json.getString("cache")));
|
||||||
|
menuDto.setHidden("1".equals(json.getString("hidden")));
|
||||||
|
menuDto.setComponent_name(json.getString("component_name"));
|
||||||
|
|
||||||
|
//构建前端需要的数据结构树
|
||||||
|
Integer sub_count = json.getInteger("sub_count");
|
||||||
|
if (sub_count <= 0) {
|
||||||
|
menuDto.setLeaf(true);
|
||||||
|
menuDto.setHasChildren(false);
|
||||||
|
} else {
|
||||||
|
menuDto.setLeaf(false);
|
||||||
|
menuDto.setHasChildren(true);
|
||||||
|
}
|
||||||
|
return menuDto;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// @Cacheable(key = "'id:' + #p0")
|
||||||
public MenuDto findById(long id) {
|
public MenuDto findById(long id) {
|
||||||
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
ValidationUtil.isNull(menu.getId(), "Menu", "id", id);
|
JSONObject json = menuTab.query("menu_id = '" + id + "'").uniqueResult(0);
|
||||||
return menuMapper.toDto(menu);
|
return this.menuJsonToMenuDto(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,16 +174,16 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
JSONObject json = arr.getJSONObject(i);
|
JSONObject json = arr.getJSONObject(i);
|
||||||
|
|
||||||
MenuDto dto = new MenuDto();
|
MenuDto dto = new MenuDto();
|
||||||
dto.setId(json.getLong("menu_id"));
|
dto.setMenu_id(json.getLong("menu_id"));
|
||||||
dto.setType(json.getInteger("type"));
|
dto.setType(json.getInteger("type"));
|
||||||
dto.setPermission(json.getString("permission"));
|
dto.setPermission(json.getString("permission"));
|
||||||
dto.setTitle(json.getString("title"));
|
dto.setTitle(json.getString("title"));
|
||||||
dto.setPath(json.getString("path"));
|
dto.setPath(json.getString("path"));
|
||||||
dto.setComponentName(json.getString("name"));
|
dto.setComponent_name(json.getString("name"));
|
||||||
dto.setComponent(json.getString("component"));
|
dto.setComponent(json.getString("component"));
|
||||||
dto.setIcon(json.getString("icon"));
|
dto.setIcon(json.getString("icon"));
|
||||||
dto.setMenuSort(json.getInteger("menu_sort"));
|
dto.setMenu_sort(json.getInteger("menu_sort"));
|
||||||
dto.setSubCount(json.getInteger("sub_count"));
|
dto.setSub_count(json.getInteger("sub_count"));
|
||||||
dto.setPid(json.getLong("pid"));
|
dto.setPid(json.getLong("pid"));
|
||||||
|
|
||||||
|
|
||||||
@@ -157,9 +197,9 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.equals(iFrame, "1")) {
|
if (StrUtil.equals(iFrame, "1")) {
|
||||||
dto.setIFrame(true);
|
dto.setI_frame(true);
|
||||||
} else {
|
} else {
|
||||||
dto.setIFrame(false);
|
dto.setI_frame(false);
|
||||||
}
|
}
|
||||||
if (StrUtil.equals(hidden, "1")) {
|
if (StrUtil.equals(hidden, "1")) {
|
||||||
dto.setHidden(true);
|
dto.setHidden(true);
|
||||||
@@ -187,6 +227,8 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
form.put("update_time", DateUtil.now());
|
form.put("update_time", DateUtil.now());
|
||||||
menuTab.insert(form);
|
menuTab.insert(form);
|
||||||
//TODO 更新子节点数量
|
//TODO 更新子节点数量
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -196,10 +238,12 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet) {
|
public Set<MenuDto> getChildMenus(List<MenuDto> menuList, Set<MenuDto> menuSet) {
|
||||||
for (Menu menu : menuList) {
|
for (MenuDto menu : menuList) {
|
||||||
menuSet.add(menu);
|
menuSet.add(menu);
|
||||||
List<Menu> menus = menuRepository.findByPid(menu.getId());
|
List<MenuDto> menus = new ArrayList<>();
|
||||||
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
|
menuTab.query("pid = '" + menu.getPid() + "'");
|
||||||
if (menus != null && menus.size() != 0) {
|
if (menus != null && menus.size() != 0) {
|
||||||
getChildMenus(menus, menuSet);
|
getChildMenus(menus, menuSet);
|
||||||
}
|
}
|
||||||
@@ -209,18 +253,18 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void delete(Set<Menu> menuSet) {
|
public void delete(Set<MenuDto> menuSet) {
|
||||||
for (Menu menu : menuSet) {
|
for (MenuDto menu : menuSet) {
|
||||||
// 清理缓存
|
// 清理缓存
|
||||||
delCaches(menu.getId());
|
delCaches(menu.getMenu_id());
|
||||||
roleService.untiedMenu(menu.getId());
|
roleService.untiedMenu(menu.getMenu_id());
|
||||||
menuRepository.deleteById(menu.getId());
|
WQLObject.getWQLObject("sys_menu").delete("menu_id = '" + menu.getMenu_id() + "'");
|
||||||
updateSubCnt(menu.getPid());
|
updateSubCnt(menu.getPid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONArray getMenus(Long pid) {
|
public List<MenuDto> getMenus(Long pid) {
|
||||||
// 菜单表【sys_menu】
|
// 菜单表【sys_menu】
|
||||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
JSONArray menus;
|
JSONArray menus;
|
||||||
@@ -229,28 +273,29 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
} else {
|
} else {
|
||||||
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
|
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
|
||||||
}
|
}
|
||||||
|
List<MenuDto> list = new ArrayList<>();
|
||||||
//判断是否叶子节点,用于前端构建树
|
//判断是否叶子节点,用于前端构建树
|
||||||
for (int i = 0; i < menus.size(); i++) {
|
for (int i = 0; i < menus.size(); i++) {
|
||||||
JSONObject json = menus.getJSONObject(i);
|
JSONObject json = menus.getJSONObject(i);
|
||||||
Integer sub_count = json.getInteger("sub_count");
|
list.add(this.menuJsonToMenuDto(json));
|
||||||
if (sub_count <= 0) {
|
|
||||||
json.put("leaf", true);
|
|
||||||
json.put("hasChildren", false);
|
|
||||||
} else {
|
|
||||||
json.put("leaf", false);
|
|
||||||
json.put("hasChildren", true);
|
|
||||||
}
|
}
|
||||||
}
|
return list;
|
||||||
return menus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<Menu> menus) {
|
public List<MenuDto> getSuperior(MenuDto menuDto, List<MenuDto> menus) {
|
||||||
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
if (menuDto.getPid() == null) {
|
if (menuDto.getPid() == null) {
|
||||||
menus.addAll(menuRepository.findByPidIsNull());
|
JSONArray arr = menuTab.query("pid is null").getResultJSONArray(0);
|
||||||
return menuMapper.toDto(menus);
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
|
JSONObject json = arr.getJSONObject(i);
|
||||||
|
menus.add(this.menuJsonToMenuDto(json));
|
||||||
}
|
}
|
||||||
menus.addAll(menuRepository.findByPid(menuDto.getPid()));
|
return menus;
|
||||||
|
}
|
||||||
|
MenuDto dto = this.findById(menuDto.getPid());
|
||||||
|
menus.addAll((Collection<? extends MenuDto>) dto);
|
||||||
return getSuperior(findById(menuDto.getPid()), menus);
|
return getSuperior(findById(menuDto.getPid()), menus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,17 +308,17 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
trees.add(menuDTO);
|
trees.add(menuDTO);
|
||||||
}
|
}
|
||||||
for (MenuDto it : menuDtos) {
|
for (MenuDto it : menuDtos) {
|
||||||
if (menuDTO.getId().equals(it.getPid())) {
|
if (menuDTO.getMenu_id().equals(it.getPid())) {
|
||||||
if (menuDTO.getChildren() == null) {
|
if (menuDTO.getChildren() == null) {
|
||||||
menuDTO.setChildren(new ArrayList<>());
|
menuDTO.setChildren(new ArrayList<>());
|
||||||
}
|
}
|
||||||
menuDTO.getChildren().add(it);
|
menuDTO.getChildren().add(it);
|
||||||
ids.add(it.getId());
|
ids.add(it.getMenu_id());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.getMenu_id())).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return trees;
|
return trees;
|
||||||
}
|
}
|
||||||
@@ -285,12 +330,12 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
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.getTitle());
|
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponent_name()) ? menuDTO.getComponent_name() : menuDTO.getTitle());
|
||||||
// 一级目录需要加斜杠,不然会报警告
|
// 一级目录需要加斜杠,不然会报警告
|
||||||
menuVo.setPath(menuDTO.getPid() == null ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
menuVo.setPath(menuDTO.getPid() == null ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||||
menuVo.setHidden(menuDTO.getHidden());
|
menuVo.setHidden(menuDTO.getHidden());
|
||||||
// 如果不是外链
|
// 如果不是外链
|
||||||
if (!menuDTO.getIFrame()) {
|
if (!menuDTO.getI_frame()) {
|
||||||
if (menuDTO.getPid() == null) {
|
if (menuDTO.getPid() == null) {
|
||||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||||
} else if (menuDTO.getPid() != null && menuDTO.getType() == 0) {
|
} else if (menuDTO.getPid() != null && menuDTO.getType() == 0) {
|
||||||
@@ -310,7 +355,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
MenuVo menuVo1 = new MenuVo();
|
MenuVo menuVo1 = new MenuVo();
|
||||||
menuVo1.setMeta(menuVo.getMeta());
|
menuVo1.setMeta(menuVo.getMeta());
|
||||||
// 非外链
|
// 非外链
|
||||||
if (!menuDTO.getIFrame()) {
|
if (!menuDTO.getI_frame()) {
|
||||||
menuVo1.setPath("index");
|
menuVo1.setPath("index");
|
||||||
menuVo1.setName(menuVo.getName());
|
menuVo1.setName(menuVo.getName());
|
||||||
menuVo1.setComponent(menuVo.getComponent());
|
menuVo1.setComponent(menuVo.getComponent());
|
||||||
@@ -331,17 +376,13 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Menu findOne(Long id) {
|
|
||||||
Menu menu = menuRepository.findById(id).orElseGet(Menu::new);
|
|
||||||
ValidationUtil.isNull(menu.getId(), "Menu", "id", id);
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSubCnt(Long menuId) {
|
private void updateSubCnt(Long menuId) {
|
||||||
if (menuId != null) {
|
if (menuId != null) {
|
||||||
int count = menuRepository.countByPid(menuId);
|
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||||
menuRepository.updateSubCntById(count, menuId);
|
JSONArray arr = menuTab.query("pid = '" + menuId + "'").getResultJSONArray(0);
|
||||||
|
JSONObject param = new JSONObject();
|
||||||
|
param.put("sub_count", arr.size());
|
||||||
|
menuTab.update(param, "menu_id = '" + menuId + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +394,7 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
public void delCaches(Long id) {
|
public void delCaches(Long id) {
|
||||||
List<User> users = userRepository.findByMenuId(id);
|
List<User> users = userRepository.findByMenuId(id);
|
||||||
redisUtils.del("menu::id:" + id);
|
redisUtils.del("menu::id:" + id);
|
||||||
redisUtils.delByKeys("menu::user:", users.stream().map(User::getUser_id).collect(Collectors.toSet()));
|
redisUtils.delByKeys("menu::user:", users.stream().map(User::getId).collect(Collectors.toSet()));
|
||||||
// 清除 Role 缓存
|
// 清除 Role 缓存
|
||||||
List<Role> roles = roleService.findInMenuId(new ArrayList<Long>() {{
|
List<Role> roles = roleService.findInMenuId(new ArrayList<Long>() {{
|
||||||
add(id);
|
add(id);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
输入.system_type TYPEAS s_string
|
输入.system_type TYPEAS s_string
|
||||||
输入.category TYPEAS s_string
|
输入.category TYPEAS s_string
|
||||||
输入.user_id TYPEAS s_string
|
输入.user_id TYPEAS s_string
|
||||||
|
输入.pid TYPEAS s_string
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -41,6 +42,27 @@
|
|||||||
##########################################
|
##########################################
|
||||||
# 3、业务主过程 #
|
# 3、业务主过程 #
|
||||||
##########################################
|
##########################################
|
||||||
|
|
||||||
|
IF 输入.flag = "0"
|
||||||
|
PAGEQUERY
|
||||||
|
SELECT
|
||||||
|
* ,
|
||||||
|
(CASE WHEN sub_count<=0 THEN 0 ELSE 1 END ) AS hasChildren
|
||||||
|
FROM
|
||||||
|
sys_menu
|
||||||
|
where 1=1
|
||||||
|
OPTION 输入.pid <> ""
|
||||||
|
pid = 输入.pid
|
||||||
|
ENDOPTION
|
||||||
|
OPTION 输入.pid = ""
|
||||||
|
pid is null
|
||||||
|
ENDOPTION
|
||||||
|
ENDSELECT
|
||||||
|
ENDPAGEQUERY
|
||||||
|
ENDIF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IF 输入.flag = "1"
|
IF 输入.flag = "1"
|
||||||
QUERY
|
QUERY
|
||||||
SELECT system_type from sys_menu GROUP BY system_type
|
SELECT system_type from sys_menu GROUP BY system_type
|
||||||
|
|||||||
Binary file not shown.
@@ -110,7 +110,7 @@
|
|||||||
:load="getMenus"
|
:load="getMenus"
|
||||||
:data="crud.data"
|
:data="crud.data"
|
||||||
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
row-key="id"
|
row-key="menu_id"
|
||||||
@select="crud.selectChange"
|
@select="crud.selectChange"
|
||||||
@select-all="crud.selectAllChange"
|
@select-all="crud.selectAllChange"
|
||||||
@selection-change="crud.selectionChangeHandler"
|
@selection-change="crud.selectionChangeHandler"
|
||||||
@@ -180,7 +180,7 @@ import udOperation from '@crud/UD.operation'
|
|||||||
import DateRangePicker from '@/components/DateRangePicker'
|
import DateRangePicker from '@/components/DateRangePicker'
|
||||||
|
|
||||||
// crud交由presenter持有
|
// crud交由presenter持有
|
||||||
const defaultForm = { id: null, title: null, menuSort: 999, path: null, system_type: null, category: null, component: null, componentName: null, iframe: 0, roles: [], pid: 0, icon: null, cache: 0, hidden: 0, type: 0, permission: null }
|
const defaultForm = { menu_id: null, title: null, menuSort: 999, path: null, system_type: null, category: null, component: null, componentName: null, iframe: 0, roles: [], pid: 0, icon: null, cache: 0, hidden: 0, type: 0, permission: null }
|
||||||
export default {
|
export default {
|
||||||
name: 'Menu',
|
name: 'Menu',
|
||||||
components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
|
components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
|
||||||
@@ -210,37 +210,37 @@ export default {
|
|||||||
// 新增与编辑前做的操作
|
// 新增与编辑前做的操作
|
||||||
[CRUD.HOOK.afterToCU](crud, form) {
|
[CRUD.HOOK.afterToCU](crud, form) {
|
||||||
this.menus = []
|
this.menus = []
|
||||||
if (form.id != null) {
|
if (form.menu_id != null) {
|
||||||
if (form.pid === null) {
|
if (form.pid === null) {
|
||||||
form.pid = 0
|
form.pid = 0
|
||||||
}
|
}
|
||||||
this.getSupDepts(form.id)
|
this.getSupDepts(form.menu_id)
|
||||||
} else {
|
} else {
|
||||||
this.menus.push({ id: 0, label: '顶级类目', children: null })
|
this.menus.push({ menu_id: 0, label: '顶级类目', children: null })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getMenus(tree, treeNode, resolve) {
|
getMenus(tree, treeNode, resolve) {
|
||||||
const params = { pid: tree.id }
|
const params = { pid: tree.menu_id }
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
crudMenu.getMenus(params).then(res => {
|
crudMenu.getMenus(params).then(res => {
|
||||||
resolve(res.content)
|
resolve(res.content)
|
||||||
})
|
})
|
||||||
}, 100)
|
}, 100)
|
||||||
},
|
},
|
||||||
getSupDepts(id) {
|
getSupDepts(menu_id) {
|
||||||
crudMenu.getMenuSuperior(id).then(res => {
|
crudMenu.getMenuSuperior(menu_id).then(res => {
|
||||||
const children = res.map(function(obj) {
|
const children = res.map(function(obj) {
|
||||||
if (!obj.leaf && !obj.children) {
|
if (!obj.leaf && !obj.children) {
|
||||||
obj.children = null
|
obj.children = null
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
})
|
})
|
||||||
this.menus = [{ id: 0, label: '顶级类目', children: children }]
|
this.menus = [{ menu_id: null, label: '顶级类目', children: children }]
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
loadMenus({ action, parentNode, callback }) {
|
loadMenus({ action, parentNode, callback }) {
|
||||||
if (action === LOAD_CHILDREN_OPTIONS) {
|
if (action === LOAD_CHILDREN_OPTIONS) {
|
||||||
crudMenu.getMenusTree(parentNode.id).then(res => {
|
crudMenu.getMenusTree(parentNode.menu_id).then(res => {
|
||||||
parentNode.children = res.map(function(obj) {
|
parentNode.children = res.map(function(obj) {
|
||||||
if (!obj.leaf) {
|
if (!obj.leaf) {
|
||||||
obj.children = null
|
obj.children = null
|
||||||
|
|||||||
Reference in New Issue
Block a user