LoginUser.java 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

17
package top.charles7c.cnadmin.common.model.dto;
18

19
import java.io.Serializable;
20
import java.time.LocalDateTime;
21
import java.util.Set;
22

23
import lombok.Data;
24

25 26 27
import cn.hutool.core.collection.CollUtil;

import top.charles7c.cnadmin.common.constant.SysConsts;
28

29
/**
30
 * 登录用户信息
31 32
 *
 * @author Charles7c
33
 * @since 2022/12/24 13:01
34 35
 */
@Data
36
public class LoginUser implements Serializable {
37 38 39 40

    private static final long serialVersionUID = 1L;

    /**
41
     * ID
42
     */
43
    private Long id;
44 45 46 47 48 49 50

    /**
     * 用户名
     */
    private String username;

    /**
51
     * 部门 ID
52
     */
53
    private Long deptId;
54

55
    /**
56
     * 权限码集合
57
     */
58
    private Set<String> permissions;
59 60

    /**
61
     * 角色编码集合
62
     */
63
    private Set<String> roleCodes;
64

65
    /**
66
     * 角色集合
67
     */
68
    private Set<RoleDTO> roles;
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

    /**
     * 令牌
     */
    private String token;

    /**
     * 登录 IP
     */
    private String clientIp;

    /**
     * 登录地点
     */
    private String location;

    /**
     * 浏览器
     */
    private String browser;

    /**
     * 登录时间
     */
    private LocalDateTime loginTime;
94

95 96 97 98 99 100
    /**
     * 是否为管理员
     *
     * @return true:是,false:否
     */
    public boolean isAdmin() {
101
        if (CollUtil.isEmpty(roleCodes)) {
102 103
            return false;
        }
104
        return roleCodes.contains(SysConsts.ADMIN_ROLE_CODE);
105
    }
106
}