package cn.reghao.bnt.web.admin.model.vo;

import cn.reghao.jutil.jdk.converter.DateTimeConverter;
import cn.reghao.bnt.web.admin.model.po.Role;
import lombok.Data;

import java.util.Locale;

/**
 * @author reghao
 * @date 2021-07-14 14:14:07
 */
@Data
public class RoleVO {
    private Integer id;
    private String name;
    private String description;
    private String createTime;
    private String updateTime;
    private int totalUsers;
    private int totalMenus;

    public RoleVO(Role role, int total) {
        this.id = role.getId();
        this.name = role.getName().split("ROLE_")[1].toLowerCase(Locale.ROOT);
        this.description = role.getDescription();
        this.createTime = DateTimeConverter.format(role.getCreateTime());
        this.updateTime = DateTimeConverter.format(role.getUpdateTime());
        this.totalUsers = total;
        this.totalMenus = role.getMenus().size();
    }
}
