luxiaotao1123
2024-06-21 569d2b6bc754b037ade5b4205a4d1cdb8339b26b
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.zy.ptc.kernel.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.asrs.framework.common.Cools;
import com.zy.ptc.kernel.common.domain.BaseParam;
import com.zy.ptc.kernel.common.domain.PageParam;
import com.zy.ptc.kernel.common.domain.PageResult;
import com.zy.ptc.kernel.system.entity.User;
import com.zy.ptc.kernel.system.mapper.UserMapper;
import com.zy.ptc.kernel.system.service.RoleMenuService;
import com.zy.ptc.kernel.system.service.UserRoleService;
import com.zy.ptc.kernel.system.service.UserService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
    @Resource
    private UserRoleService userRoleService;
    @Resource
    private RoleMenuService roleMenuService;
    @Resource
    private BCryptPasswordEncoder bCryptPasswordEncoder;
 
    @Override
    public PageResult<User> pageRel(PageParam<User, BaseParam> pageParam) {
        return new PageResult<>(this.baseMapper.selectPageRel(pageParam, pageParam.pickOutMap(true)), pageParam.getTotal());
    }
 
    @Override
    public User getByUsername(String username, Long hostId) {
        if (Cools.isEmpty(username)) {
            return null;
        }
        User user = baseMapper.selectByUsername(username, hostId);
        if (user != null) {
            user.setRoles(userRoleService.listByUserId(user.getId()));
            user.setAuthorities(roleMenuService.listMenuByUserId(user.getId(), null));
        }
        return user;
    }
 
    @Override
    public User getByIdRel(Long userId) {
        User user = this.getById(userId);
        if (user != null) {
            user.setRoles(userRoleService.listByUserId(user.getId()));
            user.setAuthorities(roleMenuService.listMenuByUserId(user.getId(), null));
        }
        return user;
    }
 
    @Override
    public boolean comparePassword(String dbPassword, String inputPassword) {
        return bCryptPasswordEncoder.matches(inputPassword, dbPassword);
    }
 
    @Override
    public String encodePassword(String password) {
        return password == null ? null : bCryptPasswordEncoder.encode(password);
    }
 
}