1. 开始迁移 menu 模块,完成 menu 列表的接口

2. 开始迁移 dict 模块,梳理了下整体的表结构,删除无用字段
pull/2/head
YunaiV 2021-01-07 21:28:23 +08:00
parent 3bf173d744
commit 74daab066d
29 changed files with 518 additions and 374 deletions

View File

@ -1,140 +0,0 @@
package com.ruoyi.web.controller.system;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.service.ISysMenuService;
/**
*
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/menu")
public class SysMenuController extends BaseController {
@Autowired
private ISysMenuService menuService;
@Autowired
private TokenService tokenService;
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/list")
public AjaxResult list(SysMenu menu) {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Long userId = loginUser.getUser().getUserId();
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
return AjaxResult.success(menus);
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:menu:query')")
@GetMapping(value = "/{menuId}")
public AjaxResult getInfo(@PathVariable Long menuId) {
return AjaxResult.success(menuService.selectMenuById(menuId));
}
/**
*
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysMenu menu) {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Long userId = loginUser.getUser().getUserId();
List<SysMenu> menus = menuService.selectMenuList(menu, userId);
return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
}
/**
*
*/
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
ajax.put("menus", menuService.buildMenuTreeSelect(menus));
return ajax;
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:menu:add')")
@Log(title = "菜单管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysMenu menu) {
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
}
menu.setCreateBy(SecurityUtils.getUsername());
return toAjax(menuService.insertMenu(menu));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:menu:edit')")
@Log(title = "菜单管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysMenu menu) {
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
&& !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
} else if (menu.getMenuId().equals(menu.getParentId())) {
return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
}
menu.setUpdateBy(SecurityUtils.getUsername());
return toAjax(menuService.updateMenu(menu));
}
/**
*
*/
@PreAuthorize("@ss.hasPermi('system:menu:remove')")
@Log(title = "菜单管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{menuId}")
public AjaxResult remove(@PathVariable("menuId") Long menuId) {
if (menuService.hasChildByMenuId(menuId)) {
return AjaxResult.error("存在子菜单,不允许删除");
}
if (menuService.checkMenuExistRole(menuId)) {
return AjaxResult.error("菜单已分配,不允许删除");
}
return toAjax(menuService.deleteMenuById(menuId));
}
}

View File

@ -1,82 +0,0 @@
package com.ruoyi.common.core.domain.entity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* sys_dict_data
*
* @author ruoyi
*/
public class SysDictData extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 字典编码 */
@Excel(name = "字典编码", cellType = ColumnType.NUMERIC)
private Long dictCode;
/** 字典排序 */
@Excel(name = "字典排序", cellType = ColumnType.NUMERIC)
private Long dictSort;
/** 字典标签 */
@Excel(name = "字典标签")
private String dictLabel;
/** 字典键值 */
@Excel(name = "字典键值")
private String dictValue;
/** 字典类型 */
@Excel(name = "字典类型")
private String dictType;
/** 样式属性(其他样式扩展) */
private String cssClass;
/** 表格字典样式 */
private String listClass;
/** 是否默认Y是 N否 */
@Excel(name = "是否默认", readConverterExp = "Y=是,N=否")
private String isDefault;
/** 状态0正常 1停用 */
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private String status;
@NotBlank(message = "字典标签不能为空")
@Size(min = 0, max = 100, message = "字典标签长度不能超过100个字符")
public String getDictLabel()
{
return dictLabel;
}
@NotBlank(message = "字典键值不能为空")
@Size(min = 0, max = 100, message = "字典键值长度不能超过100个字符")
public String getDictValue()
{
return dictValue;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型长度不能超过100个字符")
public String getDictType()
{
return dictType;
}
@Size(min = 0, max = 100, message = "样式属性长度不能超过100个字符")
public String getCssClass()
{
return cssClass;
}
}

View File

@ -1,50 +0,0 @@
package com.ruoyi.common.core.domain.entity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.ColumnType;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* sys_dict_type
*
* @author ruoyi
*/
public class SysDictType extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 字典主键 */
@Excel(name = "字典主键", cellType = ColumnType.NUMERIC)
private Long dictId;
/** 字典名称 */
@Excel(name = "字典名称")
private String dictName;
/** 字典类型 */
@Excel(name = "字典类型")
private String dictType;
/** 状态0正常 1停用 */
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private String status;
@NotBlank(message = "字典名称不能为空")
@Size(min = 0, max = 100, message = "字典类型名称长度不能超过100个字符")
public String getDictName()
{
return dictName;
}
@NotBlank(message = "字典类型不能为空")
@Size(min = 0, max = 100, message = "字典类型类型长度不能超过100个字符")
public String getDictType()
{
return dictType;
}
}

View File

@ -83,11 +83,6 @@
where m.status = '0' and r.status = '0' and ur.user_id = #{userId} where m.status = '0' and r.status = '0' and ur.user_id = #{userId}
</select> </select>
<select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
<include refid="selectMenuVo"/>
where menu_id = #{menuId}
</select>
<select id="hasChildByMenuId" resultType="Integer"> <select id="hasChildByMenuId" resultType="Integer">
select count(1) from sys_menu where parent_id = #{menuId} select count(1) from sys_menu where parent_id = #{menuId}
</select> </select>
@ -97,8 +92,4 @@
where menu_name=#{menuName} and parent_id = #{parentId} limit 1 where menu_name=#{menuName} and parent_id = #{parentId} limit 1
</select> </select>
<delete id="deleteMenuById" parameterType="Long">
delete from sys_menu where menu_id = #{menuId}
</delete>
</mapper> </mapper>

View File

@ -24,10 +24,8 @@ const permission = {
return new Promise(resolve => { return new Promise(resolve => {
// 向后端请求路由数据 // 向后端请求路由数据
getRouters().then(res => { getRouters().then(res => {
// const sdata = JSON.parse(JSON.stringify(res.data)) const sdata = JSON.parse(JSON.stringify(res.data))
// const rdata = JSON.parse(JSON.stringify(res.data)) const rdata = JSON.parse(JSON.stringify(res.data))
const sdata = JSON.parse(JSON.stringify(res))
const rdata = JSON.parse(JSON.stringify(res))
const sidebarRoutes = filterAsyncRouter(sdata) const sidebarRoutes = filterAsyncRouter(sdata)
const rewriteRoutes = filterAsyncRouter(rdata, true) const rewriteRoutes = filterAsyncRouter(rdata, true)
rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true }) rewriteRoutes.push({ path: '*', redirect: '/404', hidden: true })

View File

@ -50,8 +50,10 @@ const user = {
GetInfo({ commit, state }) { GetInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo(state.token).then(res => { getInfo(state.token).then(res => {
res = res.data; // 读取 data 数据
const user = res.user const user = res.user
const avatar = user.avatar === "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar; const avatar = user.avatar === "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
debugger
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles) commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions) commit('SET_PERMISSIONS', res.permissions)

View File

@ -76,7 +76,7 @@ service.interceptors.response.use(res => {
}) })
return Promise.reject('error') return Promise.reject('error')
} else { } else {
return res.data.data // 第二层 data 才是后端返回的 CommonResult.data return res.data
} }
}, },
error => { error => {

View File

@ -51,8 +51,8 @@
<svg-icon :icon-class="scope.row.icon" /> <svg-icon :icon-class="scope.row.icon" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="orderNum" label="排序" width="60"></el-table-column> <el-table-column prop="sort" label="排序" width="60"></el-table-column>
<el-table-column prop="perms" label="权限标识" :show-overflow-tooltip="true"></el-table-column> <el-table-column prop="permission" label="权限标识" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="component" label="组件路径" :show-overflow-tooltip="true"></el-table-column> <el-table-column prop="component" label="组件路径" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="status" label="状态" :formatter="statusFormat" width="80"></el-table-column> <el-table-column prop="status" label="状态" :formatter="statusFormat" width="80"></el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime"> <el-table-column label="创建时间" align="center" prop="createTime">
@ -104,14 +104,14 @@
<el-col :span="24"> <el-col :span="24">
<el-form-item label="菜单类型" prop="menuType"> <el-form-item label="菜单类型" prop="menuType">
<el-radio-group v-model="form.menuType"> <el-radio-group v-model="form.menuType">
<el-radio label="M">目录</el-radio> <el-radio label="1">目录</el-radio>
<el-radio label="C">菜单</el-radio> <el-radio label="2">菜单</el-radio>
<el-radio label="F">按钮</el-radio> <el-radio label="3">按钮</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="24"> <el-col :span="24">
<el-form-item v-if="form.menuType != 'F'" label="菜单图标"> <el-form-item v-if="form.menuType != '3'" label="菜单图标">
<el-popover <el-popover
placement="bottom-start" placement="bottom-start"
width="460" width="460"
@ -143,7 +143,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'" label="是否外链"> <el-form-item v-if="form.menuType != '3'" label="是否外链">
<el-radio-group v-model="form.isFrame"> <el-radio-group v-model="form.isFrame">
<el-radio label="0"></el-radio> <el-radio label="0"></el-radio>
<el-radio label="1"></el-radio> <el-radio label="1"></el-radio>
@ -151,22 +151,22 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'" label="路由地址" prop="path"> <el-form-item v-if="form.menuType != '3'" label="路由地址" prop="path">
<el-input v-model="form.path" placeholder="请输入路由地址" /> <el-input v-model="form.path" placeholder="请输入路由地址" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12" v-if="form.menuType == 'C'"> <el-col :span="12" v-if="form.menuType == '2'">
<el-form-item label="组件路径" prop="component"> <el-form-item label="组件路径" prop="component">
<el-input v-model="form.component" placeholder="请输入组件路径" /> <el-input v-model="form.component" placeholder="请输入组件路径" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'M'" label="权限标识"> <el-form-item v-if="form.menuType != '1'" label="权限标识">
<el-input v-model="form.perms" placeholder="请权限标识" maxlength="50" /> <el-input v-model="form.perms" placeholder="请权限标识" maxlength="50" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'" label="显示状态"> <el-form-item v-if="form.menuType != '3'" label="显示状态">
<el-radio-group v-model="form.visible"> <el-radio-group v-model="form.visible">
<el-radio <el-radio
v-for="dict in visibleOptions" v-for="dict in visibleOptions"
@ -177,7 +177,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'" label="菜单状态"> <el-form-item v-if="form.menuType != '3'" label="菜单状态">
<el-radio-group v-model="form.status"> <el-radio-group v-model="form.status">
<el-radio <el-radio
v-for="dict in statusOptions" v-for="dict in statusOptions"
@ -188,7 +188,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType == 'C'" label="是否缓存"> <el-form-item v-if="form.menuType == '2'" label="是否缓存">
<el-radio-group v-model="form.isCache"> <el-radio-group v-model="form.isCache">
<el-radio label="0">缓存</el-radio> <el-radio label="0">缓存</el-radio>
<el-radio label="1">不缓存</el-radio> <el-radio label="1">不缓存</el-radio>
@ -297,14 +297,14 @@ export default {
}, },
// //
visibleFormat(row, column) { visibleFormat(row, column) {
if (row.menuType == "F") { if (row.menuType == "3") {
return ""; return "";
} }
return this.selectDictLabel(this.visibleOptions, row.visible); return this.selectDictLabel(this.visibleOptions, row.visible);
}, },
// //
statusFormat(row, column) { statusFormat(row, column) {
if (row.menuType == "F") { if (row.menuType == "3") {
return ""; return "";
} }
return this.selectDictLabel(this.statusOptions, row.status); return this.selectDictLabel(this.statusOptions, row.status);
@ -321,7 +321,7 @@ export default {
parentId: 0, parentId: 0,
menuName: undefined, menuName: undefined,
icon: undefined, icon: undefined,
menuType: "M", menuType: "1",
orderNum: undefined, orderNum: undefined,
isFrame: "1", isFrame: "1",
isCache: "0", isCache: "0",

View File

@ -12,13 +12,13 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum CommonStatusEnum { public enum CommonStatusEnum {
ENABLE("0", "开启"), ENABLE(0, "开启"),
DISABLE("1", "关闭"); DISABLE(1, "关闭");
/** /**
* *
*/ */
private final String status; private final Integer status;
/** /**
* *
*/ */

View File

@ -0,0 +1,27 @@
package cn.iocoder.dashboard.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
*
*
* @author
*/
@Getter
@AllArgsConstructor
public enum OldCommonStatusEnum {
ENABLE("0", "开启"),
DISABLE("1", "关闭");
/**
*
*/
private final String status;
/**
*
*/
private final String name;
}

View File

@ -4,7 +4,6 @@ import cn.iocoder.dashboard.common.exception.GlobalException;
import cn.iocoder.dashboard.common.exception.ServiceException; import cn.iocoder.dashboard.common.exception.ServiceException;
import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.common.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindException; import org.springframework.validation.BindException;
import org.springframework.validation.FieldError; import org.springframework.validation.FieldError;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;

View File

@ -0,0 +1,3 @@
### 请求 /menu/list 接口 => 成功
GET {{baseUrl}}//menu/list
Authorization: Bearer {{token}}

View File

@ -0,0 +1,119 @@
package cn.iocoder.dashboard.modules.system.controller.permission;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuListReqVO;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuRespVO;
import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
@Api(tags = "菜单 API")
@RestController
@RequestMapping("/system/menu")
public class SysMenuController {
@Resource
private SysMenuService menuService;
/**
*
*/
// @PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/list")
public CommonResult<List<SysMenuRespVO>> list(SysMenuListReqVO reqVO) {
return success(menuService.listMenus(reqVO));
}
//
// /**
// * 根据菜单编号获取详细信息
// */
// @PreAuthorize("@ss.hasPermi('system:menu:query')")
// @GetMapping(value = "/{menuId}")
// public AjaxResult getInfo(@PathVariable Long menuId) {
// return AjaxResult.success(menuService.selectMenuById(menuId));
// }
//
// /**
// * 获取菜单下拉树列表
// */
// @GetMapping("/treeselect")
// public AjaxResult treeselect(SysMenu menu) {
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
// Long userId = loginUser.getUser().getUserId();
// List<SysMenu> menus = menuService.selectMenuList(menu, userId);
// return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
// }
//
// /**
// * 加载对应角色菜单列表树
// */
// @GetMapping(value = "/roleMenuTreeselect/{roleId}")
// public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
// LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
// List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
// AjaxResult ajax = AjaxResult.success();
// ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
// ajax.put("menus", menuService.buildMenuTreeSelect(menus));
// return ajax;
// }
//
// /**
// * 新增菜单
// */
// @PreAuthorize("@ss.hasPermi('system:menu:add')")
// @Log(title = "菜单管理", businessType = BusinessType.INSERT)
// @PostMapping
// public AjaxResult add(@Validated @RequestBody SysMenu menu) {
// if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
// return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
// } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
// && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
// return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
// }
// menu.setCreateBy(SecurityUtils.getUsername());
// return toAjax(menuService.insertMenu(menu));
// }
//
// /**
// * 修改菜单
// */
// @PreAuthorize("@ss.hasPermi('system:menu:edit')")
// @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
// @PutMapping
// public AjaxResult edit(@Validated @RequestBody SysMenu menu) {
// if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
// return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
// } else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
// && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS)) {
// return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败地址必须以http(s)://开头");
// } else if (menu.getMenuId().equals(menu.getParentId())) {
// return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
// }
// menu.setUpdateBy(SecurityUtils.getUsername());
// return toAjax(menuService.updateMenu(menu));
// }
//
// /**
// * 删除菜单
// */
// @PreAuthorize("@ss.hasPermi('system:menu:remove')")
// @Log(title = "菜单管理", businessType = BusinessType.DELETE)
// @DeleteMapping("/{menuId}")
// public AjaxResult remove(@PathVariable("menuId") Long menuId) {
// if (menuService.hasChildByMenuId(menuId)) {
// return AjaxResult.error("存在子菜单,不允许删除");
// }
// if (menuService.checkMenuExistRole(menuId)) {
// return AjaxResult.error("菜单已分配,不允许删除");
// }
// return toAjax(menuService.deleteMenuById(menuId));
// }
}

View File

@ -0,0 +1,52 @@
package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* Base VO VO 使
* VO Swagger
*/
@Data
public class SysMenuBaseVO {
@ApiModelProperty(value = "菜单名称", required = true, example = "芋道")
@NotBlank(message = "菜单名称不能为空")
@Size(max = 50, message = "菜单名称长度不能超过50个字符")
private String menuName;
@ApiModelProperty(value = "权限标识", example = "sys:menu:add", notes = "仅菜单类型为按钮时,才需要传递")
@Size(max = 100)
private String permission;
@ApiModelProperty(value = "类型", required = true, example = "1", notes = "参见 MenuTypeEnum 枚举类")
@NotBlank(message = "菜单类型不能为空")
private Integer menuType;
@ApiModelProperty(value = "显示顺序不能为空", required = true, example = "1024")
@NotBlank(message = "显示顺序不能为空")
private String sort;
@ApiModelProperty(value = "父菜单 ID", required = true, example = "1024")
@NotNull(message = "父菜单 ID 不能为空")
private Long parentId;
@ApiModelProperty(value = "路由地址", example = "post", notes = "仅菜单类型为菜单或者目录时,才需要传")
@Size(max = 200, message = "路由地址不能超过200个字符")
private String path;
@ApiModelProperty(value = "菜单图标", example = "/menu/list", notes = "仅菜单类型为菜单或者目录时,才需要传")
private String icon;
/**
*
*/
@ApiModelProperty(value = "组件路径", example = "system/post/index", notes = "仅菜单类型为菜单时,才需要传")
@Size(max = 200, message = "组件路径不能超过255个字符")
private String component;
}

View File

@ -0,0 +1,10 @@
package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModel;
import lombok.*;
@ApiModel("菜单创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysMenuCreateReqVO extends SysMenuBaseVO {
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@ApiModel("菜单列表 Request VO")
@Data
public class SysMenuListReqVO {
@ApiModelProperty(value = "菜单名称", example = "芋道", notes = "模糊匹配")
private String menuName;
@ApiModelProperty(value = "展示状态", example = "1", notes = "参见 CommonStatusEnum 枚举类")
private Integer status;
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.Date;
@ApiModel("菜单信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysMenuRespVO extends SysMenuBaseVO {
@ApiModelProperty(value = "菜单编号", required = true, example = "1024")
private Integer menuId;
@ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式")
private Date createTime;
}

View File

@ -0,0 +1,18 @@
package cn.iocoder.dashboard.modules.system.controller.permission.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import javax.validation.constraints.NotNull;
@ApiModel("菜单更新 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysMenuUpdateReqVO extends SysMenuBaseVO {
@ApiModelProperty(value = "菜单编号", required = true, example = "1024")
@NotNull(message = "菜单编号不能为空")
private Integer menuId;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.dashboard.modules.system.convert.permission;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuRespVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface SysMenuConvert {
SysMenuConvert INSTANCE = Mappers.getMapper(SysMenuConvert.class);
List<SysMenuRespVO> convertList(List<SysMenuDO> list);
}

View File

@ -0,0 +1,68 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/**
*
*
* @author ruoyi
*/
@TableName("sys_dict_data")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysDictData extends BaseDO {
/**
*
*/
@TableId
@Excel(name = "字典编码", cellType = Excel.ColumnType.NUMERIC)
private Long dictCode;
/**
*
*/
@Excel(name = "字典排序", cellType = Excel.ColumnType.NUMERIC)
private Long dictSort;
/**
*
*/
@Excel(name = "字典标签")
@NotBlank(message = "字典标签不能为空")
@Size(max = 100, message = "字典标签长度不能超过100个字符")
private String dictLabel;
/**
*
*/
@Excel(name = "字典键值")
@NotBlank(message = "字典键值不能为空")
@Size(max = 100, message = "字典键值长度不能超过100个字符")
private String dictValue;
/**
*
*/
@Excel(name = "字典类型")
@NotBlank(message = "字典类型不能为空")
@Size(max = 100, message = "字典类型长度不能超过100个字符")
private String dictType;
/**
*
*
* {@link CommonStatusEnum}
*/
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private Integer status;
/**
*
*/
private String remark;
}

View File

@ -0,0 +1,55 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.excel.Excel;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/**
*
*
* @author ruoyi
*/
@TableName("sys_dict_type")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysDictTypeDO extends BaseDO {
/**
*
*/
@TableId
@Excel(name = "字典主键", cellType = Excel.ColumnType.NUMERIC)
private Long dictId;
/**
*
*/
@Excel(name = "字典名称")
@NotBlank(message = "字典名称不能为空")
@Size(max = 100, message = "字典类型名称长度不能超过100个字符")
private String dictName;
/**
*
*/
@Excel(name = "字典类型")
@NotBlank(message = "字典类型不能为空")
@Size(max = 100, message = "字典类型类型长度不能超过100个字符")
private String dictType;
/**
*
*
* {@link CommonStatusEnum}
*/
@Excel(name = "状态", readConverterExp = "0=正常,1=停用")
private Integer status;
}

View File

@ -1,16 +1,15 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission; package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.mybatis.core.BaseDO; import cn.iocoder.dashboard.framework.mybatis.core.BaseDO;
import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/** /**
* * DO
* *
* @author ruoyi * @author ruoyi
*/ */
@ -24,57 +23,52 @@ public class SysMenuDO extends BaseDO {
*/ */
@TableId @TableId
private Long menuId; private Long menuId;
/** /**
* *
*/ */
@NotBlank(message = "菜单名称不能为空")
@Size(max = 50, message = "菜单名称长度不能超过50个字符")
private String menuName; private String menuName;
/**
*
*
* ${}:${}:${}
* system:admin:add system
*
* SysMenuDO
* - @PreAuthorize API API
* -
*/
private String permission;
/**
*
*
* {@link MenuTypeEnum}
*/
private Integer menuType;
/**
*
*/
private String sort;
/** /**
* ID * ID
*/ */
private Long parentId; private Long parentId;
/**
*
*/
@NotBlank(message = "显示顺序不能为空")
private String orderNum;
/** /**
* *
*/ */
@Size(max = 200, message = "路由地址不能超过200个字符")
private String path; private String path;
/**
*
*/
@Size(max = 200, message = "组件路径不能超过255个字符")
private String component;
/**
* M C F
*/
@NotBlank(message = "菜单类型不能为空")
private String menuType;
/**
* 0 1
*/
private String status;
/**
*
*/
@Size(max = 100, message = "权限标识长度不能超过100个字符")
private String permission;
/** /**
* *
*/ */
private String icon; private String icon;
/**
*
*/
private String component;
/**
*
*
* {@link CommonStatusEnum}
*/
private Integer status;
} }

View File

@ -12,14 +12,14 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum MenuTypeEnum { public enum MenuTypeEnum {
DIR("M"), // 目录 DIR(1), // 目录
MENU("C"), // 菜单 MENU(2), // 菜单
BUTTON("F") // 按钮 BUTTON(3) // 按钮
; ;
/** /**
* *
*/ */
private final String type; private final Integer type;
} }

View File

@ -5,8 +5,8 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
import cn.iocoder.dashboard.framework.security.config.SecurityProperties; import cn.iocoder.dashboard.framework.security.config.SecurityProperties;
import cn.iocoder.dashboard.framework.security.core.LoginUser; import cn.iocoder.dashboard.framework.security.core.LoginUser;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO; import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO;
import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO;
import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert; import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO;
@ -252,7 +252,7 @@ public class SysAuthServiceImpl implements SysAuthService {
private static List<SysAuthMenuRespVO> buildRouterTree(List<SysMenuDO> menuList) { private static List<SysAuthMenuRespVO> buildRouterTree(List<SysMenuDO> menuList) {
// 排序,保证菜单的有序性 // 排序,保证菜单的有序性
menuList.sort(Comparator.comparing(SysMenuDO::getOrderNum)); menuList.sort(Comparator.comparing(SysMenuDO::getSort));
// 构建菜单树 // 构建菜单树
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
Map<Long, SysAuthMenuRespVO> treeNodeMap = new LinkedHashMap<>(); Map<Long, SysAuthMenuRespVO> treeNodeMap = new LinkedHashMap<>();

View File

@ -1,5 +1,7 @@
package cn.iocoder.dashboard.modules.system.service.permission; package cn.iocoder.dashboard.modules.system.service.permission;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuListReqVO;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuRespVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import java.util.Collection; import java.util.Collection;
@ -15,6 +17,14 @@ public interface SysMenuService {
*/ */
void init(); void init();
/**
*
*
* @param reqVO VO
* @return
*/
List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO);
/** /**
* *
* *
@ -24,7 +34,7 @@ public interface SysMenuService {
* @param menusStatuses * @param menusStatuses
* @return * @return
*/ */
List<SysMenuDO> listMenusFromCache(Collection<String> menuTypes, Collection<String> menusStatuses); List<SysMenuDO> listMenusFromCache(Collection<Integer> menuTypes, Collection<Integer> menusStatuses);
/** /**
* *
@ -36,9 +46,7 @@ public interface SysMenuService {
* @param menusStatuses * @param menusStatuses
* @return * @return
*/ */
List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<String> menuTypes, List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<Integer> menuTypes,
Collection<String> menusStatuses); Collection<Integer> menusStatuses);
} }

View File

@ -29,8 +29,8 @@ public interface SysPermissionService {
* @param menusStatuses * @param menusStatuses
* @return * @return
*/ */
List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<String> menuTypes, List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
Collection<String> menusStatuses); Collection<Integer> menusStatuses);
/** /**
* *

View File

@ -1,5 +1,8 @@
package cn.iocoder.dashboard.modules.system.service.permission.impl; package cn.iocoder.dashboard.modules.system.service.permission.impl;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuListReqVO;
import cn.iocoder.dashboard.modules.system.controller.permission.vo.SysMenuRespVO;
import cn.iocoder.dashboard.modules.system.convert.permission.SysMenuConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysMenuMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.permission.SysMenuMapper;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO;
import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService; import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService;
@ -63,7 +66,14 @@ public class SysMenuServiceImpl implements SysMenuService {
} }
@Override @Override
public List<SysMenuDO> listMenusFromCache(Collection<String> menuTypes, Collection<String> menusStatuses) { public List<SysMenuRespVO> listMenus(SysMenuListReqVO reqVO) {
List<SysMenuDO> list = menuMapper.selectList(null);
// TODO 排序
return SysMenuConvert.INSTANCE.convertList(list);
}
@Override
public List<SysMenuDO> listMenusFromCache(Collection<Integer> menuTypes, Collection<Integer> menusStatuses) {
// 任一一个参数为空,则返回空 // 任一一个参数为空,则返回空
if (CollectionUtils.isAnyEmpty(menuTypes, menusStatuses)) { if (CollectionUtils.isAnyEmpty(menuTypes, menusStatuses)) {
return Collections.emptyList(); return Collections.emptyList();
@ -75,8 +85,8 @@ public class SysMenuServiceImpl implements SysMenuService {
} }
@Override @Override
public List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<String> menuTypes, public List<SysMenuDO> listMenusFromCache(Collection<Long> menuIds, Collection<Integer> menuTypes,
Collection<String> menusStatuses) { Collection<Integer> menusStatuses) {
// 任一一个参数为空,则返回空 // 任一一个参数为空,则返回空
if (CollectionUtils.isAnyEmpty(menuIds, menuTypes, menusStatuses)) { if (CollectionUtils.isAnyEmpty(menuIds, menuTypes, menusStatuses)) {
return Collections.emptyList(); return Collections.emptyList();

View File

@ -78,8 +78,8 @@ public class SysPermissionServiceImpl implements SysPermissionService {
} }
@Override @Override
public List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<String> menuTypes, public List<SysMenuDO> listRoleMenusFromCache(Collection<Long> roleIds, Collection<Integer> menuTypes,
Collection<String> menusStatuses) { Collection<Integer> menusStatuses) {
// 任一一个参数为空时,不返回任何菜单 // 任一一个参数为空时,不返回任何菜单
if (CollectionUtils.isAnyEmpty(roleIds, menusStatuses, menusStatuses)) { if (CollectionUtils.isAnyEmpty(roleIds, menusStatuses, menusStatuses)) {
return Collections.emptyList(); return Collections.emptyList();