mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 06:51:23 +08:00
Added role management
This commit is contained in:
@@ -2,8 +2,10 @@ package com.cfive.pinnacle;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement
|
||||
public class PinnacleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package com.cfive.pinnacle.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.Role;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.service.IRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -15,4 +22,45 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RequestMapping("/role")
|
||||
public class RoleController {
|
||||
|
||||
private IRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
public void setRoleService(IRoleService roleService) {
|
||||
this.roleService = roleService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseResult getAllRole() {
|
||||
List<Role> roles = roleService.getAllRole();
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SELECT_OK, "success", roles);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseResult addRole(@RequestBody Role role) {
|
||||
if (roleService.addRole(role)) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseResult deleteRole(@PathVariable Long id) {
|
||||
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Role::getId, id);
|
||||
if (roleService.remove(wrapper)) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_OK, "success", null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping()
|
||||
public ResponseResult modifyRole(@RequestBody Role role) {
|
||||
if (roleService.modifyRole(role)) {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_SAVE_OK, "success", null);
|
||||
} else {
|
||||
return ResponseResult.build(ResponseCode.DATABASE_DELETE_ERROR, "error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -30,6 +32,7 @@ public class Department implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -29,6 +31,7 @@ public class Group implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,14 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.cfive.pinnacle.entity.permission.Element;
|
||||
import com.cfive.pinnacle.entity.permission.Menu;
|
||||
import com.cfive.pinnacle.entity.permission.Operation;
|
||||
import com.cfive.pinnacle.entity.permission.Power;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -29,6 +36,7 @@ public class Role implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -37,6 +45,18 @@ public class Role implements Serializable {
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Menu> menus;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Element> elements;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Operation> operations;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Power> powers;
|
||||
|
||||
@TableField("deleted")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -29,18 +31,21 @@ public class RoleGroup implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
@TableField("role_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 群组
|
||||
*/
|
||||
@TableField("group_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long groupId;
|
||||
|
||||
@TableField("deleted")
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -30,12 +32,14 @@ public class Staff implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableField("user_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,6 +50,7 @@ public class User implements Serializable {
|
||||
* 部门
|
||||
*/
|
||||
@TableField("department_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -29,18 +31,21 @@ public class UserGroup implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableField("user_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户组
|
||||
*/
|
||||
@TableField("group_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long groupId;
|
||||
|
||||
@TableField("deleted")
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@@ -29,18 +31,21 @@ public class UserRole implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableField("user_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
@TableField("role_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long roleId;
|
||||
|
||||
@TableField("deleted")
|
||||
|
||||
@@ -31,6 +31,7 @@ public class UserWork implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,7 @@ public class Work implements Serializable {
|
||||
* 发布者
|
||||
*/
|
||||
@TableField("publisher_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long publisherId;
|
||||
|
||||
@TableField(exist = false)
|
||||
@@ -82,6 +83,7 @@ public class Work implements Serializable {
|
||||
* 源ID
|
||||
*/
|
||||
@TableField("origin_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long originId;
|
||||
|
||||
@TableField("deleted")
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,6 +33,7 @@ public class Element implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -43,5 +46,13 @@ public class Element implements Serializable {
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("power_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long powerId;
|
||||
|
||||
/**
|
||||
* 菜单ID
|
||||
*/
|
||||
@TableField("menu_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long menuId;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,6 +33,7 @@ public class File implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -49,5 +52,6 @@ public class File implements Serializable {
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("power_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long powerId;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,6 +33,7 @@ public class Menu implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -49,11 +52,13 @@ public class Menu implements Serializable {
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("power_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long powerId;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@TableField("parent_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long parentId;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,6 +33,7 @@ public class Operation implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -49,11 +52,20 @@ public class Operation implements Serializable {
|
||||
* 权限ID
|
||||
*/
|
||||
@TableField("power_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long powerId;
|
||||
|
||||
/**
|
||||
* 页面元素ID
|
||||
*/
|
||||
@TableField("element_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long elementId;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@TableField("parent_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long parentId;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -34,18 +36,21 @@ public class OperationLog implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
@TableField("user_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 功能
|
||||
*/
|
||||
@TableField("operation_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long operationId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,11 +33,13 @@ public class Power implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限类型
|
||||
*/
|
||||
@TableField("type_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long typeId;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.baomidou.mybatisplus.annotation.Version;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -33,18 +35,21 @@ public class PowerRole implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 权限
|
||||
*/
|
||||
@TableField("power_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long powerId;
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
@TableField("role_id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long roleId;
|
||||
|
||||
@TableField("deleted")
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -31,6 +33,7 @@ public class PowerType implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId("id")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.cfive.pinnacle.mapper;
|
||||
import java.util.List;
|
||||
|
||||
import com.cfive.pinnacle.entity.Role;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -14,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
List<Role> getAll();
|
||||
|
||||
Role getOneById(@Param("id") long id);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.cfive.pinnacle.service;
|
||||
import com.cfive.pinnacle.entity.Role;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色 服务类
|
||||
@@ -12,5 +14,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IRoleService extends IService<Role> {
|
||||
List<Role> getAllRole();
|
||||
|
||||
Role getRole(long id);
|
||||
|
||||
boolean addRole(Role role);
|
||||
|
||||
boolean modifyRole(Role role);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package com.cfive.pinnacle.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.cfive.pinnacle.entity.Role;
|
||||
import com.cfive.pinnacle.entity.permission.PowerRole;
|
||||
import com.cfive.pinnacle.mapper.RoleMapper;
|
||||
import com.cfive.pinnacle.mapper.permission.PowerRoleMapper;
|
||||
import com.cfive.pinnacle.service.IRoleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -17,4 +25,74 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
|
||||
|
||||
private RoleMapper roleMapper;
|
||||
private PowerRoleMapper powerRoleMapper;
|
||||
|
||||
@Autowired
|
||||
public void setRoleMapper(RoleMapper roleMapper) {
|
||||
this.roleMapper = roleMapper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setPowerRoleMapper(PowerRoleMapper powerRoleMapper) {
|
||||
this.powerRoleMapper = powerRoleMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Role> getAllRole() {
|
||||
return roleMapper.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Role getRole(long id) {
|
||||
return roleMapper.getOneById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addRole(Role role) {
|
||||
if (roleMapper.insert(role) == 1) {
|
||||
role.getPowers().forEach(power -> {
|
||||
PowerRole powerRole = new PowerRole();
|
||||
powerRole.setRoleId(role.getId());
|
||||
powerRole.setPowerId(power.getId());
|
||||
if (powerRoleMapper.insert(powerRole) != 1) {
|
||||
throw new RuntimeException("Add power_role failure");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("Add role failure");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean modifyRole(Role role) {
|
||||
roleMapper.updateById(role);
|
||||
Role originalRole = getRole(role.getId());
|
||||
HashSet<Long> originalPowerIds = new HashSet<>();
|
||||
originalRole.getMenus().forEach(menu -> originalPowerIds.add(menu.getPowerId()));
|
||||
originalRole.getElements().forEach(element -> originalPowerIds.add(element.getPowerId()));
|
||||
originalRole.getOperations().forEach(operation -> originalPowerIds.add(operation.getPowerId()));
|
||||
HashSet<Long> newPowerIds = new HashSet<>();
|
||||
role.getPowers().forEach(power -> newPowerIds.add(power.getId()));
|
||||
HashSet<Long> deletePowerIds = new HashSet<>(originalPowerIds);
|
||||
deletePowerIds.removeAll(newPowerIds);
|
||||
HashSet<Long> addPowerIds = new HashSet<>(newPowerIds);
|
||||
addPowerIds.removeAll(originalPowerIds);
|
||||
deletePowerIds.forEach(deletePowerId -> {
|
||||
LambdaQueryWrapper<PowerRole> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PowerRole::getRoleId, role.getId())
|
||||
.eq(PowerRole::getPowerId, deletePowerId);
|
||||
powerRoleMapper.delete(wrapper);
|
||||
});
|
||||
addPowerIds.forEach(addPowerId -> {
|
||||
PowerRole powerRole = new PowerRole();
|
||||
powerRole.setRoleId(role.getId());
|
||||
powerRole.setPowerId(addPowerId);
|
||||
powerRoleMapper.insert(powerRole);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,90 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.RoleMapper">
|
||||
|
||||
<select id="getAll" resultMap="roleMap">
|
||||
select t_role.id as role_id,
|
||||
t_role.name as role_name,
|
||||
t_role.deleted as role_deleted,
|
||||
t_role.version as role_version,
|
||||
tm.id as menu_id,
|
||||
tm.name as menu_name,
|
||||
tm.url as menu_url,
|
||||
tm.power_id as menu_power_id,
|
||||
tm.parent_id as menu_parent_id,
|
||||
te.id as element_id,
|
||||
te.name as element_name,
|
||||
te.power_id as element_power_id,
|
||||
te.menu_id as element_menu_id,
|
||||
t.id as operation_id,
|
||||
t.name as operation_name,
|
||||
t.code as operation_code,
|
||||
t.power_id as operation_power_id,
|
||||
t.element_id as operation_element_id,
|
||||
t.parent_id as operation_parent_id
|
||||
from t_role
|
||||
left join t_power_role tpr on t_role.id = tpr.role_id
|
||||
left join t_power tp on tp.id = tpr.power_id
|
||||
left join t_menu tm on tp.id = tm.power_id
|
||||
left join t_element te on tp.id = te.power_id
|
||||
left join t_operation t on tp.id = t.power_id
|
||||
where t_role.deleted = 0 and tpr.deleted = 0;
|
||||
</select>
|
||||
<select id="getOneById" resultMap="roleMap">
|
||||
select t_role.id as role_id,
|
||||
t_role.name as role_name,
|
||||
t_role.deleted as role_deleted,
|
||||
t_role.version as role_version,
|
||||
tm.id as menu_id,
|
||||
tm.name as menu_name,
|
||||
tm.url as menu_url,
|
||||
tm.power_id as menu_power_id,
|
||||
tm.parent_id as menu_parent_id,
|
||||
te.id as element_id,
|
||||
te.name as element_name,
|
||||
te.power_id as element_power_id,
|
||||
te.menu_id as element_menu_id,
|
||||
t.id as operation_id,
|
||||
t.name as operation_name,
|
||||
t.code as operation_code,
|
||||
t.power_id as operation_power_id,
|
||||
t.element_id as operation_element_id,
|
||||
t.parent_id as operation_parent_id
|
||||
from t_role
|
||||
left join t_power_role tpr on t_role.id = tpr.role_id
|
||||
left join t_power tp on tp.id = tpr.power_id
|
||||
left join t_menu tm on tp.id = tm.power_id
|
||||
left join t_element te on tp.id = te.power_id
|
||||
left join t_operation t on tp.id = t.power_id
|
||||
where t_role.deleted = 0
|
||||
and tpr.deleted = 0
|
||||
and t_role.id = #{id};
|
||||
</select>
|
||||
|
||||
<resultMap id="roleMap" type="role">
|
||||
<id property="id" column="role_id"/>
|
||||
<result property="name" column="role_name"/>
|
||||
<result property="deleted" column="role_deleted"/>
|
||||
<result property="version" column="role_version"/>
|
||||
<collection property="menus" ofType="menu">
|
||||
<id property="id" column="menu_id"/>
|
||||
<result property="name" column="menu_name"/>
|
||||
<result property="url" column="menu_url"/>
|
||||
<result property="powerId" column="menu_power_id"/>
|
||||
<result property="parentId" column="menu_parent_id"/>
|
||||
</collection>
|
||||
<collection property="elements" ofType="element">
|
||||
<id property="id" column="element_id"/>
|
||||
<result property="name" column="element_name"/>
|
||||
<result property="powerId" column="element_power_id"/>
|
||||
<result property="menuId" column="element_menu_id"/>
|
||||
</collection>
|
||||
<collection property="operations" ofType="operation">
|
||||
<id property="id" column="operation_id"/>
|
||||
<result property="name" column="operation_name"/>
|
||||
<result property="code" column="operation_code"/>
|
||||
<result property="powerId" column="operation_power_id"/>
|
||||
<result property="elementId" column="operation_element_id"/>
|
||||
<result property="parentId" column="operation_parent_id"/>
|
||||
</collection>
|
||||
</resultMap>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user