新建角色,更新角色,前后端连调修改
This commit is contained in:
parent
1d76327674
commit
25d0cee750
|
|
@ -17,6 +17,12 @@ public class EdMetaObjectHandler implements MetaObjectHandler {
|
|||
if (metaObject.hasGetter("createdAt")) {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
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.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RoleDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.RolePageDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.RoleService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -20,13 +22,23 @@ public class RoleController {
|
|||
@ApiOperation(value = "新建角色", notes = "")
|
||||
@RequestMapping(value = "/createRole", method = RequestMethod.POST)
|
||||
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 = "")
|
||||
@RequestMapping(value = "/updateRole", method = RequestMethod.POST)
|
||||
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 = "")
|
||||
|
|
|
|||
|
|
@ -20,16 +20,25 @@ public interface RoleMapper extends BaseMapper<Role> {
|
|||
" r.role_name AS roleName, " +
|
||||
" r.role_desc AS roleDesc, " +
|
||||
" 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 " +
|
||||
" ed_role r " +
|
||||
"LEFT JOIN " +
|
||||
" ed_role_permission rp ON r.role_id = rp.role_id " +
|
||||
"LEFT JOIN " +
|
||||
" 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 " +
|
||||
"<if test='ew != null'>" +
|
||||
" ${ew.sqlSegment} " +
|
||||
" 1=1 " +
|
||||
"<if test=\"ew != null and ew.sqlSegment != null and ew.sqlSegment != ''\">" +
|
||||
" AND ${ew.sqlSegment} " +
|
||||
"</if>" +
|
||||
"GROUP BY " +
|
||||
" r.role_id" +
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class Role {
|
|||
/**
|
||||
* 编辑时间
|
||||
*/
|
||||
@TableField(value = "gmt_modified", fill = FieldFill.UPDATE)
|
||||
@TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
|
||||
private Date gmtModified;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,11 @@ public class RoleDTO {
|
|||
*/
|
||||
private String allowedActions;
|
||||
|
||||
/**
|
||||
* 是否绑定用户
|
||||
*/
|
||||
private Boolean isBind;
|
||||
|
||||
/**
|
||||
* 权限数据
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.util.EleLog;
|
||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||
|
|
@ -64,7 +65,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
@Override
|
||||
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();
|
||||
|
|
@ -96,7 +101,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
@Override
|
||||
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<>();
|
||||
|
|
@ -226,7 +235,6 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
if (StringUtils.isNotBlank(rolePageDTO.getRoleName())) {
|
||||
queryWrapper.eq("r.role_name", rolePageDTO.getRoleName());
|
||||
}
|
||||
|
||||
return roleMapper.getPageRoleDTO(page, queryWrapper);
|
||||
}
|
||||
|
||||
|
|
@ -290,15 +298,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
* @param roleDTO
|
||||
* @return
|
||||
*/
|
||||
private void checkRoleNameUnique(RoleDTO roleDTO) {
|
||||
private Boolean 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);
|
||||
}
|
||||
return role == null || role.getRoleId().equals(roleDTO.getRoleId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -323,6 +327,11 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
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()) {
|
||||
for (RolePermissionDTO child : node.getChildren()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue