You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
Java
70 lines
2.1 KiB
Java
package com.supervision.police.dto;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
import com.supervision.police.domain.SystemRole;
|
|
import com.supervision.police.domain.SystemRoleMenuRelation;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import lombok.Data;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
@Data
|
|
public class RoleDTO {
|
|
|
|
@Schema(description = "角色id")
|
|
private String id;
|
|
|
|
@Schema(description = "角色名称")
|
|
private String roleName;
|
|
|
|
@Schema(description = "备注")
|
|
private String remark;
|
|
|
|
@Schema(description = "菜单id列表")
|
|
private List<String> menuIdList;
|
|
|
|
@Schema(description = "关联用户数量")
|
|
private Long userCount;
|
|
|
|
@Schema(description = "更新时间")
|
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
|
private LocalDateTime updateTime;
|
|
|
|
|
|
public RoleDTO() {
|
|
}
|
|
|
|
public RoleDTO(SystemRole role, Long userCount, List<SystemRoleMenuRelation> roleMenuRelationList) {
|
|
if (Objects.isNull(role)){
|
|
return;
|
|
}
|
|
this.id = role.getId();
|
|
this.roleName = role.getRoleName();
|
|
this.remark = role.getRemark();
|
|
this.updateTime = role.getUpdateTime();
|
|
this.userCount = Objects.isNull(userCount) ? 0L : userCount;
|
|
if (CollUtil.isNotEmpty(roleMenuRelationList)){
|
|
this.menuIdList = roleMenuRelationList.stream().map(SystemRoleMenuRelation::getMenuId).toList();
|
|
}
|
|
}
|
|
public SystemRole toSystemRole() {
|
|
SystemRole systemRole = new SystemRole();
|
|
systemRole.setId(this.id);
|
|
systemRole.setRoleName(this.roleName);
|
|
systemRole.setRemark(this.remark);
|
|
return systemRole;
|
|
}
|
|
|
|
public List<SystemRoleMenuRelation> menuIdListToRoleMenu() {
|
|
if (CollUtil.isEmpty(this.menuIdList)){
|
|
return new ArrayList<>();
|
|
}
|
|
return this.menuIdList.stream().map(menuId -> new SystemRoleMenuRelation(this.id,menuId)).toList();
|
|
}
|
|
|
|
}
|