liujie
5 天以前 3b64bcc08e7103006599278f7fe3d8cdeebf30b5
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.ruoyi.user.service.impl;
 
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.user.domain.AccountUser;
import com.ruoyi.user.mapper.AccountUserMapper;
import com.ruoyi.user.service.IAccountUserService;
 
/**
 * 会员用户 业务层实现
 *
 * @author ruoyi
 */
@Service
public class AccountUserServiceImpl implements IAccountUserService
{
    @Autowired
    private AccountUserMapper accountUserMapper;
 
    @Override
    public AccountUser selectAccountUserById(Long userId)
    {
        return accountUserMapper.selectAccountUserById(userId);
    }
 
    @Override
    public List<AccountUser> selectAccountUserList(AccountUser accountUser)
    {
        return accountUserMapper.selectAccountUserList(accountUser);
    }
 
    @Override
    public boolean checkUsernameUnique(AccountUser accountUser)
    {
        Long userId = StringUtils.isNull(accountUser.getUserId()) ? -1L : accountUser.getUserId();
        AccountUser info = accountUserMapper.selectAccountUserByUsername(accountUser.getUserName());
        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
 
    @Override
    public boolean checkPhoneUnique(AccountUser accountUser)
    {
        // 手机号非必填,为空时不做唯一性校验,否则会与库里其它空手机号记录相撞
        if (StringUtils.isEmpty(accountUser.getPhone()))
        {
            return UserConstants.UNIQUE;
        }
        Long userId = StringUtils.isNull(accountUser.getUserId()) ? -1L : accountUser.getUserId();
        AccountUser info = accountUserMapper.selectAccountUserByPhone(accountUser.getPhone());
        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
 
    @Override
    public int insertAccountUser(AccountUser accountUser)
    {
        accountUser.setPassword(SecurityUtils.encryptPassword(accountUser.getPassword()));
        return accountUserMapper.insertAccountUser(accountUser);
    }
 
    @Override
    public int updateAccountUser(AccountUser accountUser)
    {
        // 不为空才加密;为空时保持 null,mapper 的 <if> 会跳过该列,原密码不受影响
        if (StringUtils.isNotEmpty(accountUser.getPassword()))
        {
            accountUser.setPassword(SecurityUtils.encryptPassword(accountUser.getPassword()));
        }
        return accountUserMapper.updateAccountUser(accountUser);
    }
 
    @Override
    public int deleteAccountUserByIds(Long[] userIds)
    {
        return accountUserMapper.deleteAccountUserByIds(userIds);
    }
}