Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
75443f2d78
|
|
@ -17,6 +17,12 @@ public class EdMetaObjectHandler implements MetaObjectHandler {
|
||||||
if (metaObject.hasGetter("createdAt")) {
|
if (metaObject.hasGetter("createdAt")) {
|
||||||
this.strictInsertFill(metaObject, "createdAt", Date.class, new Date());
|
this.strictInsertFill(metaObject, "createdAt", Date.class, new Date());
|
||||||
}
|
}
|
||||||
|
if (metaObject.hasSetter("gmtModified")) {
|
||||||
|
this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
|
||||||
|
}
|
||||||
|
if (metaObject.hasGetter("updatedAt")) {
|
||||||
|
this.strictUpdateFill(metaObject, "updatedAt", Date.class, new Date());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
import com.electromagnetic.industry.software.manage.service.RoleService;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
@ -20,13 +22,23 @@ public class RoleController {
|
||||||
@ApiOperation(value = "新建角色", notes = "")
|
@ApiOperation(value = "新建角色", notes = "")
|
||||||
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
||||||
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
public ElectromagneticResult<?> createRole(@RequestBody RoleDTO roleDTO) {
|
||||||
return ElectromagneticResultUtil.success(roleService.createRole(roleDTO));
|
try {
|
||||||
|
Boolean res = roleService.createRole(roleDTO);
|
||||||
|
return ElectromagneticResultUtil.success(res);
|
||||||
|
} catch (BizException e) {
|
||||||
|
return ElectromagneticResultUtil.fail("400", e.getMsg());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "更新角色", notes = "")
|
@ApiOperation(value = "更新角色", notes = "")
|
||||||
@RequestMapping(value = "/updateRole", method = RequestMethod.POST)
|
@RequestMapping(value = "/updateRole", method = RequestMethod.POST)
|
||||||
public ElectromagneticResult<?> updateRole(@RequestBody RoleDTO roleDTO) {
|
public ElectromagneticResult<?> updateRole(@RequestBody RoleDTO roleDTO) {
|
||||||
return ElectromagneticResultUtil.success(roleService.updateRole(roleDTO));
|
try {
|
||||||
|
Boolean res = roleService.updateRole(roleDTO);
|
||||||
|
return ElectromagneticResultUtil.success(res);
|
||||||
|
} catch (BizException e) {
|
||||||
|
return ElectromagneticResultUtil.fail("400", e.getMsg());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "删除角色", notes = "")
|
@ApiOperation(value = "删除角色", notes = "")
|
||||||
|
|
@ -58,4 +70,10 @@ public class RoleController {
|
||||||
public ElectromagneticResult<?> getRoleNames() {
|
public ElectromagneticResult<?> getRoleNames() {
|
||||||
return ElectromagneticResultUtil.success(roleService.getAllRoleNames());
|
return ElectromagneticResultUtil.success(roleService.getAllRoleNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value="获得角色配置模版", notes = "")
|
||||||
|
@GetMapping(value = "/getRoleTemplate")
|
||||||
|
public ElectromagneticResult<?> getRoleTemplate() {
|
||||||
|
return ElectromagneticResultUtil.success(roleService.getRoleTemplate());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,25 @@ public interface RoleMapper extends BaseMapper<Role> {
|
||||||
" r.role_name AS roleName, " +
|
" r.role_name AS roleName, " +
|
||||||
" r.role_desc AS roleDesc, " +
|
" r.role_desc AS roleDesc, " +
|
||||||
" GROUP_CONCAT(DISTINCT f.file_name) AS dataScope, " +
|
" GROUP_CONCAT(DISTINCT f.file_name) AS dataScope, " +
|
||||||
" GROUP_CONCAT(DISTINCT rp.permission_code) AS allowedActions " +
|
" GROUP_CONCAT(DISTINCT rp.permission_code) AS allowedActions, " +
|
||||||
|
" CASE " +
|
||||||
|
" WHEN MAX(u.is_activated) = 1 THEN 1 " +
|
||||||
|
" ELSE 0 " +
|
||||||
|
" END AS isBind " +
|
||||||
"FROM " +
|
"FROM " +
|
||||||
" ed_role r " +
|
" ed_role r " +
|
||||||
"LEFT JOIN " +
|
"LEFT JOIN " +
|
||||||
" ed_role_permission rp ON r.role_id = rp.role_id " +
|
" ed_role_permission rp ON r.role_id = rp.role_id " +
|
||||||
"LEFT JOIN " +
|
"LEFT JOIN " +
|
||||||
" ed_file_info f ON rp.file_id = f.id " +
|
" ed_file_info f ON rp.file_id = f.id " +
|
||||||
|
"LEFT JOIN" +
|
||||||
|
" ed_user_role ur ON r.role_id = ur.user_id " +
|
||||||
|
"LEFT JOIN" +
|
||||||
|
" ed_users u ON ur.user_id = u.user_id " +
|
||||||
"WHERE " +
|
"WHERE " +
|
||||||
"<if test='ew != null'>" +
|
" 1=1 " +
|
||||||
" ${ew.sqlSegment} " +
|
"<if test=\"ew != null and ew.sqlSegment != null and ew.sqlSegment != ''\">" +
|
||||||
|
" AND ${ew.sqlSegment} " +
|
||||||
"</if>" +
|
"</if>" +
|
||||||
"GROUP BY " +
|
"GROUP BY " +
|
||||||
" r.role_id" +
|
" r.role_id" +
|
||||||
|
|
|
||||||
|
|
@ -61,13 +61,7 @@ public class Role {
|
||||||
/**
|
/**
|
||||||
* 编辑时间
|
* 编辑时间
|
||||||
*/
|
*/
|
||||||
@TableField(value = "gmt_modified", fill = FieldFill.UPDATE)
|
@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
|
||||||
private Date gmtModified;
|
private Date gmtModified;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否有效:0-无效 1-有效
|
|
||||||
*/
|
|
||||||
@TableField(value = "effect_flag")
|
|
||||||
private Integer effectFlag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ public class RoleDTO {
|
||||||
*/
|
*/
|
||||||
private String allowedActions;
|
private String allowedActions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否绑定用户
|
||||||
|
*/
|
||||||
|
private Boolean isBind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限数据
|
* 权限数据
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -65,5 +65,12 @@ public interface RoleService extends IService<Role> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
RoleDTO getRoleByName(String roleName);
|
RoleDTO getRoleByName(String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空树
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
RoleDTO getRoleTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
.eq(EdFileRelation::getId1, queryId2).eq(EdFileRelation::getId2, queryId1);
|
.eq(EdFileRelation::getId1, queryId2).eq(EdFileRelation::getId2, queryId1);
|
||||||
List<EdFileRelation> list = this.list(queryWrapper);
|
List<EdFileRelation> list = this.list(queryWrapper);
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
throw new BizException (HttpStatus.BAD_REQUEST.value(), "请勿重复建立关系");
|
throw new BizException (-1, "请勿重复建立关系");
|
||||||
}
|
}
|
||||||
|
|
||||||
edFileRelation.setId(IdWorker.getSnowFlakeIdString());
|
edFileRelation.setId(IdWorker.getSnowFlakeIdString());
|
||||||
|
|
@ -137,8 +137,6 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Boolean checkNameUnique(String parentId, String fileName) {
|
public Boolean checkNameUnique(String parentId, String fileName) {
|
||||||
EdFileInfo fileInfo = edFileInfoService.getById(parentId);
|
|
||||||
Assert.isTrue(fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code) && !fileInfo.getPrjDir(), "层级目录不允许上传文件");
|
|
||||||
String mainName = FileUtil.mainName(fileName);
|
String mainName = FileUtil.mainName(fileName);
|
||||||
String suffix = FileUtil.getSuffix(fileName);
|
String suffix = FileUtil.getSuffix(fileName);
|
||||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||||
|
|
@ -184,8 +182,14 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
||||||
public ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String descrption) {
|
public ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String descrption) {
|
||||||
|
|
||||||
Assert.isTrue(EleCommonUtil.isFileNameValid(file.getOriginalFilename()), NAME_VALID_MSG);
|
Assert.isTrue(EleCommonUtil.isFileNameValid(file.getOriginalFilename()), NAME_VALID_MSG);
|
||||||
EdFileInfo fileInfo = edFileInfoService.getById(parentId);
|
// 查找下一层,看是否存在顶级定义相关文件,如果存在,则该层属于管理员层级定义的,不允许上传文件
|
||||||
Assert.isTrue(fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code) && !fileInfo.getPrjDir(), "层级目录不允许上传文件");
|
long dirCount = edFileInfoService.count(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getParentId, parentId)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.eq(EdFileInfo::getPrjDir, true)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code));
|
||||||
|
Assert.isTrue(dirCount == 0, "层级目录不允许上传文件");
|
||||||
|
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
String mainName = FileUtil.mainName(fileName);
|
String mainName = FileUtil.mainName(fileName);
|
||||||
String suffix = FileUtil.getSuffix(fileName);
|
String suffix = FileUtil.getSuffix(fileName);
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.EleDataTypeEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.FilePermission;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.util.EleLog;
|
import com.electromagnetic.industry.software.common.util.EleLog;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
import com.electromagnetic.industry.software.manage.mapper.RoleMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
import com.electromagnetic.industry.software.manage.pojo.models.Role;
|
||||||
|
|
@ -20,10 +24,7 @@ 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.RoleDTO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePermissionDTO;
|
import com.electromagnetic.industry.software.manage.pojo.req.RolePermissionDTO;
|
||||||
import com.electromagnetic.industry.software.manage.service.PermissionService;
|
import com.electromagnetic.industry.software.manage.service.*;
|
||||||
import com.electromagnetic.industry.software.manage.service.RolePermissionService;
|
|
||||||
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
@ -44,14 +45,15 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
private RolePermissionService rolePermissionService;
|
private RolePermissionService rolePermissionService;
|
||||||
@Resource
|
@Resource
|
||||||
private UserRoleService userRoleService;
|
private UserRoleService userRoleService;
|
||||||
@Resource
|
|
||||||
private CommonService commonService;
|
|
||||||
@Resource
|
@Resource
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
|
|
||||||
private EleLog log = new EleLog(RoleServiceImpl.class);
|
private EleLog log = new EleLog(RoleServiceImpl.class);
|
||||||
@Autowired
|
@Resource
|
||||||
private RoleMapper roleMapper;
|
private RoleMapper roleMapper;
|
||||||
|
@Resource
|
||||||
|
private EdFileInfoMapper edFileInfoMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建角色
|
* 新建角色
|
||||||
|
|
@ -63,7 +65,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public Boolean createRole(RoleDTO roleDTO) {
|
public Boolean createRole(RoleDTO roleDTO) {
|
||||||
|
|
||||||
checkRoleNameUnique(roleDTO);
|
if (!checkRoleNameUnique(roleDTO) ) {
|
||||||
|
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||||
|
log.error(info);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
|
||||||
// 创建角色
|
// 创建角色
|
||||||
Role role = new Role();
|
Role role = new Role();
|
||||||
|
|
@ -95,7 +101,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateRole(RoleDTO roleDTO) {
|
public Boolean updateRole(RoleDTO roleDTO) {
|
||||||
|
|
||||||
checkRoleNameUnique(roleDTO);
|
if (!checkRoleNameUnique(roleDTO) ) {
|
||||||
|
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
||||||
|
log.error(info);
|
||||||
|
throw new BizException(-1, info);
|
||||||
|
}
|
||||||
|
|
||||||
// 更新角色信息
|
// 更新角色信息
|
||||||
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<Role> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
|
@ -129,17 +139,20 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public Boolean deleteRole(String roleId) {
|
public Boolean deleteRole(String roleId) {
|
||||||
|
|
||||||
// 保留角色权限关联表
|
// 删除角色权限关联表
|
||||||
|
LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(RolePermission::getRoleId, roleId);
|
||||||
|
rolePermissionService.remove(queryWrapper);
|
||||||
|
|
||||||
// 删除用户角色关联表
|
// 删除用户角色关联表
|
||||||
LambdaQueryWrapper<UserRole> queryWrapper1 = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<UserRole> queryWrapper1 = new LambdaQueryWrapper<>();
|
||||||
queryWrapper1.eq(UserRole::getRoleId, roleId);
|
queryWrapper1.eq(UserRole::getRoleId, roleId);
|
||||||
userRoleService.remove(queryWrapper1);
|
userRoleService.remove(queryWrapper1);
|
||||||
|
|
||||||
// 逻辑删除角色
|
// 删除角色
|
||||||
LambdaUpdateWrapper<Role> queryWrapper2 = new LambdaUpdateWrapper<>();
|
LambdaQueryWrapper<Role> queryWrapper2 = new LambdaQueryWrapper<>();
|
||||||
queryWrapper2.eq(Role::getRoleId, roleId)
|
queryWrapper2.eq(Role::getRoleId, roleId);
|
||||||
.set(Role::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code);
|
return this.remove(queryWrapper2);
|
||||||
return this.update(queryWrapper2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -160,8 +173,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
roleDTO.setRoleName(role.getRoleName());
|
roleDTO.setRoleName(role.getRoleName());
|
||||||
roleDTO.setRoleDesc(role.getRoleDesc());
|
roleDTO.setRoleDesc(role.getRoleDesc());
|
||||||
|
|
||||||
// 查询当前层级树,若层级树查询条件修改,此处也需修改
|
List<EdFileInfo> infos = getFiles();
|
||||||
List<EdFileInfo> infos = commonService.selectAllAdminFolder(PRJ_PARENT_ID);
|
|
||||||
|
|
||||||
List<RolePermissionDTO> nodes = new ArrayList<>();
|
List<RolePermissionDTO> nodes = new ArrayList<>();
|
||||||
for (EdFileInfo info : infos) {
|
for (EdFileInfo info : infos) {
|
||||||
|
|
@ -223,8 +235,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
if (StringUtils.isNotBlank(rolePageDTO.getRoleName())) {
|
if (StringUtils.isNotBlank(rolePageDTO.getRoleName())) {
|
||||||
queryWrapper.eq("r.role_name", rolePageDTO.getRoleName());
|
queryWrapper.eq("r.role_name", rolePageDTO.getRoleName());
|
||||||
}
|
}
|
||||||
queryWrapper.eq("r.effect_flag", EffectFlagEnum.EFFECT.code);
|
|
||||||
|
|
||||||
return roleMapper.getPageRoleDTO(page, queryWrapper);
|
return roleMapper.getPageRoleDTO(page, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,8 +247,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
@Override
|
@Override
|
||||||
public List<HashMap<String, String>> getAllRoleNames() {
|
public List<HashMap<String, String>> getAllRoleNames() {
|
||||||
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Role> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.select(Role::getRoleName)
|
queryWrapper.select(Role::getRoleName);
|
||||||
.eq(Role::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
|
||||||
|
|
||||||
List<String> roleNames = this.listObjs(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
|
List<String> roleNames = this.listObjs(queryWrapper).stream().map(Object::toString).collect(Collectors.toList());
|
||||||
List<HashMap<String,String>> result = new ArrayList<>();
|
List<HashMap<String,String>> result = new ArrayList<>();
|
||||||
|
|
@ -251,21 +260,49 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空树
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
@Override
|
||||||
|
public RoleDTO getRoleTemplate() {
|
||||||
|
RoleDTO roleDTO = new RoleDTO();
|
||||||
|
|
||||||
|
List<EdFileInfo> infos = getFiles();
|
||||||
|
|
||||||
|
List<RolePermissionDTO> nodes = new ArrayList<>();
|
||||||
|
for (EdFileInfo info : infos) {
|
||||||
|
RolePermissionDTO rolePermissionDTO = new RolePermissionDTO();
|
||||||
|
rolePermissionDTO.setId(info.getId());
|
||||||
|
rolePermissionDTO.setParentId(info.getParentId());
|
||||||
|
rolePermissionDTO.setFileName(info.getFileName());
|
||||||
|
List<String> permissionCodes = new ArrayList<>();
|
||||||
|
Map<String, Boolean> dataAuth = new HashMap<>();
|
||||||
|
dataAuth.put("data", false);
|
||||||
|
rolePermissionDTO.setDataAuth(dataAuth);
|
||||||
|
|
||||||
|
rolePermissionDTO.setPermission(permissionService.transToMap(permissionCodes));
|
||||||
|
nodes.add(rolePermissionDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
roleDTO.setData(buildTree(nodes));
|
||||||
|
|
||||||
|
return roleDTO;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验当前角色名称是否唯一
|
* 校验当前角色名称是否唯一
|
||||||
*
|
*
|
||||||
* @param roleDTO
|
* @param roleDTO
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private void checkRoleNameUnique(RoleDTO roleDTO) {
|
private Boolean checkRoleNameUnique(RoleDTO roleDTO) {
|
||||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("role_name", roleDTO.getRoleName());
|
queryWrapper.eq("role_name", roleDTO.getRoleName());
|
||||||
Role role = this.getOne(queryWrapper);
|
Role role = this.getOne(queryWrapper);
|
||||||
if (role != null && !role.getRoleId().equals(roleDTO.getRoleId())) {
|
return role == null || role.getRoleId().equals(roleDTO.getRoleId());
|
||||||
String info = "当前角色名称已存在:" + roleDTO.getRoleName();
|
|
||||||
log.error(info);
|
|
||||||
throw new BizException(-1, info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -290,6 +327,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
flatList.add(new RolePermission(roleId, node.getId(), code));
|
flatList.add(new RolePermission(roleId, node.getId(), code));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (node.getDataAuth().get("data").equals(Boolean.TRUE)) {
|
||||||
|
flatList.add(new RolePermission(roleId, node.getId(), FilePermission.VIEW.getCode()));
|
||||||
|
}
|
||||||
|
|
||||||
// 添加当前节点
|
// 添加当前节点
|
||||||
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
if (node.getChildren() != null && !node.getChildren().isEmpty()) {
|
||||||
for (RolePermissionDTO child : node.getChildren()) {
|
for (RolePermissionDTO child : node.getChildren()) {
|
||||||
|
|
@ -320,5 +362,16 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
||||||
.peek(node -> node.setChildren(findChildren(node, nodes))) // 递归设置子节点
|
.peek(node -> node.setChildren(findChildren(node, nodes))) // 递归设置子节点
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取层级树结构
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<EdFileInfo> getFiles() {
|
||||||
|
return edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||||
|
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code)
|
||||||
|
.eq(EdFileInfo::getPrjDir, true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ public class UserServiceImpl implements UserService {
|
||||||
private TokenMapper tokenMapper;
|
private TokenMapper tokenMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private UserRoleMapper userRoleMapper;
|
private UserRoleMapper userRoleMapper;
|
||||||
@Autowired
|
@Resource
|
||||||
private RoleMapper roleMapper;
|
private RoleMapper roleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -278,7 +278,7 @@ public class UserServiceImpl implements UserService {
|
||||||
@Override
|
@Override
|
||||||
public Boolean bindRoles(UserRoleRequest userRolesRequest) {
|
public Boolean bindRoles(UserRoleRequest userRolesRequest) {
|
||||||
if (userRolesRequest == null || userRolesRequest.getBindData().isEmpty()) {
|
if (userRolesRequest == null || userRolesRequest.getBindData().isEmpty()) {
|
||||||
throw new BizException(HttpStatus.BAD_REQUEST.value(), "请勿发布空数据");
|
throw new BizException(-1, "请勿发布空数据");
|
||||||
}
|
}
|
||||||
for (UserBindRoleDTO dto : userRolesRequest.getBindData()) {
|
for (UserBindRoleDTO dto : userRolesRequest.getBindData()) {
|
||||||
activeRole(dto);
|
activeRole(dto);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue