dev-v2 #3
|
@ -19,4 +19,5 @@ public class MessageConstant {
|
||||||
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
public static final String REQUEST_NOT_EMPTY = "请求不为空";
|
||||||
public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空";
|
public static final String UPDATE_ID_IS_NOT_EMPTY = "删除id不能为空";
|
||||||
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
public static final String DELETE_ID_IS_NOT_EMPTY = "修改id不能为空";
|
||||||
|
public static final String MENU_IS_NOT_EXIST = "菜单不存在";
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,11 @@ public class SysMenuController {
|
||||||
sysMenuService.updateById(sysMenu);
|
sysMenuService.updateById(sysMenu);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除菜单", description = "删除菜单")
|
||||||
|
@PutMapping("removeById/{id}")
|
||||||
|
public Result removeById(@PathVariable Long id) {
|
||||||
|
sysMenuService.removeById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,4 +27,19 @@ public interface SysMenuMapper {
|
||||||
* @param sysMenu 系统菜单实体类
|
* @param sysMenu 系统菜单实体类
|
||||||
*/
|
*/
|
||||||
void updateById(SysMenu sysMenu);
|
void updateById(SysMenu sysMenu);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜单
|
||||||
|
*
|
||||||
|
* @param id 菜单id
|
||||||
|
* @return 是否存在
|
||||||
|
*/
|
||||||
|
int countByParentId(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除菜单
|
||||||
|
*
|
||||||
|
* @param id 菜单id
|
||||||
|
*/
|
||||||
|
void deleteById(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,4 +25,11 @@ public interface SysMenuService {
|
||||||
* @param sysMenu 系统菜单实体类
|
* @param sysMenu 系统菜单实体类
|
||||||
*/
|
*/
|
||||||
void updateById(SysMenu sysMenu);
|
void updateById(SysMenu sysMenu);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜单
|
||||||
|
*
|
||||||
|
* @param id 菜单id
|
||||||
|
*/
|
||||||
|
void removeById(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atguigu.spzx.manger.service.impl;
|
package com.atguigu.spzx.manger.service.impl;
|
||||||
|
|
||||||
import com.atguigu.constant.MessageConstant;
|
import com.atguigu.constant.MessageConstant;
|
||||||
|
import com.atguigu.exception.BunnyException;
|
||||||
import com.atguigu.spzx.manger.mapper.SysMenuMapper;
|
import com.atguigu.spzx.manger.mapper.SysMenuMapper;
|
||||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||||
|
@ -49,4 +50,18 @@ public class SysMenuServiceImpl implements SysMenuService {
|
||||||
emptyUtil.isEmpty(sysMenu.getId(), MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
emptyUtil.isEmpty(sysMenu.getId(), MessageConstant.DELETE_ID_IS_NOT_EMPTY);
|
||||||
sysMenuMapper.updateById(sysMenu);
|
sysMenuMapper.updateById(sysMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜单
|
||||||
|
*
|
||||||
|
* @param id 菜单id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void removeById(Long id) {
|
||||||
|
int count = sysMenuMapper.countByParentId(id); // 先查询是否存在子菜单,如果存在不允许进行删除
|
||||||
|
if (count > 0) {
|
||||||
|
throw new BunnyException(MessageConstant.MENU_IS_NOT_EXIST);
|
||||||
|
}
|
||||||
|
sysMenuMapper.deleteById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,22 @@
|
||||||
where id = #{id};
|
where id = #{id};
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 根据id查询菜单 -->
|
||||||
|
<update id="countByParentId">
|
||||||
|
select count(id)
|
||||||
|
from sys_menu
|
||||||
|
where parent_id = #{parentId}
|
||||||
|
and is_deleted = 0
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!-- 根据id删除菜单 -->
|
||||||
|
<delete id="deleteById">
|
||||||
|
update sys_menu
|
||||||
|
set update_time = now(),
|
||||||
|
is_deleted = 1
|
||||||
|
where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
<!-- 查询菜单 -->
|
<!-- 查询菜单 -->
|
||||||
<select id="selectAll" resultType="com.atguigu.spzx.model.entity.system.SysMenu">
|
<select id="selectAll" resultType="com.atguigu.spzx.model.entity.system.SysMenu">
|
||||||
select
|
select
|
||||||
|
|
Loading…
Reference in New Issue