Compare commits
No commits in common. "a839b0c866b09b1fb1d3f8845f81f435ab463bb8" and "926f0ae96e6ced2a873ad534a6f5f97d2fd15f5e" have entirely different histories.
a839b0c866
...
926f0ae96e
|
|
@ -1,36 +1,10 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/data/ed/role")
|
@RequestMapping("/data/ed/role")
|
||||||
public class RoleController {
|
public class RoleController {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RoleService roleService;
|
|
||||||
|
|
||||||
@ApiOperation(value = "新建角色", notes = "")
|
|
||||||
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
|
||||||
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
|
||||||
return ElectromagneticResultUtil.success(roleService.createRole(roleDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "更新角色", notes = "")
|
|
||||||
@RequestMapping(value = "/updateRole", method = RequestMethod.POST)
|
|
||||||
public ElectromagneticResult<?> updateRole(@RequestBody RoleDTO roleDTO) {
|
|
||||||
return ElectromagneticResultUtil.success(roleService.updateRole(roleDTO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "删除角色", notes = "")
|
|
||||||
@GetMapping(value = "/deleteRole/{roleId}")
|
|
||||||
public ElectromagneticResult<?> deleteRole(@PathVariable("roleId") String roleId) {
|
|
||||||
return ElectromagneticResultUtil.success(roleService.deleteRole(roleId));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.models;
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import java.util.Date;
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("ed_role") // 指定表名
|
@TableName("ed_role") // 指定表名
|
||||||
public class Role {
|
public class Role {
|
||||||
|
|
||||||
@TableId(type = IdType.AUTO)
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,8 +51,8 @@ public class Role {
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
@TableField(value = "gmt_create", fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private Date gmtCreate;
|
private LocalDateTime gmtCreate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑者用户编码
|
* 编辑者用户编码
|
||||||
|
|
@ -67,13 +69,12 @@ public class Role {
|
||||||
* 编辑时间
|
* 编辑时间
|
||||||
*/
|
*/
|
||||||
@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
|
@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
|
||||||
private Date gmtModified;
|
private LocalDateTime gmtModified;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否有效:0-无效 1-有效
|
* 是否有效:0-无效 1-有效
|
||||||
*/
|
*/
|
||||||
@TableField(value = "effect_flag")
|
@TableField(value = "effect_flag")
|
||||||
@TableLogic(value = "1", delval = "0")
|
|
||||||
private Integer effectFlag;
|
private Integer effectFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("ed_role_permission")
|
@TableName("ed_role_permission")
|
||||||
@AllArgsConstructor
|
|
||||||
public class RolePermission {
|
public class RolePermission {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.req;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class RoleDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色编号
|
|
||||||
*/
|
|
||||||
private String roleId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色姓名
|
|
||||||
*/
|
|
||||||
private String roleName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色描述
|
|
||||||
*/
|
|
||||||
private String roleDesc;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限数据
|
|
||||||
*/
|
|
||||||
private List<RolePermissionDTO> data;
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.req;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class RolePermissionDTO {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目录(文件)编号
|
|
||||||
*/
|
|
||||||
private String fileId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 目录(文件)名称
|
|
||||||
*/
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限列表
|
|
||||||
*/
|
|
||||||
private List<String> permission;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 子目录
|
|
||||||
*/
|
|
||||||
private List<RolePermissionDTO> children;
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
|
||||||
|
|
||||||
public interface RolePermissionService extends IService<RolePermission> {
|
|
||||||
}
|
|
||||||
|
|
@ -2,30 +2,8 @@ package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
public interface RoleService extends IService<Role> {
|
public interface RoleService extends IService<Role> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 新建角色
|
|
||||||
* @param roleDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean createRole(RoleDTO roleDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新角色
|
|
||||||
* @param roleDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean updateRole(RoleDTO roleDTO);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除角色
|
|
||||||
* @param roleId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Boolean deleteRole(String roleId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.service;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
|
||||||
|
|
||||||
public interface UserRoleService extends IService<UserRole> {
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RolePermissionMapper;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
|
|
||||||
}
|
|
||||||
|
|
@ -1,166 +1,13 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
|
||||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.RolePermission;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePermissionDTO;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
import com.electromagnetic.industry.software.manage.service.RoleService;
|
||||||
import com.electromagnetic.industry.software.manage.service.UserRoleService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RolePermissionService rolePermissionService;
|
|
||||||
@Resource
|
|
||||||
private UserRoleService userRoleService;
|
|
||||||
@Autowired
|
|
||||||
private RoleMapper roleMapper;
|
|
||||||
|
|
||||||
private EleLog log = new EleLog(RoleServiceImpl.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新建角色
|
|
||||||
* @param roleDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
public Boolean createRole(RoleDTO roleDTO){
|
|
||||||
|
|
||||||
checkRoleNameUnique(roleDTO);
|
|
||||||
|
|
||||||
// 创建角色
|
|
||||||
Role role = new Role();
|
|
||||||
// 创建角色编号
|
|
||||||
String roleId = IdWorker.getSnowFlakeIdString();
|
|
||||||
|
|
||||||
role.setRoleId(roleId);
|
|
||||||
role.setRoleName(roleDTO.getRoleName());
|
|
||||||
role.setRoleDesc(roleDTO.getRoleDesc());
|
|
||||||
role.setCreator(UserThreadLocal.getUserId());
|
|
||||||
role.setCreatorName(UserThreadLocal.getUsername());
|
|
||||||
this.save(role);
|
|
||||||
|
|
||||||
// 创建权限
|
|
||||||
List<RolePermissionDTO> data = roleDTO.getData();
|
|
||||||
List<RolePermission> list = flattenTree(data, roleId);
|
|
||||||
rolePermissionService.saveBatch(list);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新角色
|
|
||||||
* @param roleDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
public Boolean updateRole(RoleDTO roleDTO){
|
|
||||||
|
|
||||||
// 更新角色信息
|
|
||||||
UpdateWrapper<Role> updateWrapper = new UpdateWrapper<>();
|
|
||||||
updateWrapper.eq("role_id", roleDTO.getRoleId());
|
|
||||||
updateWrapper.set("role_name", roleDTO.getRoleName());
|
|
||||||
updateWrapper.set("role_desc", roleDTO.getRoleDesc());
|
|
||||||
updateWrapper.set("modifier", UserThreadLocal.getUserId());
|
|
||||||
updateWrapper.set("modifier_name", UserThreadLocal.getUsername());
|
|
||||||
this.update(updateWrapper);
|
|
||||||
|
|
||||||
// 删除旧权限信息
|
|
||||||
QueryWrapper<RolePermission> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("role_id", roleDTO.getRoleId());
|
|
||||||
rolePermissionService.remove(queryWrapper);
|
|
||||||
|
|
||||||
// 插入新权限信息
|
|
||||||
List<RolePermissionDTO> data = roleDTO.getData();
|
|
||||||
List<RolePermission> list = flattenTree(data, roleDTO.getRoleId());
|
|
||||||
rolePermissionService.saveBatch(list);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除角色
|
|
||||||
* @param roleId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Transactional
|
|
||||||
@Override
|
|
||||||
public Boolean deleteRole(String roleId){
|
|
||||||
|
|
||||||
// 保留角色权限关联表
|
|
||||||
// 删除用户角色关联表
|
|
||||||
QueryWrapper<UserRole> queryWrapper1 = new QueryWrapper<>();
|
|
||||||
queryWrapper1.eq("role_id", roleId);
|
|
||||||
userRoleService.remove(queryWrapper1);
|
|
||||||
|
|
||||||
// 逻辑删除角色
|
|
||||||
QueryWrapper<Role> queryWrapper2 = new QueryWrapper<>();
|
|
||||||
queryWrapper2.eq("role_id", roleId);
|
|
||||||
this.remove(queryWrapper2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验当前角色名称是否唯一
|
|
||||||
*
|
|
||||||
* @param roleDTO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private void checkRoleNameUnique(RoleDTO roleDTO) {
|
|
||||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("role_name", roleDTO.getRoleName());
|
|
||||||
Role role = this.getOne(queryWrapper);
|
|
||||||
if (role != null && !role.getRoleId().equals(roleDTO.getRoleId())) {
|
|
||||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
|
||||||
log.error(info);
|
|
||||||
throw new BizException(-1,info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限层级数据扁平化
|
|
||||||
* @param nodes
|
|
||||||
* @param roleId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private List<RolePermission> flattenTree(List<RolePermissionDTO> nodes, String roleId) {
|
|
||||||
List<RolePermission> flatList = new ArrayList<>();
|
|
||||||
for (RolePermissionDTO node : nodes) {
|
|
||||||
flattenNode(node, flatList, roleId);
|
|
||||||
}
|
|
||||||
return flatList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void flattenNode(RolePermissionDTO node, List<RolePermission> flatList, String roleId) {
|
|
||||||
node.getPermission().forEach(code ->
|
|
||||||
flatList.add(new RolePermission(roleId, node.getFileId(), code))
|
|
||||||
);
|
|
||||||
// 添加当前节点
|
|
||||||
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
|
||||||
for (RolePermissionDTO child : node.getChildren()) {
|
|
||||||
flattenNode(child, flatList, roleId); // 递归处理子节点
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
||||||
import com.electromagnetic.industry.software.manage.mapper.UserRoleMapper;
|
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.UserRole;
|
|
||||||
import com.electromagnetic.industry.software.manage.service.UserRoleService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue