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);
|
}
|
}
|