xuhy
2024-12-31 44a8377b13e30df474360408d90d955f3ac42599
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.jilongda.manage.utils;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jilongda.common.security.JwtTokenUtils;
import com.jilongda.manage.authority.model.SecUser;
import com.jilongda.manage.authority.service.SecUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
@Component
public class LoginInfoUtil {
 
    @Autowired
    private SecUserService secUserService;
 
 
 
    public Long getUserId(){
        String username = JwtTokenUtils.getUsername();
        SecUser userName = secUserService.getOne(new QueryWrapper<SecUser>().eq("account", username).eq("isDelete",0));
        return userName.getId();
 
    }
 
    public SecUser getLoginUser(){
        String username = JwtTokenUtils.getUsername();
        if("admin".equals(username)){
            return secUserService.getOne(Wrappers.lambdaQuery(SecUser.class).eq(SecUser::getAccount,username).eq(SecUser::getIsDelete,0));
        }else {
            return secUserService.getOne(Wrappers.lambdaQuery(SecUser.class).eq(SecUser::getPhone,username).eq(SecUser::getIsDelete,0));
        }
    }
}