3.4 权限添加按钮
1)原型效果
2)接口说明
功能描述: 权限添加按钮
服务路径: /api/permission
服务方法:Post
请求参数格式:
{
"type":"1", //菜单等级 0 顶级目录 1.目录 2 菜单 3 按钮
"title":"更新角色权限",
/**
* 对应资源路径
* 1.如果类型是目录,则url为空
* 2.如果类型是菜单,则url对应路由地址
* 3.如果类型是按钮,则url对应是访问接口的地址
*/
"pid":1236916745927790560,
"url":"api/permissions/tree",//只有菜单类型有名称,默认是路由的名称
"name":"org",
"icon":"el-icon-menu",
"perms":"sys:role:update",//基于springSecrutiry约定的权限过滤便是
"method":"DELETE",//请求方式:get put delete post等
"code":"btn-role-update",//vue按钮回显控制辨识
"orderNum":100//排序
}
接口提示:请求参数:@RequestBody PermissionAddVo vo
响应数据格式:
{
"code": 0,
"msg": "添加成功"
}
代码实现
1. 表现层
@ApiOperation(value = "权限添加按钮")
@PostMapping("/permissions/tree")
public R<String> addPermissions(@RequestBody PostPermissionDomain permissionDomain){
return service.addPermissions(permissionDomain);
}
2. 服务层
R<String> addPermissions(PostPermissionDomain permissionDomain);
@Override
public R<String> addPermissions(PostPermissionDomain permissionDomain) {
long nextId = idWorkerl.nextId();
SysPermission sysPermission = new SysPermission();
BeanUtils.copyProperties(permissionDomain,sysPermission);
sysPermission.setId(nextId);
sysPermissionMapper.insert(sysPermission);
return R.ok("操作成功");
}
3. Dao层
int insert(SysPermission record);
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.jixu.stock.pojo.entity.SysPermission" useGeneratedKeys="true">
insert into sys_permission
( id,code,title
,icon,perms,url
,method,name,pid
,order_num,type,status
,create_time,update_time,deleted
)
values (#{id,jdbcType=BIGINT},#{code,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR}
,#{icon,jdbcType=VARCHAR},#{perms,jdbcType=VARCHAR},#{url,jdbcType=VARCHAR}
,#{method,jdbcType=VARCHAR},#{name,jdbcType=VARCHAR},#{pid,jdbcType=BIGINT}
,#{orderNum,jdbcType=INTEGER},#{type,jdbcType=TINYINT},#{status,jdbcType=TINYINT}
,#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{deleted,jdbcType=TINYINT}
)
</insert>
4. 实体类
package com.jixu.stock.pojo.domain;
import lombok.Data;
/**
* @program: stock_parent
* @description:
* @author: jixu
* @create: 2024-10-13 14:43
**/
@Data
public class PostPermissionDomain {
private String type;
private String title;
private Long pid;
private String url;
private String name;
private String icon;
private String perms;
private String method;
private String code;
private String orderNum;
}
3.5更新权限
1)原型效果
2)接口说明
功能描述: 更新权限
服务路径: /api/permission
服务方法:Put
请求参数格式:
{
"id": 1236916745927790556 //权限id
"type":"1", //菜单等级 0 顶级目录 1.目录 2 菜单 3 按钮
"title":"更新角色权限",
/**
* 对应资源路径
* 1.如果类型是目录,则url为空
* 2.如果类型是菜单,则url对应路由地址
* 3.如果类型是按钮,则url对应是访问接口的地址
*/
"pid":1236916745927790560,
"url":"api/permissions/tree",//只有菜单类型有名称,默认是路由的名称
"name":"org",
"icon":"el-icon-menu",
"perms":"sys:role:update",//基于springSecrutiry约定的权限过滤便是
"method":"DELETE",//请求方式:get put delete post等
"code":"btn-role-update",//vue按钮回显控制辨识
"orderNum":100//排序
}
接口提示:请求参数:@RequestBody PermissionUpdateVo vo
响应数据格式:
{
"code": 0,
"msg": "添加成功"
}
代码实现
1. 表现层
@ApiOperation(value = "更新权限")
@PutMapping("/permissions/tree")
public R<String> updataPermissions(@RequestBody PutPermissionVo putPermissionVo){
return service.updataPermissions(putPermissionVo);
}
2. 服务层
R<String> updataPermissions(PutPermissionVo putPermissionVo);
@Override
public R<String> updataPermissions(PutPermissionVo putPermissionVo) {
SysPermission sysPermission = new SysPermission();
BeanUtils.copyProperties(putPermissionVo,sysPermission);
sysPermissionMapper.updateByPrimaryKey(sysPermission);
return R.ok("操作成功");
}
3. Dao层
int updateByPrimaryKey(SysPermission record);
<update id="updateByPrimaryKey" parameterType="com.jixu.stock.pojo.entity.SysPermission">
update sys_permission
set
code = #{code,jdbcType=VARCHAR},
title = #{title,jdbcType=VARCHAR},
icon = #{icon,jdbcType=VARCHAR},
perms = #{perms,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
method = #{method,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
pid = #{pid,jdbcType=BIGINT},
order_num = #{orderNum,jdbcType=INTEGER},
type = #{type,jdbcType=TINYINT},
status = #{status,jdbcType=TINYINT},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
deleted = #{deleted,jdbcType=TINYINT}
where id = #{id,jdbcType=BIGINT}
</update>
3.6 删除权限
1)原型效果
2)接口说明
功能描述: 删除权限
服务路径: /api/permission/{permissionId}
服务方法:Delete
响应数据格式:
{
"code": 0,
"msg": "删除成功"
}
代码实现
1. 表现层
@ApiOperation(value = "删除权限")
@DeleteMapping("/permission/{permissionId}")
public R<String> delPermissions(@PathVariable Long permissionId){
return service.delPermissions(permissionId);
}
2. 服务层
R<String> delPermissions(Long permissionId);
@Override
public R<String> delPermissions(Long permissionId) {
sysPermissionMapper.deleteByPrimaryKey(permissionId);
return R.ok("操作成功");
}
3. Dao层
int deleteByPrimaryKey(Long id);
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from sys_permission
where id = #{id,jdbcType=BIGINT}
</delete>