字典及菜单模块联调

This commit is contained in:
pra 2025-03-07 10:35:37 +08:00
parent d75e6cc9ca
commit 6981bf525e
21 changed files with 442 additions and 13 deletions

View File

@ -108,7 +108,6 @@ public class AuthController {
Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
List<MenuDO> menuList = menuService.getMenuList(menuIds);
menuList = menuService.filterDisableMenus(menuList);
// 2. 拼接结果返回
return success(AuthConvert.INSTANCE.convert(user, roles, menuList));
}

View File

@ -1,5 +1,6 @@
package cd.casic.module.system.controller.admin.auth.vo;
import cd.casic.framework.commons.enums.CommonStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -88,6 +89,34 @@ public class AuthPermissionInfoRespVO {
@Schema(description = "是否总是显示", example = "false")
private Boolean alwaysShow;
@Schema(description = "是否显示子菜单", example = "false")
private Boolean showChildren;
@Schema(description = "当前激活目录", example = "/sys-conf/job")
private String currentActiveMenu;
@Schema(description = "外部站点地址", example = "/sys-conf/job")
private String frameSrc;
/**
* 目录分组
*/
@Schema(description = "目录分组", example = "3")
private String menuGroup;
@Schema(description = "目录重定向", example = "/sys-conf/job")
private String redirect;
@Schema(description = "状态", example = "1")
private Integer status;
@Schema(description = "isTag", example = "1")
private Boolean isTag;
@Schema(description = "tagDot", example = "1")
private Boolean tagDot;
@Schema(description = "tagType", example = "1")
private String tagType;
@Schema(description = "tagContent", example = "1")
private String tagContent;
/**
* 子路由
*/

View File

@ -7,10 +7,7 @@ import cd.casic.framework.commons.pojo.PageParam;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.framework.commons.util.object.BeanUtils;
import cd.casic.framework.excel.excel.core.util.ExcelUtils;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataRespVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataSimpleRespVO;
import cd.casic.module.system.controller.admin.dict.vo.data.*;
import cd.casic.module.system.dal.dataobject.dict.DictDataDO;
import cd.casic.module.system.service.dict.DictDataService;
import io.swagger.v3.oas.annotations.Operation;
@ -101,4 +98,10 @@ public class DictDataController {
BeanUtils.toBean(list, DictDataRespVO.class));
}
@GetMapping("/getDictDataTree")
@Operation(summary = "获取数据字典树")
public CommonResult<List<DictDataTreeVO>> getDictDataTree() {
return success(dictDataService.getDictDataTree());
}
}

View File

@ -2,6 +2,7 @@ package cd.casic.module.system.controller.admin.dict.vo.data;
import cd.casic.framework.excel.excel.core.annotations.DictFormat;
import cd.casic.framework.excel.excel.core.convert.DictConvert;
import cd.casic.module.system.dal.dataobject.dict.DictTypeDO;
import cd.casic.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
@ -54,4 +55,5 @@ public class DictDataRespVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;
}

View File

@ -0,0 +1,26 @@
package cd.casic.module.system.controller.admin.dict.vo.data;
import cd.casic.module.system.controller.admin.dict.vo.type.DictTypeRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author songqiang
* @date 2023-09-28 9:50
* @description
*/
@Schema(description = "管理后台 - 字典树 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class DictDataTreeVO extends DictTypeRespVO {
@Schema(description = "子节点")
private List<DictDataRespVO> children;
}

View File

@ -32,4 +32,8 @@ public class DictTypePageReqVO extends PageParam {
@Schema(description = "创建时间")
private LocalDateTime[] createTime;
@Schema(description = "值类型类型,模糊匹配")
@Size(max = 128, message = "字典类型类型长度不能超过128个字符")
private String valueType;
}

View File

@ -40,4 +40,7 @@ public class DictTypeRespVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;
@Schema(description = "值类型", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String valueType;
}

View File

@ -33,4 +33,7 @@ public class DictTypeSaveReqVO {
@Schema(description = "备注", example = "快乐的备注")
private String remark;
@Schema(description = "值类型", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String valueType;
}

View File

@ -18,4 +18,7 @@ public class DictTypeSimpleRespVO {
@Schema(description = "字典类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "sys_common_sex")
private String type;
@Schema(description = "值类型", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String valueType;
}

View File

@ -3,10 +3,7 @@ package cd.casic.module.system.controller.admin.permission;
import cd.casic.framework.commons.enums.CommonStatusEnum;
import cd.casic.framework.commons.pojo.CommonResult;
import cd.casic.framework.commons.util.object.BeanUtils;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuRespVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.*;
import cd.casic.module.system.dal.dataobject.permission.MenuDO;
import cd.casic.module.system.service.permission.MenuService;
import io.swagger.v3.oas.annotations.Operation;
@ -85,4 +82,15 @@ public class MenuController {
return success(BeanUtils.toBean(menu, MenuRespVO.class));
}
@GetMapping("/getMenuTree")
@Operation(summary = "获取菜单树")
@PreAuthorize("@ss.hasPermission('system:menu:query')")
public CommonResult<List<MenuTreeVO>> getMenuTree() {
// 获得菜单列表只要开启状态的
MenuListReqVO reqVO = new MenuListReqVO();
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
List<MenuDO> list = menuService.getMenuListByTenant(reqVO);
return success(menuService.convertMenuTree(list));
}
}

View File

@ -1,5 +1,6 @@
package cd.casic.module.system.controller.admin.permission.vo.menu;
import cd.casic.framework.commons.enums.CommonStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -69,4 +70,30 @@ public class MenuRespVO {
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "时间戳格式")
private LocalDateTime createTime;
/**
* 目录分组
*/
private String menuGroup;
/**
* 目录重定向
*/
private String redirect;
private Boolean showChildren;
/**
* 当前激活目录
*/
private String currentActiveMenu;
/**
* 外部站点地址
*/
private String frameSrc;
private Boolean isTag;
private Boolean tagDot;
private String tagType;
private String tagContent;
}

View File

@ -64,4 +64,30 @@ public class MenuSaveVO {
@Schema(description = "是否总是显示", example = "false")
private Boolean alwaysShow;
/**
* 目录分组
*/
private String menuGroup;
/**
* 目录重定向
*/
private String redirect;
private Boolean showChildren;
/**
* 当前激活目录
*/
private String currentActiveMenu;
/**
* 外部站点地址
*/
private String frameSrc;
private Boolean isTag;
private Boolean tagDot;
private String tagType;
private String tagContent;
}

View File

@ -0,0 +1,105 @@
package cd.casic.module.system.controller.admin.permission.vo.menu;
import cd.casic.framework.commons.enums.CommonStatusEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author songqiang
* @date 2023-11-08 11:40
* @description
*/
@Schema(description = "管理后台 - 菜单树 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MenuTreeVO {
@Schema(description = "菜单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "菜单名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道")
private String name;
@Schema(description = "父菜单 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long parentId;
@Schema(description = "类型,参见 MenuTypeEnum 枚举类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer type;
@Schema(description = "路由地址", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "/system")
private String path;
@Schema(description = "菜单图标", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "system")
private String icon;
@Schema(description = "组件路径", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "system/user/index")
private String component;
@Schema(description = "组件名", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "SystemUser")
private String componentName;
@Schema(description = "子菜单", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private List<MenuTreeVO> child;
/**
* 目录分组
*/
private String menuGroup;
/**
* 目录重定向
*/
private String redirect;
/**
* 状态
*
* 枚举 {@link CommonStatusEnum}
*/
private Integer status;
/**
* 是否可见
*
* 只有菜单目录使用
* 当设置为 true 该菜单不会展示在侧边栏但是路由还是存在例如说一些独立的编辑页面 /edit/1024 等等
*/
private Boolean visible;
/**
* 是否缓存
*
* 只有菜单目录使用否使用 Vue 路由的 keep-alive 特性
* 注意如果开启缓存则必须填写 {@link #componentName} 属性否则无法缓存
*/
private Boolean keepAlive;
/**
* 是否总是显示
*
* 如果为 false 当该菜单只有一个子菜单时不展示自己直接展示子菜单
*/
private Boolean alwaysShow;
/**
* 是否显示子菜单
*/
private Boolean showChildren;
/**
* 当前激活目录
*/
private String currentActiveMenu;
/**
* 外部站点地址
*/
private String frameSrc;
private Boolean isTag;
private Boolean tagDot;
private String tagType;
private String tagContent;
}

View File

@ -0,0 +1,33 @@
package cd.casic.module.system.convert.dict;
//import cd.casic.commons.pojo.PageResult;
import cd.casic.module.system.api.dict.dto.DictDataRespDTO;
import cd.casic.module.system.controller.admin.dict.vo.data.*;
import cd.casic.module.system.dal.dataobject.dict.DictDataDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DictDataConvert {
DictDataConvert INSTANCE = Mappers.getMapper(DictDataConvert.class);
List<DictDataSimpleRespVO> convertList(List<DictDataDO> list);
DictDataRespVO convert(DictDataDO bean);
// PageResult<DictDataRespVO> convertPage(PageResult<DictDataDO> page);
//
// DictDataDO convert(DictDataUpdateReqVO bean);
//
// DictDataDO convert(DictDataCreateReqVO bean);
//
// List<DictDataExcelVO> convertList02(List<DictDataDO> bean);
DictDataRespDTO convert02(DictDataDO bean);
List<DictDataRespVO> convertList03(List<DictDataDO> bean);
}

View File

@ -0,0 +1,31 @@
package cd.casic.module.system.convert.dict;
//import cd.casic.commons.pojo.PageResult;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataTreeVO;
import cd.casic.module.system.controller.admin.dict.vo.type.*;
import cd.casic.module.system.dal.dataobject.dict.DictTypeDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface DictTypeConvert {
DictTypeConvert INSTANCE = Mappers.getMapper(DictTypeConvert.class);
// PageResult<DictTypeRespVO> convertPage(PageResult<DictTypeDO> bean);
//
// DictTypeRespVO convert(DictTypeDO bean);
//
// DictTypeDO convert(DictTypeCreateReqVO bean);
//
// DictTypeDO convert(DictTypeUpdateReqVO bean);
//
// List<DictTypeSimpleRespVO> convertList(List<DictTypeDO> list);
//
// List<DictTypeExcelVO> convertList02(List<DictTypeDO> list);
List<DictDataTreeVO> convertList03(List<DictTypeDO> list);
}

View File

@ -55,4 +55,9 @@ public class DictTypeDO extends BaseDO {
*/
private LocalDateTime deletedTime;
/**
* 值类型
*/
private String valueType;
}

View File

@ -79,6 +79,14 @@ public class MenuDO extends BaseDO {
* 组件名
*/
private String componentName;
/**
* 目录分组
*/
private String menuGroup;
/**
* 目录重定向
*/
private String redirect;
/**
* 状态
*
@ -105,5 +113,23 @@ public class MenuDO extends BaseDO {
* 如果为 false 当该菜单只有一个子菜单时不展示自己直接展示子菜单
*/
private Boolean alwaysShow;
/**
* 是否显示子菜单
*/
private Boolean showChildren;
/**
* 当前激活目录
*/
private String currentActiveMenu;
/**
* 外部站点地址
*/
private String frameSrc;
private Boolean isTag;
private Boolean tagDot;
private String tagType;
private String tagContent;
}

View File

@ -3,6 +3,7 @@ package cd.casic.module.system.service.dict;
import cd.casic.framework.commons.pojo.PageResult;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataPageReqVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataSaveReqVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataTreeVO;
import cd.casic.module.system.dal.dataobject.dict.DictDataDO;
import org.springframework.lang.Nullable;
@ -107,4 +108,12 @@ public interface DictDataService {
*/
List<DictDataDO> getDictDataListByDictType(String dictType);
/**
* 生成数据字典树
* @author songqiang
* @date 2023-09-28 9:57
* @return 字典树
*/
List<DictDataTreeVO> getDictDataTree();
}

View File

@ -1,5 +1,9 @@
package cd.casic.module.system.service.dict;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataRespVO;
import cd.casic.module.system.controller.admin.dict.vo.data.DictDataTreeVO;
import cd.casic.module.system.convert.dict.DictDataConvert;
import cd.casic.module.system.convert.dict.DictTypeConvert;
import cn.hutool.core.collection.CollUtil;
import cd.casic.framework.commons.enums.CommonStatusEnum;
import cd.casic.framework.commons.pojo.PageResult;
@ -15,10 +19,8 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.module.system.enums.ErrorCodeConstants.*;
@ -176,4 +178,27 @@ public class DictDataServiceImpl implements DictDataService {
return list;
}
@Override
public List<DictDataTreeVO> getDictDataTree() {
List<DictTypeDO> dictTypeList = dictTypeService.getDictTypeList();
List<DictDataTreeVO> dataTree = DictTypeConvert.INSTANCE.convertList03(dictTypeList);
if (CollUtil.isEmpty(dataTree)) {
return Collections.emptyList();
}
List<DictDataDO> dictDataList = dictDataMapper.selectList();
dictDataList.sort(COMPARATOR_TYPE_AND_SORT);
List<DictDataRespVO> list = DictDataConvert.INSTANCE.convertList03(dictDataList);
if (CollUtil.isEmpty(list)) {
return dataTree;
}
Map<String, List<DictDataRespVO>> map = list.stream().collect(Collectors.groupingBy(DictDataRespVO::getDictType));
for (DictDataTreeVO treeVO : dataTree) {
treeVO.setChildren(map.get(treeVO.getType()));
}
return dataTree;
}
}

View File

@ -3,6 +3,7 @@ package cd.casic.module.system.service.permission;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuSaveVO;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuTreeVO;
import cd.casic.module.system.dal.dataobject.permission.MenuDO;
import java.util.Collection;
@ -93,4 +94,13 @@ public interface MenuService {
*/
List<MenuDO> getMenuList(Collection<Long> ids);
/**
* 生成菜单树
* @author songqiang
* @date 2023-11-08 14:08
* @param list
* @return
*/
List<MenuTreeVO> convertMenuTree(List<MenuDO> list);
}

View File

@ -1,5 +1,6 @@
package cd.casic.module.system.service.permission;
import cd.casic.module.system.controller.admin.permission.vo.menu.MenuTreeVO;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cd.casic.framework.commons.enums.CommonStatusEnum;
@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import static cd.casic.framework.commons.exception.util.ServiceExceptionUtil.exception;
import static cd.casic.framework.commons.util.collection.CollectionUtils.convertList;
@ -259,4 +261,54 @@ public class MenuServiceImpl implements MenuService {
}
}
@Override
public List<MenuTreeVO> convertMenuTree(List<MenuDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
list.sort(Comparator.comparing(MenuDO::getSort));
List<MenuTreeVO> menuTreeList = new ArrayList<>(list.size());
for (MenuDO menuDO : list) {
menuTreeList.add(menuDOToMenuTreeVO(menuDO));
}
List<MenuTreeVO> parentList = menuTreeList.stream()
.filter(i -> i.getParentId() == 0L)
.collect(Collectors.toList());
parentList.forEach(i -> findChild(i, menuTreeList));
return parentList;
}
private void findChild(MenuTreeVO menuTreeVO, List<MenuTreeVO> list) {
List<MenuTreeVO> collect = list.stream()
.filter(i -> i.getParentId().equals(menuTreeVO.getId()))
.collect(Collectors.toList());
menuTreeVO.setChild(collect);
collect.forEach(i -> findChild(i, list));
}
private MenuTreeVO menuDOToMenuTreeVO(MenuDO menuDO) {
if ( menuDO == null ) {
return null;
}
MenuTreeVO menuTreeVO = new MenuTreeVO();
// menuTreeVO.setId( menuDO.getId() );
// menuTreeVO.setName( menuDO.getName() );
// menuTreeVO.setParentId( menuDO.getParentId() );
// menuTreeVO.setType( menuDO.getType() );
// menuTreeVO.setPath( menuDO.getPath() );
// menuTreeVO.setIcon( menuDO.getIcon() );
// menuTreeVO.setComponent( menuDO.getComponent() );
// menuTreeVO.setComponentName( menuDO.getComponentName() );
BeanUtils.copyProperties(menuDO, menuTreeVO);
return menuTreeVO;
}
}