rbac用户角色权限控制接口完善

This commit is contained in:
zhuyijun 2022-09-24 23:17:21 +08:00
parent 53e153e787
commit 9c78ed62d0
25 changed files with 1392 additions and 16 deletions

View File

@ -1,10 +1,11 @@
package cn.zyjblogs.server.user.po;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
@ -65,7 +66,7 @@ public class UserPo implements Serializable {
private String createUserId;
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("create_time")
private LocalDateTime createTime;
@ -74,7 +75,7 @@ public class UserPo implements Serializable {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("edit_time")
private LocalDateTime editTime;

View File

@ -0,0 +1,86 @@
package cn.zyjblogs.server.authority.controller;
import cn.zyjblogs.server.authority.dto.PermissionResourcesDto;
import cn.zyjblogs.server.authority.service.PermissionResourcesService;
import cn.zyjblogs.server.authority.vo.PermissionResourcesVo;
import cn.zyjblogs.starter.common.entity.context.BaseContext;
import cn.zyjblogs.starter.common.entity.response.ResponseObject;
import cn.zyjblogs.starter.common.entity.response.ResponseResult;
import cn.zyjblogs.starter.web.apiversion.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author zhuyijun
*/
@Api(value = "权限资源控制层")
@RequestMapping("/{v}/menu")
@RestController
@ResponseBody
@ApiVersion(1)
@RequiredArgsConstructor
public class PermissionResourcesController {
private final PermissionResourcesService permissionResourcesService;
@ApiOperation(value = "新增权限组", notes = "新增权限组")
@PutMapping("/save")
@ApiVersion(1)
public ResponseObject<Object> save(@Validated @RequestBody PermissionResourcesDto dto) {
permissionResourcesService.save(dto);
return ResponseResult.success();
}
@ApiOperation(value = "修改权限组", notes = "修改权限组")
@PutMapping("/update")
@ApiVersion(1)
public ResponseObject<Object> update(@Validated @RequestBody PermissionResourcesDto dto) {
permissionResourcesService.update(dto);
return ResponseResult.success();
}
@ApiOperation(value = "删除权限组", notes = "删除权限组")
@DeleteMapping("/delete")
@ApiVersion(1)
public ResponseObject<Object> deleteById(@RequestParam("id") String id) {
permissionResourcesService.removeById(id);
return ResponseResult.success();
}
@ApiOperation(value = "查询所有权限组", notes = "查询所有权限组")
@GetMapping("/list/all")
@ApiVersion(1)
public ResponseObject<List<PermissionResourcesVo>> listAll() {
return ResponseResult.success(permissionResourcesService.listVoInTenant());
}
@ApiOperation(value = "查询用户权限组", notes = "查询用户权限组")
@GetMapping("/list/userId")
@ApiVersion(1)
public ResponseObject<List<PermissionResourcesVo>> listUser() {
return ResponseResult.success(permissionResourcesService.listByUserId(BaseContext.getUserId()));
}
@ApiOperation(value = "查询用户权限组", notes = "查询用户权限组")
@GetMapping("/list/roleId")
@ApiVersion(1)
public ResponseObject<List<PermissionResourcesVo>> listRoleId(String roleId) {
return ResponseResult.success(permissionResourcesService.listRoleId(roleId));
}
}

View File

@ -0,0 +1,122 @@
package cn.zyjblogs.server.authority.dto;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author zhuyijun
*/
@ApiModel(description = "权限资源dto对象")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class PermissionResourcesDto implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键uuid
*/
@ApiModelProperty(value = "主键id")
private String id;
/**
* 权限资源编码
*/
@ApiModelProperty(value = "编码")
private String code;
/**
* 名称
*/
@ApiModelProperty(value = "名称")
private String name;
/**
* 父记录主键uuid
*/
@ApiModelProperty(value = "父级节点id")
private String parentId;
/**
* 资源类型 0页面 1 按钮
*/
@ApiModelProperty(value = "资源类型 0 页面 1 按钮")
private Integer resourceType;
/**
* 描述
*/
@ApiModelProperty(value = "描述")
private String description;
/**
* 前端是否可见0 隐藏1 显示
*/
@ApiModelProperty(value = "前端是否可见 0 显示 1 隐藏")
private Integer uiShow;
/**
* 前端用路径
*/
@ApiModelProperty(value = "前端用路径")
private String uiPath;
/**
* 前端用编码
*/
@ApiModelProperty(value = "前端用编码")
private String uiCode;
/**
* 前端用排序
*/
@ApiModelProperty(value = "前端用排序")
private Integer uiSort;
/**
* 前端用模板
*/
@ApiModelProperty(value = "前端模板")
private String uiTemplate;
/**
* 前端面包屑1显示 0不显示
*/
@ApiModelProperty(value = "前端面包屑1显示 0不显示")
private Integer uiIsShowBreadcrumb;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = CommonConstant.DATETIME_PATTERN)
private LocalDateTime createTime;
/**
* 最后修改的时间
*/
@ApiModelProperty(value = "最后修改的时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = CommonConstant.DATETIME_PATTERN)
private LocalDateTime editTime;
}

View File

@ -0,0 +1,12 @@
package cn.zyjblogs.server.authority.mapper;
import cn.zyjblogs.server.authority.po.PermissionResourcesPo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author zhuyijun
*/
@Mapper
public interface PermissionResourcesMapper extends BaseMapper<PermissionResourcesPo> {
}

View File

@ -0,0 +1,121 @@
package cn.zyjblogs.server.authority.po;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author zhuyijun
*/
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@TableName("permission_resources")
public class PermissionResourcesPo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键uuid
*/
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
/**
* 权限资源编码
*/
@TableField("code")
private String code;
/**
* 名称
*/
@TableField("name")
private String name;
/**
* 父记录主键uuid
*/
@TableField("parent_id")
private String parentId;
/**
* 资源类型 0页面 1 按钮
*/
@TableField("resource_type")
private Integer resourceType;
/**
* 描述
*/
@TableField("description")
private String description;
/**
* 前端是否可见0 隐藏1 显示
*/
@TableField("ui_show")
private Integer uiShow;
/**
* 前端用路径
*/
@TableField("ui_path")
private String uiPath;
/**
* 前端用编码
*/
@TableField("ui_code")
private String uiCode;
/**
* 前端用排序
*/
@TableField("ui_sort")
private Integer uiSort;
/**
* 前端用模板
*/
@TableField("ui_template")
private String uiTemplate;
/**
* 前端面包屑1显示 0不显示
*/
@TableField("ui_is_show_breadcrumb")
private Integer uiIsShowBreadcrumb;
/**
* 创建时间
*/
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("create_time")
private LocalDateTime createTime;
/**
* 最后修改的时间
*/
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@TableField("edit_time")
private LocalDateTime editTime;
}

View File

@ -0,0 +1,75 @@
package cn.zyjblogs.server.authority.service;
import cn.zyjblogs.server.authority.dto.PermissionResourcesDto;
import cn.zyjblogs.server.authority.po.PermissionResourcesPo;
import cn.zyjblogs.server.authority.vo.PermissionResourcesVo;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author zhuyijun
*/
public interface PermissionResourcesService extends IService<PermissionResourcesPo> {
/**
* 保存
*
* @param dto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
Boolean save(PermissionResourcesDto dto);
/**
* 更新
*
* @param dto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
Boolean update(PermissionResourcesDto dto);
/**
* 查询当前租户权限资源
*
* @param
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<PermissionResourcesVo> listVoInTenant();
/**
* 通过用户id查询权限资源
*
* @param userId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<PermissionResourcesVo> listByUserId(String userId);
/**
* 通过角色id查询权限资源
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<PermissionResourcesVo> listRoleId(String roleId);
/**
* 通过资源父级节点查询限资源
*
* @param
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<PermissionResourcesVo> listVoInTenant(String parentId);
}

View File

@ -0,0 +1,153 @@
package cn.zyjblogs.server.authority.service.impl;
import cn.zyjblogs.server.authority.dto.PermissionResourcesDto;
import cn.zyjblogs.server.authority.mapper.PermissionResourcesMapper;
import cn.zyjblogs.server.authority.po.PermissionResourcesPo;
import cn.zyjblogs.server.authority.service.PermissionResourcesService;
import cn.zyjblogs.server.authority.vo.PermissionResourcesVo;
import cn.zyjblogs.server.role.service.RolePermissionRelService;
import cn.zyjblogs.server.user.service.UserRoleService;
import cn.zyjblogs.starter.common.entity.response.HttpCode;
import cn.zyjblogs.starter.common.exception.CommonBusinessException;
import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
/**
* @author zhuyijun
*/
@Service
@RequiredArgsConstructor
public class PermissionResourcesServiceImpl extends ServiceImpl<PermissionResourcesMapper, PermissionResourcesPo> implements PermissionResourcesService {
private final PermissionResourcesMapper permissionResourcesMapper;
private final UserRoleService userRoleService;
private final RolePermissionRelService rolePermissionRelService;
/**
* 权限资源保存
*
* @param dto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean save(PermissionResourcesDto dto) {
dto.setId(null);
String parentId = dto.getParentId();
PermissionResourcesPo newParentPo = this.getById(parentId);
if (Objects.isNull(newParentPo)) {
throw new CommonBusinessException(HttpCode.NOT_FOUND, "该资源父级节点不存在");
}
PermissionResourcesPo po = BeanUtils.map(dto, PermissionResourcesPo.class);
po.setCreateTime(LocalDateTime.now());
po.setCode(IdWorker.get32UUID());
return this.save(po);
}
/**
* 权限资源更新
*
* @param dto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Transactional(rollbackFor = Exception.class)
@Override
public Boolean update(PermissionResourcesDto dto) {
PermissionResourcesPo po = BeanUtils.map(dto, PermissionResourcesPo.class);
po.setEditTime(LocalDateTime.now());
return this.updateById(po);
}
/**
* 查询当前租户所有权限
*
* @param
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public List<PermissionResourcesVo> listVoInTenant() {
LambdaQueryWrapper<PermissionResourcesPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.orderByAsc(PermissionResourcesPo::getCreateTime, PermissionResourcesPo::getId);
List<PermissionResourcesPo> permissionResourcesPos = this.list(queryWrapper);
return BeanUtils.map(permissionResourcesPos, PermissionResourcesVo.class);
}
/**
* 用过用户id查询
*
* @param userId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public List<PermissionResourcesVo> listByUserId(String userId) {
// 获取用户所有角色信息
List<String> roleIdList = userRoleService.findRoleListByUserId(userId);
if (CollectionUtils.isEmpty(roleIdList)) {
throw new CommonBusinessException(HttpCode.BAD_REQUEST, "未查询到该用户关联角色");
}
List<String> permissionIds = rolePermissionRelService.findListByRoleIds(roleIdList);
if (CollectionUtils.isEmpty(permissionIds)) {
throw new CommonBusinessException(HttpCode.BAD_REQUEST, "未查询到该用户角色权限");
}
LambdaQueryWrapper<PermissionResourcesPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(PermissionResourcesPo::getId, permissionIds)
.orderByAsc(PermissionResourcesPo::getCreateTime, PermissionResourcesPo::getId);
List<PermissionResourcesPo> permissionResourcesPos = this.list(queryWrapper);
return BeanUtils.map(permissionResourcesPos, PermissionResourcesVo.class);
}
/**
* 通过角色id查询
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public List<PermissionResourcesVo> listRoleId(String roleId) {
List<String> permissionIds = rolePermissionRelService.findListByRoleIds(List.of(roleId));
if (CollectionUtils.isEmpty(permissionIds)) {
throw new CommonBusinessException(HttpCode.BAD_REQUEST, "未查询到该用户角色权限");
}
LambdaQueryWrapper<PermissionResourcesPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(PermissionResourcesPo::getId, permissionIds)
.orderByAsc(PermissionResourcesPo::getCreateTime, PermissionResourcesPo::getId);
List<PermissionResourcesPo> permissionResourcesPos = this.list(queryWrapper);
return BeanUtils.map(permissionResourcesPos, PermissionResourcesVo.class);
}
/**
* 通过父级节点查询下级组织
*
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public List<PermissionResourcesVo> listVoInTenant(String parentId) {
LambdaQueryWrapper<PermissionResourcesPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(PermissionResourcesPo::getParentId, parentId)
.orderByAsc(PermissionResourcesPo::getCreateTime, PermissionResourcesPo::getId);
List<PermissionResourcesPo> permissionResourcesPos = this.list(queryWrapper);
return BeanUtils.map(permissionResourcesPos, PermissionResourcesVo.class);
}
}

View File

@ -0,0 +1,115 @@
package cn.zyjblogs.server.authority.vo;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author zhuyijun
*/
@ApiModel(description = "权限资源vo对象")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class PermissionResourcesVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键uuid
*/
@ApiModelProperty(value = "主键id")
private String id;
/**
* 权限资源编码
*/
@ApiModelProperty(value = "编码")
private String code;
/**
* 名称
*/
@ApiModelProperty(value = "名称")
private String name;
/**
* 父记录主键uuid
*/
@ApiModelProperty(value = "父级节点id")
private String parentId;
/**
* 资源类型 0页面 1 按钮
*/
@ApiModelProperty(value = "资源类型 0 页面 1 按钮")
private Integer resourceType;
/**
* 描述
*/
@ApiModelProperty(value = "描述")
private String description;
/**
* 前端是否可见0 隐藏1 显示
*/
@ApiModelProperty(value = "前端是否可见 0 显示 1 隐藏")
private Integer uiShow;
/**
* 前端用路径
*/
@ApiModelProperty(value = "前端用路径")
private String uiPath;
/**
* 前端用编码
*/
@ApiModelProperty(value = "前端用编码")
private String uiCode;
/**
* 前端用排序
*/
@ApiModelProperty(value = "前端用排序")
private Integer uiSort;
/**
* 前端用模板
*/
@ApiModelProperty(value = "前端模板")
private String uiTemplate;
/**
* 前端面包屑1显示 0不显示
*/
@ApiModelProperty(value = "前端面包屑1显示 0不显示")
private Integer uiIsShowBreadcrumb;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime createTime;
/**
* 最后修改的时间
*/
@ApiModelProperty(value = "最后修改的时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime editTime;
}

View File

@ -1,6 +1,7 @@
package cn.zyjblogs.server.role.controller;
import cn.zyjblogs.server.role.dto.RolePageDto;
import cn.zyjblogs.server.role.po.RoleDto;
import cn.zyjblogs.server.role.po.RolePo;
import cn.zyjblogs.server.role.service.RoleService;
import cn.zyjblogs.server.role.vo.RoleVo;
@ -13,8 +14,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@ -92,4 +95,36 @@ public class RoleController {
public ResponseObject<List<RoleVo>> findByIds(List<String> ids) {
return ResponseResult.success(roleService.findByIds(ids));
}
/**
* 角色保存
*
* @param roleDto
* @return cn.zyjblogs.starter.common.entity.response.ResponseObject<com.baomidou.mybatisplus.extension.plugins.pagination.Page < cn.zyjblogs.rbac.server.user.po.UserPo>>
* @author zhuyijun
* @date 2022/9/19 上午1:14
*/
@ApiOperation(value = "通过角色id查询", notes = "通过角色id查询")
@ApiVersion(1)
@PostMapping("/save")
public ResponseObject<Object> save(@Validated @RequestBody RoleDto roleDto) {
roleService.save(roleDto);
return ResponseResult.success();
}
/**
* 角色更新
*
* @param roleDto
* @return cn.zyjblogs.starter.common.entity.response.ResponseObject<com.baomidou.mybatisplus.extension.plugins.pagination.Page < cn.zyjblogs.rbac.server.user.po.UserPo>>
* @author zhuyijun
* @date 2022/9/19 上午1:14
*/
@ApiOperation(value = "通过角色id查询", notes = "通过角色id查询")
@ApiVersion(1)
@PostMapping("/update")
public ResponseObject<Object> update(@Validated @RequestBody RoleDto roleDto) {
roleService.update(roleDto);
return ResponseResult.success();
}
}

View File

@ -0,0 +1,147 @@
package cn.zyjblogs.server.role.controller;
import cn.zyjblogs.server.role.service.RolePermissionRelService;
import cn.zyjblogs.server.role.vo.RolePermissionRelVo;
import cn.zyjblogs.starter.common.entity.response.ResponseObject;
import cn.zyjblogs.starter.common.entity.response.ResponseResult;
import cn.zyjblogs.starter.web.apiversion.ApiVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.List;
/**
* @author zhuyijun
*/
@Api(value = "角色权限关联控制层")
@RestController
@RequestMapping("/{v}/role/rel")
@ApiVersion(1)
@ResponseBody
@RequiredArgsConstructor
public class RolePermissionRelController {
private final RolePermissionRelService rolePermissionRelService;
/**
* @param roleId 角色id
* @author zhuyijun
* @date 2022/9/24 上午11:56
* return 权限id
*/
@ApiOperation(value = "通过角色id查询权限集合", notes = "通过角色id查询权限集合")
@ApiVersion(1)
@GetMapping("/findListByRoleId")
public ResponseObject<List<String>> findListByRoleId(String roleId) {
return ResponseResult.success(rolePermissionRelService.findListByRoleId(roleId));
}
/**
* @param roleIds 角色id
* @author zhuyijun
* @date 2022/9/24 上午11:56
* return 权限id
*/
@ApiOperation(value = "通过角色id集合查询权限id集合", notes = "通过角色id集合查询权限id集合")
@ApiVersion(1)
@PostMapping("/findListByRoleIds")
public ResponseObject<List<String>> findListByRoleIds(List<String> roleIds) {
return ResponseResult.success(rolePermissionRelService.findListByRoleIds(roleIds));
}
/**
* @param roleId 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@ApiOperation(value = "通过角色id查询关联对象集合", notes = "通过角色id查询关联对象集合")
@ApiVersion(1)
@GetMapping("/findListVoByRoleId")
public ResponseObject<List<RolePermissionRelVo>> findListVoByRoleId(String roleId) {
return ResponseResult.success(rolePermissionRelService.findListVoByRoleId(roleId));
}
/**
* @param roleIds 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@ApiOperation(value = "通过角色id集合查询关联对象集合", notes = "通过角色id集合查询关联对象集合")
@ApiVersion(1)
@PostMapping("/findListVoByRoleIds")
public ResponseObject<List<RolePermissionRelVo>> findListVoByRoleIds(List<String> roleIds) {
return ResponseResult.success(rolePermissionRelService.findListVoByRoleIds(roleIds));
}
/**
* 通过角色id删除权限
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@ApiOperation(value = "通过角色id删除角色", notes = "通过角色id删除角色")
@ApiVersion(1)
@PostMapping("/deleteByRoleId")
public ResponseObject<Boolean> deleteByRoleId(String roleId) {
return ResponseResult.success(rolePermissionRelService.deleteByRoleId(roleId));
}
/**
* 通过角色id删除权限
*
* @param roleIds
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@ApiOperation(value = "通过角色id集合删除角色", notes = "通过角色id集合删除角色")
@ApiVersion(1)
@PostMapping("/deleteByRoleIds")
public ResponseObject<Boolean> deleteByRoleIds(List<String> roleIds) {
return ResponseResult.success(rolePermissionRelService.deleteByRoleIds(roleIds));
}
/**
* 保存或更新角色权限关联
*
* @param roleId
* @param permissionIds
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@ApiOperation(value = "角色权限保存", notes = "角色权限关联保存")
@ApiVersion(1)
@PutMapping("/save")
public ResponseObject<Boolean> save(String roleId, Collection<String> permissionIds) {
return ResponseResult.success(rolePermissionRelService.saveUpdate(roleId, permissionIds, false));
}
/**
* 保存或更新角色权限关联
*
* @param roleId
* @param permissionIds
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@ApiOperation(value = "角色权限更新", notes = "角色权限更新")
@ApiVersion(1)
@PutMapping("/update")
public ResponseObject<Boolean> update(String roleId, Collection<String> permissionIds) {
return ResponseResult.success(rolePermissionRelService.saveUpdate(roleId, permissionIds, false));
}
}

View File

@ -0,0 +1,34 @@
package cn.zyjblogs.server.role.mapper;
import cn.zyjblogs.server.role.po.RolePermissionRelPo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author zhuyijun
*/
@Mapper
public interface RolePermissionRelMapper extends BaseMapper<RolePermissionRelPo> {
/**
* 通过角色id查询权限id集合
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<String> findListByRoleId(@Param("roleId") String roleId, @Param("tenantId") String tenantId);
/**
* 通过角色id集合查询权限id集合
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
List<String> findListByRoleIds(@Param("roleIds") List<String> roleId, @Param("tenantId") String tenantId);
}

View File

@ -0,0 +1,63 @@
package cn.zyjblogs.server.role.po;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
/**
* @author zhuyijun
*/
@ApiModel(description = "角色实体类")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RoleDto implements Serializable {
@ApiModelProperty(value = "主键id")
private String id;
@ApiModelProperty(value = "名称")
@NotBlank(message = "角色名称不能为空")
private String name;
@ApiModelProperty(value = "状态")
private Integer status;
@ApiModelProperty(value = "类型")
private Integer roleType;
@ApiModelProperty(value = "是否删除")
private Integer deleted;
@ApiModelProperty(value = "描述")
private String description;
@ApiModelProperty(value = "创建人")
private String createUserId;
@ApiModelProperty(value = "创建时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime createTime;
@ApiModelProperty(value = "编辑人")
private String editUserId;
@ApiModelProperty(value = "编辑时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime editTime;
@ApiModelProperty(value = "租户id")
private String tenantId;
@ApiModelProperty(value = "权限集合")
private List<String> permissionIds;
}

View File

@ -0,0 +1,49 @@
package cn.zyjblogs.server.role.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author zhuyijun
*/
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@TableName("role_permission_rel")
public class RolePermissionRelPo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键uuid
*/
@TableId(value = "id", type = IdType.ASSIGN_UUID)
private String id;
/**
* 角色表主键uuid
*/
@TableField("role_id")
private String roleId;
/**
* 权限组表主键uuid
*/
@TableField("permission_id")
private String permissionId;
/**
* 租户id
*/
@TableField("tenant_id")
private String tenantId;
}

View File

@ -1,9 +1,10 @@
package cn.zyjblogs.server.role.po;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
@ -44,7 +45,7 @@ public class RolePo implements Serializable {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("create_time")
private LocalDateTime createTime;
@ -53,7 +54,7 @@ public class RolePo implements Serializable {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("edit_time")
private LocalDateTime editTime;

View File

@ -0,0 +1,77 @@
package cn.zyjblogs.server.role.service;
import cn.zyjblogs.server.role.po.RolePermissionRelPo;
import cn.zyjblogs.server.role.vo.RolePermissionRelVo;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Collection;
import java.util.List;
/**
* @author zhuyijun
*/
public interface RolePermissionRelService extends IService<RolePermissionRelPo> {
/**
* @param roleId 角色id
* @author zhuyijun
* @date 2022/9/24 上午11:56
* return 权限id
*/
List<String> findListByRoleId(String roleId);
/**
* @param roleIds 角色id
* @author zhuyijun
* @date 2022/9/24 上午11:56
* return 权限id
*/
List<String> findListByRoleIds(List<String> roleIds);
/**
* @param roleId 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
List<RolePermissionRelVo> findListVoByRoleId(String roleId);
/**
* @param roleIds 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
List<RolePermissionRelVo> findListVoByRoleIds(List<String> roleIds);
/**
* 通过角色id删除权限
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
boolean deleteByRoleId(String roleId);
/**
* 通过角色id集合删除权限
*
* @param roleIds
* @return
* @author zhuyijun
* @date 2022/9/24
*/
boolean deleteByRoleIds(List<String> roleIds);
/**
* 保存或更新角色权限关联
*
* @param roleId
* @param permissionIds
* @param needClear
* @return
* @author zhuyijun
* @date 2022/9/24
*/
boolean saveUpdate(String roleId, Collection<String> permissionIds, boolean needClear);
}

View File

@ -1,6 +1,7 @@
package cn.zyjblogs.server.role.service;
import cn.zyjblogs.server.role.dto.RolePageDto;
import cn.zyjblogs.server.role.po.RoleDto;
import cn.zyjblogs.server.role.po.RolePo;
import cn.zyjblogs.server.role.vo.RoleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -37,4 +38,20 @@ public interface RoleService extends IService<RolePo> {
*/
List<RoleVo> findList(String tenantId);
/**
* @param roleDto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
void save(RoleDto roleDto);
/**
* @param roleDto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
void update(RoleDto roleDto);
}

View File

@ -0,0 +1,138 @@
package cn.zyjblogs.server.role.service.impl;
import cn.zyjblogs.server.role.mapper.RolePermissionRelMapper;
import cn.zyjblogs.server.role.po.RolePermissionRelPo;
import cn.zyjblogs.server.role.service.RolePermissionRelService;
import cn.zyjblogs.server.role.vo.RolePermissionRelVo;
import cn.zyjblogs.starter.common.entity.context.BaseContext;
import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 角色权限关联业务层
*
* @author zhuyijun
*/
@Service
@RequiredArgsConstructor
public class RolePermissionRelServiceImpl extends ServiceImpl<RolePermissionRelMapper, RolePermissionRelPo> implements RolePermissionRelService {
private final RolePermissionRelMapper rolePermissionRelMapper;
/**
* @param roleId 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@Override
public List<String> findListByRoleId(String roleId) {
return rolePermissionRelMapper.findListByRoleId(roleId, BaseContext.getTenantId());
}
/**
* @param roleIds 角色id集合查询权限id集合
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@Override
public List<String> findListByRoleIds(List<String> roleIds) {
return rolePermissionRelMapper.findListByRoleIds(roleIds, BaseContext.getTenantId());
}
/**
* @param roleId 角色id
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@Override
public List<RolePermissionRelVo> findListVoByRoleId(String roleId) {
LambdaQueryWrapper<RolePermissionRelPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(RolePermissionRelPo::getRoleId, roleId)
.eq(RolePermissionRelPo::getTenantId, BaseContext.getTenantId());
List<RolePermissionRelPo> rolePermissionRelPos = rolePermissionRelMapper.selectList(queryWrapper);
return BeanUtils.map(rolePermissionRelPos, RolePermissionRelVo.class);
}
/**
* @param roleIds 角色id集合
* @return 角色和权限关联表
* @author zhuyijun
* @date 2022/9/24 上午11:56
*/
@Override
public List<RolePermissionRelVo> findListVoByRoleIds(List<String> roleIds) {
LambdaQueryWrapper<RolePermissionRelPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(RolePermissionRelPo::getRoleId, roleIds)
.eq(RolePermissionRelPo::getTenantId, BaseContext.getTenantId());
List<RolePermissionRelPo> rolePermissionRelPos = rolePermissionRelMapper.selectList(queryWrapper);
return BeanUtils.map(rolePermissionRelPos, RolePermissionRelVo.class);
}
/**
* 通过角色id删除
*
* @param roleId
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteByRoleId(String roleId) {
LambdaQueryWrapper<RolePermissionRelPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(RolePermissionRelPo::getRoleId, roleId)
.eq(RolePermissionRelPo::getTenantId, BaseContext.getTenantId());
return rolePermissionRelMapper.delete(queryWrapper) > 0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteByRoleIds(List<String> roleIds) {
LambdaQueryWrapper<RolePermissionRelPo> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(RolePermissionRelPo::getRoleId, roleIds)
.eq(RolePermissionRelPo::getTenantId, BaseContext.getTenantId());
return rolePermissionRelMapper.delete(queryWrapper) > 0;
}
/**
* 保存或更新角色权限关联
*
* @param roleId
* @param permissionIds
* @param needClear
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveUpdate(String roleId, Collection<String> permissionIds, boolean needClear) {
if (needClear) {
deleteByRoleId(roleId);
}
if (CollectionUtils.isEmpty(permissionIds)) {
return true;
}
String tenantId = BaseContext.getTenantId();
List<RolePermissionRelPo> list = new ArrayList<>(permissionIds.size());
permissionIds.forEach(permissionId -> list.add(RolePermissionRelPo.builder()
.roleId(roleId)
.permissionId(permissionId)
.tenantId(tenantId)
.build()));
return this.saveBatch(list);
}
}

View File

@ -2,13 +2,18 @@ package cn.zyjblogs.server.role.service.impl;
import cn.zyjblogs.server.role.dto.RolePageDto;
import cn.zyjblogs.server.role.mapper.RoleMapper;
import cn.zyjblogs.server.role.po.RoleDto;
import cn.zyjblogs.server.role.po.RolePo;
import cn.zyjblogs.server.role.service.RolePermissionRelService;
import cn.zyjblogs.server.role.service.RoleService;
import cn.zyjblogs.server.role.vo.RoleVo;
import cn.zyjblogs.starter.common.entity.context.BaseContext;
import cn.zyjblogs.starter.common.entity.response.HttpCode;
import cn.zyjblogs.starter.common.exception.CommonBusinessException;
import cn.zyjblogs.starter.common.utils.bean.BeanUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -16,6 +21,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -27,6 +33,7 @@ import java.util.List;
@RequiredArgsConstructor
public class RoleServiceImpl extends ServiceImpl<RoleMapper, RolePo> implements RoleService {
private final RoleMapper roleMapper;
private final RolePermissionRelService rolePermissionRelService;
/**
* 分页查询
@ -77,4 +84,50 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, RolePo> implements
}
return BeanUtils.map(rolePos, RoleVo.class);
}
/**
* 保存角色
*
* @param roleDto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public void save(RoleDto roleDto) {
List<String> permissionIds = roleDto.getPermissionIds();
if (CollectionUtils.isEmpty(permissionIds)) {
throw new CommonBusinessException(HttpCode.BAD_REQUEST, "角色未关联权限资源");
}
roleDto.setPermissionIds(null);
RolePo rolePo = BeanUtils.map(roleDto, RolePo.class);
rolePo.setId(IdWorker.get32UUID());
rolePo.setCreateTime(LocalDateTime.now());
rolePo.setCreateUserId(BaseContext.getUserId());
rolePo.setTenantId(BaseContext.getTenantId());
roleMapper.insert(rolePo);
rolePermissionRelService.saveUpdate(rolePo.getId(), permissionIds, false);
}
/**
* 更新角色
*
* @param roleDto
* @return
* @author zhuyijun
* @date 2022/9/24
*/
@Override
public void update(RoleDto roleDto) {
List<String> permissionIds = roleDto.getPermissionIds();
if (CollectionUtils.isEmpty(permissionIds)) {
throw new CommonBusinessException(HttpCode.BAD_REQUEST, "角色未关联权限资源");
}
roleDto.setPermissionIds(null);
RolePo rolePo = BeanUtils.map(roleDto, RolePo.class);
rolePo.setEditTime(LocalDateTime.now());
rolePo.setEditUserId(BaseContext.getUserId());
roleMapper.updateById(rolePo);
rolePermissionRelService.saveUpdate(rolePo.getId(), permissionIds, true);
}
}

View File

@ -0,0 +1,47 @@
package cn.zyjblogs.server.role.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* @author zhuyijun
*/
@ApiModel(description = "角色权限关联表")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
public class RolePermissionRelVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键uuid
*/
@ApiModelProperty(value = "主键id")
private String id;
/**
* 角色表主键uuid
*/
@ApiModelProperty(value = "角色id")
private String roleId;
/**
* 权限资源主键uuid
*/
@ApiModelProperty(value = "权限id")
private String permissionId;
/**
* 租户id
*/
@ApiModelProperty(value = "租户id")
private String tenantId;
}

View File

@ -1,6 +1,7 @@
package cn.zyjblogs.server.role.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModel;
@ -41,7 +42,7 @@ public class RoleVo implements Serializable {
@ApiModelProperty(value = "创建时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime createTime;
@ApiModelProperty(value = "编辑人")
@ -49,7 +50,7 @@ public class RoleVo implements Serializable {
@ApiModelProperty(value = "编辑时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
private LocalDateTime editTime;
@ApiModelProperty(value = "租户id")
private String tenantId;

View File

@ -56,11 +56,13 @@ public class UserDto {
@ApiModelProperty(value = "创建人")
private String createUserId;
@ApiModelProperty(value = "创建时间")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = CommonConstant.DATETIME_PATTERN)
private LocalDateTime createTime;
@ApiModelProperty(value = "编辑人")
private String editUserId;
@ -70,6 +72,7 @@ public class UserDto {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime editTime;
@ApiModelProperty(value = "角色id集合")
@NotNull(message = "角色不能为空")
private Set<String> roleIds;

View File

@ -1,10 +1,11 @@
package cn.zyjblogs.server.user.po;
import cn.zyjblogs.starter.common.entity.constant.CommonConstant;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
@ -68,7 +69,7 @@ public class UserPo implements Serializable {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("create_time")
private LocalDateTime createTime;
@ -77,7 +78,7 @@ public class UserPo implements Serializable {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = CommonConstant.DATETIME_PATTERN)
@TableField("edit_time")
private LocalDateTime editTime;

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zyjblogs.server.role.mapper.RolePermissionRelMapper">
<select id="findListByRoleId" resultType="java.lang.String">
select permission_id
from role_permission_rel
where role_id = #{roleId}
<if test="tenantId != '' and tenantId = null ">
and tenant_id=#{tenantId}
</if>
</select>
<select id="findListByRoleIds" resultType="java.lang.String">
<if test="roleIds != null and roleIds.size() > 0 ">
select permission_id
from role_permission_rel
where role_id in
<foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
#{roleId}
</foreach>
<if test="tenantId != '' and tenantId = null ">
and tenant_id=#{tenantId}
</if>
</if>
</select>
</mapper>

View File

@ -1,7 +1,7 @@
package cn.zyjblogs.starter.common.entity.constant;
public class LengthConstant {
public static final int ID_SIZE = 32;
public static final int ID_SIZE = 64;
public static final int MIN_SIZE = 1;
public static final int SHORT_SIZE = 16;
public static final int NORMAL_SIZE = 100;

View File

@ -7,12 +7,12 @@ import cn.zyjblogs.starter.common.entity.response.HttpCode;
*
* @author zhuyijun
*/
public class CommonBusinessExcetion extends AbstractBusinessException {
public CommonBusinessExcetion() {
public class CommonBusinessException extends AbstractBusinessException {
public CommonBusinessException() {
super();
}
public CommonBusinessExcetion(HttpCode responseCode, String message) {
public CommonBusinessException(HttpCode responseCode, String message) {
super(responseCode, message);
}
}