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 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 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 menuIdListToRoleMenu() { if (CollUtil.isEmpty(this.menuIdList)){ return new ArrayList<>(); } return this.menuIdList.stream().map(menuId -> new SystemRoleMenuRelation(this.id,menuId)).toList(); } }